Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize THIR unsafeck #117673

Merged
merged 3 commits into from
Jan 5, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Handle context for const patterns correctly
matthewjasper committed Jan 5, 2024
commit 7832ebbd4ff090aced6e338ff92e1353bbe88f76
8 changes: 7 additions & 1 deletion compiler/rustc_mir_build/src/check_unsafety.rs
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions tests/ui/unsafe/const_pat_in_layout_restricted.rs
Original file line number Diff line number Diff line change
@@ -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
},
) => (),
_ => (),
}
}