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.
This commit is contained in:
parent
cc574be985
commit
7afbbf7e8a
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user