@@ -6,7 +6,7 @@ use std::ops::{Range, RangeFrom};
6
6
use rustc_abi:: { ExternAbi , FieldIdx } ;
7
7
use rustc_attr:: InlineAttr ;
8
8
use rustc_hir:: def:: DefKind ;
9
- use rustc_hir:: def_id:: { DefId , LocalDefId } ;
9
+ use rustc_hir:: def_id:: DefId ;
10
10
use rustc_index:: Idx ;
11
11
use rustc_index:: bit_set:: BitSet ;
12
12
use rustc_middle:: bug;
@@ -98,12 +98,12 @@ impl<'tcx> crate::MirPass<'tcx> for ForceInline {
98
98
}
99
99
100
100
trait Inliner < ' tcx > {
101
- fn new ( tcx : TyCtxt < ' tcx > , def_id : LocalDefId , body : & Body < ' tcx > ) -> Self ;
101
+ fn new ( tcx : TyCtxt < ' tcx > , def_id : DefId , body : & Body < ' tcx > ) -> Self ;
102
102
103
103
fn tcx ( & self ) -> TyCtxt < ' tcx > ;
104
104
fn typing_env ( & self ) -> ty:: TypingEnv < ' tcx > ;
105
105
fn history ( & self ) -> & [ DefId ] ;
106
- fn caller_def_id ( & self ) -> LocalDefId ;
106
+ fn caller_def_id ( & self ) -> DefId ;
107
107
108
108
/// Has the caller body been changed?
109
109
fn changed ( self ) -> bool ;
@@ -146,7 +146,7 @@ struct ForceInliner<'tcx> {
146
146
tcx : TyCtxt < ' tcx > ,
147
147
typing_env : ty:: TypingEnv < ' tcx > ,
148
148
/// `DefId` of caller.
149
- def_id : LocalDefId ,
149
+ def_id : DefId ,
150
150
/// Stack of inlined instances.
151
151
/// We only check the `DefId` and not the args because we want to
152
152
/// avoid inlining cases of polymorphic recursion.
@@ -158,7 +158,7 @@ struct ForceInliner<'tcx> {
158
158
}
159
159
160
160
impl < ' tcx > Inliner < ' tcx > for ForceInliner < ' tcx > {
161
- fn new ( tcx : TyCtxt < ' tcx > , def_id : LocalDefId , body : & Body < ' tcx > ) -> Self {
161
+ fn new ( tcx : TyCtxt < ' tcx > , def_id : DefId , body : & Body < ' tcx > ) -> Self {
162
162
Self { tcx, typing_env : body. typing_env ( tcx) , def_id, history : Vec :: new ( ) , changed : false }
163
163
}
164
164
@@ -174,7 +174,7 @@ impl<'tcx> Inliner<'tcx> for ForceInliner<'tcx> {
174
174
& self . history
175
175
}
176
176
177
- fn caller_def_id ( & self ) -> LocalDefId {
177
+ fn caller_def_id ( & self ) -> DefId {
178
178
self . def_id
179
179
}
180
180
@@ -248,7 +248,7 @@ struct NormalInliner<'tcx> {
248
248
tcx : TyCtxt < ' tcx > ,
249
249
typing_env : ty:: TypingEnv < ' tcx > ,
250
250
/// `DefId` of caller.
251
- def_id : LocalDefId ,
251
+ def_id : DefId ,
252
252
/// Stack of inlined instances.
253
253
/// We only check the `DefId` and not the args because we want to
254
254
/// avoid inlining cases of polymorphic recursion.
@@ -263,7 +263,7 @@ struct NormalInliner<'tcx> {
263
263
}
264
264
265
265
impl < ' tcx > Inliner < ' tcx > for NormalInliner < ' tcx > {
266
- fn new ( tcx : TyCtxt < ' tcx > , def_id : LocalDefId , body : & Body < ' tcx > ) -> Self {
266
+ fn new ( tcx : TyCtxt < ' tcx > , def_id : DefId , body : & Body < ' tcx > ) -> Self {
267
267
let typing_env = body. typing_env ( tcx) ;
268
268
let codegen_fn_attrs = tcx. codegen_fn_attrs ( def_id) ;
269
269
@@ -284,7 +284,7 @@ impl<'tcx> Inliner<'tcx> for NormalInliner<'tcx> {
284
284
self . tcx
285
285
}
286
286
287
- fn caller_def_id ( & self ) -> LocalDefId {
287
+ fn caller_def_id ( & self ) -> DefId {
288
288
self . def_id
289
289
}
290
290
@@ -442,7 +442,7 @@ impl<'tcx> Inliner<'tcx> for NormalInliner<'tcx> {
442
442
}
443
443
444
444
fn inline < ' tcx , T : Inliner < ' tcx > > ( tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) -> bool {
445
- let def_id = body. source . def_id ( ) . expect_local ( ) ;
445
+ let def_id = body. source . def_id ( ) ;
446
446
447
447
// Only do inlining into fn bodies.
448
448
if !tcx. hir ( ) . body_owner_kind ( def_id) . is_fn_or_closure ( ) {
@@ -722,7 +722,11 @@ fn check_mir_is_available<'tcx, I: Inliner<'tcx>>(
722
722
return Ok ( ( ) ) ;
723
723
}
724
724
725
- if callee_def_id. is_local ( ) {
725
+ if callee_def_id. is_local ( )
726
+ && !inliner
727
+ . tcx ( )
728
+ . is_lang_item ( inliner. tcx ( ) . parent ( caller_def_id) , rustc_hir:: LangItem :: FnOnce )
729
+ {
726
730
// If we know for sure that the function we're calling will itself try to
727
731
// call us, then we avoid inlining that function.
728
732
if inliner. tcx ( ) . mir_callgraph_reachable ( ( callee, caller_def_id. expect_local ( ) ) ) {
0 commit comments