Skip to content

Commit e919d7e

Browse files
committed
Add Clause::ConstArgHasType variant
1 parent 9556b56 commit e919d7e

File tree

24 files changed

+68
-6
lines changed

24 files changed

+68
-6
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1328,7 +1328,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
13281328
ty::Clause::TypeOutlives(_) => {
13291329
// Do nothing, we deal with regions separately
13301330
}
1331-
ty::Clause::RegionOutlives(_) => bug!(),
1331+
ty::Clause::RegionOutlives(_) | ty::Clause::ConstArgHasType(..) => bug!(),
13321332
},
13331333
ty::PredicateKind::WellFormed(_)
13341334
| ty::PredicateKind::AliasEq(..)

compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ fn trait_predicate_kind<'tcx>(
517517
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(_))
518518
| ty::PredicateKind::Clause(ty::Clause::TypeOutlives(_))
519519
| ty::PredicateKind::Clause(ty::Clause::Projection(_))
520+
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
520521
| ty::PredicateKind::AliasEq(..)
521522
| ty::PredicateKind::WellFormed(_)
522523
| ty::PredicateKind::Subtype(_)

compiler/rustc_hir_analysis/src/outlives/explicit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> {
5454

5555
ty::PredicateKind::Clause(ty::Clause::Trait(..))
5656
| ty::PredicateKind::Clause(ty::Clause::Projection(..))
57+
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
5758
| ty::PredicateKind::WellFormed(..)
5859
| ty::PredicateKind::AliasEq(..)
5960
| ty::PredicateKind::ObjectSafe(..)

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
663663

664664
ty::PredicateKind::Clause(ty::Clause::Trait(..))
665665
| ty::PredicateKind::Clause(ty::Clause::Projection(..))
666+
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
666667
| ty::PredicateKind::Subtype(..)
667668
| ty::PredicateKind::Coerce(..)
668669
| ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..))

compiler/rustc_hir_typeck/src/method/probe.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
826826
}
827827
}
828828
ty::PredicateKind::Subtype(..)
829+
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
829830
| ty::PredicateKind::Coerce(..)
830831
| ty::PredicateKind::Clause(ty::Clause::Projection(..))
831832
| ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..))

compiler/rustc_infer/src/infer/outlives/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub fn explicit_outlives_bounds<'tcx>(
2121
.filter_map(move |kind| match kind {
2222
ty::PredicateKind::Clause(ty::Clause::Projection(..))
2323
| ty::PredicateKind::Clause(ty::Clause::Trait(..))
24+
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
2425
| ty::PredicateKind::AliasEq(..)
2526
| ty::PredicateKind::Coerce(..)
2627
| ty::PredicateKind::Subtype(..)

compiler/rustc_infer/src/traits/util.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ impl<'tcx> Elaborator<'tcx> {
297297
ty::PredicateKind::AliasEq(..) => {
298298
// No
299299
}
300+
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..)) => {
301+
// Nothing to elaborate
302+
}
300303
}
301304
}
302305
}

compiler/rustc_lint/src/builtin.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,6 +1595,8 @@ impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
15951595
Clause(Clause::TypeOutlives(..)) |
15961596
Clause(Clause::RegionOutlives(..)) => "lifetime",
15971597

1598+
// `ConstArgHasType` is never global as `ct` is always a param
1599+
Clause(Clause::ConstArgHasType(..)) |
15981600
// Ignore projections, as they can only be global
15991601
// if the trait bound is global
16001602
Clause(Clause::Projection(..)) |

