Skip to content

Commit 9f0791e

Browse files
committed
Part 2 refactoring of moving placeholder types to rustc_type_ir
1 parent fb292b7 commit 9f0791e

File tree

52 files changed

+623
-547
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+623
-547
lines changed

compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ pub(crate) trait TypeOpInfo<'tcx> {
169169

170170
let placeholder_region = ty::Region::new_placeholder(
171171
tcx,
172-
ty::Placeholder::new(adjusted_universe.into(), placeholder.bound),
172+
ty::PlaceholderRegion::new(adjusted_universe.into(), placeholder.bound),
173173
);
174174

175175
let error_region =
@@ -179,7 +179,7 @@ pub(crate) trait TypeOpInfo<'tcx> {
179179
adjusted_universe.map(|adjusted| {
180180
ty::Region::new_placeholder(
181181
tcx,
182-
ty::Placeholder::new(adjusted.into(), error_placeholder.bound),
182+
ty::PlaceholderRegion::new(adjusted.into(), error_placeholder.bound),
183183
)
184184
})
185185
} else {

compiler/rustc_borrowck/src/region_infer/graphviz.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn render_region_vid<'tcx>(
5252
format!(" (for<{}>)", tcx.item_name(def_id))
5353
}
5454
ty::BoundRegionKind::ClosureEnv | ty::BoundRegionKind::Anon => " (for<'_>)".to_string(),
55-
ty::BoundRegionKind::NamedAnon(_) => {
55+
ty::BoundRegionKind::NamedForPrinting(_) => {
5656
bug!("only used for pretty printing")
5757
}
5858
},

compiler/rustc_borrowck/src/region_infer/values.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use rustc_middle::ty::{self, RegionVid};
1010
use rustc_mir_dataflow::points::{DenseLocationMap, PointIndex};
1111
use tracing::debug;
1212

13+
use crate::BorrowIndex;
1314
use crate::polonius::LiveLoans;
14-
use crate::{BorrowIndex, TyCtxt};
1515

