Skip to content

Commit 1c8230e

Browse files
Uplift OutlivesPredicate, remove a bunch of unnecessary associated types from Interner
1 parent 28ce588 commit 1c8230e

File tree

15 files changed

+79
-75
lines changed

15 files changed

+79
-75
lines changed

compiler/rustc_borrowck/src/type_check/constraint_conversion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
136136

137137
fn convert(
138138
&mut self,
139-
predicate: ty::OutlivesPredicate<ty::GenericArg<'tcx>, ty::Region<'tcx>>,
139+
predicate: ty::OutlivesPredicate<'tcx, ty::GenericArg<'tcx>>,
140140
constraint_category: ConstraintCategory<'tcx>,
141141
) {
142142
debug!("generate: constraints at: {:#?}", self.locations);
@@ -276,7 +276,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
276276
&self,
277277
ty: Ty<'tcx>,
278278
next_outlives_predicates: &mut Vec<(
279-
ty::OutlivesPredicate<ty::GenericArg<'tcx>, ty::Region<'tcx>>,
279+
ty::OutlivesPredicate<'tcx, ty::GenericArg<'tcx>>,
280280
ConstraintCategory<'tcx>,
281281
)>,
282282
) -> Ty<'tcx> {

compiler/rustc_hir_analysis/src/outlives/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use smallvec::smallvec;
99
/// Tracks the `T: 'a` or `'a: 'a` predicates that we have inferred
1010
/// must be added to the struct header.
1111
pub(crate) type RequiredPredicates<'tcx> =
12-
FxIndexMap<ty::OutlivesPredicate<GenericArg<'tcx>, ty::Region<'tcx>>, Span>;
12+
FxIndexMap<ty::OutlivesPredicate<'tcx, ty::GenericArg<'tcx>>, Span>;
1313

1414
/// Given a requirement `T: 'a` or `'b: 'a`, deduce the
1515
/// outlives_component and add it to `required_predicates`

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ struct OutlivesEnvironmentBuilder<'tcx> {
6464
/// "Region-bound pairs" tracks outlives relations that are known to
6565
/// be true, either because of explicit where-clauses like `T: 'a` or
6666
/// because of implied bounds.
67-
pub type RegionBoundPairs<'tcx> =
68-
FxIndexSet<ty::OutlivesPredicate<GenericKind<'tcx>, Region<'tcx>>>;
67+
pub type RegionBoundPairs<'tcx> = FxIndexSet<ty::OutlivesPredicate<'tcx, GenericKind<'tcx>>>;
6968

7069
impl<'tcx> OutlivesEnvironment<'tcx> {
7170
/// Create a builder using `ParamEnv` and add explicit outlives bounds into it.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
9494
pub fn approx_declared_bounds_from_env(
9595
&self,
9696
alias_ty: ty::AliasTy<'tcx>,
97-
) -> Vec<ty::Binder<'tcx, ty::OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>>> {
97+
) -> Vec<ty::PolyTypeOutlivesPredicate<'tcx>> {
9898
let erased_alias_ty = self.tcx.erase_regions(alias_ty.to_ty(self.tcx));
9999
self.declared_generic_bounds_from_env_for_erased_ty(erased_alias_ty)
100100
}
@@ -193,7 +193,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
193193
fn declared_generic_bounds_from_env(
194194
&self,
195195
generic_ty: Ty<'tcx>,
196-
) -> Vec<ty::Binder<'tcx, ty::OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>>> {
196+
) -> Vec<ty::PolyTypeOutlivesPredicate<'tcx>> {
197197
assert!(matches!(generic_ty.kind(), ty::Param(_) | ty::Placeholder(_)));
198198
self.declared_generic_bounds_from_env_for_erased_ty(generic_ty)
199199
}
@@ -213,7 +213,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
213213
fn declared_generic_bounds_from_env_for_erased_ty(
214214
&self,
215215
erased_ty: Ty<'tcx>,
216-
) -> Vec<ty::Binder<'tcx, ty::OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>>> {
216+
) -> Vec<ty::PolyTypeOutlivesPredicate<'tcx>> {
217217
let tcx = self.tcx;
218218

219219
// To start, collect bounds from user environment. Note that

compiler/rustc_middle/src/infer/canonical.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use std::collections::hash_map::Entry;
3232
use crate::infer::MemberConstraint;
3333
use crate::mir::ConstraintCategory;
3434
use crate::ty::GenericArg;
35-
use crate::ty::{self, List, Region, Ty, TyCtxt, TypeFlags, TypeVisitableExt};
35+
use crate::ty::{self, List, Ty, TyCtxt, TypeFlags, TypeVisitableExt};
3636

