forked from rust-lang/rust-clippy
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suggest
.cast
/.cast_const
/.cast_mut
in transmute_ptr_as_ptr
- Loading branch information
Showing
7 changed files
with
142 additions
and
80 deletions.
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
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 |
---|---|---|
@@ -1,47 +1,78 @@ | ||
error: transmute from a pointer to a pointer | ||
--> tests/ui/transmute_ptr_to_ptr.rs:30:29 | ||
--> tests/ui/transmute_ptr_to_ptr.rs:32:29 | ||
| | ||
LL | let _: *const f32 = std::mem::transmute(ptr); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `ptr as *const f32` | ||
LL | let _: *const f32 = transmute(ptr); | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
= note: `-D clippy::transmute-ptr-to-ptr` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::transmute_ptr_to_ptr)]` | ||
help: use `pointer::cast` instead | ||
| | ||
LL | let _: *const f32 = ptr.cast::<f32>(); | ||
| ~~~~~~~~~~~~~~~~~ | ||
|
||
error: transmute from a pointer to a pointer | ||
--> tests/ui/transmute_ptr_to_ptr.rs:33:27 | ||
--> tests/ui/transmute_ptr_to_ptr.rs:34:27 | ||
| | ||
LL | let _: *mut f32 = transmute(mut_ptr); | ||
| ^^^^^^^^^^^^^^^^^^ | ||
| | ||
LL | let _: *mut f32 = std::mem::transmute(mut_ptr); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `mut_ptr as *mut f32` | ||
help: use `pointer::cast` instead | ||
| | ||
LL | let _: *mut f32 = mut_ptr.cast::<f32>(); | ||
| ~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
error: transmute from a reference to a reference | ||
--> tests/ui/transmute_ptr_to_ptr.rs:36:23 | ||
--> tests/ui/transmute_ptr_to_ptr.rs:37:23 | ||
| | ||
LL | let _: &f32 = std::mem::transmute(&1u32); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(&1u32 as *const u32 as *const f32)` | ||
LL | let _: &f32 = transmute(&1u32); | ||
| ^^^^^^^^^^^^^^^^ help: try: `&*(&1u32 as *const u32 as *const f32)` | ||
|
||
error: transmute from a reference to a reference | ||
--> tests/ui/transmute_ptr_to_ptr.rs:38:23 | ||
--> tests/ui/transmute_ptr_to_ptr.rs:39:23 | ||
| | ||
LL | let _: &f32 = std::mem::transmute(&1f64); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(&1f64 as *const f64 as *const f32)` | ||
LL | let _: &f32 = transmute(&1f64); | ||
| ^^^^^^^^^^^^^^^^ help: try: `&*(&1f64 as *const f64 as *const f32)` | ||
|
||
error: transmute from a reference to a reference | ||
--> tests/ui/transmute_ptr_to_ptr.rs:42:27 | ||
--> tests/ui/transmute_ptr_to_ptr.rs:43:27 | ||
| | ||
LL | let _: &mut f32 = std::mem::transmute(&mut 1u32); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&mut *(&mut 1u32 as *mut u32 as *mut f32)` | ||
LL | let _: &mut f32 = transmute(&mut 1u32); | ||
| ^^^^^^^^^^^^^^^^^^^^ help: try: `&mut *(&mut 1u32 as *mut u32 as *mut f32)` | ||
|
||
error: transmute from a reference to a reference | ||
--> tests/ui/transmute_ptr_to_ptr.rs:44:37 | ||
--> tests/ui/transmute_ptr_to_ptr.rs:45:37 | ||
| | ||
LL | let _: &GenericParam<f32> = std::mem::transmute(&GenericParam { t: 1u32 }); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(&GenericParam { t: 1u32 } as *const GenericParam<u32> as *const GenericParam<f32>)` | ||
LL | let _: &GenericParam<f32> = transmute(&GenericParam { t: 1u32 }); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(&GenericParam { t: 1u32 } as *const GenericParam<u32> as *const GenericParam<f32>)` | ||
|
||
error: transmute from a reference to a reference | ||
--> tests/ui/transmute_ptr_to_ptr.rs:47:36 | ||
--> tests/ui/transmute_ptr_to_ptr.rs:48:27 | ||
| | ||
LL | let u8_ref: &u8 = transmute(u64_ref); | ||
| ^^^^^^^^^^^^^^^^^^ help: try: `&*(u64_ref as *const u64 as *const u8)` | ||
|
||
error: transmute from a pointer to a pointer | ||
--> tests/ui/transmute_ptr_to_ptr.rs:50:29 | ||
| | ||
LL | let _: *const u32 = transmute(mut_ptr); | ||
| ^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: use `pointer::cast_const` instead | ||
| | ||
LL | let _: *const u32 = mut_ptr.cast_const(); | ||
| ~~~~~~~~~~~~~~~~~~~~ | ||
|
||
error: transmute from a pointer to a pointer | ||
--> tests/ui/transmute_ptr_to_ptr.rs:52:27 | ||
| | ||
LL | let _: *mut u32 = transmute(ptr); | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
help: use `pointer::cast_mut` instead | ||
| | ||
LL | let u8_ref: &u8 = unsafe { std::mem::transmute(u64_ref) }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `&*(u64_ref as *const u64 as *const u8)` | ||
LL | let _: *mut u32 = ptr.cast_mut(); | ||
| ~~~~~~~~~~~~~~ | ||
|
||
error: aborting due to 7 previous errors | ||
error: aborting due to 9 previous errors | ||
|
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