Skip to content

Commit

Permalink
Make thir_check_unsafety itself responsible for checking gate
Browse files Browse the repository at this point in the history
  • Loading branch information
LeSeulArtichaut committed May 24, 2021
1 parent 13e7b23 commit af3d9a3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
5 changes: 2 additions & 3 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,9 +873,8 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {

sess.time("MIR_effect_checking", || {
for def_id in tcx.body_owners() {
if tcx.sess.opts.debugging_opts.thir_unsafeck {
tcx.ensure().thir_check_unsafety(def_id);
} else {
tcx.ensure().thir_check_unsafety(def_id);
if !tcx.sess.opts.debugging_opts.thir_unsafeck {
mir::transform::check_unsafety::check_unsafety(tcx, def_id);
}

Expand Down
16 changes: 7 additions & 9 deletions compiler/rustc_mir_build/src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,13 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
let body_owner_kind = tcx.hir().body_owner_kind(id);
let typeck_results = tcx.typeck_opt_const_arg(def);

if tcx.sess.opts.debugging_opts.thir_unsafeck {
// Ensure unsafeck is ran before we steal the THIR.
match def {
ty::WithOptConstParam { did, const_param_did: Some(const_param_did) } => {
tcx.ensure().thir_check_unsafety_for_const_arg((did, const_param_did))
}
ty::WithOptConstParam { did, const_param_did: None } => {
tcx.ensure().thir_check_unsafety(did)
}
// Ensure unsafeck is ran before we steal the THIR.
match def {
ty::WithOptConstParam { did, const_param_did: Some(const_param_did) } => {
tcx.ensure().thir_check_unsafety_for_const_arg((did, const_param_did))
}
ty::WithOptConstParam { did, const_param_did: None } => {
tcx.ensure().thir_check_unsafety(did)
}
}

Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_mir_build/src/check_unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@ impl UnsafeOpKind {
// FIXME: checking unsafety for closures should be handled by their parent body,
// as they inherit their "safety context" from their declaration site.
pub fn check_unsafety<'tcx>(tcx: TyCtxt<'tcx>, def: ty::WithOptConstParam<LocalDefId>) {
// THIR unsafeck is gated under `-Z thir-unsafeck`
if !tcx.sess.opts.debugging_opts.thir_unsafeck {
return;
}

let (thir, expr) = tcx.thir_body(def);
let thir = &thir.borrow();
// If `thir` is empty, a type error occured, skip this body.
Expand Down

0 comments on commit af3d9a3

Please sign in to comment.