Skip to content

Commit 23ab246

Browse files
committed
add AliasEq to PredicateKind
1 parent 9b8dbd5 commit 23ab246

File tree

25 files changed

+80
-5
lines changed

25 files changed

+80
-5
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1328,6 +1328,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
13281328
ty::Clause::RegionOutlives(_) => bug!(),
13291329
},
13301330
ty::PredicateKind::WellFormed(_)
1331+
| ty::PredicateKind::AliasEq(..)
13311332
| ty::PredicateKind::ObjectSafe(_)
13321333
| ty::PredicateKind::ClosureKind(_, _, _)
13331334
| ty::PredicateKind::Subtype(_)

compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs

+1
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::AliasEq(..)
520521
| ty::PredicateKind::WellFormed(_)
521522
| ty::PredicateKind::Subtype(_)
522523
| ty::PredicateKind::Coerce(_)

compiler/rustc_hir_analysis/src/outlives/explicit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> {
5555
ty::PredicateKind::Clause(ty::Clause::Trait(..))
5656
| ty::PredicateKind::Clause(ty::Clause::Projection(..))
5757
| ty::PredicateKind::WellFormed(..)
58+
| ty::PredicateKind::AliasEq(..)
5859
| ty::PredicateKind::ObjectSafe(..)
5960
| ty::PredicateKind::ClosureKind(..)
6061
| ty::PredicateKind::Subtype(..)

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+1
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
669669
| ty::PredicateKind::Clause(ty::Clause::TypeOutlives(..))
670670
| ty::PredicateKind::WellFormed(..)
671671
| ty::PredicateKind::ObjectSafe(..)
672+
| ty::PredicateKind::AliasEq(..)
672673
| ty::PredicateKind::ConstEvaluatable(..)
673674
| ty::PredicateKind::ConstEquate(..)
674675
// N.B., this predicate is created by breaking down a

compiler/rustc_hir_typeck/src/method/probe.rs

+1
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
837837
| ty::PredicateKind::ConstEvaluatable(..)
838838
| ty::PredicateKind::ConstEquate(..)
839839
| ty::PredicateKind::Ambiguous
840+
| ty::PredicateKind::AliasEq(..)
840841
| ty::PredicateKind::TypeWellFormedFromEnv(..) => None,
841842
}
842843
});

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

+1
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::AliasEq(..)
2425
| ty::PredicateKind::Coerce(..)
2526
| ty::PredicateKind::Subtype(..)
2627
| ty::PredicateKind::WellFormed(..)

compiler/rustc_infer/src/traits/util.rs

+3
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,9 @@ impl<'tcx> Elaborator<'tcx> {
294294
// Nothing to elaborate
295295
}
296296
ty::PredicateKind::Ambiguous => {}
297+
ty::PredicateKind::AliasEq(..) => {
298+
// No
299+
}
297300
}
298301
}
299302
}

compiler/rustc_lint/src/builtin.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1594,12 +1594,14 @@ impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
15941594
// Ignore projections, as they can only be global
15951595
// if the trait bound is global
15961596
Clause(Clause::Projection(..)) |
1597+
AliasEq(..) |
15971598
// Ignore bounds that a user can't type
15981599
WellFormed(..) |
15991600
ObjectSafe(..) |
16001601
ClosureKind(..) |
16011602
Subtype(..) |
16021603
Coerce(..) |
1604+
// FIXME(generic_const_exprs): `ConstEvaluatable` can be written
16031605
ConstEvaluatable(..) |
16041606
ConstEquate(..) |
16051607
Ambiguous |