1616
rustc_index::newtype_index! {
1717
/// A single integer representing a `ty::Placeholder`.
@@ -420,18 +420,18 @@ impl ToElementIndex<'_> for RegionVid {
420420
impl<'tcx> ToElementIndex<'tcx> for ty::PlaceholderRegion<'tcx> {
421421
fn add_to_row<N: Idx>(self, values: &mut RegionValues<'tcx, N>, row: N) -> bool
422422
where
423-
Self: Into<ty::Placeholder<TyCtxt<'tcx>, ty::BoundRegion>>,
423+
Self: Into<ty::PlaceholderRegion<'tcx>>,
424424
{
425-
let placeholder: ty::Placeholder<TyCtxt<'tcx>, ty::BoundRegion> = self.into();
425+
let placeholder: ty::PlaceholderRegion<'tcx> = self.into();
426426
let index = values.placeholder_indices.lookup_index(placeholder);
427427
values.placeholders.insert(row, index)
428428
}
429429

430430
fn contained_in_row<N: Idx>(self, values: &RegionValues<'tcx, N>, row: N) -> bool
431431
where
432-
Self: Into<ty::Placeholder<TyCtxt<'tcx>, ty::BoundRegion>>,
432+
Self: Into<ty::PlaceholderRegion<'tcx>>,
433433
{
434-
let placeholder: ty::Placeholder<TyCtxt<'tcx>, ty::BoundRegion> = self.into();
434+
let placeholder: ty::PlaceholderRegion<'tcx> = self.into();
435435
let index = values.placeholder_indices.lookup_index(placeholder);
436436
values.placeholders.contains(row, index)
437437
}

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
772772
ty::BoundRegionKind::Anon => sym::anon,
773773
ty::BoundRegionKind::Named(def_id) => tcx.item_name(def_id),
774774
ty::BoundRegionKind::ClosureEnv => sym::env,
775-
ty::BoundRegionKind::NamedAnon(_) => {
775+
ty::BoundRegionKind::NamedForPrinting(_) => {
776776
bug!("only used for pretty printing")
777777
}
778778
};

compiler/rustc_borrowck/src/type_check/relate_tys.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
174174
let infcx = self.type_checker.infcx;
175175
let mut lazy_universe = None;
176176
let delegate = FnMutDelegate {
177-
regions: &mut |br: ty::BoundRegion| {
177+
regions: &mut |br: ty::BoundRegion<'tcx>| {
178178
// The first time this closure is called, create a
179179
// new universe for the placeholders we will make
180180
// from here out.
@@ -191,10 +191,10 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
191191

192192
placeholder_reg
193193
},
194-
types: &mut |_bound_ty: ty::BoundTy| {
194+
types: &mut |_bound_ty: ty::BoundTy<'tcx>| {
195195
unreachable!("we only replace regions in nll_relate, not types")
196196
},
197-
consts: &mut |_bound_const: ty::BoundConst| {
197+
consts: &mut |_bound_const: ty::BoundConst<'tcx>| {
198198
unreachable!("we only replace regions in nll_relate, not consts")
199199
},
200200
};
@@ -218,7 +218,7 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
218218
let infcx = self.type_checker.infcx;
219219
let mut reg_map = FxHashMap::default();
220220
let delegate = FnMutDelegate {
221-
regions: &mut |br: ty::BoundRegion| {
221+
regions: &mut |br: ty::BoundRegion<'tcx>| {
222222
if let Some(ex_reg_var) = reg_map.get(&br) {
223223
*ex_reg_var
224224
} else {
@@ -230,10 +230,10 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
230230
ex_reg_var
231231
}
232232
},
233-
types: &mut |_bound_ty: ty::BoundTy| {
233+
types: &mut |_bound_ty: ty::BoundTy<'tcx>| {
234234
unreachable!("we only replace regions in nll_relate, not types")
235235
},
236-
consts: &mut |_bound_const: ty::BoundConst| {
236+
consts: &mut |_bound_const: ty::BoundConst<'tcx>| {
237237
unreachable!("we only replace regions in nll_relate, not consts")
238238
},
239239
};
@@ -268,7 +268,7 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
268268
ty::BoundRegionKind::Anon => sym::anon,
269269
ty::BoundRegionKind::Named(def_id) => self.type_checker.tcx().item_name(def_id),
270270
ty::BoundRegionKind::ClosureEnv => sym::env,
271-
ty::BoundRegionKind::NamedAnon(_) => bug!("only used for pretty printing"),
271+
ty::BoundRegionKind::NamedForPrinting(_) => bug!("only used for pretty printing"),
272272
};
273273

274274
if cfg!(debug_assertions) {

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
592592
ty,
593593
Ty::new_placeholder(
594594
tcx,
595-
ty::Placeholder::new(
595+
ty::PlaceholderType::new(
596596
universe,
597597
ty::BoundTy { var: idx, kind: ty::BoundTyKind::Anon },
598598
),
@@ -2551,7 +2551,7 @@ fn param_env_with_gat_bounds<'tcx>(
25512551
}
25522552
};
25532553

2554-
let mut bound_vars: smallvec::SmallVec<[ty::BoundVariableKind; 8]> =
2554+
let mut bound_vars: smallvec::SmallVec<[ty::BoundVariableKind<'tcx>; 8]> =
25552555
smallvec::SmallVec::with_capacity(tcx.generics_of(impl_ty.def_id).own_params.len());
25562556
// Extend the impl's identity args with late-bound GAT vars
25572557
let normalize_impl_ty_args = ty::GenericArgs::identity_for_item(tcx, container_id)
@@ -2587,7 +2587,7 @@ fn param_env_with_gat_bounds<'tcx>(
25872587
ty::Const::new_bound(
25882588
tcx,
25892589
ty::INNERMOST,
2590-
ty::BoundConst { var: ty::BoundVar::from_usize(bound_vars.len() - 1) },
2590+
ty::BoundConst::new(ty::BoundVar::from_usize(bound_vars.len() - 1)),
25912591
)
25922592
.into()
25932593
}

compiler/rustc_hir_analysis/src/collect/item_bounds.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ struct MapAndCompressBoundVars<'tcx> {
241241
binder: ty::DebruijnIndex,
242242
/// List of bound vars that remain unsubstituted because they were not
243243
/// mentioned in the GAT's args.
244-
still_bound_vars: Vec<ty::BoundVariableKind>,
244+
still_bound_vars: Vec<ty::BoundVariableKind<'tcx>>,
245245
/// Subtle invariant: If the `GenericArg` is bound, then it should be
246246
/// stored with the debruijn index of `INNERMOST` so it can be shifted
247247
/// correctly during substitution.
@@ -330,7 +330,8 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for MapAndCompressBoundVars<'tcx> {
330330
} else {
331331
let var = ty::BoundVar::from_usize(self.still_bound_vars.len());
332332
self.still_bound_vars.push(ty::BoundVariableKind::Const);
333-
let mapped = ty::Const::new_bound(self.tcx, ty::INNERMOST, ty::BoundConst { var });
333+
let mapped =
334+
ty::Const::new_bound(self.tcx, ty::INNERMOST, ty::BoundConst::new(var));
334335
self.mapping.insert(old_bound.var, mapped.into());
335336
mapped
336337
};

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ 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,
68-
scope: ScopeRef<'a>,
68+
scope: ScopeRef<'a, 'tcx>,
6969
opaque_capture_errors: RefCell<Option<OpaqueHigherRankedLifetimeCaptureErrors>>,
7070
}
7171

@@ -76,7 +76,7 @@ struct OpaqueHigherRankedLifetimeCaptureErrors {
7676
}
7777

7878
#[derive(Debug)]
79-
enum Scope<'a> {
79+
enum Scope<'a, 'tcx> {
8080
/// Declares lifetimes, and each can be early-bound or late-bound.
8181
/// The `DebruijnIndex` of late-bound lifetimes starts at `1` and
8282
/// it should be shifted by the number of `Binder`s in between the
@@ -94,7 +94,7 @@ enum Scope<'a> {
9494
/// to append to.
9595
hir_id: HirId,
9696

97-
s: ScopeRef<'a>,
97+
s: ScopeRef<'a, 'tcx>,
9898

9999
/// If this binder comes from a where clause, specify how it was created.
100100
/// This is used to diagnose inaccessible lifetimes in APIT:
@@ -110,28 +110,28 @@ enum Scope<'a> {
110110
/// e.g., `(&T, fn(&T) -> &T);` becomes `(&'_ T, for<'a> fn(&'a T) -> &'a T)`.
111111
Body {
112112
id: hir::BodyId,
113-
s: ScopeRef<'a>,
113+
s: ScopeRef<'a, 'tcx>,
114114
},
115115

116116
/// Use a specific lifetime (if `Some`) or leave it unset (to be
117117
/// inferred in a function body or potentially error outside one),
118118
/// for the default choice of lifetime in a trait object type.
119119
ObjectLifetimeDefault {
120120
lifetime: Option<ResolvedArg>,
121-
s: ScopeRef<'a>,
121+
s: ScopeRef<'a, 'tcx>,
122122
},
123123

124124
/// When we have nested trait refs, we concatenate late bound vars for inner
125125
/// trait refs from outer ones. But we also need to include any HRTB
126126
/// lifetimes encountered when identifying the trait that an associated type
127127
/// is declared on.
128128
Supertrait {
129-
bound_vars: Vec<ty::BoundVariableKind>,
130-
s: ScopeRef<'a>,
129+
bound_vars: Vec<ty::BoundVariableKind<'tcx>>,
130+
s: ScopeRef<'a, 'tcx>,
131131
},
132132

133133
TraitRefBoundary {
134-
s: ScopeRef<'a>,
134+
s: ScopeRef<'a, 'tcx>,
135135
},
136136

137137
/// Remap lifetimes that appear in opaque types to fresh lifetime parameters. Given:
@@ -148,7 +148,7 @@ enum Scope<'a> {
148148
/// Mapping from each captured lifetime `'a` to the duplicate generic parameter `'b`.
149149
captures: &'a RefCell<FxIndexMap<ResolvedArg, LocalDefId>>,
150150

151-
s: ScopeRef<'a>,
151+
s: ScopeRef<'a, 'tcx>,
152152
},
153153

154154
/// Disallows capturing late-bound vars from parent scopes.
@@ -157,7 +157,7 @@ enum Scope<'a> {
157157
/// since we don't do something more correct like replacing any captured
158158
/// late-bound vars with early-bound params in the const's own generics.
159159
LateBoundary {
160-
s: ScopeRef<'a>,
160+
s: ScopeRef<'a, 'tcx>,
161161
what: &'static str,
162162
deny_late_regions: bool,
163163
},
@@ -167,7 +167,7 @@ enum Scope<'a> {
167167
},
168168
}
169169

