-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2661 from devonhollowood/ptr-ptr-casts
Replace `misaligned_transmute` lint
- Loading branch information
Showing
11 changed files
with
198 additions
and
36 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
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,19 @@ | ||
//! Test casts for alignment issues | ||
#[warn(cast_ptr_alignment)] | ||
#[allow(no_effect, unnecessary_operation, cast_lossless)] | ||
fn main() { | ||
/* These should be warned against */ | ||
|
||
// cast to more-strictly-aligned type | ||
(&1u8 as *const u8) as *const u16; | ||
(&mut 1u8 as *mut u8) as *mut u16; | ||
|
||
/* These should be okay */ | ||
|
||
// not a pointer type | ||
1u8 as u16; | ||
// cast to less-strictly-aligned type | ||
(&1u16 as *const u16) as *const u8; | ||
(&mut 1u16 as *mut u16) as *mut u8; | ||
} |
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,16 @@ | ||
error: casting from `*const u8` to a less-strictly-aligned pointer (`*const u16`) | ||
--> $DIR/cast_alignment.rs:9:5 | ||
| | ||
9 | (&1u8 as *const u8) as *const u16; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `-D cast-ptr-alignment` implied by `-D warnings` | ||
|
||
error: casting from `*mut u8` to a less-strictly-aligned pointer (`*mut u16`) | ||
--> $DIR/cast_alignment.rs:10:5 | ||
| | ||
10 | (&mut 1u8 as *mut u8) as *mut u16; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,6 @@ | |
|
||
#[warn(unstable_as_mut_slice)] | ||
|
||
#[warn(misaligned_transmute)] | ||
|
||
fn main() {} |
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