compiler/rustc_middle/src/ty/flags.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,7 @@ impl FlagComputation {
264264
term,
265265
})) => {
266266
self.add_projection_ty(projection_ty);
267-
match term.unpack() {
268-
ty::TermKind::Ty(ty) => self.add_ty(ty),
269-
ty::TermKind::Const(c) => self.add_const(c),
270-
}
267+
self.add_term(term);
271268
}
272269
ty::PredicateKind::WellFormed(arg) => {
273270
self.add_substs(slice::from_ref(&arg));
@@ -287,6 +284,10 @@ impl FlagComputation {
287284
self.add_ty(ty);
288285
}
289286
ty::PredicateKind::Ambiguous => {}
287+
ty::PredicateKind::AliasEq(t1, t2) => {
288+
self.add_term(t1);
289+
self.add_term(t2);
290+
}
290291
}
291292
}
292293

@@ -380,4 +381,11 @@ impl FlagComputation {
380381
}
381382
}
382383
}
384+
385+
fn add_term(&mut self, term: ty::Term<'_>) {
386+
match term.unpack() {
387+
ty::TermKind::Ty(ty) => self.add_ty(ty),
388+
ty::TermKind::Const(ct) => self.add_const(ct),
389+
}
390+
}
383391
}

compiler/rustc_middle/src/ty/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ impl<'tcx> Predicate<'tcx> {
545545
| PredicateKind::Clause(Clause::RegionOutlives(_))
546546
| PredicateKind::Clause(Clause::TypeOutlives(_))
547547
| PredicateKind::Clause(Clause::Projection(_))
548+
| PredicateKind::AliasEq(..)
548549
| PredicateKind::ObjectSafe(_)
549550
| PredicateKind::ClosureKind(_, _, _)
550551
| PredicateKind::Subtype(_)
@@ -632,6 +633,12 @@ pub enum PredicateKind<'tcx> {
632633
/// A marker predicate that is always ambiguous.
633634
/// Used for coherence to mark opaque types as possibly equal to each other but ambiguous.
634635
Ambiguous,
636+
637+
/// Separate from `Clause::Projection` which is used for normalization in new solver.
638+
/// This predicate requires two terms to be equal to eachother.
639+
///
640+
/// Only used for new solver
641+
AliasEq(Term<'tcx>, Term<'tcx>),
635642
}
636643

637644
/// The crate outlives map is computed during typeck and contains the
@@ -1152,6 +1159,7 @@ impl<'tcx> Predicate<'tcx> {
11521159
match predicate.skip_binder() {
11531160
PredicateKind::Clause(Clause::Trait(t)) => Some(predicate.rebind(t)),
11541161
PredicateKind::Clause(Clause::Projection(..))
1162+
| PredicateKind::AliasEq(..)
11551163
| PredicateKind::Subtype(..)
11561164
| PredicateKind::Coerce(..)
11571165
| PredicateKind::Clause(Clause::RegionOutlives(..))
@@ -1171,6 +1179,7 @@ impl<'tcx> Predicate<'tcx> {
11711179
match predicate.skip_binder() {
11721180
PredicateKind::Clause(Clause::Projection(t)) => Some(predicate.rebind(t)),
11731181
PredicateKind::Clause(Clause::Trait(..))
1182+
| PredicateKind::AliasEq(..)
11741183
| PredicateKind::Subtype(..)
11751184
| PredicateKind::Coerce(..)
11761185
| PredicateKind::Clause(Clause::RegionOutlives(..))
@@ -1191,6 +1200,7 @@ impl<'tcx> Predicate<'tcx> {
11911200
PredicateKind::Clause(Clause::TypeOutlives(data)) => Some(predicate.rebind(data)),
11921201
PredicateKind::Clause(Clause::Trait(..))
11931202
| PredicateKind::Clause(Clause::Projection(..))
1203+
| PredicateKind::AliasEq(..)
11941204
| PredicateKind::Subtype(..)
11951205
| PredicateKind::Coerce(..)
11961206
| PredicateKind::Clause(Clause::RegionOutlives(..))

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

+1
Original file line numberDiff line numberDiff line change
@@ -2841,6 +2841,7 @@ define_print_and_forward_display! {
28412841
p!("the type `", print(ty), "` is found in the environment")
28422842
}
28432843
ty::PredicateKind::Ambiguous => p!("ambiguous"),
2844+
ty::PredicateKind::AliasEq(t1, t2) => p!(print(t1), " == ", print(t2)),
28442845
}
28452846
}
28462847

compiler/rustc_middle/src/ty/structural_impls.rs

+1
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ impl<'tcx> fmt::Debug for ty::PredicateKind<'tcx> {
177177
write!(f, "TypeWellFormedFromEnv({:?})", ty)
178178
}
179179
ty::PredicateKind::Ambiguous => write!(f, "Ambiguous"),
180+
ty::PredicateKind::AliasEq(t1, t2) => write!(f, "AliasEq({t1:?}, {t2:?})"),
180181
}
181182
}
182183
}

