about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_mir_build/src/check_unsafety.rs8
-rw-r--r--tests/ui/unsafe/const_pat_in_layout_restricted.rs24
2 files changed, 31 insertions, 1 deletions
diff --git a/compiler/rustc_mir_build/src/check_unsafety.rs b/compiler/rustc_mir_build/src/check_unsafety.rs
index 7d0ce53997a..b4a02fae454 100644
--- a/compiler/rustc_mir_build/src/check_unsafety.rs
+++ b/compiler/rustc_mir_build/src/check_unsafety.rs
@@ -144,11 +144,17 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
             let hir_context = self.tcx.local_def_id_to_hir_id(def);
             let safety_context = mem::replace(&mut self.safety_context, SafetyContext::Safe);
             let mut inner_visitor = UnsafetyVisitor {
+                tcx: self.tcx,
                 thir: inner_thir,
                 hir_context,
                 safety_context,
+                body_target_features: self.body_target_features,
+                assignment_info: self.assignment_info,
+                in_union_destructure: false,
+                param_env: self.param_env,
+                inside_adt: false,
                 warnings: self.warnings,
-                ..*self
+                suggest_unsafe_block: self.suggest_unsafe_block,
             };
             inner_visitor.visit_expr(&inner_thir[expr]);
             // Unsafe blocks can be used in the inner body, make sure to take it into account
diff --git a/tests/ui/unsafe/const_pat_in_layout_restricted.rs b/tests/ui/unsafe/const_pat_in_layout_restricted.rs
new file mode 100644
index 00000000000..5bc7a7113e4
--- /dev/null
+++ b/tests/ui/unsafe/const_pat_in_layout_restricted.rs
@@ -0,0 +1,24 @@
+// Check that ref mut patterns within a const pattern don't get considered
+// unsafe because they're within a pattern for a layout constrained stuct.
+// check-pass
+
+#![allow(incomplete_features)]
+#![feature(rustc_attrs)]
+#![feature(inline_const_pat)]
+
+#[rustc_layout_scalar_valid_range_start(3)]
+struct Gt2(i32);
+
+fn main() {
+    match unsafe { Gt2(5) } {
+        Gt2(
+            const {
+                || match () {
+                    ref mut y => (),
+                };
+                4
+            },
+        ) => (),
+        _ => (),
+    }
+}