11use rustc_abi:: ExternAbi ;
2- use rustc_hir:: def_id:: { LOCAL_CRATE , LocalDefId } ;
2+ use rustc_hir:: def_id:: LOCAL_CRATE ;
33use rustc_middle:: mir:: * ;
44use rustc_middle:: query:: { LocalCrate , Providers } ;
55use rustc_middle:: ty:: { self , TyCtxt , layout} ;
@@ -11,17 +11,10 @@ use tracing::debug;
1111use crate :: errors;
1212
1313// Check if the body of this def_id can possibly leak a foreign unwind into Rust code.
14- fn has_ffi_unwind_calls ( tcx : TyCtxt < ' _ > , local_def_id : LocalDefId ) -> bool {
15- debug ! ( "has_ffi_unwind_calls({local_def_id:?})" ) ;
14+ pub ( crate ) fn has_ffi_unwind_calls < ' tcx > ( tcx : TyCtxt < ' tcx > , body : & Body < ' tcx > ) -> bool {
15+ let def_id = body . source . def_id ( ) ;
1616
17- // Only perform check on functions because constants cannot call FFI functions.
18- let def_id = local_def_id. to_def_id ( ) ;
19- let kind = tcx. def_kind ( def_id) ;
20- if !kind. is_fn_like ( ) {
21- return false ;
22- }
23-
24- let body = & * tcx. mir_built ( local_def_id) . borrow ( ) ;
17+ debug ! ( "has_ffi_unwind_calls({def_id:?})" ) ;
2518
2619 let body_ty = tcx. type_of ( def_id) . skip_binder ( ) ;
2720 let body_abi = match body_ty. kind ( ) {
@@ -110,7 +103,7 @@ fn required_panic_strategy(tcx: TyCtxt<'_>, _: LocalCrate) -> Option<PanicStrate
110103 }
111104
112105 for def_id in tcx. hir_body_owners ( ) {
113- if tcx. has_ffi_unwind_calls ( def_id) {
106+ if tcx. has_ffi_unwind_calls ( def_id. into ( ) ) {
114107 // Given that this crate is compiled in `-C panic=unwind`, the `AbortUnwindingCalls`
115108 // MIR pass will not be run on FFI-unwind call sites, therefore a foreign exception
116109 // can enter Rust through these sites.
@@ -141,5 +134,5 @@ fn required_panic_strategy(tcx: TyCtxt<'_>, _: LocalCrate) -> Option<PanicStrate
141134}
142135
143136pub ( crate ) fn provide ( providers : & mut Providers ) {
144- * providers = Providers { has_ffi_unwind_calls , required_panic_strategy, ..* providers } ;
137+ * providers = Providers { required_panic_strategy, ..* providers } ;
145138}
0 commit comments