compiler/rustc_trait_selection/src/solve/fulfill.rs

+5
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentCtxt<'tcx> {
7373
MismatchedProjectionTypes { err: TypeError::Mismatch },
7474
)
7575
}
76+
ty::PredicateKind::AliasEq(_, _) => {
77+
FulfillmentErrorCode::CodeProjectionError(
78+
MismatchedProjectionTypes { err: TypeError::Mismatch },
79+
)
80+
}
7681
ty::PredicateKind::Subtype(pred) => {
7782
let (a, b) = infcx.instantiate_binder_with_placeholders(
7883
goal.predicate.kind().rebind((pred.a, pred.b)),

compiler/rustc_trait_selection/src/solve/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
302302
ty::PredicateKind::TypeWellFormedFromEnv(..) => {
303303
bug!("TypeWellFormedFromEnv is only used for Chalk")
304304
}
305+
ty::PredicateKind::AliasEq(..) => {
306+
// FIXME(deferred_projection_equality)
307+
todo!()
308+
}
305309
}
306310
} else {
307311
let kind = self.infcx.instantiate_binder_with_placeholders(kind);

compiler/rustc_trait_selection/src/traits/auto_trait.rs

+3
Original file line numberDiff line numberDiff line change
@@ -823,14 +823,17 @@ impl<'tcx> AutoTraitFinder<'tcx> {
823823
_ => return false,
824824
}
825825
}
826+
826827
// There's not really much we can do with these predicates -
827828
// we start out with a `ParamEnv` with no inference variables,
828829
// and these don't correspond to adding any new bounds to
829830
// the `ParamEnv`.
830831
ty::PredicateKind::WellFormed(..)
832+
| ty::PredicateKind::AliasEq(..)
831833
| ty::PredicateKind::ObjectSafe(..)
832834
| ty::PredicateKind::ClosureKind(..)
833835
| ty::PredicateKind::Subtype(..)
836+
// FIXME(generic_const_exprs): you can absolutely add this as a where clauses
834837
| ty::PredicateKind::ConstEvaluatable(..)
835838
| ty::PredicateKind::Coerce(..)
836839
| ty::PredicateKind::TypeWellFormedFromEnv(..) => {}

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

+5
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,11 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
12781278
span,
12791279
"TypeWellFormedFromEnv predicate should only exist in the environment"
12801280
),
1281+
1282+
ty::PredicateKind::AliasEq(..) => span_bug!(
1283+
span,
1284+
"AliasEq predicate should never be the predicate cause of a SelectionError"
1285+
),
12811286
}
12821287
}
12831288

compiler/rustc_trait_selection/src/traits/fulfill.rs

+6
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
328328
ty::PredicateKind::TypeWellFormedFromEnv(..) => {
329329
bug!("TypeWellFormedFromEnv is only used for Chalk")
330330
}
331+
ty::PredicateKind::AliasEq(..) => {
332+
bug!("AliasEq is only used for new solver")
333+
}
331334
},
332335
Some(pred) => match pred {
333336
ty::PredicateKind::Clause(ty::Clause::Trait(data)) => {
@@ -594,6 +597,9 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
594597
ty::PredicateKind::TypeWellFormedFromEnv(..) => {
595598
bug!("TypeWellFormedFromEnv is only used for Chalk")
596599
}
600+
ty::PredicateKind::AliasEq(..) => {
601+
bug!("AliasEq is only used for new solver")
602+
}
597603
},
598604
}
599605
}

