about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/unsafe/ranged_ints2.mirunsafeck.stderr (renamed from src/test/ui/unsafe/ranged_ints2.stderr)2
-rw-r--r--src/test/ui/unsafe/ranged_ints2.rs3
-rw-r--r--src/test/ui/unsafe/ranged_ints2.thirunsafeck.stderr11
-rw-r--r--src/test/ui/unsafe/ranged_ints2_const.mirunsafeck.stderr (renamed from src/test/ui/unsafe/ranged_ints2_const.stderr)8
-rw-r--r--src/test/ui/unsafe/ranged_ints2_const.rs3
-rw-r--r--src/test/ui/unsafe/ranged_ints2_const.thirunsafeck.stderr39
-rw-r--r--src/test/ui/unsafe/ranged_ints3.mirunsafeck.stderr (renamed from src/test/ui/unsafe/ranged_ints3.stderr)2
-rw-r--r--src/test/ui/unsafe/ranged_ints3.rs3
-rw-r--r--src/test/ui/unsafe/ranged_ints3.thirunsafeck.stderr11
-rw-r--r--src/test/ui/unsafe/ranged_ints3_const.mirunsafeck.stderr (renamed from src/test/ui/unsafe/ranged_ints3_const.stderr)6
-rw-r--r--src/test/ui/unsafe/ranged_ints3_const.rs3
-rw-r--r--src/test/ui/unsafe/ranged_ints3_const.thirunsafeck.stderr30
-rw-r--r--src/test/ui/unsafe/ranged_ints3_match.mirunsafeck.stderr19
-rw-r--r--src/test/ui/unsafe/ranged_ints3_match.rs22
-rw-r--r--src/test/ui/unsafe/ranged_ints3_match.thirunsafeck.stderr19
-rw-r--r--src/test/ui/unsafe/ranged_ints4.mirunsafeck.stderr (renamed from src/test/ui/unsafe/ranged_ints4.stderr)2
-rw-r--r--src/test/ui/unsafe/ranged_ints4.rs3
-rw-r--r--src/test/ui/unsafe/ranged_ints4.thirunsafeck.stderr (renamed from src/test/ui/unsafe/ranged_ints4_const.stderr)2
-rw-r--r--src/test/ui/unsafe/ranged_ints4_const.mirunsafeck.stderr11
-rw-r--r--src/test/ui/unsafe/ranged_ints4_const.rs3
-rw-r--r--src/test/ui/unsafe/ranged_ints4_const.thirunsafeck.stderr11
-rw-r--r--src/test/ui/unsafe/unsafe-assign.mirunsafeck.stderr11
-rw-r--r--src/test/ui/unsafe/unsafe-assign.rs25
-rw-r--r--src/test/ui/unsafe/unsafe-assign.thirunsafeck.stderr11
-rw-r--r--src/test/ui/unsafe/unsafe-borrow.mirunsafeck.stderr27
-rw-r--r--src/test/ui/unsafe/unsafe-borrow.rs56
-rw-r--r--src/test/ui/unsafe/unsafe-borrow.thirunsafeck.stderr27
27 files changed, 359 insertions, 11 deletions
diff --git a/src/test/ui/unsafe/ranged_ints2.stderr b/src/test/ui/unsafe/ranged_ints2.mirunsafeck.stderr
index ee1d1f10e71..427843f8d45 100644
--- a/src/test/ui/unsafe/ranged_ints2.stderr
+++ b/src/test/ui/unsafe/ranged_ints2.mirunsafeck.stderr
@@ -1,5 +1,5 @@
 error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block
-  --> $DIR/ranged_ints2.rs:8:13
+  --> $DIR/ranged_ints2.rs:11:13
    |
 LL |     let y = &mut x.0;
    |             ^^^^^^^^ mutation of layout constrained field
diff --git a/src/test/ui/unsafe/ranged_ints2.rs b/src/test/ui/unsafe/ranged_ints2.rs
index 68ba120b279..9a6bb18f926 100644
--- a/src/test/ui/unsafe/ranged_ints2.rs
+++ b/src/test/ui/unsafe/ranged_ints2.rs
@@ -1,3 +1,6 @@
+// revisions: mirunsafeck thirunsafeck
+// [thirunsafeck]compile-flags: -Z thir-unsafeck
+
 #![feature(rustc_attrs)]
 
 #[rustc_layout_scalar_valid_range_start(1)]
