@@ -12,7 +12,7 @@ use rustc::hir::def_id::DefId;
12
12
use rustc:: mir:: interpret:: { ConstEvalErr , ErrorHandled , ScalarMaybeUndef } ;
13
13
use rustc:: mir;
14
14
use rustc:: ty:: { self , Ty , TyCtxt , subst:: Subst } ;
15
- use rustc:: ty:: layout:: { self , LayoutOf , VariantIdx } ;
15
+ use rustc:: ty:: layout:: { self , HasTyCtxt , LayoutOf , VariantIdx } ;
16
16
use rustc:: traits:: Reveal ;
17
17
use rustc_data_structures:: fx:: FxHashMap ;
18
18
use crate :: interpret:: eval_nullary_intrinsic;
@@ -347,7 +347,11 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
347
347
//
348
348
// For the moment we only do this for functions which take no arguments
349
349
// (or all arguments are ZSTs) so that we don't memoize too much.
350
- if args. iter ( ) . all ( |a| a. layout . is_zst ( ) ) {
350
+ //
351
+ // Because `#[track_caller]` adds an implicit non-ZST argument, we also cannot
352
+ // perform this optimization on items tagged with it.
353
+ let no_implicit_args = !instance. def . requires_caller_location ( ecx. tcx ( ) ) ;
354
+ if args. iter ( ) . all ( |a| a. layout . is_zst ( ) ) && no_implicit_args {
351
355
let gid = GlobalId { instance, promoted : None } ;
352
356
ecx. eval_const_fn_call ( gid, ret) ?;
353
357
return Ok ( None ) ;
0 commit comments