compiler/rustc_middle/src/ty/flags.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ impl FlagComputation {
251251
self.add_ty(ty);
252252
self.add_region(region);
253253
}
254+
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(ct, ty)) => {
255+
self.add_const(ct);
256+
self.add_ty(ty);
257+
}
254258
ty::PredicateKind::Subtype(ty::SubtypePredicate { a_is_expected: _, a, b }) => {
255259
self.add_ty(a);
256260
self.add_ty(b);

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ impl<'tcx> Predicate<'tcx> {
552552
| PredicateKind::Clause(Clause::RegionOutlives(_))
553553
| PredicateKind::Clause(Clause::TypeOutlives(_))
554554
| PredicateKind::Clause(Clause::Projection(_))
555+
| PredicateKind::Clause(Clause::ConstArgHasType(..))
555556
| PredicateKind::AliasEq(..)
556557
| PredicateKind::ObjectSafe(_)
557558
| PredicateKind::ClosureKind(_, _, _)
@@ -590,6 +591,10 @@ pub enum Clause<'tcx> {
590591
/// `where <T as TraitRef>::Name == X`, approximately.
591592
/// See the `ProjectionPredicate` struct for details.
592593
Projection(ProjectionPredicate<'tcx>),
594+
595+
/// Ensures that a const generic argument to a parameter `const N: u8`
596+
/// is of type `u8`.
597+
ConstArgHasType(Const<'tcx>, Ty<'tcx>),
593598
}
594599

595600
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
@@ -1193,6 +1198,7 @@ impl<'tcx> Predicate<'tcx> {
11931198
match predicate.skip_binder() {
11941199
PredicateKind::Clause(Clause::Trait(t)) => Some(predicate.rebind(t)),
11951200
PredicateKind::Clause(Clause::Projection(..))
1201+
| PredicateKind::Clause(Clause::ConstArgHasType(..))
11961202
| PredicateKind::AliasEq(..)
11971203
| PredicateKind::Subtype(..)
11981204
| PredicateKind::Coerce(..)
@@ -1213,6 +1219,7 @@ impl<'tcx> Predicate<'tcx> {
12131219
match predicate.skip_binder() {
12141220
PredicateKind::Clause(Clause::Projection(t)) => Some(predicate.rebind(t)),
12151221
PredicateKind::Clause(Clause::Trait(..))
1222+
| PredicateKind::Clause(Clause::ConstArgHasType(..))
12161223
| PredicateKind::AliasEq(..)
12171224
| PredicateKind::Subtype(..)
12181225
| PredicateKind::Coerce(..)
@@ -1233,6 +1240,7 @@ impl<'tcx> Predicate<'tcx> {
12331240
match predicate.skip_binder() {
12341241
PredicateKind::Clause(Clause::TypeOutlives(data)) => Some(predicate.rebind(data)),
12351242
PredicateKind::Clause(Clause::Trait(..))
1243+
| PredicateKind::Clause(Clause::ConstArgHasType(..))
12361244
| PredicateKind::Clause(Clause::Projection(..))
12371245
| PredicateKind::AliasEq(..)
12381246
| PredicateKind::Subtype(..)

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2822,15 +2822,18 @@ define_print_and_forward_display! {
28222822
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(predicate)) => p!(print(predicate)),
28232823
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(predicate)) => p!(print(predicate)),
28242824
ty::PredicateKind::Clause(ty::Clause::Projection(predicate)) => p!(print(predicate)),
2825+
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(ct, ty)) => {
2826+
p!("the constant `", print(ct), "` has type `", print(ty), "`")
2827+
},
28252828
ty::PredicateKind::WellFormed(arg) => p!(print(arg), " well-formed"),
28262829
ty::PredicateKind::ObjectSafe(trait_def_id) => {
28272830
p!("the trait `", print_def_path(trait_def_id, &[]), "` is object-safe")
28282831
}
2829-
ty::PredicateKind::ClosureKind(closure_def_id, _closure_substs, kind) => {
2830-
p!("the closure `",
2832+
ty::PredicateKind::ClosureKind(closure_def_id, _closure_substs, kind) => p!(
2833+
"the closure `",
28312834
print_value_path(closure_def_id, &[]),
2832-
write("` implements the trait `{}`", kind))
2833-
}
2835+
write("` implements the trait `{}`", kind)
2836+
),
28342837
ty::PredicateKind::ConstEvaluatable(ct) => {
28352838
p!("the constant `", print(ct), "` can be evaluated")
28362839
}

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ impl<'tcx> fmt::Debug for ty::Predicate<'tcx> {
147147
impl<'tcx> fmt::Debug for ty::Clause<'tcx> {
148148
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
149149
match *self {
150+
ty::Clause::ConstArgHasType(ct, ty) => write!(f, "ConstArgHasType({ct:?}, {ty:?})"),
150151
ty::Clause::Trait(ref a) => a.fmt(f),
151152
ty::Clause::RegionOutlives(ref pair) => pair.fmt(f),
152153
ty::Clause::TypeOutlives(ref pair) => pair.fmt(f),

compiler/rustc_trait_selection/src/solve/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
290290
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(predicate)) => {
291291
self.compute_region_outlives_goal(Goal { param_env, predicate })
292292
}
293+
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..)) => {
294+
unimplemented!()
295+
}
293296
ty::PredicateKind::Subtype(predicate) => {
294297
self.compute_subtype_goal(Goal { param_env, predicate })
295298
}

compiler/rustc_trait_selection/src/traits/auto_trait.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
830830
// and these don't correspond to adding any new bounds to
831831
// the `ParamEnv`.
832832
ty::PredicateKind::WellFormed(..)
833+
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
833834
| ty::PredicateKind::AliasEq(..)
834835
| ty::PredicateKind::ObjectSafe(..)
835836
| ty::PredicateKind::ClosureKind(..)

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,11 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
12821282
span,
12831283
"AliasEq predicate should never be the predicate cause of a SelectionError"
12841284
),
1285+
1286+
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..)) => {
1287+
// FIXME: don't know how selection error works so unsure when this is reachable (if it is)
1288+
unimplemented!()
1289+
}
12851290
}
12861291
}
12871292

compiler/rustc_trait_selection/src/traits/fulfill.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
313313
}
314314
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(_))
315315
| ty::PredicateKind::Clause(ty::Clause::TypeOutlives(_))
316+
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
316317
| ty::PredicateKind::WellFormed(_)
317318
| ty::PredicateKind::ObjectSafe(_)
318319
| ty::PredicateKind::ClosureKind(..)
@@ -600,6 +601,9 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
600601
ty::PredicateKind::AliasEq(..) => {
601602
bug!("AliasEq is only used for new solver")
602603
}
604+
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..)) => {
605+
unimplemented!()
606+
}
603607
},
604608
}
605609
}

