postpone evaluation of constants whose substs depend on inference vars or regions
This commit is contained in:
parent
87ec5680c9
commit
7530c43b79
1 changed files with 17 additions and 3 deletions
|
@ -21,6 +21,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
|
||||||
use rustc_middle::infer::canonical::{Canonical, CanonicalVarValues};
|
use rustc_middle::infer::canonical::{Canonical, CanonicalVarValues};
|
||||||
use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue};
|
use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue};
|
||||||
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind, ToType};
|
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind, ToType};
|
||||||
|
use rustc_middle::mir::interpret::ErrorHandled;
|
||||||
use rustc_middle::mir::interpret::EvalToConstValueResult;
|
use rustc_middle::mir::interpret::EvalToConstValueResult;
|
||||||
use rustc_middle::traits::select;
|
use rustc_middle::traits::select;
|
||||||
use rustc_middle::ty::error::{ExpectedFound, TypeError};
|
use rustc_middle::ty::error::{ExpectedFound, TypeError};
|
||||||
|
@ -1584,10 +1585,23 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
unevaluated: ty::Unevaluated<'tcx>,
|
unevaluated: ty::Unevaluated<'tcx>,
|
||||||
span: Option<Span>,
|
span: Option<Span>,
|
||||||
) -> EvalToConstValueResult<'tcx> {
|
) -> EvalToConstValueResult<'tcx> {
|
||||||
let mut original_values = OriginalQueryValues::default();
|
let param_env = self.tcx.erase_regions(param_env);
|
||||||
let canonical = self.canonicalize_query((param_env, unevaluated), &mut original_values);
|
let mut substs = unevaluated.substs(self.tcx);
|
||||||
|
substs = self.tcx.erase_regions(substs);
|
||||||
|
substs = self.resolve_vars_if_possible(substs);
|
||||||
|
|
||||||
|
// Postpone the evaluation of constants whose substs depend on inference
|
||||||
|
// variables
|
||||||
|
if substs.has_infer_types_or_consts() {
|
||||||
|
return Err(ErrorHandled::TooGeneric);
|
||||||
|
}
|
||||||
|
|
||||||
|
let unevaluated = ty::Unevaluated {
|
||||||
|
def: unevaluated.def,
|
||||||
|
substs_: Some(substs),
|
||||||
|
promoted: unevaluated.promoted,
|
||||||
|
};
|
||||||
|
|
||||||
let (param_env, unevaluated) = canonical.value;
|
|
||||||
// The return value is the evaluated value which doesn't contain any reference to inference
|
// The return value is the evaluated value which doesn't contain any reference to inference
|
||||||
// variables, thus we don't need to substitute back the original values.
|
// variables, thus we don't need to substitute back the original values.
|
||||||
self.tcx.const_eval_resolve(param_env, unevaluated, span)
|
self.tcx.const_eval_resolve(param_env, unevaluated, span)
|
||||||
|
|
Loading…
Add table
Reference in a new issue