diff --git a/src/test/ui/unsafe/ranged_ints2.thirunsafeck.stderr b/src/test/ui/unsafe/ranged_ints2.thirunsafeck.stderr
new file mode 100644
index 00000000000..427843f8d45
--- /dev/null
+++ b/src/test/ui/unsafe/ranged_ints2.thirunsafeck.stderr
@@ -0,0 +1,11 @@
+error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block
+  --> $DIR/ranged_ints2.rs:11:13
+   |
+LL |     let y = &mut x.0;
+   |             ^^^^^^^^ mutation of layout constrained field
+   |
+   = note: mutating layout constrained fields cannot statically be checked for valid values
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0133`.
diff --git a/src/test/ui/unsafe/ranged_ints2_const.stderr b/src/test/ui/unsafe/ranged_ints2_const.mirunsafeck.stderr
index a0dc950e76d..c16550a5800 100644
--- a/src/test/ui/unsafe/ranged_ints2_const.stderr
+++ b/src/test/ui/unsafe/ranged_ints2_const.mirunsafeck.stderr
@@ -1,5 +1,5 @@
 error[E0658]: mutable references are not allowed in constant functions
-  --> $DIR/ranged_ints2_const.rs:11:13
+  --> $DIR/ranged_ints2_const.rs:14:13
    |
 LL |     let y = &mut x.0;
    |             ^^^^^^^^
@@ -8,7 +8,7 @@ LL |     let y = &mut x.0;
    = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
 
 error[E0658]: mutable references are not allowed in constant functions
-  --> $DIR/ranged_ints2_const.rs:18:22
+  --> $DIR/ranged_ints2_const.rs:21:22
    |
 LL |     let y = unsafe { &mut x.0 };
    |                      ^^^^^^^^
@@ -17,7 +17,7 @@ LL |     let y = unsafe { &mut x.0 };
    = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
 
 error[E0658]: mutable references are not allowed in constant functions
-  --> $DIR/ranged_ints2_const.rs:24:22
+  --> $DIR/ranged_ints2_const.rs:27:22
    |
 LL |     unsafe { let y = &mut x.0; }
    |                      ^^^^^^^^
@@ -26,7 +26,7 @@ LL |     unsafe { let y = &mut x.0; }
    = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
 
 error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block
-  --> $DIR/ranged_ints2_const.rs:11:13
+  --> $DIR/ranged_ints2_const.rs:14:13
    |
 LL |     let y = &mut x.0;
    |             ^^^^^^^^ mutation of layout constrained field
diff --git a/src/test/ui/unsafe/ranged_ints2_const.rs b/src/test/ui/unsafe/ranged_ints2_const.rs
index b7178c2b52b..56f5407bb6e 100644
--- a/src/test/ui/unsafe/ranged_ints2_const.rs
+++ b/src/test/ui/unsafe/ranged_ints2_const.rs
@@ -1,3 +1,6 @@
+// revisions: mirunsafeck thirunsafeck
+// [thirunsafeck]compile-flags: -Z thir-unsafeck
+
 #![feature(rustc_attrs)]
 
 #[rustc_layout_scalar_valid_range_start(1)]
diff --git a/src/test/ui/unsafe/ranged_ints2_const.thirunsafeck.stderr b/src/test/ui/unsafe/ranged_ints2_const.thirunsafeck.stderr
new file mode 100644
index 00000000000..b3f139f7213
--- /dev/null
+++ b/src/test/ui/unsafe/ranged_ints2_const.thirunsafeck.stderr
@@ -0,0 +1,39 @@
+error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block
+  --> $DIR/ranged_ints2_const.rs:14:13
+   |
+LL |     let y = &mut x.0;
+   |             ^^^^^^^^ mutation of layout constrained field
+   |
+   = note: mutating layout constrained fields cannot statically be checked for valid values
+
+error[E0658]: mutable references are not allowed in constant functions
+  --> $DIR/ranged_ints2_const.rs:14:13
+   |
+LL |     let y = &mut x.0;
+   |             ^^^^^^^^
+   |
+   = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
+   = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
+
+error[E0658]: mutable references are not allowed in constant functions
+  --> $DIR/ranged_ints2_const.rs:21:22
+   |
+LL |     let y = unsafe { &mut x.0 };
+   |                      ^^^^^^^^
+   |
+   = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
+   = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
+
+error[E0658]: mutable references are not allowed in constant functions
+  --> $DIR/ranged_ints2_const.rs:27:22
+   |
+LL |     unsafe { let y = &mut x.0; }
+   |                      ^^^^^^^^
+   |
+   = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
+   = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
+
+error: aborting due to 4 previous errors
+
+Some errors have detailed explanations: E0133, E0658.
+For more information about an error, try `rustc --explain E0133`.
diff --git a/src/test/ui/unsafe/ranged_ints3.stderr b/src/test/ui/unsafe/ranged_ints3.mirunsafeck.stderr
index 4d4c9167150..9eec0b09e9b 100644
--- a/src/test/ui/unsafe/ranged_ints3.stderr
+++ b/src/test/ui/unsafe/ranged_ints3.mirunsafeck.stderr
@@ -1,5 +1,5 @@
 error[E0133]: borrow of layout constrained field with interior mutability is unsafe and requires unsafe function or block
-  --> $DIR/ranged_ints3.rs:10:13
+  --> $DIR/ranged_ints3.rs:13:13
    |
 LL |     let y = &x.0;
    |             ^^^^ borrow of layout constrained field with interior mutability
diff --git a/src/test/ui/unsafe/ranged_ints3.rs b/src/test/ui/unsafe/ranged_ints3.rs
index 47d67fac678..76d4bfe9530 100644
--- a/src/test/ui/unsafe/ranged_ints3.rs
+++ b/src/test/ui/unsafe/ranged_ints3.rs
@@ -1,3 +1,6 @@
+// revisions: mirunsafeck thirunsafeck
+// [thirunsafeck]compile-flags: -Z thir-unsafeck
+
 #![feature(rustc_attrs)]
 
 use std::cell::Cell;
diff --git a/src/test/ui/unsafe/ranged_ints3.thirunsafeck.stderr b/src/test/ui/unsafe/ranged_ints3.thirunsafeck.stderr
new file mode 100644
index 00000000000..9eec0b09e9b
--- /dev/null
+++ b/src/test/ui/unsafe/ranged_ints3.thirunsafeck.stderr
@@ -0,0 +1,11 @@
+error[E0133]: borrow of layout constrained field with interior mutability is unsafe and requires unsafe function or block
+  --> $DIR/ranged_ints3.rs:13:13
+   |
+LL |     let y = &x.0;
+   |             ^^^^ borrow of layout constrained field with interior mutability
+   |
+   = note: references to fields of layout constrained fields lose the constraints. Coupled with interior mutability, the field can be changed to invalid values
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0133`.
diff --git a/src/test/ui/unsafe/ranged_ints3_const.stderr b/src/test/ui/unsafe/ranged_ints3_const.mirunsafeck.stderr
index 215005571f6..62df9333069 100644
--- a/src/test/ui/unsafe/ranged_ints3_const.stderr
+++ b/src/test/ui/unsafe/ranged_ints3_const.mirunsafeck.stderr
@@ -1,5 +1,5 @@
 error[E0658]: cannot borrow here, since the borrowed element may contain interior mutability