compiler/rustc_trait_selection/src/traits/object_safety.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@ fn predicate_references_self<'tcx>(
327327
// possible alternatives.
328328
data.projection_ty.substs[1..].iter().any(has_self_ty).then_some(sp)
329329
}
330+
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(_ct, ty)) => {
331+
has_self_ty(&ty.into()).then_some(sp)
332+
}
333+
330334
ty::PredicateKind::AliasEq(..) => bug!("`AliasEq` not allowed as assumption"),
331335

332336
ty::PredicateKind::WellFormed(..)
@@ -362,6 +366,7 @@ fn generics_require_sized_self(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
362366
trait_pred.def_id() == sized_def_id && trait_pred.self_ty().is_param(0)
363367
}
364368
ty::PredicateKind::Clause(ty::Clause::Projection(..))
369+
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
365370
| ty::PredicateKind::Subtype(..)
366371
| ty::PredicateKind::Coerce(..)
367372
| ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..))

compiler/rustc_trait_selection/src/traits/select/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
993993
bug!("AliasEq is only used for new solver")
994994
}
995995
ty::PredicateKind::Ambiguous => Ok(EvaluatedToAmbig),
996+
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..)) => {
997+
unimplemented!()
998+
}
996999
}
9971000
})
9981001
}

compiler/rustc_trait_selection/src/traits/wf.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ pub fn predicate_obligations<'tcx>(
163163
ty::TermKind::Const(c) => c.into(),
164164
})
165165
}
166+
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(ct, ty)) => {
167+
wf.compute(ct.into());
168+
wf.compute(ty.into());
169+
}
166170
ty::PredicateKind::WellFormed(arg) => {
167171
wf.compute(arg);
168172
}
@@ -922,6 +926,7 @@ pub(crate) fn required_region_bounds<'tcx>(
922926
match obligation.predicate.kind().skip_binder() {
923927
ty::PredicateKind::Clause(ty::Clause::Projection(..))
924928
| ty::PredicateKind::Clause(ty::Clause::Trait(..))
929+
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
925930
| ty::PredicateKind::Subtype(..)
926931
| ty::PredicateKind::Coerce(..)
927932
| ty::PredicateKind::WellFormed(..)

compiler/rustc_traits/src/chalk/lowering.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
117117
)),
118118
},
119119
ty::PredicateKind::ObjectSafe(..)
120+
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
120121
| ty::PredicateKind::AliasEq(..)
121122
| ty::PredicateKind::ClosureKind(..)
122123
| ty::PredicateKind::Subtype(..)
@@ -212,6 +213,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predi
212213
// We can defer this, but ultimately we'll want to express
213214
// some of these in terms of chalk operations.
214215
ty::PredicateKind::ClosureKind(..)
216+
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
215217
| ty::PredicateKind::AliasEq(..)
216218
| ty::PredicateKind::Coerce(..)
217219
| ty::PredicateKind::ConstEvaluatable(..)
@@ -646,6 +648,7 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_ir::QuantifiedWhereClause<RustInterner<'
646648
Some(chalk_ir::WhereClause::AliasEq(predicate.lower_into(interner)))
647649
}
648650
ty::PredicateKind::WellFormed(_ty) => None,
651+
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..)) => None,
649652

