Rollup merge of #125088 - compiler-errors:uplift-alias-ty, r=lcnr · rust-lang/rust@712e7c3 (original) (raw)
`@@ -76,6 +76,7 @@ use rustc_type_ir::TyKind::*;
`
76
76
`use rustc_type_ir::WithCachedTypeInfo;
`
77
77
`use rustc_type_ir::{CollectAndApply, Interner, TypeFlags};
`
78
78
``
``
79
`+
use std::assert_matches::assert_matches;
`
79
80
`use std::borrow::Borrow;
`
80
81
`use std::cmp::Ordering;
`
81
82
`use std::fmt;
`
`@@ -91,67 +92,124 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
`
91
92
`type DefiningOpaqueTypes = &'tcx ty::List;
`
92
93
`type AdtDef = ty::AdtDef<'tcx>;
`
93
94
`type GenericArgs = ty::GenericArgsRef<'tcx>;
`
``
95
`+
type GenericArgsSlice = &'tcx [ty::GenericArg<'tcx>];
`
94
96
`type GenericArg = ty::GenericArg<'tcx>;
`
95
``
`-
type Term = ty::Term<'tcx>;
`
96
97
``
``
98
`+
type Term = ty::Term<'tcx>;
`
97
99
`type Binder<T: TypeVisitable<TyCtxt<'tcx>>> = Binder<'tcx, T>;
`
98
100
`type BoundVars = &'tcx Listty::BoundVariableKind;
`
99
101
`type BoundVar = ty::BoundVariableKind;
`
100
``
`-
type CanonicalVars = CanonicalVarInfos<'tcx>;
`
101
102
``
``
103
`+
type CanonicalVars = CanonicalVarInfos<'tcx>;
`
102
104
`type Ty = Ty<'tcx>;
`
103
105
`type Tys = &'tcx List<Ty<'tcx>>;
`
104
``
`-
type AliasTy = ty::AliasTy<'tcx>;
`
105
106
`type ParamTy = ParamTy;
`
106
107
`type BoundTy = ty::BoundTy;
`
107
108
`type PlaceholderTy = ty::PlaceholderType;
`
108
``
`-
type ErrorGuaranteed = ErrorGuaranteed;
`
109
109
``
``
110
`+
type ErrorGuaranteed = ErrorGuaranteed;
`
110
111
`type BoundExistentialPredicates = &'tcx List<PolyExistentialPredicate<'tcx>>;
`
111
112
`type PolyFnSig = PolyFnSig<'tcx>;
`
112
113
`type AllocId = crate::mir::interpret::AllocId;
`
113
``
`-
type Pat = Pattern<'tcx>;
`
114
114
``
``
115
`+
type Pat = Pattern<'tcx>;
`
115
116
`type Const = ty::Const<'tcx>;
`
116
117
`type AliasConst = ty::UnevaluatedConst<'tcx>;
`
117
118
`type PlaceholderConst = ty::PlaceholderConst;
`
118
119
`type ParamConst = ty::ParamConst;
`
119
120
`type BoundConst = ty::BoundVar;
`
120
121
`type ValueConst = ty::ValTree<'tcx>;
`
121
``
`-
type ExprConst = ty::Expr<'tcx>;
`
122
122
``
``
123
`+
type ExprConst = ty::Expr<'tcx>;
`
123
124
`type Region = Region<'tcx>;
`
124
125
`type EarlyParamRegion = ty::EarlyParamRegion;
`
125
126
`type LateParamRegion = ty::LateParamRegion;
`
126
127
`type BoundRegion = ty::BoundRegion;
`
127
128
`type InferRegion = ty::RegionVid;
`
128
``
`-
type PlaceholderRegion = ty::PlaceholderRegion;
`
129
129
``
``
130
`+
type PlaceholderRegion = ty::PlaceholderRegion;
`
130
131
`type Predicate = Predicate<'tcx>;
`
131
132
`type TraitPredicate = ty::TraitPredicate<'tcx>;
`
132
133
`type RegionOutlivesPredicate = ty::RegionOutlivesPredicate<'tcx>;
`
133
134
`type TypeOutlivesPredicate = ty::TypeOutlivesPredicate<'tcx>;
`
134
135
`type ProjectionPredicate = ty::ProjectionPredicate<'tcx>;
`
135
``
`-
type AliasTerm = ty::AliasTerm<'tcx>;
`
136
136
`type NormalizesTo = ty::NormalizesTo<'tcx>;
`
137
137
`type SubtypePredicate = ty::SubtypePredicate<'tcx>;
`
138
138
`type CoercePredicate = ty::CoercePredicate<'tcx>;
`
139
139
`type ClosureKind = ty::ClosureKind;
`
140
``
`-
type Clauses = ty::Clauses<'tcx>;
`
141
140
``
``
141
`+
type Clauses = ty::Clauses<'tcx>;
`
142
142
`fn mk_canonical_var_infos(self, infos: &[ty::CanonicalVarInfo]) -> Self::CanonicalVars {
`
143
143
`self.mk_canonical_var_infos(infos)
`
144
144
`}
`
145
145
``
146
146
`type GenericsOf = &'tcx ty::Generics;
`
``
147
+
147
148
`fn generics_of(self, def_id: DefId) -> &'tcx ty::Generics {
`
148
149
`self.generics_of(def_id)
`
149
150
`}
`
150
151
``
``
152
`+
fn type_of_instantiated(self, def_id: DefId, args: ty::GenericArgsRef<'tcx>) -> Ty<'tcx> {
`
``
153
`+
self.type_of(def_id).instantiate(self, args)
`
``
154
`+
}
`
``
155
+
``
156
`+
fn alias_ty_kind(self, alias: ty::AliasTy<'tcx>) -> ty::AliasTyKind {
`
``
157
`+
match self.def_kind(alias.def_id) {
`
``
158
`+
DefKind::AssocTy => {
`
``
159
`+
if let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(alias.def_id))
`
``
160
`+
{
`
``
161
`+
ty::Inherent
`
``
162
`+
} else {
`
``
163
`+
ty::Projection
`
``
164
`+
}
`
``
165
`+
}
`
``
166
`+
DefKind::OpaqueTy => ty::Opaque,
`
``
167
`+
DefKind::TyAlias => ty::Weak,
`
``
168
`+
kind => bug!("unexpected DefKind in AliasTy: {kind:?}"),
`
``
169
`+
}
`
``
170
`+
}
`
``
171
+
``
172
`+
fn alias_term_kind(self, alias: ty::AliasTerm<'tcx>) -> ty::AliasTermKind {
`
``
173
`+
match self.def_kind(alias.def_id) {
`
``
174
`+
DefKind::AssocTy => {
`
``
175
`+
if let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(alias.def_id))
`
``
176
`+
{
`
``
177
`+
ty::AliasTermKind::InherentTy
`
``
178
`+
} else {
`
``
179
`+
ty::AliasTermKind::ProjectionTy
`
``
180
`+
}
`
``
181
`+
}
`
``
182
`+
DefKind::OpaqueTy => ty::AliasTermKind::OpaqueTy,
`
``
183
`+
DefKind::TyAlias => ty::AliasTermKind::WeakTy,
`
``
184
`+
DefKind::AssocConst => ty::AliasTermKind::ProjectionConst,
`
``
185
`+
DefKind::AnonConst => ty::AliasTermKind::UnevaluatedConst,
`
``
186
`+
kind => bug!("unexpected DefKind in AliasTy: {kind:?}"),
`
``
187
`+
}
`
``
188
`+
}
`
``
189
+
``
190
`+
fn trait_ref_and_own_args_for_alias(
`
``
191
`+
self,
`
``
192
`+
def_id: Self::DefId,
`
``
193
`+
args: Self::GenericArgs,
`
``
194
`+
) -> (rustc_type_ir::TraitRef, Self::GenericArgsSlice) {
`
``
195
`+
assert_matches!(self.def_kind(def_id), DefKind::AssocTy | DefKind::AssocConst);
`
``
196
`+
let trait_def_id = self.parent(def_id);
`
``
197
`+
assert_matches!(self.def_kind(trait_def_id), DefKind::Trait);
`
``
198
`+
let trait_generics = self.generics_of(trait_def_id);
`
``
199
`+
(
`
``
200
`+
ty::TraitRef::new(self, trait_def_id, args.truncate_to(self, trait_generics)),
`
``
201
`+
&args[trait_generics.count()..],
`
``
202
`+
)
`
``
203
`+
}
`
``
204
+
151
205
`fn mk_args(self, args: &[Self::GenericArg]) -> Self::GenericArgs {
`
152
206
`self.mk_args(args)
`
153
207
`}
`
154
208
``
``
209
`+
fn mk_args_from_iter(self, args: impl Iterator<Item = Self::GenericArg>) -> Self::GenericArgs {
`
``
210
`+
self.mk_args_from_iter(args)
`
``
211
`+
}
`
``
212
+
155
213
`fn check_and_mk_args(
`
156
214
`self,
`
157
215
`def_id: DefId,
`