Skip to content

Commit 4342262

Browse files
committed
Fetch the value of has_ffi_unwind_calls before stealing mir_built.
1 parent 0fbfc3e commit 4342262

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

compiler/rustc_mir_transform/src/ffi_unwind_calls.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,12 @@ fn has_ffi_unwind_calls(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> bool {
4747
return false;
4848
}
4949

50-
let body = &*tcx.mir_built(ty::WithOptConstParam::unknown(local_def_id)).borrow();
51-
5250
let body_ty = tcx.type_of(def_id).skip_binder();
5351
let body_abi = match body_ty.kind() {
5452
ty::FnDef(..) => body_ty.fn_sig(tcx).abi(),
5553
ty::Closure(..) => Abi::RustCall,
5654
ty::Generator(..) => Abi::Rust,
57-
_ => span_bug!(body.span, "unexpected body ty: {:?}", body_ty),
55+
_ => span_bug!(tcx.def_span(def_id), "unexpected body ty: {:?}", body_ty),
5856
};
5957
let body_can_unwind = layout::fn_can_unwind(tcx, Some(def_id), body_abi);
6058

@@ -65,6 +63,7 @@ fn has_ffi_unwind_calls(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> bool {
6563

6664
let mut tainted = false;
6765

66+
let body = &*tcx.mir_built(ty::WithOptConstParam::unknown(local_def_id)).borrow();
6867
for block in body.basic_blocks.iter() {
6968
if block.is_cleanup {
7069
continue;

compiler/rustc_mir_transform/src/lib.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,12 @@ fn mir_const(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> &Steal<
284284
}
285285
}
286286

287-
// has_ffi_unwind_calls query uses the raw mir, so make sure it is run.
288-
tcx.ensure().has_ffi_unwind_calls(def.did);
287+
// has_ffi_unwind_calls query uses `mir_built(WithOptConstParam::unknown(def.did))`,
288+
// so make sure it is run.
289+
if def.const_param_did.is_none() {
290+
// Actually fetch the value, to avoid having to compute the query later.
291+
let _ = tcx.has_ffi_unwind_calls(def.did);
292+
}
289293

290294
let mut body = tcx.mir_built(def).steal();
291295

0 commit comments

Comments
 (0)