-  --> $DIR/ranged_ints3_const.rs:12:13
+  --> $DIR/ranged_ints3_const.rs:15:13
    |
 LL |     let y = &x.0;
    |             ^^^^
@@ -8,7 +8,7 @@ LL |     let y = &x.0;
    = help: add `#![feature(const_refs_to_cell)]` to the crate attributes to enable
 
 error[E0658]: cannot borrow here, since the borrowed element may contain interior mutability
-  --> $DIR/ranged_ints3_const.rs:19:22
+  --> $DIR/ranged_ints3_const.rs:22:22
    |
 LL |     let y = unsafe { &x.0 };
    |                      ^^^^
@@ -17,7 +17,7 @@ LL |     let y = unsafe { &x.0 };
    = help: add `#![feature(const_refs_to_cell)]` to the crate attributes to enable
 
 error[E0133]: borrow of layout constrained field with interior mutability is unsafe and requires unsafe function or block
-  --> $DIR/ranged_ints3_const.rs:12:13
+  --> $DIR/ranged_ints3_const.rs:15:13
    |
 LL |     let y = &x.0;
    |             ^^^^ borrow of layout constrained field with interior mutability
diff --git a/src/test/ui/unsafe/ranged_ints3_const.rs b/src/test/ui/unsafe/ranged_ints3_const.rs
index c069ae7da02..637198d3604 100644
--- a/src/test/ui/unsafe/ranged_ints3_const.rs
+++ b/src/test/ui/unsafe/ranged_ints3_const.rs
@@ -1,3 +1,6 @@
+// revisions: mirunsafeck thirunsafeck
+// [thirunsafeck]compile-flags: -Z thir-unsafeck
+
 #![feature(rustc_attrs)]
 
 use std::cell::Cell;
