Add Clause::ConstArgHasType
variant
This commit is contained in:
parent
9556b56dbd
commit
e919d7e348
@ -1328,7 +1328,7 @@ fn conv_object_ty_poly_trait_ref(
|
||||
ty::Clause::TypeOutlives(_) => {
|
||||
// Do nothing, we deal with regions separately
|
||||
}
|
||||
ty::Clause::RegionOutlives(_) => bug!(),
|
||||
ty::Clause::RegionOutlives(_) | ty::Clause::ConstArgHasType(..) => bug!(),
|
||||
},
|
||||
ty::PredicateKind::WellFormed(_)
|
||||
| ty::PredicateKind::AliasEq(..)
|
||||
|
@ -517,6 +517,7 @@ fn trait_predicate_kind<'tcx>(
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(_))
|
||||
| ty::PredicateKind::Clause(ty::Clause::TypeOutlives(_))
|
||||
| ty::PredicateKind::Clause(ty::Clause::Projection(_))
|
||||
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
|
||||
| ty::PredicateKind::AliasEq(..)
|
||||
| ty::PredicateKind::WellFormed(_)
|
||||
| ty::PredicateKind::Subtype(_)
|
||||
|
@ -54,6 +54,7 @@ pub(crate) fn explicit_predicates_of(
|
||||
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(..))
|
||||
| ty::PredicateKind::Clause(ty::Clause::Projection(..))
|
||||
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
|
||||
| ty::PredicateKind::WellFormed(..)
|
||||
| ty::PredicateKind::AliasEq(..)
|
||||
| ty::PredicateKind::ObjectSafe(..)
|
||||
|
@ -663,6 +663,7 @@ pub(in super::super) fn obligations_for_self_ty<'b>(
|
||||
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(..))
|
||||
| ty::PredicateKind::Clause(ty::Clause::Projection(..))
|
||||
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
|
||||
| ty::PredicateKind::Subtype(..)
|
||||
| ty::PredicateKind::Coerce(..)
|
||||
| ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..))
|
||||
|
@ -826,6 +826,7 @@ fn assemble_inherent_candidates_from_param(&mut self, param_ty: ty::ParamTy) {
|
||||
}
|
||||
}
|
||||
ty::PredicateKind::Subtype(..)
|
||||
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
|
||||
| ty::PredicateKind::Coerce(..)
|
||||
| ty::PredicateKind::Clause(ty::Clause::Projection(..))
|
||||
| ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..))
|
||||
|
@ -21,6 +21,7 @@ pub fn explicit_outlives_bounds<'tcx>(
|
||||
.filter_map(move |kind| match kind {
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(..))
|
||||
| ty::PredicateKind::Clause(ty::Clause::Trait(..))
|
||||
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
|
||||
| ty::PredicateKind::AliasEq(..)
|
||||
| ty::PredicateKind::Coerce(..)
|
||||
| ty::PredicateKind::Subtype(..)
|
||||
|
@ -297,6 +297,9 @@ fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) {
|
||||
ty::PredicateKind::AliasEq(..) => {
|
||||
// No
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..)) => {
|
||||
// Nothing to elaborate
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1595,6 +1595,8 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
|
||||
Clause(Clause::TypeOutlives(..)) |
|
||||
Clause(Clause::RegionOutlives(..)) => "lifetime",
|
||||
|
||||
// `ConstArgHasType` is never global as `ct` is always a param
|
||||
Clause(Clause::ConstArgHasType(..)) |
|
||||
// Ignore projections, as they can only be global
|
||||
// if the trait bound is global
|
||||
Clause(Clause::Projection(..)) |
|
||||
|
@ -251,6 +251,10 @@ fn add_predicate_atom(&mut self, atom: ty::PredicateKind<'_>) {
|
||||
self.add_ty(ty);
|
||||
self.add_region(region);
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(ct, ty)) => {
|
||||
self.add_const(ct);
|
||||
self.add_ty(ty);
|
||||
}
|
||||
ty::PredicateKind::Subtype(ty::SubtypePredicate { a_is_expected: _, a, b }) => {
|
||||
self.add_ty(a);
|
||||
self.add_ty(b);
|
||||
|
@ -552,6 +552,7 @@ pub fn allow_normalization(self) -> bool {
|
||||
| PredicateKind::Clause(Clause::RegionOutlives(_))
|
||||
| PredicateKind::Clause(Clause::TypeOutlives(_))
|
||||
| PredicateKind::Clause(Clause::Projection(_))
|
||||
| PredicateKind::Clause(Clause::ConstArgHasType(..))
|
||||
| PredicateKind::AliasEq(..)
|
||||
| PredicateKind::ObjectSafe(_)
|
||||
| PredicateKind::ClosureKind(_, _, _)
|
||||
@ -590,6 +591,10 @@ pub enum Clause<'tcx> {
|
||||
/// `where <T as TraitRef>::Name == X`, approximately.
|
||||
/// See the `ProjectionPredicate` struct for details.
|
||||
Projection(ProjectionPredicate<'tcx>),
|
||||
|
||||
/// Ensures that a const generic argument to a parameter `const N: u8`
|
||||
/// is of type `u8`.
|
||||
ConstArgHasType(Const<'tcx>, Ty<'tcx>),
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
|
||||
@ -1193,6 +1198,7 @@ pub fn to_opt_poly_trait_pred(self) -> Option<PolyTraitPredicate<'tcx>> {
|
||||
match predicate.skip_binder() {
|
||||
PredicateKind::Clause(Clause::Trait(t)) => Some(predicate.rebind(t)),
|
||||
PredicateKind::Clause(Clause::Projection(..))
|
||||
| PredicateKind::Clause(Clause::ConstArgHasType(..))
|
||||
| PredicateKind::AliasEq(..)
|
||||
| PredicateKind::Subtype(..)
|
||||
| PredicateKind::Coerce(..)
|
||||
@ -1213,6 +1219,7 @@ pub fn to_opt_poly_projection_pred(self) -> Option<PolyProjectionPredicate<'tcx>
|
||||
match predicate.skip_binder() {
|
||||
PredicateKind::Clause(Clause::Projection(t)) => Some(predicate.rebind(t)),
|
||||
PredicateKind::Clause(Clause::Trait(..))
|
||||
| PredicateKind::Clause(Clause::ConstArgHasType(..))
|
||||
| PredicateKind::AliasEq(..)
|
||||
| PredicateKind::Subtype(..)
|
||||
| PredicateKind::Coerce(..)
|
||||
@ -1233,6 +1240,7 @@ pub fn to_opt_type_outlives(self) -> Option<PolyTypeOutlivesPredicate<'tcx>> {
|
||||
match predicate.skip_binder() {
|
||||
PredicateKind::Clause(Clause::TypeOutlives(data)) => Some(predicate.rebind(data)),
|
||||
PredicateKind::Clause(Clause::Trait(..))
|
||||
| PredicateKind::Clause(Clause::ConstArgHasType(..))
|
||||
| PredicateKind::Clause(Clause::Projection(..))
|
||||
| PredicateKind::AliasEq(..)
|
||||
| PredicateKind::Subtype(..)
|
||||
|
@ -2822,15 +2822,18 @@ pub struct PrintClosureAsImpl<'tcx> {
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(predicate)) => p!(print(predicate)),
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(predicate)) => p!(print(predicate)),
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(predicate)) => p!(print(predicate)),
|
||||
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(ct, ty)) => {
|
||||
p!("the constant `", print(ct), "` has type `", print(ty), "`")
|
||||
},
|
||||
ty::PredicateKind::WellFormed(arg) => p!(print(arg), " well-formed"),
|
||||
ty::PredicateKind::ObjectSafe(trait_def_id) => {
|
||||
p!("the trait `", print_def_path(trait_def_id, &[]), "` is object-safe")
|
||||
}
|
||||
ty::PredicateKind::ClosureKind(closure_def_id, _closure_substs, kind) => {
|
||||
p!("the closure `",
|
||||
ty::PredicateKind::ClosureKind(closure_def_id, _closure_substs, kind) => p!(
|
||||
"the closure `",
|
||||
print_value_path(closure_def_id, &[]),
|
||||
write("` implements the trait `{}`", kind))
|
||||
}
|
||||
write("` implements the trait `{}`", kind)
|
||||
),
|
||||
ty::PredicateKind::ConstEvaluatable(ct) => {
|
||||
p!("the constant `", print(ct), "` can be evaluated")
|
||||
}
|
||||
|
@ -147,6 +147,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
impl<'tcx> fmt::Debug for ty::Clause<'tcx> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match *self {
|
||||
ty::Clause::ConstArgHasType(ct, ty) => write!(f, "ConstArgHasType({ct:?}, {ty:?})"),
|
||||
ty::Clause::Trait(ref a) => a.fmt(f),
|
||||
ty::Clause::RegionOutlives(ref pair) => pair.fmt(f),
|
||||
ty::Clause::TypeOutlives(ref pair) => pair.fmt(f),
|
||||
|
@ -290,6 +290,9 @@ fn compute_goal(&mut self, goal: Goal<'tcx, ty::Predicate<'tcx>>) -> QueryResult
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(predicate)) => {
|
||||
self.compute_region_outlives_goal(Goal { param_env, predicate })
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..)) => {
|
||||
unimplemented!()
|
||||
}
|
||||
ty::PredicateKind::Subtype(predicate) => {
|
||||
self.compute_subtype_goal(Goal { param_env, predicate })
|
||||
}
|
||||
|
@ -830,6 +830,7 @@ fn evaluate_nested_obligations(
|
||||
// and these don't correspond to adding any new bounds to
|
||||
// the `ParamEnv`.
|
||||
ty::PredicateKind::WellFormed(..)
|
||||
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
|
||||
| ty::PredicateKind::AliasEq(..)
|
||||
| ty::PredicateKind::ObjectSafe(..)
|
||||
| ty::PredicateKind::ClosureKind(..)
|
||||
|
@ -1282,6 +1282,11 @@ fn report_selection_error(
|
||||
span,
|
||||
"AliasEq predicate should never be the predicate cause of a SelectionError"
|
||||
),
|
||||
|
||||
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..)) => {
|
||||
// FIXME: don't know how selection error works so unsure when this is reachable (if it is)
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -313,6 +313,7 @@ fn process_obligation(
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(_))
|
||||
| ty::PredicateKind::Clause(ty::Clause::TypeOutlives(_))
|
||||
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
|
||||
| ty::PredicateKind::WellFormed(_)
|
||||
| ty::PredicateKind::ObjectSafe(_)
|
||||
| ty::PredicateKind::ClosureKind(..)
|
||||
@ -600,6 +601,9 @@ fn process_obligation(
|
||||
ty::PredicateKind::AliasEq(..) => {
|
||||
bug!("AliasEq is only used for new solver")
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..)) => {
|
||||
unimplemented!()
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -327,6 +327,10 @@ fn predicate_references_self<'tcx>(
|
||||
// possible alternatives.
|
||||
data.projection_ty.substs[1..].iter().any(has_self_ty).then_some(sp)
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(_ct, ty)) => {
|
||||
has_self_ty(&ty.into()).then_some(sp)
|
||||
}
|
||||
|
||||
ty::PredicateKind::AliasEq(..) => bug!("`AliasEq` not allowed as assumption"),
|
||||
|
||||
ty::PredicateKind::WellFormed(..)
|
||||
@ -362,6 +366,7 @@ fn generics_require_sized_self(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
|
||||
trait_pred.def_id() == sized_def_id && trait_pred.self_ty().is_param(0)
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(..))
|
||||
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
|
||||
| ty::PredicateKind::Subtype(..)
|
||||
| ty::PredicateKind::Coerce(..)
|
||||
| ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..))
|
||||
|
@ -993,6 +993,9 @@ fn evaluate_predicate_recursively<'o>(
|
||||
bug!("AliasEq is only used for new solver")
|
||||
}
|
||||
ty::PredicateKind::Ambiguous => Ok(EvaluatedToAmbig),
|
||||
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..)) => {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -163,6 +163,10 @@ pub fn predicate_obligations<'tcx>(
|
||||
ty::TermKind::Const(c) => c.into(),
|
||||
})
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(ct, ty)) => {
|
||||
wf.compute(ct.into());
|
||||
wf.compute(ty.into());
|
||||
}
|
||||
ty::PredicateKind::WellFormed(arg) => {
|
||||
wf.compute(arg);
|
||||
}
|
||||
@ -922,6 +926,7 @@ pub(crate) fn required_region_bounds<'tcx>(
|
||||
match obligation.predicate.kind().skip_binder() {
|
||||
ty::PredicateKind::Clause(ty::Clause::Projection(..))
|
||||
| ty::PredicateKind::Clause(ty::Clause::Trait(..))
|
||||
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
|
||||
| ty::PredicateKind::Subtype(..)
|
||||
| ty::PredicateKind::Coerce(..)
|
||||
| ty::PredicateKind::WellFormed(..)
|
||||
|
@ -117,6 +117,7 @@ fn lower_into(
|
||||
)),
|
||||
},
|
||||
ty::PredicateKind::ObjectSafe(..)
|
||||
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
|
||||
| ty::PredicateKind::AliasEq(..)
|
||||
| ty::PredicateKind::ClosureKind(..)
|
||||
| ty::PredicateKind::Subtype(..)
|
||||
@ -212,6 +213,7 @@ fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::GoalData<RustInte
|
||||
// We can defer this, but ultimately we'll want to express
|
||||
// some of these in terms of chalk operations.
|
||||
ty::PredicateKind::ClosureKind(..)
|
||||
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
|
||||
| ty::PredicateKind::AliasEq(..)
|
||||
| ty::PredicateKind::Coerce(..)
|
||||
| ty::PredicateKind::ConstEvaluatable(..)
|
||||
@ -646,6 +648,7 @@ fn lower_into(
|
||||
Some(chalk_ir::WhereClause::AliasEq(predicate.lower_into(interner)))
|
||||
}
|
||||
ty::PredicateKind::WellFormed(_ty) => None,
|
||||
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..)) => None,
|
||||
|
||||
ty::PredicateKind::ObjectSafe(..)
|
||||
| ty::PredicateKind::AliasEq(..)
|
||||
@ -780,6 +783,7 @@ fn lower_into(
|
||||
}
|
||||
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(_predicate)) => None,
|
||||
ty::PredicateKind::WellFormed(_ty) => None,
|
||||
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..)) => None,
|
||||
|
||||
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..))
|
||||
| ty::PredicateKind::AliasEq(..)
|
||||
|
@ -99,6 +99,9 @@ fn compute_implied_outlives_bounds<'tcx>(
|
||||
};
|
||||
match pred {
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(..))
|
||||
// FIXME(const_generics): Make sure that `<'a, 'b, const N: &'a &'b u32>` is sound
|
||||
// if we ever support that
|
||||
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
|
||||
| ty::PredicateKind::Subtype(..)
|
||||
| ty::PredicateKind::Coerce(..)
|
||||
| ty::PredicateKind::Clause(ty::Clause::Projection(..))
|
||||
|
@ -60,6 +60,7 @@ fn not_outlives_predicate(p: ty::Predicate<'_>) -> bool {
|
||||
| ty::PredicateKind::Clause(ty::Clause::TypeOutlives(..)) => false,
|
||||
ty::PredicateKind::Clause(ty::Clause::Trait(..))
|
||||
| ty::PredicateKind::Clause(ty::Clause::Projection(..))
|
||||
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
|
||||
| ty::PredicateKind::AliasEq(..)
|
||||
| ty::PredicateKind::WellFormed(..)
|
||||
| ty::PredicateKind::ObjectSafe(..)
|
||||
|
@ -320,6 +320,7 @@ pub(crate) fn clean_predicate<'tcx>(
|
||||
// FIXME(generic_const_exprs): should this do something?
|
||||
ty::PredicateKind::ConstEvaluatable(..) => None,
|
||||
ty::PredicateKind::WellFormed(..) => None,
|
||||
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..)) => None,
|
||||
|
||||
ty::PredicateKind::Subtype(..)
|
||||
| ty::PredicateKind::AliasEq(..)
|
||||
|
@ -30,7 +30,8 @@ pub fn is_min_const_fn<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, msrv: &Msrv)
|
||||
ty::Clause::RegionOutlives(_)
|
||||
| ty::Clause::TypeOutlives(_)
|
||||
| ty::Clause::Projection(_)
|
||||
| ty::Clause::Trait(..),
|
||||
| ty::Clause::Trait(..)
|
||||
| ty::Clause::ConstArgHasType(..),
|
||||
)
|
||||
| ty::PredicateKind::WellFormed(_)
|
||||
| ty::PredicateKind::ConstEvaluatable(..)
|
||||
|
Loading…
Reference in New Issue
Block a user