1
- use rustc_hir:: def_id:: { LOCAL_CRATE , LocalDefId } ;
1
+ use rustc_hir:: def_id:: LOCAL_CRATE ;
2
2
use rustc_middle:: mir:: * ;
3
3
use rustc_middle:: query:: { LocalCrate , Providers } ;
4
4
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 ( ) {
@@ -108,7 +101,7 @@ fn required_panic_strategy(tcx: TyCtxt<'_>, _: LocalCrate) -> Option<PanicStrate
108
101
}
109
102
110
103
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 ( ) ) {
112
105
// Given that this crate is compiled in `-C panic=unwind`, the `AbortUnwindingCalls`
113
106
// MIR pass will not be run on FFI-unwind call sites, therefore a foreign exception
114
107
// can enter Rust through these sites.
@@ -139,5 +132,5 @@ fn required_panic_strategy(tcx: TyCtxt<'_>, _: LocalCrate) -> Option<PanicStrate
139
132
}
140
133
141
134
pub ( crate ) fn provide ( providers : & mut Providers ) {
142
- * providers = Providers { has_ffi_unwind_calls , required_panic_strategy, ..* providers } ;
135
+ * providers = Providers { required_panic_strategy, ..* providers } ;
143
136
}
0 commit comments