diff --git a/src/test/ui/unsafe/ranged_ints3_const.thirunsafeck.stderr b/src/test/ui/unsafe/ranged_ints3_const.thirunsafeck.stderr
new file mode 100644
index 00000000000..5dbc563aad2
--- /dev/null
+++ b/src/test/ui/unsafe/ranged_ints3_const.thirunsafeck.stderr
@@ -0,0 +1,30 @@
+error[E0133]: borrow of layout constrained field with interior mutability is unsafe and requires unsafe function or block
+  --> $DIR/ranged_ints3_const.rs:15:13
+   |
+LL |     let y = &x.0;
+   |             ^^^^ borrow of layout constrained field with interior mutability
+   |
+   = note: references to fields of layout constrained fields lose the constraints. Coupled with interior mutability, the field can be changed to invalid values
+
+error[E0658]: cannot borrow here, since the borrowed element may contain interior mutability
+  --> $DIR/ranged_ints3_const.rs:15:13
+   |
+LL |     let y = &x.0;
+   |             ^^^^
+   |
+   = note: see issue #80384 <https://github.com/rust-lang/rust/issues/80384> for more information
+   = help: add `#![feature(const_refs_to_cell)]` to the crate attributes to enable
+
+error[E0658]: cannot borrow here, since the borrowed element may contain interior mutability
+  --> $DIR/ranged_ints3_const.rs:22:22
+   |
+LL |     let y = unsafe { &x.0 };
+   |                      ^^^^
+   |
+   = note: see issue #80384 <https://github.com/rust-lang/rust/issues/80384> for more information
+   = help: add `#![feature(const_refs_to_cell)]` to the crate attributes to enable
+
+error: aborting due to 3 previous errors
+
+Some errors have detailed explanations: E0133, E0658.
+For more information about an error, try `rustc --explain E0133`.
diff --git a/src/test/ui/unsafe/ranged_ints3_match.mirunsafeck.stderr b/src/test/ui/unsafe/ranged_ints3_match.mirunsafeck.stderr
new file mode 100644
index 00000000000..27c06640928
--- /dev/null
+++ b/src/test/ui/unsafe/ranged_ints3_match.mirunsafeck.stderr
@@ -0,0 +1,19 @@
+error[E0133]: borrow of layout constrained field with interior mutability is unsafe and requires unsafe function or block
+  --> $DIR/ranged_ints3_match.rs:14:17
+   |
+LL |         NonZero(ref x) => { x }
+   |                 ^^^^^ borrow of layout constrained field with interior mutability
+   |
+   = note: references to fields of layout constrained fields lose the constraints. Coupled with interior mutability, the field can be changed to invalid values
+
+error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block
+  --> $DIR/ranged_ints3_match.rs:20:23
+   |
+LL |     match y { NonZero(ref mut y) => { y } };
+   |                       ^^^^^^^^^ mutation of layout constrained field
+   |
+   = note: mutating layout constrained fields cannot statically be checked for valid values
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0133`.
diff --git a/src/test/ui/unsafe/ranged_ints3_match.rs b/src/test/ui/unsafe/ranged_ints3_match.rs
new file mode 100644
index 00000000000..d9fcf0bd665
--- /dev/null
+++ b/src/test/ui/unsafe/ranged_ints3_match.rs
@@ -0,0 +1,22 @@
+// revisions: mirunsafeck thirunsafeck
+// [thirunsafeck]compile-flags: -Z thir-unsafeck
+
+#![feature(rustc_attrs)]
+
+use std::cell::Cell;
+
+#[rustc_layout_scalar_valid_range_start(1)]
+#[repr(transparent)]
+pub(crate) struct NonZero<T>(pub(crate) T);
+fn main() {
+    let mut x = unsafe { NonZero(Cell::new(1)) };
+    match x {
+        NonZero(ref x) => { x }
+        //~^ ERROR borrow of layout constrained field with interior mutability
+    };
+
+    let mut y = unsafe { NonZero(42) };
+    match y { NonZero(ref y) => { y } }; // OK, type of `y` is freeze
+    match y { NonZero(ref mut y) => { y } };
+    //~^ ERROR mutation of layout constrained field
+}
diff --git a/src/test/ui/unsafe/ranged_ints3_match.thirunsafeck.stderr b/src/test/ui/unsafe/ranged_ints3_match.thirunsafeck.stderr
new file mode 100644
index 00000000000..27c06640928
--- /dev/null
+++ b/src/test/ui/unsafe/ranged_ints3_match.thirunsafeck.stderr
@@ -0,0 +1,19 @@
+error[E0133]: borrow of layout constrained field with interior mutability is unsafe and requires unsafe function or block
+  --> $DIR/ranged_ints3_match.rs:14:17
+   |
+LL |         NonZero(ref x) => { x }
+   |                 ^^^^^ borrow of layout constrained field with interior mutability
+   |
+   = note: references to fields of layout constrained fields lose the constraints. Coupled with interior mutability, the field can be changed to invalid values
+
+error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block
+  --> $DIR/ranged_ints3_match.rs:20:23
+   |
+LL |     match y { NonZero(ref mut y) => { y } };
+   |                       ^^^^^^^^^ mutation of layout constrained field
+   |
+   = note: mutating layout constrained fields cannot statically be checked for valid values
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0133`.
diff --git a/src/test/ui/unsafe/ranged_ints4.stderr b/src/test/ui/unsafe/ranged_ints4.mirunsafeck.stderr
index 68c22589d3f..493483d2c45 100644
--- a/src/test/ui/unsafe/ranged_ints4.stderr
+++ b/src/test/ui/unsafe/ranged_ints4.mirunsafeck.stderr
@@ -1,5 +1,5 @@
 error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block
