Skip to content

Commit 20a4669

Browse files
committed
add in where equality predicate
1 parent eba3228 commit 20a4669

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+458
-21
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,9 +1322,11 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
13221322
generics.span,
13231323
);
13241324

1325-
for predicate in &generics.where_clause.predicates {
1326-
if let WherePredicate::EqPredicate(ref predicate) = *predicate {
1327-
deny_equality_constraints(self, predicate, generics);
1325+
if !self.session.features_untracked().type_equality_constraints {
1326+
for predicate in &generics.where_clause.predicates {
1327+
if let WherePredicate::EqPredicate(ref predicate) = *predicate {
1328+
deny_equality_constraints(self, predicate, generics);
1329+
}
13281330
}
13291331
}
13301332
walk_list!(self, visit_generic_param, &generics.params);
@@ -1546,6 +1548,9 @@ fn deny_equality_constraints(
15461548
predicate.span,
15471549
"equality constraints are not yet supported in `where` clauses",
15481550
);
1551+
if this.session.is_nightly_build() {
1552+
err.help("add `#![feature(type_equality_constraints)]` to the crate attributes to enable");
1553+
}
15491554
err.span_label(predicate.span, "not supported");
15501555

15511556
// Given `<A as Foo>::Bar = RhsTy`, suggest `A: Foo<Bar = RhsTy>`.

compiler/rustc_feature/src/active.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,9 @@ declare_features! (
680680
/// Allows `#[derive(Default)]` and `#[default]` on enums.
681681
(active, derive_default_enum, "1.56.0", Some(86985), None),
682682

683+
/// Allows `where T = U` in where predicates.
684+
(active, type_equality_constraints, "1.56.0", Some(87533), None),
685+
683686
// -------------------------------------------------------------------------
684687
// feature-group-end: actual feature gates
685688
// -------------------------------------------------------------------------

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub fn explicit_outlives_bounds<'tcx>(
2626
| ty::PredicateKind::TypeOutlives(..)
2727
| ty::PredicateKind::ConstEvaluatable(..)
2828
| ty::PredicateKind::ConstEquate(..)
29+
| ty::PredicateKind::TypeEquate(..)
2930
| ty::PredicateKind::TypeWellFormedFromEnv(..) => None,
3031
ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(r_a, r_b)) => {
3132
Some(OutlivesBound::RegionSubRegion(r_b, r_a))

compiler/rustc_infer/src/traits/util.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ impl Elaborator<'tcx> {
172172
// Currently, we do not elaborate const-equate
173173
// predicates.
174174
}
175+
ty::PredicateKind::TypeEquate(..) => {
176+
// Currently, we do not elaborate type-equate
177+
// predicates.
178+
}
175179
ty::PredicateKind::RegionOutlives(..) => {
176180
// Nothing to elaborate from `'a: 'b`.
177181
}

compiler/rustc_lint/src/builtin.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,6 +1612,7 @@ impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
16121612
Subtype(..) |
16131613
ConstEvaluatable(..) |
16141614
ConstEquate(..) |
1615+
TypeEquate(..) |
16151616
TypeWellFormedFromEnv(..) => continue,
16161617
};
16171618
if predicate.is_global() {

compiler/rustc_middle/src/ty/flags.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ impl FlagComputation {
252252
ty::PredicateKind::TypeWellFormedFromEnv(ty) => {
253253
self.add_ty(ty);
254254
}
255+
ty::PredicateKind::TypeEquate(lhs, rhs) => {
256+
self.add_ty(lhs);
257+
self.add_ty(rhs);
258+
}
255259
}
256260
}
257261

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,9 @@ pub enum PredicateKind<'tcx> {
492492
///
493493
/// Only used for Chalk.
494494
TypeWellFormedFromEnv(Ty<'tcx>),
495+
496+
/// `where T = U`
497+
TypeEquate(Ty<'tcx>, Ty<'tcx>),
495498
}
496499

497500
/// The crate outlives map is computed during typeck and contains the
@@ -800,6 +803,7 @@ impl<'tcx> Predicate<'tcx> {
800803
| PredicateKind::TypeOutlives(..)
801804
| PredicateKind::ConstEvaluatable(..)
802805
| PredicateKind::ConstEquate(..)
806+
| PredicateKind::TypeEquate(..)
803807
| PredicateKind::TypeWellFormedFromEnv(..) => None,
804808
}
805809
}
@@ -817,6 +821,7 @@ impl<'tcx> Predicate<'tcx> {
817821
| PredicateKind::ClosureKind(..)
818822
| PredicateKind::ConstEvaluatable(..)
819823
| PredicateKind::ConstEquate(..)
824+
| PredicateKind::TypeEquate(..)
820825
| PredicateKind::TypeWellFormedFromEnv(..) => None,
821826
}
822827
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,6 +2292,9 @@ define_print_and_forward_display! {
22922292
ty::PredicateKind::TypeWellFormedFromEnv(ty) => {
22932293
p!("the type `", print(ty), "` is found in the environment")
22942294
}
2295+
ty::PredicateKind::TypeEquate(lhs, rhs) => {
2296+
p!("the type `", print(lhs), "` equals `", print(rhs), "`")
2297+
}
22952298
}
22962299
}
22972300

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ impl fmt::Debug for ty::PredicateKind<'tcx> {
198198
ty::PredicateKind::TypeWellFormedFromEnv(ty) => {
199199
write!(f, "TypeWellFormedFromEnv({:?})", ty)
200200
}
201+
ty::PredicateKind::TypeEquate(lhs, rhs) => {
202+
write!(f, "TypeEquate({:?}, {:?})", lhs, rhs)
203+
}
201204
}
202205
}
203206
}
@@ -450,6 +453,9 @@ impl<'a, 'tcx> Lift<'tcx> for ty::PredicateKind<'a> {
450453
ty::PredicateKind::TypeWellFormedFromEnv(ty) => {
451454
tcx.lift(ty).map(ty::PredicateKind::TypeWellFormedFromEnv)
452455
}
456+
ty::PredicateKind::TypeEquate(lhs, rhs) => {
457+
tcx.lift((lhs, rhs)).map(|(lhs, rhs)| ty::PredicateKind::TypeEquate(lhs, rhs))
458+
}
453459
}
454460
}
455461
}

compiler/rustc_mir/src/transform/check_consts/check.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ impl Checker<'mir, 'tcx> {
413413
| ty::PredicateKind::Projection(_)
414414
| ty::PredicateKind::ConstEvaluatable(..)
415415
| ty::PredicateKind::ConstEquate(..)
416+
| ty::PredicateKind::TypeEquate(..)
416417
| ty::PredicateKind::TypeWellFormedFromEnv(..) => continue,
417418
ty::PredicateKind::ObjectSafe(_) => {
418419
bug!("object safe predicate on function: {:#?}", predicate)

0 commit comments

Comments
 (0)