From 7afbbf7e8add3c14e5fe30b1b5e4c4a26179b9b7 Mon Sep 17 00:00:00 2001 From: Adam Perry Date: Fri, 6 Dec 2019 07:11:28 -0800 Subject: [PATCH] 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. --- src/librustc_mir/const_eval.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index b6a2cc0a9ff..0123d68d878 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -12,7 +12,7 @@ use rustc::mir::interpret::{ConstEvalErr, ErrorHandled, ScalarMaybeUndef}; use rustc::mir; use rustc::ty::{self, Ty, TyCtxt, subst::Subst}; -use rustc::ty::layout::{self, LayoutOf, VariantIdx}; +use rustc::ty::layout::{self, HasTyCtxt, LayoutOf, VariantIdx}; use rustc::traits::Reveal; use rustc_data_structures::fx::FxHashMap; use crate::interpret::eval_nullary_intrinsic; @@ -347,7 +347,11 @@ fn find_mir_or_eval_fn( // // For the moment we only do this for functions which take no arguments // (or all arguments are ZSTs) so that we don't memoize too much. - if args.iter().all(|a| a.layout.is_zst()) { + // + // Because `#[track_caller]` adds an implicit non-ZST argument, we also cannot + // perform this optimization on items tagged with it. + let no_implicit_args = !instance.def.requires_caller_location(ecx.tcx()); + if args.iter().all(|a| a.layout.is_zst()) && no_implicit_args { let gid = GlobalId { instance, promoted: None }; ecx.eval_const_fn_call(gid, ret)?; return Ok(None);