|
1 | 1 | mod crosspointer_transmute; |
2 | 2 | mod eager_transmute; |
3 | 3 | mod missing_transmute_annotations; |
| 4 | +mod transmute_adt_arguement; |
4 | 5 | mod transmute_int_to_bool; |
5 | 6 | mod transmute_int_to_non_zero; |
6 | 7 | mod transmute_null_to_fn; |
@@ -44,6 +45,22 @@ declare_clippy_lint! { |
44 | 45 | correctness, |
45 | 46 | "transmutes that are confusing at best, undefined behavior at worst and always useless" |
46 | 47 | } |
| 48 | +declare_clippy_lint! { |
| 49 | + /// ### What it does |
| 50 | + /// Checks for transmutes between the same adt, where at least one of the type arguement goes from &T to &mut T. |
| 51 | + /// This is an a more complicated version of https://doc.rust-lang.org/rustc/lints/listing/deny-by-default.html#mutable-transmutes. |
| 52 | + /// ### Example |
| 53 | + /// |
| 54 | + /// ```ignore |
| 55 | + /// unsafe { |
| 56 | + /// std::mem::transmute::<Option<&i32>, Option<&mut i32>>(&Some(5)); |
| 57 | + /// } |
| 58 | + /// ``` |
| 59 | + #[clippy::version = "1.92.0"] |
| 60 | + pub MUTABLE_ADT_ARGUEMENT_TRANSMUTE, |
| 61 | + correctness, |
| 62 | + "transmutes on the same adt where at least one of the type arguement goes from &T to &mut T" |
| 63 | +} |
47 | 64 |
|
48 | 65 | declare_clippy_lint! { |
49 | 66 | /// ### What it does |
@@ -516,6 +533,7 @@ impl<'tcx> LateLintPass<'tcx> for Transmute { |
516 | 533 | } |
517 | 534 |
|
518 | 535 | let linted = wrong_transmute::check(cx, e, from_ty, to_ty) |
| 536 | + | transmute_adt_arguement::check(cx, e, from_ty, to_ty) |
519 | 537 | | crosspointer_transmute::check(cx, e, from_ty, to_ty) |
520 | 538 | | transmuting_null::check(cx, e, arg, to_ty) |
521 | 539 | | transmute_null_to_fn::check(cx, e, arg, to_ty) |
|
0 commit comments