Skip to content

Commit d36238d

Browse files
committed
Removal of needless types, commented out code, update lifetimes rough
implementation of `HashStable`
1 parent a5c4cc0 commit d36238d

File tree

25 files changed

+190
-189
lines changed

25 files changed

+190
-189
lines changed

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl ResolvedArg {
6363

6464
struct BoundVarContext<'a, 'tcx> {
6565
tcx: TyCtxt<'tcx>,
66-
rbv: &'a mut ResolveBoundVars,
66+
rbv: &'a mut ResolveBoundVars<'tcx>,
6767
disambiguator: &'a mut DisambiguatorState,
6868
scope: ScopeRef<'a>,
6969
opaque_capture_errors: RefCell<Option<OpaqueHigherRankedLifetimeCaptureErrors>>,
@@ -253,7 +253,7 @@ pub(crate) fn provide(providers: &mut Providers) {
253253
/// You should not read the result of this query directly, but rather use
254254
/// `named_variable_map`, `late_bound_vars_map`, etc.
255255
#[instrument(level = "debug", skip(tcx))]
256-
fn resolve_bound_vars(tcx: TyCtxt<'_>, local_def_id: hir::OwnerId) -> ResolveBoundVars {
256+
fn resolve_bound_vars(tcx: TyCtxt<'_>, local_def_id: hir::OwnerId) -> ResolveBoundVars<'tcx> {
257257
let mut rbv = ResolveBoundVars::default();
258258
let mut visitor = BoundVarContext {
259259
tcx,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ where
394394
&mut self,
395395
origin: infer::SubregionOrigin<'tcx>,
396396
region: ty::Region<'tcx>,
397-
placeholder_ty: ty::PlaceholderType<TyCtxt<'tcx>>,
397+
placeholder_ty: ty::PlaceholderType<'tcx>,
398398
) {
399399
let verify_bound = self
400400
.verify_bound

compiler/rustc_infer/src/infer/region_constraints/leak_check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ impl<'a, 'tcx> LeakCheck<'a, 'tcx> {
266266

267267
fn error(
268268
&self,
269-
placeholder: ty::PlaceholderRegion<TyCtx<'tcx>>,
269+
placeholder: ty::PlaceholderRegion<'tcx>,
270270
other_region: ty::Region<'tcx>,
271271
) -> TypeError<'tcx> {
272272
debug!("error: placeholder={:?}, other_region={:?}", placeholder, other_region);

compiler/rustc_middle/src/middle/resolve_bound_vars.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub enum ObjectLifetimeDefault {
4848
/// Maps the id of each bound variable reference to the variable decl
4949
/// that it corresponds to.
5050
#[derive(Debug, Default, HashStable)]
51-
pub struct ResolveBoundVars {
51+
pub struct ResolveBoundVars<'tcx> {
5252
// Maps from every use of a named (not anonymous) bound var to a
5353
// `ResolvedArg` describing how that variable is bound.
5454
pub defs: SortedMap<ItemLocalId, ResolvedArg>,
@@ -59,7 +59,7 @@ pub struct ResolveBoundVars {
5959
// - closures
6060
// - trait refs
6161
// - bound types (like `T` in `for<'a> T<'a>: Foo`)
62-
pub late_bound_vars: SortedMap<ItemLocalId, Vec<ty::BoundVariableKind>>,
62+
pub late_bound_vars: SortedMap<ItemLocalId, Vec<ty::BoundVariableKind<'tcx>>>,
6363

6464
// List captured variables for each opaque type.
6565
pub opaque_captured_lifetimes: LocalDefIdMap<Vec<(ResolvedArg, LocalDefId)>>,

compiler/rustc_middle/src/query/erase.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ trivial! {
341341
rustc_middle::ty::AssocContainer,
342342
rustc_middle::ty::Asyncness,
343343
rustc_middle::ty::AsyncDestructor,
344-
rustc_middle::ty::BoundVariableKind,
345344
rustc_middle::ty::AnonConstKind,
346345
rustc_middle::ty::Destructor,
347346
rustc_middle::ty::fast_reject::SimplifiedType,
@@ -410,6 +409,7 @@ tcx_lifetime! {
410409
rustc_middle::ty::ConstConditions,
411410
rustc_middle::ty::inhabitedness::InhabitedPredicate,
412411
rustc_middle::ty::Instance,
412+
rustc_middle::ty::BoundVariableKind,
413413
rustc_middle::ty::InstanceKind,
414414
rustc_middle::ty::layout::FnAbiError,
415415
rustc_middle::ty::layout::LayoutError,

compiler/rustc_middle/src/query/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,7 +2104,7 @@ rustc_queries! {
21042104
/// Does lifetime resolution on items. Importantly, we can't resolve
21052105
/// lifetimes directly on things like trait methods, because of trait params.
21062106
/// See `rustc_resolve::late::lifetimes` for details.
2107-
query resolve_bound_vars(owner_id: hir::OwnerId) -> &'tcx ResolveBoundVars {
2107+
query resolve_bound_vars(owner_id: hir::OwnerId) -> &'tcx ResolveBoundVars<'tcx> {
21082108
arena_cache
21092109
desc { |tcx| "resolving lifetimes for `{}`", tcx.def_path_str(owner_id) }
21102110
}
@@ -2133,7 +2133,7 @@ rustc_queries! {
21332133
separate_provide_extern
21342134
}
21352135
query late_bound_vars_map(owner_id: hir::OwnerId)
2136-
-> &'tcx SortedMap<ItemLocalId, Vec<ty::BoundVariableKind>> {
2136+
-> &'tcx SortedMap<ItemLocalId, Vec<ty::BoundVariableKind<'tcx>>> {
21372137
desc { |tcx| "looking up late bound vars inside `{}`", tcx.def_path_str(owner_id) }
21382138
}
21392139
/// For an opaque type, return the list of (captured lifetime, inner generic param).

compiler/rustc_middle/src/ty/codec.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,11 +427,11 @@ impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for [Spanned<MonoItem<'tcx>
427427
}
428428
}
429429

430-
impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for ty::List<ty::BoundVariableKind> {
430+
impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for ty::List<ty::BoundVariableKind<'tcx>> {
431431
fn decode(decoder: &mut D) -> &'tcx Self {
432432
let len = decoder.read_usize();
433433
decoder.interner().mk_bound_variable_kinds_from_iter(
434-
(0..len).map::<ty::BoundVariableKind, _>(|_| Decodable::decode(decoder)),
434+
(0..len).map::<ty::BoundVariableKind<'tcx>, _>(|_| Decodable::decode(decoder)),
435435
)
436436
}
437437
}
@@ -495,7 +495,7 @@ impl_decodable_via_ref! {
495495
&'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
496496
&'tcx traits::ImplSource<'tcx, ()>,
497497
&'tcx mir::Body<'tcx>,
498-
&'tcx ty::List<ty::BoundVariableKind>,
498+
&'tcx ty::List<ty::BoundVariableKind<'tcx>>,
499499
&'tcx ty::List<ty::Pattern<'tcx>>,
500500
&'tcx ty::ListWithCachedTypeInfo<ty::Clause<'tcx>>,
501501
}

compiler/rustc_middle/src/ty/consts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl<'tcx> Const<'tcx> {
110110
#[inline]
111111
pub fn new_placeholder(
112112
tcx: TyCtxt<'tcx>,
113-
placeholder: ty::PlaceholderConst<TyCtxt<'tcx>>,
113+
placeholder: ty::PlaceholderConst<'tcx>,
114114
) -> Const<'tcx> {
115115
Const::new(tcx, ty::ConstKind::Placeholder(placeholder))
116116
}
@@ -196,7 +196,7 @@ impl<'tcx> rustc_type_ir::inherent::Const<TyCtxt<'tcx>> for Const<'tcx> {
196196
Const::new_canonical_bound(tcx, var)
197197
}
198198

199-
fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderConst<TyCtxt<'tcx>>) -> Self {
199+
fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderConst<'tcx>) -> Self {
200200
Const::new_placeholder(tcx, placeholder)
201201
}
202202

compiler/rustc_middle/src/ty/context.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,8 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
109109
type GenericArgsSlice = &'tcx [ty::GenericArg<'tcx>];
110110
type GenericArg = ty::GenericArg<'tcx>;
111111
type Term = ty::Term<'tcx>;
112-
type BoundVarKinds = &'tcx List<ty::BoundVariableKind>;
112+
type BoundVarKinds = &'tcx List<ty::BoundVariableKind<'tcx>>;
113113

114-
type BoundVarKind = ty::BoundVariableKind;
115114
type PredefinedOpaques = solve::PredefinedOpaques<'tcx>;
116115

117116
fn mk_predefined_opaques_in_body(
@@ -147,7 +146,6 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
147146
type ParamTy = ParamTy;
148147
type Symbol = Symbol;
149148

150-
type PlaceholderTy = ty::PlaceholderType<TyCtxt<'tcx>>;
151149
type ErrorGuaranteed = ErrorGuaranteed;
152150
type BoundExistentialPredicates = &'tcx List<PolyExistentialPredicate<'tcx>>;
153151

@@ -167,9 +165,6 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
167165
type Region = Region<'tcx>;
168166
type EarlyParamRegion = ty::EarlyParamRegion;
169167
type LateParamRegion = ty::LateParamRegion;
170-
type BoundRegion = ty::BoundRegion;
171-
type BoundRegionKind = ty::BoundRegionKind;
172-
type BoundVariableKind = ty::BoundVariableKind;
173168

174169
type RegionAssumptions = &'tcx ty::List<ty::ArgOutlivesPredicate<'tcx>>;
175170

@@ -941,7 +936,7 @@ pub struct CtxtInterners<'tcx> {
941936
const_: InternedSet<'tcx, WithCachedTypeInfo<ty::ConstKind<'tcx>>>,
942937
pat: InternedSet<'tcx, PatternKind<'tcx>>,
943938
const_allocation: InternedSet<'tcx, Allocation>,
944-
bound_variable_kinds: InternedSet<'tcx, List<ty::BoundVariableKind>>,
939+
bound_variable_kinds: InternedSet<'tcx, List<ty::BoundVariableKind<'tcx>>>,
945940
layout: InternedSet<'tcx, LayoutData<FieldIdx, VariantIdx>>,
946941
adt_def: InternedSet<'tcx, AdtDefData>,
947942
external_constraints: InternedSet<'tcx, ExternalConstraintsData<TyCtxt<'tcx>>>,
@@ -2533,7 +2528,7 @@ nop_list_lift! { type_lists; Ty<'a> => Ty<'tcx> }
25332528
nop_list_lift! {
25342529
poly_existential_predicates; PolyExistentialPredicate<'a> => PolyExistentialPredicate<'tcx>
25352530
}
2536-
nop_list_lift! { bound_variable_kinds; ty::BoundVariableKind => ty::BoundVariableKind }
2531+
nop_list_lift! { bound_variable_kinds; ty::BoundVariableKind<'tcx> => ty::BoundVariableKind<'tcx> }
25372532

25382533
// This is the impl for `&'a GenericArgs<'a>`.
25392534
nop_list_lift! { args; GenericArg<'a> => GenericArg<'tcx> }
@@ -2820,7 +2815,7 @@ slice_interners!(
28202815
poly_existential_predicates: intern_poly_existential_predicates(PolyExistentialPredicate<'tcx>),
28212816
projs: pub mk_projs(ProjectionKind),
28222817
place_elems: pub mk_place_elems(PlaceElem<'tcx>),
2823-
bound_variable_kinds: pub mk_bound_variable_kinds(ty::BoundVariableKind),
2818+
bound_variable_kinds: pub mk_bound_variable_kinds(ty::BoundVariableKind<'tcx>),
28242819
fields: pub mk_fields(FieldIdx),
28252820
local_def_ids: intern_local_def_ids(LocalDefId),
28262821
captures: intern_captures(&'tcx ty::CapturedPlace<'tcx>),
@@ -3245,7 +3240,7 @@ impl<'tcx> TyCtxt<'tcx> {
32453240
pub fn mk_bound_variable_kinds_from_iter<I, T>(self, iter: I) -> T::Output
32463241
where
32473242
I: Iterator<Item = T>,
3248-
T: CollectAndApply<ty::BoundVariableKind, &'tcx List<ty::BoundVariableKind>>,
3243+
T: CollectAndApply<ty::BoundVariableKind<'tcx>, &'tcx List<ty::BoundVariableKind<'tcx>>>,
32493244
{
32503245
T::collect_and_apply(iter, |xs| self.mk_bound_variable_kinds(xs))
32513246
}
@@ -3367,7 +3362,7 @@ impl<'tcx> TyCtxt<'tcx> {
33673362
self.is_late_bound_map(id.owner).is_some_and(|set| set.contains(&id.local_id))
33683363
}
33693364

3370-
pub fn late_bound_vars(self, id: HirId) -> &'tcx List<ty::BoundVariableKind> {
3365+
pub fn late_bound_vars(self, id: HirId) -> &'tcx List<ty::BoundVariableKind<'tcx>> {
33713366
self.mk_bound_variable_kinds(
33723367
&self
33733368
.late_bound_vars_map(id.owner)

compiler/rustc_middle/src/ty/fold.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,25 @@ where
5858
/// gets mapped to the same result. `BoundVarReplacer` caches by using
5959
/// a `DelayedMap` which does not cache the first few types it encounters.
6060
pub trait BoundVarReplacerDelegate<'tcx> {
61-
fn replace_region(&mut self, br: ty::BoundRegion) -> ty::Region<'tcx>;
62-
fn replace_ty(&mut self, bt: ty::BoundTy) -> Ty<'tcx>;
61+
fn replace_region(&mut self, br: ty::BoundRegion<'tcx>) -> ty::Region<'tcx>;
62+
fn replace_ty(&mut self, bt: ty::BoundTy<'tcx>) -> Ty<'tcx>;
6363
fn replace_const(&mut self, bc: ty::BoundConst) -> ty::Const<'tcx>;
6464
}
6565

6666
/// A simple delegate taking 3 mutable functions. The used functions must
6767
/// always return the same result for each bound variable, no matter how
6868
/// frequently they are called.
6969
pub struct FnMutDelegate<'a, 'tcx> {
70-
pub regions: &'a mut (dyn FnMut(ty::BoundRegion) -> ty::Region<'tcx> + 'a),
71-
pub types: &'a mut (dyn FnMut(ty::BoundTy) -> Ty<'tcx> + 'a),
70+
pub regions: &'a mut (dyn FnMut(ty::BoundRegion<'tcx>) -> ty::Region<'tcx> + 'a),
71+
pub types: &'a mut (dyn FnMut(ty::BoundTy<'tcx>) -> Ty<'tcx> + 'a),
7272
pub consts: &'a mut (dyn FnMut(ty::BoundConst) -> ty::Const<'tcx> + 'a),
7373
}
7474

7575
impl<'a, 'tcx> BoundVarReplacerDelegate<'tcx> for FnMutDelegate<'a, 'tcx> {
76-
fn replace_region(&mut self, br: ty::BoundRegion) -> ty::Region<'tcx> {
76+
fn replace_region(&mut self, br: ty::BoundRegion<'tcx>) -> ty::Region<'tcx> {
7777
(self.regions)(br)
7878
}
79-
fn replace_ty(&mut self, bt: ty::BoundTy) -> Ty<'tcx> {
79+
fn replace_ty(&mut self, bt: ty::BoundTy<'tcx>) -> Ty<'tcx> {
8080
(self.types)(bt)
8181
}
8282
fn replace_const(&mut self, bc: ty::BoundConst) -> ty::Const<'tcx> {
@@ -207,13 +207,14 @@ impl<'tcx> TyCtxt<'tcx> {
207207
self,
208208
value: Binder<'tcx, T>,
209209
mut fld_r: F,
210-
) -> (T, FxIndexMap<ty::BoundRegion, ty::Region<'tcx>>)
210+
) -> (T, FxIndexMap<ty::BoundRegion<'tcx>, ty::Region<'tcx>>)
211211
where
212-
F: FnMut(ty::BoundRegion) -> ty::Region<'tcx>,
212+
F: FnMut(ty::BoundRegion<'tcx>) -> ty::Region<'tcx>,
213213
T: TypeFoldable<TyCtxt<'tcx>>,
214214
{
215215
let mut region_map = FxIndexMap::default();
216-
let real_fld_r = |br: ty::BoundRegion| *region_map.entry(br).or_insert_with(|| fld_r(br));
216+
let real_fld_r =
217+
|br: ty::BoundRegion<'tcx>| *region_map.entry(br).or_insert_with(|| fld_r(br));
217218
let value = self.instantiate_bound_regions_uncached(value, real_fld_r);
218219
(value, region_map)
219220
}
@@ -224,7 +225,7 @@ impl<'tcx> TyCtxt<'tcx> {
224225
mut replace_regions: F,
225226
) -> T
226227
where
227-
F: FnMut(ty::BoundRegion) -> ty::Region<'tcx>,
228+
F: FnMut(ty::BoundRegion<'tcx>) -> ty::Region<'tcx>,
228229
T: TypeFoldable<TyCtxt<'tcx>>,
229230
{
230231
let value = value.skip_binder();
@@ -292,14 +293,14 @@ impl<'tcx> TyCtxt<'tcx> {
292293
self.replace_escaping_bound_vars_uncached(
293294
value,
294295
FnMutDelegate {
295-
regions: &mut |r: ty::BoundRegion| {
296+
regions: &mut |r: ty::BoundRegion<'tcx>| {
296297
ty::Region::new_bound(
297298
self,
298299
ty::INNERMOST,
299300
ty::BoundRegion { var: shift_bv(r.var), kind: r.kind },
300301
)
301302
},
302-
types: &mut |t: ty::BoundTy| {
303+
types: &mut |t: ty::BoundTy<'tcx>| {
303304
Ty::new_bound(
304305
self,
305306
ty::INNERMOST,
@@ -333,10 +334,10 @@ impl<'tcx> TyCtxt<'tcx> {
333334
{
334335
struct Anonymize<'a, 'tcx> {
335336
tcx: TyCtxt<'tcx>,
336-
map: &'a mut FxIndexMap<ty::BoundVar, ty::BoundVariableKind>,
337+
map: &'a mut FxIndexMap<ty::BoundVar, ty::BoundVariableKind<'tcx>>,
337338
}
338339
impl<'tcx> BoundVarReplacerDelegate<'tcx> for Anonymize<'_, 'tcx> {
339-
fn replace_region(&mut self, br: ty::BoundRegion) -> ty::Region<'tcx> {
340+
fn replace_region(&mut self, br: ty::BoundRegion<'tcx>) -> ty::Region<'tcx> {
340341
let entry = self.map.entry(br.var);
341342
let index = entry.index();
342343
let var = ty::BoundVar::from_usize(index);
@@ -346,7 +347,7 @@ impl<'tcx> TyCtxt<'tcx> {
346347
let br = ty::BoundRegion { var, kind };
347348
ty::Region::new_bound(self.tcx, ty::INNERMOST, br)
348349
}
349-
fn replace_ty(&mut self, bt: ty::BoundTy) -> Ty<'tcx> {
350+
fn replace_ty(&mut self, bt: ty::BoundTy<'tcx>) -> Ty<'tcx> {
350351
let entry = self.map.entry(bt.var);
351352
let index = entry.index();
352353
let var = ty::BoundVar::from_usize(index);

0 commit comments

Comments
 (0)