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(..)

0 commit comments

Comments
 (0)