|
1 | 1 | use rustc_data_structures::captures::Captures;
|
2 | 2 | use rustc_data_structures::intern::Interned;
|
3 | 3 | use rustc_hir::def_id::DefId;
|
4 |
| -use rustc_macros::{HashStable, Lift, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable}; |
5 |
| -use rustc_type_ir::ClauseKind as IrClauseKind; |
6 |
| -use rustc_type_ir::CoercePredicate as IrCoercePredicate; |
7 |
| -use rustc_type_ir::ExistentialProjection as IrExistentialProjection; |
8 |
| -use rustc_type_ir::ExistentialTraitRef as IrExistentialTraitRef; |
9 |
| -use rustc_type_ir::NormalizesTo as IrNormalizesTo; |
10 |
| -use rustc_type_ir::PredicateKind as IrPredicateKind; |
11 |
| -use rustc_type_ir::ProjectionPredicate as IrProjectionPredicate; |
12 |
| -use rustc_type_ir::SubtypePredicate as IrSubtypePredicate; |
13 |
| -use rustc_type_ir::TraitPredicate as IrTraitPredicate; |
14 |
| -use rustc_type_ir::TraitRef as IrTraitRef; |
| 4 | +use rustc_macros::{ |
| 5 | + extension, HashStable, Lift, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable, |
| 6 | +}; |
| 7 | +use rustc_type_ir as ir; |
15 | 8 | use std::cmp::Ordering;
|
16 | 9 |
|
17 | 10 | use crate::ty::{
|
18 |
| - self, Binder, DebruijnIndex, DebugWithInfcx, EarlyBinder, PredicatePolarity, Term, Ty, TyCtxt, |
19 |
| - TypeFlags, WithCachedTypeInfo, |
| 11 | + self, Binder, DebruijnIndex, EarlyBinder, PredicatePolarity, Term, Ty, TyCtxt, TypeFlags, |
| 12 | + WithCachedTypeInfo, |
20 | 13 | };
|
21 | 14 |
|
22 |
| -pub type TraitRef<'tcx> = IrTraitRef<TyCtxt<'tcx>>; |
23 |
| -pub type ProjectionPredicate<'tcx> = IrProjectionPredicate<TyCtxt<'tcx>>; |
24 |
| -pub type ExistentialTraitRef<'tcx> = IrExistentialTraitRef<TyCtxt<'tcx>>; |
25 |
| -pub type ExistentialProjection<'tcx> = IrExistentialProjection<TyCtxt<'tcx>>; |
26 |
| -pub type TraitPredicate<'tcx> = IrTraitPredicate<TyCtxt<'tcx>>; |
27 |
| -pub type ClauseKind<'tcx> = IrClauseKind<TyCtxt<'tcx>>; |
28 |
| -pub type PredicateKind<'tcx> = IrPredicateKind<TyCtxt<'tcx>>; |
29 |
| -pub type NormalizesTo<'tcx> = IrNormalizesTo<TyCtxt<'tcx>>; |
30 |
| -pub type CoercePredicate<'tcx> = IrCoercePredicate<TyCtxt<'tcx>>; |
31 |
| -pub type SubtypePredicate<'tcx> = IrSubtypePredicate<TyCtxt<'tcx>>; |
| 15 | +pub type TraitRef<'tcx> = ir::TraitRef<TyCtxt<'tcx>>; |
| 16 | +pub type ProjectionPredicate<'tcx> = ir::ProjectionPredicate<TyCtxt<'tcx>>; |
| 17 | +pub type ExistentialPredicate<'tcx> = ir::ExistentialPredicate<TyCtxt<'tcx>>; |
| 18 | +pub type ExistentialTraitRef<'tcx> = ir::ExistentialTraitRef<TyCtxt<'tcx>>; |
| 19 | +pub type ExistentialProjection<'tcx> = ir::ExistentialProjection<TyCtxt<'tcx>>; |
| 20 | +pub type TraitPredicate<'tcx> = ir::TraitPredicate<TyCtxt<'tcx>>; |
| 21 | +pub type ClauseKind<'tcx> = ir::ClauseKind<TyCtxt<'tcx>>; |
| 22 | +pub type PredicateKind<'tcx> = ir::PredicateKind<TyCtxt<'tcx>>; |
| 23 | +pub type NormalizesTo<'tcx> = ir::NormalizesTo<TyCtxt<'tcx>>; |
| 24 | +pub type CoercePredicate<'tcx> = ir::CoercePredicate<TyCtxt<'tcx>>; |
| 25 | +pub type SubtypePredicate<'tcx> = ir::SubtypePredicate<TyCtxt<'tcx>>; |
32 | 26 |
|
33 | 27 | /// A statement that can be proven by a trait solver. This includes things that may
|
34 | 28 | /// show up in where clauses, such as trait predicates and projection predicates,
|
@@ -207,43 +201,25 @@ impl<'tcx> Clause<'tcx> {
|
207 | 201 | }
|
208 | 202 | }
|
209 | 203 |
|
210 |
| -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] |
211 |
| -#[derive(HashStable, TypeFoldable, TypeVisitable, Lift)] |
212 |
| -pub enum ExistentialPredicate<'tcx> { |
213 |
| - /// E.g., `Iterator`. |
214 |
| - Trait(ExistentialTraitRef<'tcx>), |
215 |
| - /// E.g., `Iterator::Item = T`. |
216 |
| - Projection(ExistentialProjection<'tcx>), |
217 |
| - /// E.g., `Send`. |
218 |
| - AutoTrait(DefId), |
219 |
| -} |
220 |
| - |
221 |
| -impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ExistentialPredicate<'tcx> { |
222 |
| - fn fmt<Infcx: rustc_type_ir::InferCtxtLike<Interner = TyCtxt<'tcx>>>( |
223 |
| - this: rustc_type_ir::WithInfcx<'_, Infcx, &Self>, |
224 |
| - f: &mut std::fmt::Formatter<'_>, |
225 |
| - ) -> std::fmt::Result { |
226 |
| - std::fmt::Debug::fmt(&this.data, f) |
227 |
| - } |
228 |
| -} |
229 |
| - |
| 204 | +#[extension(pub trait ExistentialPredicateStableCmpExt<'tcx>)] |
230 | 205 | impl<'tcx> ExistentialPredicate<'tcx> {
|
231 | 206 | /// Compares via an ordering that will not change if modules are reordered or other changes are
|
232 | 207 | /// made to the tree. In particular, this ordering is preserved across incremental compilations.
|
233 |
| - pub fn stable_cmp(&self, tcx: TyCtxt<'tcx>, other: &Self) -> Ordering { |
234 |
| - use self::ExistentialPredicate::*; |
| 208 | + fn stable_cmp(&self, tcx: TyCtxt<'tcx>, other: &Self) -> Ordering { |
235 | 209 | match (*self, *other) {
|
236 |
| - (Trait(_), Trait(_)) => Ordering::Equal, |
237 |
| - (Projection(ref a), Projection(ref b)) => { |
| 210 | + (ExistentialPredicate::Trait(_), ExistentialPredicate::Trait(_)) => Ordering::Equal, |
| 211 | + (ExistentialPredicate::Projection(ref a), ExistentialPredicate::Projection(ref b)) => { |
238 | 212 | tcx.def_path_hash(a.def_id).cmp(&tcx.def_path_hash(b.def_id))
|
239 | 213 | }
|
240 |
| - (AutoTrait(ref a), AutoTrait(ref b)) => { |
| 214 | + (ExistentialPredicate::AutoTrait(ref a), ExistentialPredicate::AutoTrait(ref b)) => { |
241 | 215 | tcx.def_path_hash(*a).cmp(&tcx.def_path_hash(*b))
|
242 | 216 | }
|
243 |
| - (Trait(_), _) => Ordering::Less, |
244 |
| - (Projection(_), Trait(_)) => Ordering::Greater, |
245 |
| - (Projection(_), _) => Ordering::Less, |
246 |
| - (AutoTrait(_), _) => Ordering::Greater, |
| 217 | + (ExistentialPredicate::Trait(_), _) => Ordering::Less, |
| 218 | + (ExistentialPredicate::Projection(_), ExistentialPredicate::Trait(_)) => { |
| 219 | + Ordering::Greater |
| 220 | + } |
| 221 | + (ExistentialPredicate::Projection(_), _) => Ordering::Less, |
| 222 | + (ExistentialPredicate::AutoTrait(_), _) => Ordering::Greater, |
247 | 223 | }
|
248 | 224 | }
|
249 | 225 | }
|
|
0 commit comments