compiler/rustc_trait_selection/src/traits/object_safety.rs

+4
Original file line numberDiff line numberDiff line change
@@ -327,13 +327,16 @@ fn predicate_references_self<'tcx>(
327327
// possible alternatives.
328328
if data.projection_ty.substs[1..].iter().any(has_self_ty) { Some(sp) } else { None }
329329
}
330+
ty::PredicateKind::AliasEq(..) => bug!("`AliasEq` not allowed as assumption"),
331+
330332
ty::PredicateKind::WellFormed(..)
331333
| ty::PredicateKind::ObjectSafe(..)
332334
| ty::PredicateKind::Clause(ty::Clause::TypeOutlives(..))
333335
| ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..))
334336
| ty::PredicateKind::ClosureKind(..)
335337
| ty::PredicateKind::Subtype(..)
336338
| ty::PredicateKind::Coerce(..)
339+
// FIXME(generic_const_exprs): this can mention `Self`
337340
| ty::PredicateKind::ConstEvaluatable(..)
338341
| ty::PredicateKind::ConstEquate(..)
339342
| ty::PredicateKind::Ambiguous
@@ -368,6 +371,7 @@ fn generics_require_sized_self(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
368371
| ty::PredicateKind::Clause(ty::Clause::TypeOutlives(..))
369372
| ty::PredicateKind::ConstEvaluatable(..)
370373
| ty::PredicateKind::ConstEquate(..)
374+
| ty::PredicateKind::AliasEq(..)
371375
| ty::PredicateKind::Ambiguous
372376
| ty::PredicateKind::TypeWellFormedFromEnv(..) => false,
373377
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
991991
ty::PredicateKind::TypeWellFormedFromEnv(..) => {
992992
bug!("TypeWellFormedFromEnv is only used for chalk")
993993
}
994+
ty::PredicateKind::AliasEq(..) => {
995+
bug!("AliasEq is only used for new solver")
996+
}
994997
ty::PredicateKind::Ambiguous => Ok(EvaluatedToAmbig),
995998
}
996999
})

compiler/rustc_trait_selection/src/traits/wf.rs

+4
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ pub fn predicate_obligations<'tcx>(
187187
ty::PredicateKind::TypeWellFormedFromEnv(..) => {
188188
bug!("TypeWellFormedFromEnv is only used for Chalk")
189189
}
190+
ty::PredicateKind::AliasEq(..) => {
191+
bug!("We should only wf check where clauses and `AliasEq` is not a `Clause`")
192+
}
190193
}
191194

192195
wf.normalize(infcx)
@@ -928,6 +931,7 @@ pub(crate) fn required_region_bounds<'tcx>(
928931
| ty::PredicateKind::ConstEvaluatable(..)
929932
| ty::PredicateKind::ConstEquate(..)
930933
| ty::PredicateKind::Ambiguous
934+
| ty::PredicateKind::AliasEq(..)
931935
| ty::PredicateKind::TypeWellFormedFromEnv(..) => None,
932936
ty::PredicateKind::Clause(ty::Clause::TypeOutlives(ty::OutlivesPredicate(
933937
ref t,

compiler/rustc_traits/src/chalk/lowering.rs

+4
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
116116
)),
117117
},
118118
ty::PredicateKind::ObjectSafe(..)
119+
| ty::PredicateKind::AliasEq(..)
119120
| ty::PredicateKind::ClosureKind(..)
120121
| ty::PredicateKind::Subtype(..)
121122
| ty::PredicateKind::Coerce(..)
@@ -210,6 +211,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predi
210211
// We can defer this, but ultimately we'll want to express
211212
// some of these in terms of chalk operations.
212213
ty::PredicateKind::ClosureKind(..)
214+
| ty::PredicateKind::AliasEq(..)
213215
| ty::PredicateKind::Coerce(..)
214216
| ty::PredicateKind::ConstEvaluatable(..)
215217
| ty::PredicateKind::Ambiguous
@@ -642,6 +644,7 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_ir::QuantifiedWhereClause<RustInterner<'
642644
ty::PredicateKind::WellFormed(_ty) => None,
643645

