Skip to content

Commit 7afbbf7

Browse files
committed
Always call const fns with #[track_caller].
The caller location is passed as an implicit argument, so we must consider it when checking the sizedness of arguments.
1 parent cc574be commit 7afbbf7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/librustc_mir/const_eval.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc::hir::def_id::DefId;
1212
use rustc::mir::interpret::{ConstEvalErr, ErrorHandled, ScalarMaybeUndef};
1313
use rustc::mir;
1414
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};
1616
use rustc::traits::Reveal;
1717
use rustc_data_structures::fx::FxHashMap;
1818
use 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

Comments
 (0)