Skip to content

Commit af3d9a3

Browse files
Make thir_check_unsafety itself responsible for checking gate
1 parent 13e7b23 commit af3d9a3

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

compiler/rustc_interface/src/passes.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -873,9 +873,8 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
873873

874874
sess.time("MIR_effect_checking", || {
875875
for def_id in tcx.body_owners() {
876-
if tcx.sess.opts.debugging_opts.thir_unsafeck {
877-
tcx.ensure().thir_check_unsafety(def_id);
878-
} else {
876+
tcx.ensure().thir_check_unsafety(def_id);
877+
if !tcx.sess.opts.debugging_opts.thir_unsafeck {
879878
mir::transform::check_unsafety::check_unsafety(tcx, def_id);
880879
}
881880

compiler/rustc_mir_build/src/build/mod.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,13 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
4646
let body_owner_kind = tcx.hir().body_owner_kind(id);
4747
let typeck_results = tcx.typeck_opt_const_arg(def);
4848

49-
if tcx.sess.opts.debugging_opts.thir_unsafeck {
50-
// Ensure unsafeck is ran before we steal the THIR.
51-
match def {
52-
ty::WithOptConstParam { did, const_param_did: Some(const_param_did) } => {
53-
tcx.ensure().thir_check_unsafety_for_const_arg((did, const_param_did))
54-
}
55-
ty::WithOptConstParam { did, const_param_did: None } => {
56-
tcx.ensure().thir_check_unsafety(did)
57-
}
49+
// Ensure unsafeck is ran before we steal the THIR.
50+
match def {
51+
ty::WithOptConstParam { did, const_param_did: Some(const_param_did) } => {
52+
tcx.ensure().thir_check_unsafety_for_const_arg((did, const_param_did))
53+
}
54+
ty::WithOptConstParam { did, const_param_did: None } => {
55+
tcx.ensure().thir_check_unsafety(did)
5856
}
5957
}
6058

compiler/rustc_mir_build/src/check_unsafety.rs

+5
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,11 @@ impl UnsafeOpKind {
329329
// FIXME: checking unsafety for closures should be handled by their parent body,
330330
// as they inherit their "safety context" from their declaration site.
331331
pub fn check_unsafety<'tcx>(tcx: TyCtxt<'tcx>, def: ty::WithOptConstParam<LocalDefId>) {
332+
// THIR unsafeck is gated under `-Z thir-unsafeck`
333+
if !tcx.sess.opts.debugging_opts.thir_unsafeck {
334+
return;
335+
}
336+
332337
let (thir, expr) = tcx.thir_body(def);
333338
let thir = &thir.borrow();
334339
// If `thir` is empty, a type error occured, skip this body.

0 commit comments

Comments
 (0)