make unevaluated const substs optional
This commit is contained in:
parent
f4b606fd17
commit
bfaf13af4e
46 changed files with 234 additions and 188 deletions
|
@ -742,10 +742,9 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted })
|
||||
if self.tcx().lazy_normalization() =>
|
||||
{
|
||||
assert_eq!(promoted, None);
|
||||
ty::ConstKind::Unevaluated(uv) if self.tcx().lazy_normalization() => {
|
||||
assert_eq!(uv.promoted, None);
|
||||
let substs = uv.substs(self.tcx());
|
||||
let substs = self.relate_with_variance(
|
||||
ty::Variance::Invariant,
|
||||
ty::VarianceDiagInfo::default(),
|
||||
|
@ -754,7 +753,7 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
|
|||
)?;
|
||||
Ok(self.tcx().mk_const(ty::Const {
|
||||
ty: c.ty,
|
||||
val: ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }),
|
||||
val: ty::ConstKind::Unevaluated(ty::Unevaluated::new(uv.def, substs)),
|
||||
}))
|
||||
}
|
||||
_ => relate::super_relate_consts(self, c, c),
|
||||
|
@ -976,10 +975,9 @@ impl TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted })
|
||||
if self.tcx().lazy_normalization() =>
|
||||
{
|
||||
assert_eq!(promoted, None);
|
||||
ty::ConstKind::Unevaluated(uv) if self.tcx().lazy_normalization() => {
|
||||
assert_eq!(uv.promoted, None);
|
||||
let substs = uv.substs(self.tcx());
|
||||
let substs = self.relate_with_variance(
|
||||
ty::Variance::Invariant,
|
||||
ty::VarianceDiagInfo::default(),
|
||||
|
@ -988,7 +986,7 @@ impl TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
|
|||
)?;
|
||||
Ok(self.tcx().mk_const(ty::Const {
|
||||
ty: c.ty,
|
||||
val: ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }),
|
||||
val: ty::ConstKind::Unevaluated(ty::Unevaluated::new(uv.def, substs)),
|
||||
}))
|
||||
}
|
||||
_ => relate::super_relate_consts(self, c, c),
|
||||
|
|
|
@ -1537,8 +1537,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'tcx> ty::fold::TypeVisitor<'tcx> for OpaqueTypesVisitor<'tcx> {
|
||||
fn tcx_for_anon_const_substs<'a>(&'a self) -> TyCtxt<'tcx> {
|
||||
self.tcx
|
||||
fn tcx_for_anon_const_substs(&self) -> Option<TyCtxt<'tcx>> {
|
||||
Some(self.tcx)
|
||||
}
|
||||
|
||||
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||
|
|
|
@ -479,8 +479,10 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
pub(super) struct TraitObjectVisitor(pub(super) FxHashSet<DefId>);
|
||||
|
||||
impl<'tcx> TypeVisitor<'tcx> for TraitObjectVisitor {
|
||||
fn tcx_for_anon_const_substs<'a>(&'a self) -> TyCtxt<'tcx> {
|
||||
bug!("tcx_for_anon_const_substs called for TraitObjectVisitor");
|
||||
fn tcx_for_anon_const_substs(&self) -> Option<TyCtxt<'tcx>> {
|
||||
// The default anon const substs cannot include
|
||||
// trait objects, so we don't have to bother looking.
|
||||
None
|
||||
}
|
||||
|
||||
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||
|
|
|
@ -679,7 +679,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
b: ty::Unevaluated<'tcx>,
|
||||
) -> bool {
|
||||
let canonical = self.canonicalize_query(
|
||||
((a.def, a.substs), (b.def, b.substs)),
|
||||
((a.def, a.substs(self.tcx)), (b.def, b.substs(self.tcx))),
|
||||
&mut OriginalQueryValues::default(),
|
||||
);
|
||||
debug!("canonical consts: {:?}", &canonical.value);
|
||||
|
@ -1592,16 +1592,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
pub fn const_eval_resolve(
|
||||
&self,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
ty::Unevaluated { def, substs, promoted }: ty::Unevaluated<'tcx>,
|
||||
unevaluated: ty::Unevaluated<'tcx>,
|
||||
span: Option<Span>,
|
||||
) -> EvalToConstValueResult<'tcx> {
|
||||
let mut original_values = OriginalQueryValues::default();
|
||||
let canonical = self.canonicalize_query((param_env, substs), &mut original_values);
|
||||
let canonical = self.canonicalize_query((param_env, unevaluated), &mut original_values);
|
||||
|
||||
let (param_env, substs) = canonical.value;
|
||||
let (param_env, unevaluated) = canonical.value;
|
||||
// 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.
|
||||
self.tcx.const_eval_resolve(param_env, ty::Unevaluated { def, substs, promoted }, span)
|
||||
self.tcx.const_eval_resolve(param_env, unevaluated, span)
|
||||
}
|
||||
|
||||
/// If `typ` is a type variable of some kind, resolve it one level
|
||||
|
|
|
@ -766,8 +766,8 @@ struct ScopeInstantiator<'me, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'me, 'tcx> TypeVisitor<'tcx> for ScopeInstantiator<'me, 'tcx> {
|
||||
fn tcx_for_anon_const_substs<'a>(&'a self) -> TyCtxt<'tcx> {
|
||||
self.tcx
|
||||
fn tcx_for_anon_const_substs(&self) -> Option<TyCtxt<'tcx>> {
|
||||
Some(self.tcx)
|
||||
}
|
||||
|
||||
fn visit_binder<T: TypeFoldable<'tcx>>(
|
||||
|
|
|
@ -127,8 +127,8 @@ impl<'a, 'tcx> UnresolvedTypeFinder<'a, 'tcx> {
|
|||
impl<'a, 'tcx> TypeVisitor<'tcx> for UnresolvedTypeFinder<'a, 'tcx> {
|
||||
type BreakTy = (Ty<'tcx>, Option<Span>);
|
||||
|
||||
fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> {
|
||||
self.infcx.tcx
|
||||
fn tcx_for_anon_const_substs(&self) -> Option<TyCtxt<'tcx>> {
|
||||
Some(self.infcx.tcx)
|
||||
}
|
||||
|
||||
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue