forked from rust-lang/rust-clippy
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#11849 - GuillaumeGomez:add-more-transmute_ref…
…_to_ref-tests, r=blyxyas Add tests for issues rust-lang#10285, rust-lang#10286, rust-lang#10289, rust-lang#10287 Fixes rust-lang#10285. Fixes rust-lang#10286. Fixes rust-lang#10289. Fixes rust-lang#10287. This PR simply adds tests for the listed issues as they're already implemented so we can close them. r? `@blyxyas` changelog:none
- Loading branch information
Showing
5 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|