]> git.lizzy.rs Git - rust.git/blob - tests/ui/unsafe/unsafe-assign.rs
Rollup merge of #106766 - GuillaumeGomez:rm-stripper-dead-code, r=notriddle
[rust.git] / tests / ui / unsafe / unsafe-assign.rs
1 // revisions: mirunsafeck thirunsafeck
2 // [thirunsafeck]compile-flags: -Z thir-unsafeck
3
4 #![feature(rustc_attrs)]
5 #![allow(unused,dead_code)]
6
7 fn nested_field() {
8     #[rustc_layout_scalar_valid_range_start(1)]
9     struct NonZero<T>(T);
10
11     let mut foo = unsafe { NonZero((1,)) };
12     foo.0.0 = 0;
13     //~^ ERROR: mutation of layout constrained field is unsafe
14 }
15
16 fn block() {
17     #[rustc_layout_scalar_valid_range_start(1)]
18     struct NonZero<T>(T);
19
20     let mut foo = unsafe { NonZero((1,)) };
21     { foo.0 }.0 = 0;
22     // ^ not unsafe because the result of the block expression is a new place
23 }
24
25 fn main() {}