-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Special-case raw ref op for diverging check in HIR typeck #129371
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//@ known-bug: #117288 | ||
//@ check-pass | ||
|
||
#![feature(never_type)] | ||
|
||
fn make_up_a_value<T>() -> T { | ||
unsafe { | ||
let x: *const ! = 0 as _; | ||
let _: ! = *x; | ||
// Since `*x` "diverges" in HIR, but doesn't count as a read in MIR, this | ||
// is unsound since we act as if it diverges but it doesn't. | ||
} | ||
} | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#![feature(never_type)] | ||
|
||
fn make_up_a_value<T>() -> T { | ||
unsafe { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After #129248, we can take away the |
||
//~^ ERROR mismatched types | ||
let x: *const ! = 0 as _; | ||
&raw const *x; | ||
// Since `*x` is `!`, HIR typeck used to think that it diverges | ||
// and allowed the block to coerce to any value, leading to UB. | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, a return type of |
||
} | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/never-place-isnt-diverging.rs:4:5 | ||
| | ||
LL | fn make_up_a_value<T>() -> T { | ||
| - expected this type parameter | ||
LL | / unsafe { | ||
LL | | | ||
LL | | let x: *const ! = 0 as _; | ||
LL | | &raw const *x; | ||
LL | | // Since `*x` is `!`, HIR typeck used to think that it diverges | ||
LL | | // and allowed the block to coerce to any value, leading to UB. | ||
LL | | } | ||
| |_____^ expected type parameter `T`, found `()` | ||
| | ||
= note: expected type parameter `T` | ||
found unit type `()` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make the return type of this function
!
? I think that makes it much clearer that we're testing for "HIR detecting divergence" here.