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.
This is done by adding two new lints: cast_ptr_alignment and transmute_ptr_to_ptr. These will replace misaligned_transmute.
- Loading branch information
1 parent
976bbe8
commit c6bc682
Showing
8 changed files
with
190 additions
and
3 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 |
---|---|---|
@@ -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
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