170-
impl<'a> Scope<'a> {
170+
impl<'a, 'tcx> Scope<'a, 'tcx> {
171171
// A helper for debugging scopes without printing parent scopes
172172
fn debug_truncated(&self) -> impl fmt::Debug {
173173
fmt::from_fn(move |f| match self {
@@ -227,7 +227,7 @@ enum BinderScopeType {
227227
Concatenating,
228228
}
229229

230-
type ScopeRef<'a> = &'a Scope<'a>;
230+
type ScopeRef<'a, 'tcx> = &'a Scope<'a, 'tcx>;
231231

232232
/// Adds query implementations to the [Providers] vtable, see [`rustc_middle::query`]
233233
pub(crate) fn provide(providers: &mut Providers) {
@@ -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<'_> {
257257
let mut rbv = ResolveBoundVars::default();
258258
let mut visitor = BoundVarContext {
259259
tcx,
@@ -287,7 +287,7 @@ fn resolve_bound_vars(tcx: TyCtxt<'_>, local_def_id: hir::OwnerId) -> ResolveBou
287287
rbv
288288
}
289289

290-
fn late_arg_as_bound_arg<'tcx>(param: &GenericParam<'tcx>) -> ty::BoundVariableKind {
290+
fn late_arg_as_bound_arg<'tcx>(param: &GenericParam<'tcx>) -> ty::BoundVariableKind<'tcx> {
291291
let def_id = param.def_id.to_def_id();
292292
match param.kind {
293293
GenericParamKind::Lifetime { .. } => {
@@ -301,7 +301,9 @@ fn late_arg_as_bound_arg<'tcx>(param: &GenericParam<'tcx>) -> ty::BoundVariableK
301301
/// Turn a [`ty::GenericParamDef`] into a bound arg. Generally, this should only
302302
/// be used when turning early-bound vars into late-bound vars when lowering
303303
/// return type notation.
304-
fn generic_param_def_as_bound_arg(param: &ty::GenericParamDef) -> ty::BoundVariableKind {
304+
fn generic_param_def_as_bound_arg<'tcx>(
305+
param: &ty::GenericParamDef,
306+
) -> ty::BoundVariableKind<'tcx> {
305307
match param.kind {
306308
ty::GenericParamDefKind::Lifetime => {
307309
ty::BoundVariableKind::Region(ty::BoundRegionKind::Named(param.def_id))
@@ -329,7 +331,9 @@ fn opaque_captures_all_in_scope_lifetimes<'tcx>(opaque: &'tcx hir::OpaqueTy<'tcx
329331

330332
impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
331333
/// Returns the binders in scope and the type of `Binder` that should be created for a poly trait ref.
332-
fn poly_trait_ref_binder_info(&mut self) -> (Vec<ty::BoundVariableKind>, BinderScopeType) {
334+
fn poly_trait_ref_binder_info(
335+
&mut self,
336+
) -> (Vec<ty::BoundVariableKind<'tcx>>, BinderScopeType) {
333337
let mut scope = self.scope;
334338
let mut supertrait_bound_vars = vec![];
335339
loop {
@@ -364,7 +368,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
364368

365369
Scope::Binder { hir_id, .. } => {
366370
// Nested poly trait refs have the binders concatenated
367-
let mut full_binders =
371+
let mut full_binders: Vec<ty::BoundVariableKind<'tcx>> =
368372
self.rbv.late_bound_vars.get_mut_or_insert_default(hir_id.local_id).clone();
369373
full_binders.extend(supertrait_bound_vars);
370374
break (full_binders, BinderScopeType::Concatenating);
@@ -1094,7 +1098,7 @@ fn object_lifetime_default(tcx: TyCtxt<'_>, param_def_id: LocalDefId) -> ObjectL
10941098
}
10951099

10961100
impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
1097-
fn with<F>(&mut self, wrap_scope: Scope<'_>, f: F)
1101+
fn with<F>(&mut self, wrap_scope: Scope<'_, 'tcx>, f: F)
10981102
where
10991103
F: for<'b> FnOnce(&mut BoundVarContext<'b, 'tcx>),
11001104
{
@@ -1115,7 +1119,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
11151119
*self.opaque_capture_errors.borrow_mut() = this.opaque_capture_errors.into_inner();
11161120
}
11171121

1118-
fn record_late_bound_vars(&mut self, hir_id: HirId, binder: Vec<ty::BoundVariableKind>) {
1122+
fn record_late_bound_vars(&mut self, hir_id: HirId, binder: Vec<ty::BoundVariableKind<'tcx>>) {
11191123
if let Some(old) = self.rbv.late_bound_vars.insert(hir_id.local_id, binder) {
11201124
bug!(
11211125
"overwrote bound vars for {hir_id:?}:\nold={old:?}\nnew={:?}",
@@ -1931,7 +1935,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
19311935
def_id: DefId,
19321936
assoc_ident: Ident,
19331937
assoc_tag: ty::AssocTag,
1934-
) -> Option<(Vec<ty::BoundVariableKind>, &'tcx ty::AssocItem)> {
1938+
) -> Option<(Vec<ty::BoundVariableKind<'tcx>>, &'tcx ty::AssocItem)> {
19351939
let trait_defines_associated_item_named = |trait_def_id: DefId| {
19361940
tcx.associated_items(trait_def_id).find_by_ident_and_kind(
19371941
tcx,
@@ -1942,7 +1946,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
19421946
};
19431947

19441948
use smallvec::{SmallVec, smallvec};
1945-
let mut stack: SmallVec<[(DefId, SmallVec<[ty::BoundVariableKind; 8]>); 8]> =
1949+
let mut stack: SmallVec<[(DefId, SmallVec<[ty::BoundVariableKind<'tcx>; 8]>); 8]> =
19461950
smallvec![(def_id, smallvec![])];
19471951
let mut visited: FxHashSet<DefId> = FxHashSet::default();
19481952
loop {

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
362362
param_ty: Ty<'tcx>,
363363
hir_bounds: I,
364364
bounds: &mut Vec<(ty::Clause<'tcx>, Span)>,
365-
bound_vars: &'tcx ty::List<ty::BoundVariableKind>,
365+
bound_vars: &'tcx ty::List<ty::BoundVariableKind<'tcx>>,
366366
predicate_filter: PredicateFilter,
367367
overlapping_assoc_constraints: OverlappingAsssocItemConstraints,
368368
) where
@@ -1000,7 +1000,9 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GenericParamAndBoundVarCollector<'_, 't
10001000
.delayed_bug(format!("unexpected bound region kind: {:?}", br.kind));
10011001
return ControlFlow::Break(guar);
10021002
}
1003-
ty::BoundRegionKind::NamedAnon(_) => bug!("only used for pretty printing"),
1003+
ty::BoundRegionKind::NamedForPrinting(_) => {
1004+
bug!("only used for pretty printing")
1005+
}
10041006
});
10051007
}
10061008
_ => {}

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2310,7 +2310,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
23102310
Some(rbv::ResolvedArg::LateBound(debruijn, index, _)) => ty::Const::new_bound(
23112311
tcx,
23122312
debruijn,
2313-
ty::BoundConst { var: ty::BoundVar::from_u32(index) },
2313+
ty::BoundConst::new(ty::BoundVar::from_u32(index)),
23142314
),
23152315
Some(rbv::ResolvedArg::Error(guar)) => ty::Const::new_error(tcx, guar),
23162316
arg => bug!("unexpected bound var resolution for {:?}: {arg:?}", path_hir_id),
@@ -3196,8 +3196,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
31963196
#[instrument(level = "trace", skip(self, generate_err))]
31973197
fn validate_late_bound_regions<'cx>(
31983198
&'cx self,
3199-
constrained_regions: FxIndexSet<ty::BoundRegionKind>,
3200-
referenced_regions: FxIndexSet<ty::BoundRegionKind>,
3199+
constrained_regions: FxIndexSet<ty::BoundRegionKind<'tcx>>,
3200+
referenced_regions: FxIndexSet<ty::BoundRegionKind<'tcx>>,
32013201
generate_err: impl Fn(&str) -> Diag<'cx>,
32023202
) {
32033203
for br in referenced_regions.difference(&constrained_regions) {

0 commit comments

Comments
 (0)