1
1
use rustc_abi:: ExternAbi ;
2
- use rustc_hir:: def_id:: { LOCAL_CRATE , LocalDefId } ;
2
+ use rustc_hir:: def_id:: LOCAL_CRATE ;
3
3
use rustc_middle:: mir:: * ;
4
4
use rustc_middle:: query:: { LocalCrate , Providers } ;
5
5
use rustc_middle:: ty:: { self , TyCtxt , layout} ;
@@ -11,17 +11,10 @@ use tracing::debug;
11
11
use crate :: errors;
12
12
13
13
// 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 ( ) ;
16
16
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:?})" ) ;
25
18
26
19
let body_ty = tcx. type_of ( def_id) . skip_binder ( ) ;
27
20
let body_abi = match body_ty. kind ( ) {
@@ -112,7 +105,7 @@ fn required_panic_strategy(tcx: TyCtxt<'_>, _: LocalCrate) -> Option<PanicStrate
112
105
}
113
106
114
107
for def_id in tcx. hir ( ) . body_owners ( ) {
115
- if tcx. has_ffi_unwind_calls ( def_id) {
108
+ if tcx. has_ffi_unwind_calls ( def_id. into ( ) ) {
116
109
// Given that this crate is compiled in `-C panic=unwind`, the `AbortUnwindingCalls`
117
110
// MIR pass will not be run on FFI-unwind call sites, therefore a foreign exception
118
111
// can enter Rust through these sites.
@@ -143,5 +136,5 @@ fn required_panic_strategy(tcx: TyCtxt<'_>, _: LocalCrate) -> Option<PanicStrate
143
136
}
144
137
145
138
pub ( crate ) fn provide ( providers : & mut Providers ) {
146
- * providers = Providers { has_ffi_unwind_calls , required_panic_strategy, ..* providers } ;
139
+ * providers = Providers { required_panic_strategy, ..* providers } ;
147
140
}
0 commit comments