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 ( ) {
@@ -110,7 +103,7 @@ fn required_panic_strategy(tcx: TyCtxt<'_>, _: LocalCrate) -> Option<PanicStrate
110
103
}
111
104
112
105
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 ( ) ) {
114
107
// Given that this crate is compiled in `-C panic=unwind`, the `AbortUnwindingCalls`
115
108
// MIR pass will not be run on FFI-unwind call sites, therefore a foreign exception
116
109
// can enter Rust through these sites.
@@ -141,5 +134,5 @@ fn required_panic_strategy(tcx: TyCtxt<'_>, _: LocalCrate) -> Option<PanicStrate
141
134
}
142
135
143
136
pub ( crate ) fn provide ( providers : & mut Providers ) {
144
- * providers = Providers { has_ffi_unwind_calls , required_panic_strategy, ..* providers } ;
137
+ * providers = Providers { required_panic_strategy, ..* providers } ;
145
138
}
0 commit comments