forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
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#130531 - compiler-errors:thir-unsafeck-param, r=Urgau Check params for unsafety in THIR Self-explanatory. I'm not surprised this was overlooked, given the way that THIR visitors work. Perhaps we should provide a better entrypoint. Fixes rust-lang#130528
- Loading branch information
Showing
3 changed files
with
52 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
union U { | ||
a: &'static i32, | ||
b: usize, | ||
} | ||
|
||
fn fun(U { a }: U) { | ||
//~^ ERROR access to union field is unsafe | ||
dbg!(*a); | ||
} | ||
|
||
fn main() { | ||
fun(U { b: 0 }); | ||
|
||
let closure = |U { a }| { | ||
//~^ ERROR access to union field is unsafe | ||
dbg!(*a); | ||
}; | ||
closure(U { b: 0 }); | ||
} |
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[E0133]: access to union field is unsafe and requires unsafe function or block | ||
--> $DIR/union-pat-in-param.rs:6:12 | ||
| | ||
LL | fn fun(U { a }: U) { | ||
| ^ access to union field | ||
| | ||
= note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | ||
|
||
error[E0133]: access to union field is unsafe and requires unsafe function or block | ||
--> $DIR/union-pat-in-param.rs:14:24 | ||
| | ||
LL | let closure = |U { a }| { | ||
| ^ access to union field | ||
| | ||
= note: the field may not be properly initialized: using uninitialized data will cause undefined behavior | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0133`. |