@@ -9,7 +9,7 @@ use rustc_middle::thir::visit::{self, Visitor};
9
9
use rustc_middle:: thir:: { BodyTy , Expr , ExprId , ExprKind , Thir } ;
10
10
use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
11
11
use rustc_span:: def_id:: { DefId , LocalDefId } ;
12
- use rustc_span:: { DUMMY_SP , ErrorGuaranteed , Span } ;
12
+ use rustc_span:: { ErrorGuaranteed , Span } ;
13
13
14
14
pub ( crate ) fn check_tail_calls ( tcx : TyCtxt < ' _ > , def : LocalDefId ) -> Result < ( ) , ErrorGuaranteed > {
15
15
let ( thir, expr) = tcx. thir_body ( def) ?;
@@ -21,7 +21,6 @@ pub(crate) fn check_tail_calls(tcx: TyCtxt<'_>, def: LocalDefId) -> Result<(), E
21
21
}
22
22
23
23
let is_closure = matches ! ( tcx. def_kind( def) , DefKind :: Closure ) ;
24
- let caller_ty = tcx. type_of ( def) . skip_binder ( ) ;
25
24
26
25
let mut visitor = TailCallCkVisitor {
27
26
tcx,
@@ -30,7 +29,7 @@ pub(crate) fn check_tail_calls(tcx: TyCtxt<'_>, def: LocalDefId) -> Result<(), E
30
29
// FIXME(#132279): we're clearly in a body here.
31
30
typing_env : ty:: TypingEnv :: non_body_analysis ( tcx, def) ,
32
31
is_closure,
33
- caller_ty ,
32
+ caller_def_id : def ,
34
33
} ;
35
34
36
35
visitor. visit_expr ( & thir[ expr] ) ;
@@ -47,8 +46,8 @@ struct TailCallCkVisitor<'a, 'tcx> {
47
46
/// The result of the checks, `Err(_)` if there was a problem with some
48
47
/// tail call, `Ok(())` if all of them were fine.
49
48
found_errors : Result < ( ) , ErrorGuaranteed > ,
50
- /// Type of the caller function.
51
- caller_ty : Ty < ' tcx > ,
49
+ /// `LocalDefId` of the caller function.
50
+ caller_def_id : LocalDefId ,
52
51
}
53
52
54
53
impl < ' tcx > TailCallCkVisitor < ' _ , ' tcx > {
@@ -168,7 +167,7 @@ impl<'tcx> TailCallCkVisitor<'_, 'tcx> {
168
167
// coercing the function to an `fn()` pointer. (although in that case the tailcall is
169
168
// basically useless -- the shim calls the actual function, so tailcalling the shim is
170
169
// equivalent to calling the function)
171
- let caller_needs_location = self . needs_location ( self . caller_ty ) ;
170
+ let caller_needs_location = self . caller_needs_location ( ) ;
172
171
173
172
if caller_needs_location {
174
173
self . report_track_caller_caller ( expr. span ) ;
@@ -184,27 +183,13 @@ impl<'tcx> TailCallCkVisitor<'_, 'tcx> {
184
183
}
185
184
}
186
185
187
- /// Returns true if function of type `ty` needs location argument
188
- /// (i.e. if a function is marked as `#[track_caller]`,
189
- /// is an override of a default trait method marked as `#[track_caller]`
190
- /// or an implementation of a prototype method marked as `#[track_caller]`)
191
- fn needs_location ( & self , ty : Ty < ' tcx > ) -> bool {
192
- if let & ty:: FnDef ( did, substs) = ty. kind ( ) {
193
- // If this is a default trait method, it won't be resolved to a concrete instance.
194
- if self
195
- . tcx
196
- . opt_associated_item ( did)
197
- . is_some_and ( |impl_item| impl_item. container == ty:: AssocItemContainer :: Trait )
198
- {
199
- self . tcx . codegen_fn_attrs ( did) . flags . intersects ( CodegenFnAttrFlags :: TRACK_CALLER )
200
- } else {
201
- let instance =
202
- ty:: Instance :: expect_resolve ( self . tcx , self . typing_env , did, substs, DUMMY_SP ) ;
203
- instance. def . requires_caller_location ( self . tcx )
204
- }
205
- } else {
206
- false
207
- }
186
+ /// Returns true if the caller function needs location argument
187
+ /// (i.e. if a function is marked as `#[track_caller]`)
188
+ fn caller_needs_location ( & self ) -> bool {
189
+ self . tcx
190
+ . codegen_fn_attrs ( self . caller_def_id )
191
+ . flags
192
+ . contains ( CodegenFnAttrFlags :: TRACK_CALLER )
208
193
}
209
194
210
195
fn report_in_closure ( & mut self , expr : & Expr < ' _ > ) {
0 commit comments