1- use rustc_hir:: def_id:: { LOCAL_CRATE , LocalDefId } ;
1+ use rustc_hir:: def_id:: LOCAL_CRATE ;
22use rustc_middle:: mir:: * ;
33use rustc_middle:: query:: { LocalCrate , Providers } ;
44use 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 ( ) {
@@ -108,7 +101,7 @@ fn required_panic_strategy(tcx: TyCtxt<'_>, _: LocalCrate) -> Option<PanicStrate
108101 }
109102
110103 for def_id in tcx. hir ( ) . body_owners ( ) {
111- if tcx. has_ffi_unwind_calls ( def_id) {
104+ if tcx. has_ffi_unwind_calls ( def_id. into ( ) ) {
112105 // Given that this crate is compiled in `-C panic=unwind`, the `AbortUnwindingCalls`
113106 // MIR pass will not be run on FFI-unwind call sites, therefore a foreign exception
114107 // can enter Rust through these sites.
@@ -139,5 +132,5 @@ fn required_panic_strategy(tcx: TyCtxt<'_>, _: LocalCrate) -> Option<PanicStrate
139132}
140133
141134pub ( crate ) fn provide ( providers : & mut Providers ) {
142- * providers = Providers { has_ffi_unwind_calls , required_panic_strategy, ..* providers } ;
135+ * providers = Providers { required_panic_strategy, ..* providers } ;
143136}
0 commit comments