forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
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#129392 - compiler-errors:raw-ref-op-doesnt-di…
…verge-but-more, r=<try> [EXPERIMENT] Do not consider match/let/raw-ref of deref that evalautes to ! to diverge This is the more involved version of rust-lang#129371. It doesn't fully fix rust-lang#117288, since we still need to fix the fact that never type fallback can cause an unintended load via the `NeverToAny` coercion. But I did want to probe crater to see if anyone relies on this behavior currently, since that's almost certainly UB. r? `@ghost`
- Loading branch information
Showing
6 changed files
with
99 additions
and
2 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
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 { | ||
//~^ ERROR mismatched types | ||
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() {} |
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,20 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/diverging-place-match.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 | | let _: ! = *x; | ||
LL | | // Since `*x` "diverges" in HIR, but doesn't count as a read in MIR, this | ||
LL | | // is unsound since we act as if it diverges but it doesn't. | ||
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`. |
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,13 @@ | ||
#![feature(never_type)] | ||
|
||
fn make_up_a_value<T>() -> T { | ||
unsafe { | ||
//~^ 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. | ||
} | ||
} | ||
|
||
fn main() {} |
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,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`. |