3737
pub type Canonical<'tcx, V> = ir::Canonical<TyCtxt<'tcx>, V>;
3838
pub type CanonicalVarInfo<'tcx> = ir::CanonicalVarInfo<TyCtxt<'tcx>>;
@@ -141,7 +141,7 @@ impl<'tcx, R> QueryResponse<'tcx, R> {
141141
}
142142

143143
pub type QueryOutlivesConstraint<'tcx> =
144-
(ty::OutlivesPredicate<GenericArg<'tcx>, Region<'tcx>>, ConstraintCategory<'tcx>);
144+
(ty::OutlivesPredicate<'tcx, GenericArg<'tcx>>, ConstraintCategory<'tcx>);
145145

146146
TrivialTypeTraversalImpls! {
147147
crate::infer::canonical::Certainty,

compiler/rustc_middle/src/ty/context.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
121121
type Abi = abi::Abi;
122122

123123
type Const = ty::Const<'tcx>;
124-
type AliasConst = ty::UnevaluatedConst<'tcx>;
125124
type PlaceholderConst = ty::PlaceholderConst;
126125
type ParamConst = ty::ParamConst;
127126
type BoundConst = ty::BoundVar;
@@ -137,15 +136,6 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
137136
type ParamEnv = ty::ParamEnv<'tcx>;
138137
type Predicate = Predicate<'tcx>;
139138
type Clause = Clause<'tcx>;
140-
type TraitPredicate = ty::TraitPredicate<'tcx>;
141-
type RegionOutlivesPredicate = ty::RegionOutlivesPredicate<'tcx>;
142-
type TypeOutlivesPredicate = ty::TypeOutlivesPredicate<'tcx>;
143-
type ProjectionPredicate = ty::ProjectionPredicate<'tcx>;
144-
type NormalizesTo = ty::NormalizesTo<'tcx>;
145-
type SubtypePredicate = ty::SubtypePredicate<'tcx>;
146-
147-
type CoercePredicate = ty::CoercePredicate<'tcx>;
148-
type ClosureKind = ty::ClosureKind;
149139

150140
type Clauses = ty::Clauses<'tcx>;
151141

compiler/rustc_middle/src/ty/predicate.rs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use rustc_data_structures::captures::Captures;
22
use rustc_data_structures::intern::Interned;
33
use rustc_hir::def_id::DefId;
4-
use rustc_macros::{
5-
extension, HashStable, Lift, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable,
6-
};
4+
use rustc_macros::{extension, HashStable};
75
use rustc_type_ir as ir;
86
use std::cmp::Ordering;
97

@@ -24,6 +22,15 @@ pub type PredicateKind<'tcx> = ir::PredicateKind<TyCtxt<'tcx>>;
2422
pub type NormalizesTo<'tcx> = ir::NormalizesTo<TyCtxt<'tcx>>;
2523
pub type CoercePredicate<'tcx> = ir::CoercePredicate<TyCtxt<'tcx>>;
2624
pub type SubtypePredicate<'tcx> = ir::SubtypePredicate<TyCtxt<'tcx>>;
25+
pub type OutlivesPredicate<'tcx, T> = ir::OutlivesPredicate<TyCtxt<'tcx>, T>;
26+
pub type RegionOutlivesPredicate<'tcx> = OutlivesPredicate<'tcx, ty::Region<'tcx>>;
27+
pub type TypeOutlivesPredicate<'tcx> = OutlivesPredicate<'tcx, Ty<'tcx>>;
28+
pub type PolyTraitPredicate<'tcx> = ty::Binder<'tcx, TraitPredicate<'tcx>>;
29+
pub type PolyRegionOutlivesPredicate<'tcx> = ty::Binder<'tcx, RegionOutlivesPredicate<'tcx>>;
30+
pub type PolyTypeOutlivesPredicate<'tcx> = ty::Binder<'tcx, TypeOutlivesPredicate<'tcx>>;
31+
pub type PolySubtypePredicate<'tcx> = ty::Binder<'tcx, SubtypePredicate<'tcx>>;
32+
pub type PolyCoercePredicate<'tcx> = ty::Binder<'tcx, CoercePredicate<'tcx>>;
33+
pub type PolyProjectionPredicate<'tcx> = ty::Binder<'tcx, ProjectionPredicate<'tcx>>;
2734

2835
/// A statement that can be proven by a trait solver. This includes things that may
2936
/// show up in where clauses, such as trait predicates and projection predicates,
@@ -405,20 +412,6 @@ impl<'tcx> Clause<'tcx> {
405412
}
406413
}
407414

408-
pub type PolyTraitPredicate<'tcx> = ty::Binder<'tcx, TraitPredicate<'tcx>>;
409-
410-
/// `A: B`
411-
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)]
412-
#[derive(HashStable, TypeFoldable, TypeVisitable, Lift)]
413-
pub struct OutlivesPredicate<A, B>(pub A, pub B);
414-
pub type RegionOutlivesPredicate<'tcx> = OutlivesPredicate<ty::Region<'tcx>, ty::Region<'tcx>>;
415-
pub type TypeOutlivesPredicate<'tcx> = OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>;
416-
pub type PolyRegionOutlivesPredicate<'tcx> = ty::Binder<'tcx, RegionOutlivesPredicate<'tcx>>;
417-
pub type PolyTypeOutlivesPredicate<'tcx> = ty::Binder<'tcx, TypeOutlivesPredicate<'tcx>>;
418-
pub type PolySubtypePredicate<'tcx> = ty::Binder<'tcx, SubtypePredicate<'tcx>>;
419-
pub type PolyCoercePredicate<'tcx> = ty::Binder<'tcx, CoercePredicate<'tcx>>;
420-
pub type PolyProjectionPredicate<'tcx> = Binder<'tcx, ProjectionPredicate<'tcx>>;
421-
422415
pub trait ToPolyTraitRef<'tcx> {
423416
fn to_poly_trait_ref(&self) -> PolyTraitRef<'tcx>;
424417
}
@@ -545,10 +538,8 @@ impl<'tcx> UpcastFrom<TyCtxt<'tcx>, PolyRegionOutlivesPredicate<'tcx>> for Predi
545538
}
546539
}
547540

