diff options
| author | Veera <sveera.2001@gmail.com> | 2024-09-22 19:32:56 -0400 |
|---|---|---|
| committer | Veera <sveera.2001@gmail.com> | 2024-10-05 12:48:02 +0000 |
| commit | 98b59a1cf65848d4d9ed036f8663d2ec5e0a8963 (patch) | |
| tree | 26c775f7f85c04b17fb5351a2cbb5e30020e77f8 | |
| parent | c8f5136fe84c3cced0ac1ef57a3f82983604167a (diff) | |
| download | rust-98b59a1cf65848d4d9ed036f8663d2ec5e0a8963.tar.gz rust-98b59a1cf65848d4d9ed036f8663d2ec5e0a8963.zip | |
Add a Lint for Pointer to Integer Transmutes in Consts
| -rw-r--r-- | tests/ui/transmutes_expressible_as_ptr_casts.fixed | 9 | ||||
| -rw-r--r-- | tests/ui/transmutes_expressible_as_ptr_casts.rs | 9 |
2 files changed, 12 insertions, 6 deletions
diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.fixed b/tests/ui/transmutes_expressible_as_ptr_casts.fixed index e95054a7ccb..617d32d1fa7 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.fixed +++ b/tests/ui/transmutes_expressible_as_ptr_casts.fixed @@ -84,8 +84,11 @@ fn issue_10449() { } // Pointers cannot be cast to integers in const contexts +#[allow(ptr_to_integer_transmute_in_consts, reason = "This is tested in the compiler test suite")] const fn issue_12402<P>(ptr: *const P) { - unsafe { transmute::<*const i32, usize>(&42i32) }; - unsafe { transmute::<fn(*const P), usize>(issue_12402) }; - let _ = unsafe { transmute::<_, usize>(ptr) }; + // This test exists even though the compiler lints against it + // to test that clippy's transmute lints do not trigger on this. + unsafe { std::mem::transmute::<*const i32, usize>(&42i32) }; + unsafe { std::mem::transmute::<fn(*const P), usize>(issue_12402) }; + let _ = unsafe { std::mem::transmute::<_, usize>(ptr) }; } diff --git a/tests/ui/transmutes_expressible_as_ptr_casts.rs b/tests/ui/transmutes_expressible_as_ptr_casts.rs index e5fcdef7a1c..d68db3c2deb 100644 --- a/tests/ui/transmutes_expressible_as_ptr_casts.rs +++ b/tests/ui/transmutes_expressible_as_ptr_casts.rs @@ -84,8 +84,11 @@ fn issue_10449() { } // Pointers cannot be cast to integers in const contexts +#[allow(ptr_to_integer_transmute_in_consts, reason = "This is tested in the compiler test suite")] const fn issue_12402<P>(ptr: *const P) { - unsafe { transmute::<*const i32, usize>(&42i32) }; - unsafe { transmute::<fn(*const P), usize>(issue_12402) }; - let _ = unsafe { transmute::<_, usize>(ptr) }; + // This test exists even though the compiler lints against it + // to test that clippy's transmute lints do not trigger on this. + unsafe { std::mem::transmute::<*const i32, usize>(&42i32) }; + unsafe { std::mem::transmute::<fn(*const P), usize>(issue_12402) }; + let _ = unsafe { std::mem::transmute::<_, usize>(ptr) }; } |
