|
1 | 1 | mod crosspointer_transmute; |
2 | 2 | mod eager_transmute; |
3 | 3 | mod missing_transmute_annotations; |
| 4 | +mod transmute_adt_argument; |
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 argument 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_ARGUMENT_TRANSMUTE, |
| 61 | + correctness, |
| 62 | + "transmutes on the same adt where at least one of the type argument goes from &T to &mut T" |
| 63 | +} |
47 | 64 |
|
48 | 65 | declare_clippy_lint! { |
49 | 66 | /// ### What it does |
@@ -475,6 +492,7 @@ impl_lint_pass!(Transmute => [ |
475 | 492 | USELESS_TRANSMUTE, |
476 | 493 | WRONG_TRANSMUTE, |
477 | 494 | TRANSMUTE_BYTES_TO_STR, |
| 495 | + MUTABLE_ADT_ARGUMENT_TRANSMUTE, |
478 | 496 | TRANSMUTE_INT_TO_BOOL, |
479 | 497 | TRANSMUTE_INT_TO_NON_ZERO, |
480 | 498 | UNSOUND_COLLECTION_TRANSMUTE, |
@@ -516,6 +534,7 @@ impl<'tcx> LateLintPass<'tcx> for Transmute { |
516 | 534 | } |
517 | 535 |
|
518 | 536 | let linted = wrong_transmute::check(cx, e, from_ty, to_ty) |
| 537 | + | transmute_adt_argument::check(cx, e, from_ty, to_ty) |
519 | 538 | | crosspointer_transmute::check(cx, e, from_ty, to_ty) |
520 | 539 | | transmuting_null::check(cx, e, arg, to_ty) |
521 | 540 | | transmute_null_to_fn::check(cx, e, arg, to_ty) |
|
0 commit comments