548-
impl<'tcx> UpcastFrom<TyCtxt<'tcx>, OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>>
549-
for Predicate<'tcx>
550-
{
551-
fn upcast_from(from: OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>, tcx: TyCtxt<'tcx>) -> Self {
541+
impl<'tcx> UpcastFrom<TyCtxt<'tcx>, TypeOutlivesPredicate<'tcx>> for Predicate<'tcx> {
542+
fn upcast_from(from: TypeOutlivesPredicate<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
552543
ty::Binder::dummy(PredicateKind::Clause(ClauseKind::TypeOutlives(from))).upcast(tcx)
553544
}
554545
}

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2860,10 +2860,9 @@ where
28602860
}
28612861
}
28622862

2863-
impl<'tcx, T, U, P: PrettyPrinter<'tcx>> Print<'tcx, P> for ty::OutlivesPredicate<T, U>
2863+
impl<'tcx, T, P: PrettyPrinter<'tcx>> Print<'tcx, P> for ty::OutlivesPredicate<'tcx, T>
28642864
where
28652865
T: Print<'tcx, P>,
2866-
U: Print<'tcx, P>,
28672866
{
28682867
fn print(&self, cx: &mut P) -> Result<(), PrintError> {
28692868
define_scoped_cx!(cx);
@@ -3016,10 +3015,7 @@ forward_display_to_print! {
30163015
ty::Region<'tcx>,
30173016
Ty<'tcx>,
30183017
&'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
3019-
ty::Const<'tcx>,
3020-
3021-
ty::OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>,
3022-
ty::OutlivesPredicate<ty::Region<'tcx>, ty::Region<'tcx>>
3018+
ty::Const<'tcx>
30233019
}
30243020

30253021
define_print! {

compiler/rustc_smir/src/rustc_smir/convert/ty.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -707,12 +707,11 @@ impl<'tcx> Stable<'tcx> for ty::TraitPredicate<'tcx> {
707707
}
708708
}
709709

710-
impl<'tcx, A, B, U, V> Stable<'tcx> for ty::OutlivesPredicate<A, B>
710+
impl<'tcx, T> Stable<'tcx> for ty::OutlivesPredicate<'tcx, T>
711711
where
712-
A: Stable<'tcx, T = U>,
713-
B: Stable<'tcx, T = V>,
712+
T: Stable<'tcx>,
714713
{
715-
type T = stable_mir::ty::OutlivesPredicate<U, V>;
714+
type T = stable_mir::ty::OutlivesPredicate<T::T, Region>;
716715

717716
fn stable(&self, tables: &mut Tables<'_>) -> Self::T {
718717
let ty::OutlivesPredicate(a, b) = self;

compiler/rustc_trait_selection/src/traits/query/type_op/implied_outlives_bounds.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ pub fn compute_implied_outlives_bounds_compat_inner<'tcx>(
162162
let mut checked_wf_args = rustc_data_structures::fx::FxHashSet::default();
163163
let mut wf_args = vec![ty.into()];
164164

165-
let mut outlives_bounds: Vec<ty::OutlivesPredicate<ty::GenericArg<'tcx>, ty::Region<'tcx>>> =
166-
vec![];
165+
let mut outlives_bounds: Vec<ty::OutlivesPredicate<'tcx, ty::GenericArg<'tcx>>> = vec![];
167166

168167
while let Some(arg) = wf_args.pop() {
169168
if !checked_wf_args.insert(arg) {

0 commit comments

Comments
 (0)