@@ -12,7 +12,7 @@ use rustc::hir::def_id::DefId;
1212use rustc:: mir:: interpret:: { ConstEvalErr , ErrorHandled , ScalarMaybeUndef } ;
1313use rustc:: mir;
1414use rustc:: ty:: { self , Ty , TyCtxt , subst:: Subst } ;
15- use rustc:: ty:: layout:: { self , LayoutOf , VariantIdx } ;
15+ use rustc:: ty:: layout:: { self , HasTyCtxt , LayoutOf , VariantIdx } ;
1616use rustc:: traits:: Reveal ;
1717use rustc_data_structures:: fx:: FxHashMap ;
1818use crate :: interpret:: eval_nullary_intrinsic;
@@ -347,7 +347,11 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
347347 //
348348 // For the moment we only do this for functions which take no arguments
349349 // (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 {
351355 let gid = GlobalId { instance, promoted : None } ;
352356 ecx. eval_const_fn_call ( gid, ret) ?;
353357 return Ok ( None ) ;
0 commit comments