forked from rust-lang/rust
-
-
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.
Auto merge of rust-lang#11152 - Alexendoo:unnecessary-cast-applicabil…
…ity, r=Manishearth Set `unnecessary_cast` suggestion to `MaybeIncorrect` for pointer casts Closes rust-lang#11113 changelog: none
- Loading branch information
Showing
3 changed files
with
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#![warn(clippy::unnecessary_cast)] | ||
|
||
fn main() { | ||
let _ = std::ptr::null() as *const u8; | ||
} | ||
|
||
mod issue11113 { | ||
#[repr(C)] | ||
struct Vtbl { | ||
query: unsafe extern "system" fn(), | ||
} | ||
|
||
struct TearOff { | ||
object: *mut std::ffi::c_void, | ||
} | ||
|
||
impl TearOff { | ||
unsafe fn query(&self) { | ||
((*(*(self.object as *mut *mut _) as *mut Vtbl)).query)() | ||
} | ||
} | ||
} |
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 raw pointers to the same type and constness is unnecessary (`*const u8` -> `*const u8`) | ||
--> $DIR/unnecessary_cast_unfixable.rs:4:13 | ||
| | ||
LL | let _ = std::ptr::null() as *const u8; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `std::ptr::null()` | ||
| | ||
= note: `-D clippy::unnecessary-cast` implied by `-D warnings` | ||
|
||
error: casting raw pointers to the same type and constness is unnecessary (`*mut issue11113::Vtbl` -> `*mut issue11113::Vtbl`) | ||
--> $DIR/unnecessary_cast_unfixable.rs:19:16 | ||
| | ||
LL | ((*(*(self.object as *mut *mut _) as *mut Vtbl)).query)() | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `*(self.object as *mut *mut _)` | ||
|
||
error: aborting due to 2 previous errors | ||
|