Skip to content

Commit 7832ebb

Browse files
committed
Handle context for const patterns correctly
1 parent 26f48b4 commit 7832ebb

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

compiler/rustc_mir_build/src/check_unsafety.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,17 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> {
144144
let hir_context = self.tcx.local_def_id_to_hir_id(def);
145145
let safety_context = mem::replace(&mut self.safety_context, SafetyContext::Safe);
146146
let mut inner_visitor = UnsafetyVisitor {
147+
tcx: self.tcx,
147148
thir: inner_thir,
148149
hir_context,
149150
safety_context,
151+
body_target_features: self.body_target_features,
152+
assignment_info: self.assignment_info,
153+
in_union_destructure: false,
154+
param_env: self.param_env,
155+
inside_adt: false,
150156
warnings: self.warnings,
151-
..*self
157+
suggest_unsafe_block: self.suggest_unsafe_block,
152158
};
153159
inner_visitor.visit_expr(&inner_thir[expr]);
154160
// Unsafe blocks can be used in the inner body, make sure to take it into account
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Check that ref mut patterns within a const pattern don't get considered
2+
// unsafe because they're within a pattern for a layout constrained stuct.
3+
// check-pass
4+
5+
#![allow(incomplete_features)]
6+
#![feature(rustc_attrs)]
7+
#![feature(inline_const_pat)]
8+
9+
#[rustc_layout_scalar_valid_range_start(3)]
10+
struct Gt2(i32);
11+
12+
fn main() {
13+
match unsafe { Gt2(5) } {
14+
Gt2(
15+
const {
16+
|| match () {
17+
ref mut y => (),
18+
};
19+
4
20+
},
21+
) => (),
22+
_ => (),
23+
}
24+
}

0 commit comments

Comments
 (0)