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.
Rollup merge of rust-lang#130533 - compiler-errors:never-pat-unsafeck, r=Nadrieril Never patterns constitute a read for unsafety This code is otherwise unsound if we don't emit an unsafety error here. Noticed when fixing rust-lang#130528, but it's totally unrelated. r? `@Nadrieril`
- Loading branch information
Showing
3 changed files
with
41 additions
and
4 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
16 changes: 16 additions & 0 deletions
16
tests/ui/rfcs/rfc-0000-never_patterns/never-pattern-is-a-read.rs
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 @@ | ||
// Make sure we consider `!` to be a union read. | ||
|
||
#![feature(never_type, never_patterns)] | ||
//~^ WARN the feature `never_patterns` is incomplete | ||
|
||
union U { | ||
a: !, | ||
b: usize, | ||
} | ||
|
||
fn foo<T>(u: U) -> ! { | ||
let U { a: ! } = u; | ||
//~^ ERROR access to union field is unsafe | ||
} | ||
|
||
fn main() {} |
20 changes: 20 additions & 0 deletions
20
tests/ui/rfcs/rfc-0000-never_patterns/never-pattern-is-a-read.stderr
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 @@ | ||
warning: the feature `never_patterns` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/never-pattern-is-a-read.rs:3:24 | ||
| | ||
LL | #![feature(never_type, never_patterns)] | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #118155 <https://github.com/rust-lang/rust/issues/118155> for more information | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
error[E0133]: access to union field is unsafe and requires unsafe function or block | ||
--> $DIR/never-pattern-is-a-read.rs:12:16 | ||
| | ||
LL | let U { a: ! } = u; | ||
| ^ access to union field | ||
| | ||
= note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | ||
|
||
error: aborting due to 1 previous error; 1 warning emitted | ||
|
||
For more information about this error, try `rustc --explain E0133`. |