650653
ty::PredicateKind::ObjectSafe(..)
651654
| ty::PredicateKind::AliasEq(..)
@@ -780,6 +783,7 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_solve::rust_ir::QuantifiedInlineBound<Ru
780783
}
781784
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(_predicate)) => None,
782785
ty::PredicateKind::WellFormed(_ty) => None,
786+
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..)) => None,
783787

784788
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..))
785789
| ty::PredicateKind::AliasEq(..)

compiler/rustc_traits/src/implied_outlives_bounds.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ fn compute_implied_outlives_bounds<'tcx>(
9999
};
100100
match pred {
101101
ty::PredicateKind::Clause(ty::Clause::Trait(..))
102+
// FIXME(const_generics): Make sure that `<'a, 'b, const N: &'a &'b u32>` is sound
103+
// if we ever support that
104+
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
102105
| ty::PredicateKind::Subtype(..)
103106
| ty::PredicateKind::Coerce(..)
104107
| ty::PredicateKind::Clause(ty::Clause::Projection(..))

compiler/rustc_traits/src/normalize_erasing_regions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ fn not_outlives_predicate(p: ty::Predicate<'_>) -> bool {
6060
| ty::PredicateKind::Clause(ty::Clause::TypeOutlives(..)) => false,
6161
ty::PredicateKind::Clause(ty::Clause::Trait(..))
6262
| ty::PredicateKind::Clause(ty::Clause::Projection(..))
63+
| ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..))
6364
| ty::PredicateKind::AliasEq(..)
6465
| ty::PredicateKind::WellFormed(..)
6566
| ty::PredicateKind::ObjectSafe(..)

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ pub(crate) fn clean_predicate<'tcx>(
320320
// FIXME(generic_const_exprs): should this do something?
321321
ty::PredicateKind::ConstEvaluatable(..) => None,
322322
ty::PredicateKind::WellFormed(..) => None,
323+
ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(..)) => None,
323324

324325
ty::PredicateKind::Subtype(..)
325326
| ty::PredicateKind::AliasEq(..)

src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ pub fn is_min_const_fn<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, msrv: &Msrv)
3030
ty::Clause::RegionOutlives(_)
3131
| ty::Clause::TypeOutlives(_)
3232
| ty::Clause::Projection(_)
33-
| ty::Clause::Trait(..),
33+
| ty::Clause::Trait(..)
34+
| ty::Clause::ConstArgHasType(..),
3435
)
3536
| ty::PredicateKind::WellFormed(_)
3637
| ty::PredicateKind::ConstEvaluatable(..)

0 commit comments

Comments
 (0)