-  --> $DIR/ranged_ints4.rs:8:5
+  --> $DIR/ranged_ints4.rs:11:5
    |
 LL |     x.0 = 0;
    |     ^^^^^^^ mutation of layout constrained field
diff --git a/src/test/ui/unsafe/ranged_ints4.rs b/src/test/ui/unsafe/ranged_ints4.rs
index d8632c48434..fe80af454cb 100644
--- a/src/test/ui/unsafe/ranged_ints4.rs
+++ b/src/test/ui/unsafe/ranged_ints4.rs
@@ -1,3 +1,6 @@
+// revisions: mirunsafeck thirunsafeck
+// [thirunsafeck]compile-flags: -Z thir-unsafeck
+
 #![feature(rustc_attrs)]
 
 #[rustc_layout_scalar_valid_range_start(1)]
diff --git a/src/test/ui/unsafe/ranged_ints4_const.stderr b/src/test/ui/unsafe/ranged_ints4.thirunsafeck.stderr
index fe83b15ce5c..493483d2c45 100644
--- a/src/test/ui/unsafe/ranged_ints4_const.stderr
+++ b/src/test/ui/unsafe/ranged_ints4.thirunsafeck.stderr
@@ -1,5 +1,5 @@
 error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block
-  --> $DIR/ranged_ints4_const.rs:10:5
+  --> $DIR/ranged_ints4.rs:11:5
    |
 LL |     x.0 = 0;
    |     ^^^^^^^ mutation of layout constrained field
