make unevaluated const substs optional
This commit is contained in:
parent
f4b606fd17
commit
bfaf13af4e
46 changed files with 234 additions and 188 deletions
|
@ -558,8 +558,8 @@ impl<'tcx, OP> TypeVisitor<'tcx> for ConstrainOpaqueTypeRegionVisitor<'tcx, OP>
|
|||
where
|
||||
OP: FnMut(ty::Region<'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>>(
|
||||
|
|
|
@ -155,11 +155,8 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
|
|||
// and hopefully soon change this to an error.
|
||||
//
|
||||
// See #74595 for more details about this.
|
||||
let concrete = infcx.const_eval_resolve(
|
||||
param_env,
|
||||
ty::Unevaluated { def, substs, promoted: None },
|
||||
Some(span),
|
||||
);
|
||||
let concrete =
|
||||
infcx.const_eval_resolve(param_env, ty::Unevaluated::new(def, substs), Some(span));
|
||||
|
||||
if concrete.is_ok() && substs.has_param_types_or_consts() {
|
||||
match infcx.tcx.def_kind(def.did) {
|
||||
|
@ -217,9 +214,7 @@ impl AbstractConst<'tcx> {
|
|||
ct: &ty::Const<'tcx>,
|
||||
) -> Result<Option<AbstractConst<'tcx>>, ErrorReported> {
|
||||
match ct.val {
|
||||
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted: _ }) => {
|
||||
AbstractConst::new(tcx, def, substs)
|
||||
}
|
||||
ty::ConstKind::Unevaluated(uv) => AbstractConst::new(tcx, uv.def, uv.substs(tcx)),
|
||||
ty::ConstKind::Error(_) => Err(ErrorReported),
|
||||
_ => Ok(None),
|
||||
}
|
||||
|
|
|
@ -570,7 +570,8 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
|
|||
|
||||
ty::PredicateKind::ConstEquate(c1, c2) => {
|
||||
debug!(?c1, ?c2, "equating consts");
|
||||
if self.selcx.tcx().features().const_evaluatable_checked {
|
||||
let tcx = self.selcx.tcx();
|
||||
if tcx.features().const_evaluatable_checked {
|
||||
// FIXME: we probably should only try to unify abstract constants
|
||||
// if the constants depend on generic parameters.
|
||||
//
|
||||
|
@ -597,7 +598,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
|
|||
Err(ErrorHandled::TooGeneric) => {
|
||||
stalled_on.extend(
|
||||
unevaluated
|
||||
.substs
|
||||
.substs(tcx)
|
||||
.iter()
|
||||
.filter_map(TyOrConstInferVar::maybe_from_generic_arg),
|
||||
);
|
||||
|
|
|
@ -771,8 +771,8 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeFoldable<'tcx>>(
|
|||
|
||||
impl<'tcx> TypeVisitor<'tcx> for IllegalSelfTypeVisitor<'tcx> {
|
||||
type BreakTy = ();
|
||||
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> {
|
||||
|
|
|
@ -130,8 +130,8 @@ impl Search<'a, 'tcx> {
|
|||
|
||||
impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
|
||||
type BreakTy = NonStructuralMatchTy<'tcx>;
|
||||
fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> {
|
||||
self.tcx()
|
||||
fn tcx_for_anon_const_substs(&self) -> Option<TyCtxt<'tcx>> {
|
||||
Some(self.tcx())
|
||||
}
|
||||
|
||||
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||
|
|
|
@ -435,13 +435,14 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
|||
|
||||
GenericArgKind::Const(constant) => {
|
||||
match constant.val {
|
||||
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }) => {
|
||||
assert!(promoted.is_none());
|
||||
ty::ConstKind::Unevaluated(uv) => {
|
||||
assert!(uv.promoted.is_none());
|
||||
let substs = uv.substs(self.tcx());
|
||||
|
||||
let obligations = self.nominal_obligations(def.did, substs);
|
||||
let obligations = self.nominal_obligations(uv.def.did, substs);
|
||||
self.out.extend(obligations);
|
||||
|
||||
let predicate = ty::PredicateKind::ConstEvaluatable(def, substs)
|
||||
let predicate = ty::PredicateKind::ConstEvaluatable(uv.def, substs)
|
||||
.to_predicate(self.tcx());
|
||||
let cause = self.cause(traits::MiscObligation);
|
||||
self.out.push(traits::Obligation::with_depth(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue