1
Fork 0

Make thir_check_unsafety itself responsible for checking gate

This commit is contained in:
LeSeulArtichaut 2021-05-24 15:09:33 +02:00
parent 13e7b237fd
commit af3d9a3aa3
3 changed files with 14 additions and 12 deletions

View file

@ -873,9 +873,8 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
sess.time("MIR_effect_checking", || { sess.time("MIR_effect_checking", || {
for def_id in tcx.body_owners() { for def_id in tcx.body_owners() {
if tcx.sess.opts.debugging_opts.thir_unsafeck {
tcx.ensure().thir_check_unsafety(def_id); tcx.ensure().thir_check_unsafety(def_id);
} else { if !tcx.sess.opts.debugging_opts.thir_unsafeck {
mir::transform::check_unsafety::check_unsafety(tcx, def_id); mir::transform::check_unsafety::check_unsafety(tcx, def_id);
} }

View file

@ -46,7 +46,6 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
let body_owner_kind = tcx.hir().body_owner_kind(id); let body_owner_kind = tcx.hir().body_owner_kind(id);
let typeck_results = tcx.typeck_opt_const_arg(def); 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. // Ensure unsafeck is ran before we steal the THIR.
match def { match def {
ty::WithOptConstParam { did, const_param_did: Some(const_param_did) } => { ty::WithOptConstParam { did, const_param_did: Some(const_param_did) } => {
@ -56,7 +55,6 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
tcx.ensure().thir_check_unsafety(did) tcx.ensure().thir_check_unsafety(did)
} }
} }
}
// Figure out what primary body this item has. // Figure out what primary body this item has.
let (body_id, return_ty_span, span_with_body) = match tcx.hir().get(id) { let (body_id, return_ty_span, span_with_body) = match tcx.hir().get(id) {

View file

@ -329,6 +329,11 @@ impl UnsafeOpKind {
// FIXME: checking unsafety for closures should be handled by their parent body, // FIXME: checking unsafety for closures should be handled by their parent body,
// as they inherit their "safety context" from their declaration site. // as they inherit their "safety context" from their declaration site.
pub fn check_unsafety<'tcx>(tcx: TyCtxt<'tcx>, def: ty::WithOptConstParam<LocalDefId>) { 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, expr) = tcx.thir_body(def);
let thir = &thir.borrow(); let thir = &thir.borrow();
// If `thir` is empty, a type error occured, skip this body. // If `thir` is empty, a type error occured, skip this body.