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#12617 - y21:issue-12616, r=Alexendoo
avoid an ICE in `ptr_as_ptr` when getting the def_id of a local Fixes rust-lang#12616 `Res::def_id` can panic, so avoid calling it in favor of `opt_def_id`, so we can gracefully handle resolutions that don't have a `DefId` (e.g. local variables) and get a false negative in the worst case, rather than an ICE changelog: Fix ICE in [`ptr_as_ptr`] when the cast expression is a function call to a local variable
- Loading branch information
Showing
4 changed files
with
34 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,7 @@ | ||
#![warn(clippy::ptr_as_ptr)] | ||
#![allow(clippy::unnecessary_operation, clippy::unnecessary_cast)] | ||
|
||
fn main() { | ||
let s = std::ptr::null::<()>; | ||
s().cast::<()>(); | ||
} |
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,7 @@ | ||
#![warn(clippy::ptr_as_ptr)] | ||
#![allow(clippy::unnecessary_operation, clippy::unnecessary_cast)] | ||
|
||
fn main() { | ||
let s = std::ptr::null::<()>; | ||
s() as *const (); | ||
} |
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 @@ | ||
error: `as` casting between raw pointers without changing its mutability | ||
--> tests/ui/crashes/ice-12616.rs:6:5 | ||
| | ||
LL | s() as *const (); | ||
| ^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `s().cast::<()>()` | ||
| | ||
= note: `-D clippy::ptr-as-ptr` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::ptr_as_ptr)]` | ||
|
||
error: `as` casting between raw pointers without changing its mutability | ||
--> tests/ui/crashes/ice-12616.rs:6:5 | ||
| | ||
LL | s() as *const (); | ||
| ^^^^^^^^^^^^^^^^ help: try `pointer::cast`, a safer alternative: `s().cast::<()>()` | ||
| | ||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` | ||
|
||
error: aborting due to 2 previous errors | ||
|