644646
ty::PredicateKind::ObjectSafe(..)
647+
| ty::PredicateKind::AliasEq(..)
645648
| ty::PredicateKind::ClosureKind(..)
646649
| ty::PredicateKind::Subtype(..)
647650
| ty::PredicateKind::Coerce(..)
@@ -775,6 +778,7 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_solve::rust_ir::QuantifiedInlineBound<Ru
775778
ty::PredicateKind::WellFormed(_ty) => None,
776779

777780
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..))
781+
| ty::PredicateKind::AliasEq(..)
778782
| ty::PredicateKind::ObjectSafe(..)
779783
| ty::PredicateKind::ClosureKind(..)
780784
| ty::PredicateKind::Subtype(..)

compiler/rustc_traits/src/implied_outlives_bounds.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ fn compute_implied_outlives_bounds<'tcx>(
8585
// learn anything new from those.
8686
if obligation.predicate.has_non_region_infer() {
8787
match obligation.predicate.kind().skip_binder() {
88-
ty::PredicateKind::Clause(ty::Clause::Projection(..)) => {
88+
ty::PredicateKind::Clause(ty::Clause::Projection(..))
89+
| ty::PredicateKind::AliasEq(..) => {
8990
ocx.register_obligation(obligation.clone());
9091
}
9192
_ => {}
@@ -106,6 +107,7 @@ fn compute_implied_outlives_bounds<'tcx>(
106107
| ty::PredicateKind::ConstEvaluatable(..)
107108
| ty::PredicateKind::ConstEquate(..)
108109
| ty::PredicateKind::Ambiguous
110+
| ty::PredicateKind::AliasEq(..)
109111
| ty::PredicateKind::TypeWellFormedFromEnv(..) => {}
110112

111113
// We need to search through *all* WellFormed predicates

compiler/rustc_traits/src/normalize_erasing_regions.rs

+1
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::AliasEq(..)
6364
| ty::PredicateKind::WellFormed(..)
6465
| ty::PredicateKind::ObjectSafe(..)
6566
| ty::PredicateKind::ClosureKind(..)

src/librustdoc/clean/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,12 @@ pub(crate) fn clean_predicate<'tcx>(
310310
ty::PredicateKind::Clause(ty::Clause::Projection(pred)) => {
311311
Some(clean_projection_predicate(bound_predicate.rebind(pred), cx))
312312
}
313+
// FIXME(generic_const_exprs): should this do something?
313314
ty::PredicateKind::ConstEvaluatable(..) => None,
314315
ty::PredicateKind::WellFormed(..) => None,
315316

316317
ty::PredicateKind::Subtype(..)
318+
| ty::PredicateKind::AliasEq(..)
317319
| ty::PredicateKind::Coerce(..)
318320
| ty::PredicateKind::ObjectSafe(..)
319321
| ty::PredicateKind::ClosureKind(..)

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

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub fn is_min_const_fn<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, msrv: &Msrv)
3636
| ty::PredicateKind::ConstEvaluatable(..)
3737
| ty::PredicateKind::ConstEquate(..)
3838
| ty::PredicateKind::TypeWellFormedFromEnv(..) => continue,
39+
ty::PredicateKind::AliasEq(..) => panic!("alias eq predicate on function: {predicate:#?}"),
3940
ty::PredicateKind::ObjectSafe(_) => panic!("object safe predicate on function: {predicate:#?}"),
4041
ty::PredicateKind::ClosureKind(..) => panic!("closure kind predicate on function: {predicate:#?}"),
4142
ty::PredicateKind::Subtype(_) => panic!("subtype predicate on function: {predicate:#?}"),

0 commit comments

Comments
 (0)