Forbid casting to/from a pointer of unknown kind#45735
Conversation
|
r? @pnkfelix (rust_highfive has picked a reviewer for you, use r? to override) |
src/librustc_typeck/check/cast.rs
Outdated
There was a problem hiding this comment.
Does this case occur only by lack of type information? I'm not pretty sure.
|
It's not a good idea to assume things when encountering a use std::fmt;
fn main() {
let x: *const _ = 0 as *const _; // we don't want to allow this if...
let y: Option<*const fmt::Debug> = Some(x) as _;
// ^ later, we have x = *const fmt::Debug
}
fn not_ok() {
let x = 0 as *const i32 as *const _ as *mut _; //~ ERROR ?
}Instead, you should make |
|
Added a new error code for casting with unknown pointer kind. r? @arielb1 |
src/librustc_typeck/check/cast.rs
Outdated
There was a problem hiding this comment.
This forbids casting an *const _ to an *const u32, please move the check after the following if to avoid breaking user code.
|
Updated, but I couldn't trigger the |
|
Can't you have |
|
@bors r+ |
|
📌 Commit 99ada04 has been approved by |
|
It just compiles. I'm not sure when inference occurs, but maybe |
Forbid casting to/from a pointer of unknown kind Fixes #45730. Before, it ICE'd when `pointer_kind` encountered `TyInfer`.
|
☀️ Test successful - status-appveyor, status-travis |
Fixes #45730.
Before, it ICE'd when
pointer_kindencounteredTyInfer.