Auto merge of #11849 - GuillaumeGomez:add-more-transmute_ref_to_ref-tests, r=blyxyas
Add tests for issues #10285, #10286, #10289, #10287 Fixes #10285. Fixes #10286. Fixes #10289. Fixes #10287. This PR simply adds tests for the listed issues as they're already implemented so we can close them. r? `@blyxyas` changelog:none
This commit is contained in:
commit
b21c9d4d31
@ -43,6 +43,9 @@ fn transmute_ptr_to_ptr() {
|
||||
//~^ ERROR: transmute from a reference to a reference
|
||||
let _: &GenericParam<f32> = &*(&GenericParam { t: 1u32 } as *const GenericParam<u32> as *const GenericParam<f32>);
|
||||
//~^ ERROR: transmute from a reference to a reference
|
||||
let u8_ref: &u8 = &0u8;
|
||||
let u64_ref: &u64 = unsafe { &*(u8_ref as *const u8 as *const u64) };
|
||||
//~^ ERROR: transmute from a reference to a reference
|
||||
}
|
||||
|
||||
// these are recommendations for solving the above; if these lint we need to update
|
||||
|
@ -43,6 +43,9 @@ fn transmute_ptr_to_ptr() {
|
||||
//~^ ERROR: transmute from a reference to a reference
|
||||
let _: &GenericParam<f32> = std::mem::transmute(&GenericParam { t: 1u32 });
|
||||
//~^ ERROR: transmute from a reference to a reference
|
||||
let u8_ref: &u8 = &0u8;
|
||||
let u64_ref: &u64 = unsafe { std::mem::transmute(u8_ref) };
|
||||
//~^ ERROR: transmute from a reference to a reference
|
||||
}
|
||||
|
||||
// these are recommendations for solving the above; if these lint we need to update
|
||||
|
@ -37,5 +37,11 @@ error: transmute from a reference to a reference
|
||||
LL | let _: &GenericParam<f32> = std::mem::transmute(&GenericParam { t: 1u32 });
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(&GenericParam { t: 1u32 } as *const GenericParam<u32> as *const GenericParam<f32>)`
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
error: transmute from a reference to a reference
|
||||
--> $DIR/transmute_ptr_to_ptr.rs:47:38
|
||||
|
|
||||
LL | let u64_ref: &u64 = unsafe { std::mem::transmute(u8_ref) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(u8_ref as *const u8 as *const u64)`
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
|
18
tests/ui/transmute_ref_to_ref.rs
Normal file
18
tests/ui/transmute_ref_to_ref.rs
Normal file
@ -0,0 +1,18 @@
|
||||
//@no-rustfix
|
||||
|
||||
#![deny(clippy::transmute_ptr_to_ptr)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
let single_u64: &[u64] = &[0xDEAD_BEEF_DEAD_BEEF];
|
||||
let bools: &[bool] = unsafe { std::mem::transmute(single_u64) };
|
||||
//~^ ERROR: transmute from a reference to a reference
|
||||
let a: &[u32] = &[0x12345678, 0x90ABCDEF, 0xFEDCBA09, 0x87654321];
|
||||
let b: &[u8] = unsafe { std::mem::transmute(a) };
|
||||
//~^ ERROR: transmute from a reference to a reference
|
||||
let bytes = &[1u8, 2u8, 3u8, 4u8] as &[u8];
|
||||
let alt_slice: &[u32] = unsafe { core::mem::transmute(bytes) };
|
||||
//~^ ERROR: transmute from a reference to a reference
|
||||
}
|
||||
}
|
26
tests/ui/transmute_ref_to_ref.stderr
Normal file
26
tests/ui/transmute_ref_to_ref.stderr
Normal file
@ -0,0 +1,26 @@
|
||||
error: transmute from a reference to a reference
|
||||
--> $DIR/transmute_ref_to_ref.rs:9:39
|
||||
|
|
||||
LL | let bools: &[bool] = unsafe { std::mem::transmute(single_u64) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(single_u64 as *const [u64] as *const [bool])`
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/transmute_ref_to_ref.rs:3:9
|
||||
|
|
||||
LL | #![deny(clippy::transmute_ptr_to_ptr)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: transmute from a reference to a reference
|
||||
--> $DIR/transmute_ref_to_ref.rs:12:33
|
||||
|
|
||||
LL | let b: &[u8] = unsafe { std::mem::transmute(a) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(a as *const [u32] as *const [u8])`
|
||||
|
||||
error: transmute from a reference to a reference
|
||||
--> $DIR/transmute_ref_to_ref.rs:15:42
|
||||
|
|
||||
LL | let alt_slice: &[u32] = unsafe { core::mem::transmute(bytes) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(bytes as *const [u8] as *const [u32])`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
Loading…
Reference in New Issue
Block a user