diff --git a/src/test/ui/unsafe/ranged_ints4_const.mirunsafeck.stderr b/src/test/ui/unsafe/ranged_ints4_const.mirunsafeck.stderr
new file mode 100644
index 00000000000..a06c6f479b8
--- /dev/null
+++ b/src/test/ui/unsafe/ranged_ints4_const.mirunsafeck.stderr
@@ -0,0 +1,11 @@
+error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block
+  --> $DIR/ranged_ints4_const.rs:13:5
+   |
+LL |     x.0 = 0;
+   |     ^^^^^^^ mutation of layout constrained field
+   |
+   = note: mutating layout constrained fields cannot statically be checked for valid values
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0133`.
diff --git a/src/test/ui/unsafe/ranged_ints4_const.rs b/src/test/ui/unsafe/ranged_ints4_const.rs
index f09168c3d3f..a43c8be71c4 100644
--- a/src/test/ui/unsafe/ranged_ints4_const.rs
+++ b/src/test/ui/unsafe/ranged_ints4_const.rs
@@ -1,3 +1,6 @@
+// revisions: mirunsafeck thirunsafeck
+// [thirunsafeck]compile-flags: -Z thir-unsafeck
+
 #![feature(rustc_attrs)]
 
 #[rustc_layout_scalar_valid_range_start(1)]
diff --git a/src/test/ui/unsafe/ranged_ints4_const.thirunsafeck.stderr b/src/test/ui/unsafe/ranged_ints4_const.thirunsafeck.stderr
new file mode 100644
index 00000000000..a06c6f479b8
--- /dev/null
+++ b/src/test/ui/unsafe/ranged_ints4_const.thirunsafeck.stderr
@@ -0,0 +1,11 @@
+error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block
+  --> $DIR/ranged_ints4_const.rs:13:5
+   |
+LL |     x.0 = 0;
+   |     ^^^^^^^ mutation of layout constrained field
+   |
+   = note: mutating layout constrained fields cannot statically be checked for valid values
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0133`.
diff --git a/src/test/ui/unsafe/unsafe-assign.mirunsafeck.stderr b/src/test/ui/unsafe/unsafe-assign.mirunsafeck.stderr
new file mode 100644
index 00000000000..9abc51424ab
--- /dev/null
+++ b/src/test/ui/unsafe/unsafe-assign.mirunsafeck.stderr
@@ -0,0 +1,11 @@
+error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block
+  --> $DIR/unsafe-assign.rs:12:5
+   |
+LL |     foo.0.0 = 0;
+   |     ^^^^^^^^^^^ mutation of layout constrained field
+   |
+   = note: mutating layout constrained fields cannot statically be checked for valid values
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0133`.
diff --git a/src/test/ui/unsafe/unsafe-assign.rs b/src/test/ui/unsafe/unsafe-assign.rs
new file mode 100644
index 00000000000..15273165b5e
--- /dev/null
+++ b/src/test/ui/unsafe/unsafe-assign.rs
@@ -0,0 +1,25 @@
+// revisions: mirunsafeck thirunsafeck
+// [thirunsafeck]compile-flags: -Z thir-unsafeck
+
+#![feature(rustc_attrs)]
+#![allow(unused,dead_code)]
+
+fn nested_field() {
+    #[rustc_layout_scalar_valid_range_start(1)]
+    struct NonZero<T>(T);
+
+    let mut foo = unsafe { NonZero((1,)) };
+    foo.0.0 = 0;
+    //~^ ERROR: mutation of layout constrained field is unsafe
+}
+
+fn block() {
+    #[rustc_layout_scalar_valid_range_start(1)]
+    struct NonZero<T>(T);
+
+    let mut foo = unsafe { NonZero((1,)) };
+    { foo.0 }.0 = 0;
+    // ^ not unsafe because the result of the block expression is a new place
+}
+
+fn main() {}
diff --git a/src/test/ui/unsafe/unsafe-assign.thirunsafeck.stderr b/src/test/ui/unsafe/unsafe-assign.thirunsafeck.stderr
new file mode 100644
index 00000000000..9abc51424ab
--- /dev/null
+++ b/src/test/ui/unsafe/unsafe-assign.thirunsafeck.stderr
@@ -0,0 +1,11 @@
+error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block
+  --> $DIR/unsafe-assign.rs:12:5
+   |
+LL |     foo.0.0 = 0;
+   |     ^^^^^^^^^^^ mutation of layout constrained field
+   |
+   = note: mutating layout constrained fields cannot statically be checked for valid values
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0133`.
diff --git a/src/test/ui/unsafe/unsafe-borrow.mirunsafeck.stderr b/src/test/ui/unsafe/unsafe-borrow.mirunsafeck.stderr
new file mode 100644
index 00000000000..a206722495a
--- /dev/null
+++ b/src/test/ui/unsafe/unsafe-borrow.mirunsafeck.stderr
@@ -0,0 +1,27 @@
+error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block
+  --> $DIR/unsafe-borrow.rs:12:13
+   |
+LL |     let a = &mut foo.0.0;
+   |             ^^^^^^^^^^^^ mutation of layout constrained field
+   |
+   = note: mutating layout constrained fields cannot statically be checked for valid values
+
+error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block
+  --> $DIR/unsafe-borrow.rs:32:13
+   |
+LL |     let a = &mut foo.0[2];
+   |             ^^^^^^^^^^^^^ mutation of layout constrained field
+   |
+   = note: mutating layout constrained fields cannot statically be checked for valid values
+
+error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block
+  --> $DIR/unsafe-borrow.rs:51:18
+   |
+LL |         NonZero((a,)) => *a = 0,
+   |                  ^ mutation of layout constrained field
+   |
+   = note: mutating layout constrained fields cannot statically be checked for valid values
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0133`.
diff --git a/src/test/ui/unsafe/unsafe-borrow.rs b/src/test/ui/unsafe/unsafe-borrow.rs
new file mode 100644
index 00000000000..8dddc70be45
--- /dev/null
+++ b/src/test/ui/unsafe/unsafe-borrow.rs
@@ -0,0 +1,56 @@
+// revisions: mirunsafeck thirunsafeck
+// [thirunsafeck]compile-flags: -Z thir-unsafeck
+
+#![feature(rustc_attrs)]
+#![allow(unused,dead_code)]
+
+fn tuple_struct() {
+    #[rustc_layout_scalar_valid_range_start(1)]
+    struct NonZero<T>(T);
+
+    let mut foo = unsafe { NonZero((1,)) };
+    let a = &mut foo.0.0;
+    //~^ ERROR: mutation of layout constrained field is unsafe
+}
+
+fn slice() {
+    #[rustc_layout_scalar_valid_range_start(1)]
+    struct NonZero<'a, T>(&'a mut [T]);
+
+    let mut nums = [1, 2, 3, 4];
+    let mut foo = unsafe { NonZero(&mut nums[..]) };
+    let a = &mut foo.0[2];
+    // ^ not unsafe because there is an implicit dereference here
+}
+
+fn array() {
+    #[rustc_layout_scalar_valid_range_start(1)]
+    struct NonZero<T>([T; 4]);
+
+    let nums = [1, 2, 3, 4];
+    let mut foo = unsafe { NonZero(nums) };
+    let a = &mut foo.0[2];
+    //~^ ERROR: mutation of layout constrained field is unsafe
+}
+
+fn block() {
+    #[rustc_layout_scalar_valid_range_start(1)]
+    struct NonZero<T>(T);
+
+    let foo = unsafe { NonZero((1,)) };
+    &mut { foo.0 }.0;
+    // ^ not unsafe because the result of the block expression is a new place
+}
+
+fn mtch() {
+    #[rustc_layout_scalar_valid_range_start(1)]
+    struct NonZero<T>(T);
+
+    let mut foo = unsafe { NonZero((1,)) };
+    match &mut foo {
+        NonZero((a,)) => *a = 0,
+        //~^ ERROR: mutation of layout constrained field is unsafe
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/unsafe/unsafe-borrow.thirunsafeck.stderr b/src/test/ui/unsafe/unsafe-borrow.thirunsafeck.stderr
new file mode 100644
index 00000000000..a206722495a
--- /dev/null
+++ b/src/test/ui/unsafe/unsafe-borrow.thirunsafeck.stderr
@@ -0,0 +1,27 @@
+error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block
+  --> $DIR/unsafe-borrow.rs:12:13
+   |
+LL |     let a = &mut foo.0.0;
+   |             ^^^^^^^^^^^^ mutation of layout constrained field
+   |
+   = note: mutating layout constrained fields cannot statically be checked for valid values
+
+error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block
+  --> $DIR/unsafe-borrow.rs:32:13
+   |
+LL |     let a = &mut foo.0[2];
+   |             ^^^^^^^^^^^^^ mutation of layout constrained field
+   |
+   = note: mutating layout constrained fields cannot statically be checked for valid values
+
+error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block
+  --> $DIR/unsafe-borrow.rs:51:18
+   |
+LL |         NonZero((a,)) => *a = 0,
+   |                  ^ mutation of layout constrained field
+   |
+   = note: mutating layout constrained fields cannot statically be checked for valid values
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0133`.