Skip to content

Commit 4646b3d

Browse files
committed
Use BoundTy and BoundRegion instead of kind of PlaceholderTy and PlaceholderRegion
1 parent c934ce9 commit 4646b3d

File tree

20 files changed

+121
-75
lines changed

20 files changed

+121
-75
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
@@ -181,8 +181,8 @@ trait TypeOpInfo<'tcx> {
181181
};
182182

183183
let placeholder_region = tcx.mk_re_placeholder(ty::Placeholder {
184-
name: placeholder.name,
185184
universe: adjusted_universe.into(),
185+
bound: placeholder.bound,
186186
});
187187

188188
let error_region =
@@ -191,8 +191,8 @@ trait TypeOpInfo<'tcx> {
191191
error_placeholder.universe.as_u32().checked_sub(base_universe.as_u32());
192192
adjusted_universe.map(|adjusted| {
193193
tcx.mk_re_placeholder(ty::Placeholder {
194-
name: error_placeholder.name,
195194
universe: adjusted.into(),
195+
bound: error_placeholder.bound,
196196
})
197197
})
198198
} else {

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
467467
if let ty::Ref(region, ..) = ty.kind() {
468468
match **region {
469469
ty::ReLateBound(_, ty::BoundRegion { kind: br, .. })
470-
| ty::RePlaceholder(ty::PlaceholderRegion { name: br, .. }) => {
471-
printer.region_highlight_mode.highlighting_bound_region(br, counter)
472-
}
470+
| ty::RePlaceholder(ty::PlaceholderRegion {
471+
bound: ty::BoundRegion { kind: br, .. },
472+
..
473+
}) => printer.region_highlight_mode.highlighting_bound_region(br, counter),
473474
_ => {}
474475
}
475476
}
@@ -485,9 +486,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
485486
let region = if let ty::Ref(region, ..) = ty.kind() {
486487
match **region {
487488
ty::ReLateBound(_, ty::BoundRegion { kind: br, .. })
488-
| ty::RePlaceholder(ty::PlaceholderRegion { name: br, .. }) => {
489-
printer.region_highlight_mode.highlighting_bound_region(br, counter)
490-
}
489+
| ty::RePlaceholder(ty::PlaceholderRegion {
490+
bound: ty::BoundRegion { kind: br, .. },
491+
..
492+
}) => printer.region_highlight_mode.highlighting_bound_region(br, counter),
491493
_ => {}
492494
}
493495
region

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
207207
.regioncx
208208
.placeholders_contained_in(lower_bound)
209209
.map(|placeholder| {
210-
if let Some(id) = placeholder.name.get_id()
210+
if let Some(id) = placeholder.bound.kind.get_id()
211211
&& let Some(placeholder_id) = id.as_local()
212212
&& let gat_hir_id = hir.local_def_id_to_hir_id(placeholder_id)
213213
&& let Some(generics_impl) = hir.get_parent(gat_hir_id).generics()

compiler/rustc_borrowck/src/type_check/relate_tys.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx>
123123
.constraints
124124
.placeholder_region(self.type_checker.infcx, placeholder);
125125

126-
let reg_info = match placeholder.name {
126+
let reg_info = match placeholder.bound.kind {
127127
ty::BoundRegionKind::BrAnon(_, Some(span)) => BoundRegionInfo::Span(span),
128128
ty::BoundRegionKind::BrAnon(..) => BoundRegionInfo::Name(Symbol::intern("anon")),
129129
ty::BoundRegionKind::BrNamed(_, name) => BoundRegionInfo::Name(name),

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2336,10 +2336,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
23362336
FnMutDelegate {
23372337
regions: &mut |_| tcx.lifetimes.re_erased,
23382338
types: &mut |bv| {
2339-
tcx.mk_placeholder(ty::PlaceholderType { universe, name: bv.kind })
2339+
tcx.mk_placeholder(ty::PlaceholderType { universe, bound: bv })
23402340
},
23412341
consts: &mut |bv, ty| {
2342-
tcx.mk_const(ty::PlaceholderConst { universe, name: bv }, ty)
2342+
tcx.mk_const(ty::PlaceholderConst { universe, bound: bv }, ty)
23432343
},
23442344
},
23452345
);
@@ -2525,11 +2525,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
25252525
regions: &mut |_| tcx.lifetimes.re_erased,
25262526
types: &mut |bv| tcx.mk_placeholder(ty::PlaceholderType {
25272527
universe,
2528-
name: bv.kind,
2528+
bound: bv,
25292529
}),
25302530
consts: &mut |bv, ty| tcx.mk_const(ty::PlaceholderConst {
25312531
universe,
2532-
name: bv
2532+
bound: bv,
25332533
}, ty),
25342534
})
25352535
)

compiler/rustc_infer/src/infer/canonical/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ impl<'tcx> InferCtxt<'tcx> {
125125
ty.into()
126126
}
127127

128-
CanonicalVarKind::PlaceholderTy(ty::PlaceholderType { universe, name }) => {
128+
CanonicalVarKind::PlaceholderTy(ty::PlaceholderType { universe, bound }) => {
129129
let universe_mapped = universe_map(universe);
130-
let placeholder_mapped = ty::PlaceholderType { universe: universe_mapped, name };
130+
let placeholder_mapped = ty::PlaceholderType { universe: universe_mapped, bound };
131131
self.tcx.mk_placeholder(placeholder_mapped).into()
132132
}
133133

@@ -138,9 +138,9 @@ impl<'tcx> InferCtxt<'tcx> {
138138
)
139139
.into(),
140140

141-
CanonicalVarKind::PlaceholderRegion(ty::PlaceholderRegion { universe, name }) => {
141+
CanonicalVarKind::PlaceholderRegion(ty::PlaceholderRegion { universe, bound }) => {
142142
let universe_mapped = universe_map(universe);
143-
let placeholder_mapped = ty::PlaceholderRegion { universe: universe_mapped, name };
143+
let placeholder_mapped = ty::PlaceholderRegion { universe: universe_mapped, bound };
144144
self.tcx.mk_re_placeholder(placeholder_mapped).into()
145145
}
146146

@@ -152,9 +152,9 @@ impl<'tcx> InferCtxt<'tcx> {
152152
)
153153
.into(),
154154

155-
CanonicalVarKind::PlaceholderConst(ty::PlaceholderConst { universe, name }, ty) => {
155+
CanonicalVarKind::PlaceholderConst(ty::PlaceholderConst { universe, bound }, ty) => {
156156
let universe_mapped = universe_map(universe);
157-
let placeholder_mapped = ty::PlaceholderConst { universe: universe_mapped, name };
157+
let placeholder_mapped = ty::PlaceholderConst { universe: universe_mapped, bound };
158158
self.tcx.mk_const(placeholder_mapped, ty).into()
159159
}
160160
}

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,15 @@ fn msg_span_from_named_region<'tcx>(
170170
}
171171
ty::ReStatic => ("the static lifetime".to_owned(), alt_span),
172172
ty::RePlaceholder(ty::PlaceholderRegion {
173-
name: ty::BoundRegionKind::BrNamed(def_id, name),
173+
bound: ty::BoundRegion { kind: ty::BoundRegionKind::BrNamed(def_id, name), .. },
174174
..
175175
}) => (format!("the lifetime `{name}` as defined here"), Some(tcx.def_span(def_id))),
176176
ty::RePlaceholder(ty::PlaceholderRegion {
177-
name: ty::BoundRegionKind::BrAnon(_, Some(span)),
177+
bound: ty::BoundRegion { kind: ty::BoundRegionKind::BrAnon(_, Some(span)), .. },
178178
..
179179
}) => (format!("the anonymous lifetime defined here"), Some(span)),
180180
ty::RePlaceholder(ty::PlaceholderRegion {
181-
name: ty::BoundRegionKind::BrAnon(_, None),
181+
bound: ty::BoundRegion { kind: ty::BoundRegionKind::BrAnon(_, None), .. },
182182
..
183183
}) => (format!("an anonymous lifetime"), None),
184184
_ => bug!("{:?}", region),

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_relation.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,20 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
1616
match &self.error {
1717
Some(RegionResolutionError::ConcreteFailure(
1818
SubregionOrigin::RelateRegionParamBound(span),
19-
Region(Interned(RePlaceholder(ty::Placeholder { name: sub_name, .. }), _)),
20-
Region(Interned(RePlaceholder(ty::Placeholder { name: sup_name, .. }), _)),
19+
Region(Interned(
20+
RePlaceholder(ty::Placeholder {
21+
bound: ty::BoundRegion { kind: sub_name, .. },
22+
..
23+
}),
24+
_,
25+
)),
26+
Region(Interned(
27+
RePlaceholder(ty::Placeholder {
28+
bound: ty::BoundRegion { kind: sup_name, .. },
29+
..
30+
}),
31+
_,
32+
)),
2133
)) => {
2234
let span = *span;
2335
let (sub_span, sub_symbol) = match sub_name {

compiler/rustc_infer/src/infer/higher_ranked/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,20 @@ impl<'tcx> InferCtxt<'tcx> {
8282

8383
let delegate = FnMutDelegate {
8484
regions: &mut |br: ty::BoundRegion| {
85-
self.tcx.mk_re_placeholder(ty::PlaceholderRegion {
86-
universe: next_universe,
87-
name: br.kind,
88-
})
85+
self.tcx
86+
.mk_re_placeholder(ty::PlaceholderRegion { universe: next_universe, bound: br })
8987
},
9088
types: &mut |bound_ty: ty::BoundTy| {
9189
self.tcx.mk_placeholder(ty::PlaceholderType {
9290
universe: next_universe,
93-
name: bound_ty.kind,
91+
bound: bound_ty,
9492
})
9593
},
9694
consts: &mut |bound_var: ty::BoundVar, ty| {
97-
self.tcx
98-
.mk_const(ty::PlaceholderConst { universe: next_universe, name: bound_var }, ty)
95+
self.tcx.mk_const(
96+
ty::PlaceholderConst { universe: next_universe, bound: bound_var },
97+
ty,
98+
)
9999
},
100100
};
101101

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2130,13 +2130,17 @@ fn replace_param_and_infer_substs_with_placeholder<'tcx>(
21302130

21312131
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
21322132
if let ty::Infer(_) = t.kind() {
2133+
let idx = {
2134+
let idx = self.idx;
2135+
self.idx += 1;
2136+
idx
2137+
};
21332138
self.tcx.mk_placeholder(ty::PlaceholderType {
21342139
universe: ty::UniverseIndex::ROOT,
2135-
name: ty::BoundTyKind::Anon({
2136-
let idx = self.idx;
2137-
self.idx += 1;
2138-
idx
2139-
}),
2140+
bound: ty::BoundTy {
2141+
var: ty::BoundVar::from_u32(idx),
2142+
kind: ty::BoundTyKind::Anon(idx),
2143+
},
21402144
})
21412145
} else {
21422146
t.super_fold_with(self)
@@ -2153,7 +2157,7 @@ fn replace_param_and_infer_substs_with_placeholder<'tcx>(
21532157
self.tcx.mk_const(
21542158
ty::PlaceholderConst {
21552159
universe: ty::UniverseIndex::ROOT,
2156-
name: ty::BoundVar::from_u32({
2160+
bound: ty::BoundVar::from_u32({
21572161
let idx = self.idx;
21582162
self.idx += 1;
21592163
idx

compiler/rustc_infer/src/infer/nll_relate/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ where
296296
universe
297297
});
298298

299-
let placeholder = ty::PlaceholderRegion { universe, name: br.kind };
299+
let placeholder = ty::PlaceholderRegion { universe, bound: br };
300300
debug!(?placeholder);
301301
let placeholder_reg = nll_delegate.next_placeholder_region(placeholder);
302302
debug!(?placeholder_reg);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,9 @@ impl<'me, 'tcx> LeakCheck<'me, 'tcx> {
290290
) -> TypeError<'tcx> {
291291
debug!("error: placeholder={:?}, other_region={:?}", placeholder, other_region);
292292
if self.overly_polymorphic {
293-
TypeError::RegionsOverlyPolymorphic(placeholder.name, other_region)
293+
TypeError::RegionsOverlyPolymorphic(placeholder.bound.kind, other_region)
294294
} else {
295-
TypeError::RegionsInsufficientlyPolymorphic(placeholder.name, other_region)
295+
TypeError::RegionsInsufficientlyPolymorphic(placeholder.bound.kind, other_region)
296296
}
297297
}
298298
}

compiler/rustc_middle/src/infer/canonical.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,11 @@ impl<'tcx> CanonicalVarInfo<'tcx> {
155155
| CanonicalVarKind::Region(_)
156156
| CanonicalVarKind::Const(_, _) => bug!("expected placeholder: {self:?}"),
157157

158-
CanonicalVarKind::PlaceholderRegion(placeholder) => placeholder.name.expect_anon(),
159-
CanonicalVarKind::PlaceholderTy(placeholder) => placeholder.name.expect_anon(),
160-
CanonicalVarKind::PlaceholderConst(placeholder, _) => placeholder.name.as_u32(),
158+
CanonicalVarKind::PlaceholderRegion(placeholder) => {
159+
placeholder.bound.kind.expect_anon()
160+
}
161+
CanonicalVarKind::PlaceholderTy(placeholder) => placeholder.bound.kind.expect_anon(),
162+
CanonicalVarKind::PlaceholderConst(placeholder, _) => placeholder.bound.as_u32(),
161163
}
162164
}
163165
}

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,12 +1454,12 @@ impl<'tcx> OpaqueHiddenType<'tcx> {
14541454
#[derive(HashStable, TyEncodable, TyDecodable)]
14551455
pub struct Placeholder<T> {
14561456
pub universe: UniverseIndex,
1457-
pub name: T,
1457+
pub bound: T,
14581458
}
14591459

1460-
pub type PlaceholderRegion = Placeholder<BoundRegionKind>;
1460+
pub type PlaceholderRegion = Placeholder<BoundRegion>;
14611461

1462-
pub type PlaceholderType = Placeholder<BoundTyKind>;
1462+
pub type PlaceholderType = Placeholder<BoundTy>;
14631463

14641464
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable)]
14651465
#[derive(TyEncodable, TyDecodable, PartialOrd, Ord)]

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ pub trait PrettyPrinter<'tcx>:
739739
p!(print(data))
740740
}
741741
}
742-
ty::Placeholder(placeholder) => match placeholder.name {
742+
ty::Placeholder(placeholder) => match placeholder.bound.kind {
743743
ty::BoundTyKind::Anon(_) => p!(write("Placeholder({:?})", placeholder)),
744744
ty::BoundTyKind::Param(_, name) => p!(write("{}", name)),
745745
},
@@ -2104,7 +2104,9 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
21042104

21052105
ty::ReLateBound(_, ty::BoundRegion { kind: br, .. })
21062106
| ty::ReFree(ty::FreeRegion { bound_region: br, .. })
2107-
| ty::RePlaceholder(ty::Placeholder { name: br, .. }) => {
2107+
| ty::RePlaceholder(ty::Placeholder {
2108+
bound: ty::BoundRegion { kind: br, .. }, ..
2109+
}) => {
21082110
if br.is_named() {
21092111
return true;
21102112
}
@@ -2181,7 +2183,9 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
21812183
}
21822184
ty::ReLateBound(_, ty::BoundRegion { kind: br, .. })
21832185
| ty::ReFree(ty::FreeRegion { bound_region: br, .. })
2184-
| ty::RePlaceholder(ty::Placeholder { name: br, .. }) => {
2186+
| ty::RePlaceholder(ty::Placeholder {
2187+
bound: ty::BoundRegion { kind: br, .. }, ..
2188+
}) => {
21852189
if let ty::BrNamed(_, name) = br && br.is_named() {
21862190
p!(write("{}", name));
21872191
return Ok(self);
@@ -2259,7 +2263,10 @@ impl<'a, 'tcx> ty::TypeFolder<TyCtxt<'tcx>> for RegionFolder<'a, 'tcx> {
22592263
ty::ReLateBound(db, br) if db >= self.current_index => {
22602264
*self.region_map.entry(br).or_insert_with(|| name(Some(db), self.current_index, br))
22612265
}
2262-
ty::RePlaceholder(ty::PlaceholderRegion { name: kind, .. }) => {
2266+
ty::RePlaceholder(ty::PlaceholderRegion {
2267+
bound: ty::BoundRegion { kind, .. },
2268+
..
2269+
}) => {
22632270
// If this is an anonymous placeholder, don't rename. Otherwise, in some
22642271
// async fns, we get a `for<'r> Send` bound
22652272
match kind {

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ TrivialTypeTraversalAndLiftImpls! {
254254
crate::ty::AssocKind,
255255
crate::ty::AliasKind,
256256
crate::ty::AliasRelationDirection,
257-
crate::ty::Placeholder<crate::ty::BoundRegionKind>,
258-
crate::ty::Placeholder<crate::ty::BoundTyKind>,
257+
crate::ty::Placeholder<crate::ty::BoundRegion>,
258+
crate::ty::Placeholder<crate::ty::BoundTy>,
259259
crate::ty::ClosureKind,
260260
crate::ty::FreeRegion,
261261
crate::ty::InferTy,

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,7 +1632,7 @@ impl<'tcx> Region<'tcx> {
16321632
ty::ReLateBound(_, br) => br.kind.get_name(),
16331633
ty::ReFree(fr) => fr.bound_region.get_name(),
16341634
ty::ReStatic => Some(kw::StaticLifetime),
1635-
ty::RePlaceholder(placeholder) => placeholder.name.get_name(),
1635+
ty::RePlaceholder(placeholder) => placeholder.bound.kind.get_name(),
16361636
_ => None,
16371637
};
16381638

@@ -1650,7 +1650,7 @@ impl<'tcx> Region<'tcx> {
16501650
ty::ReFree(fr) => fr.bound_region.is_named(),
16511651
ty::ReStatic => true,
16521652
ty::ReVar(..) => false,
1653-
ty::RePlaceholder(placeholder) => placeholder.name.is_named(),
1653+
ty::RePlaceholder(placeholder) => placeholder.bound.kind.is_named(),
16541654
ty::ReErased => false,
16551655
ty::ReError(_) => false,
16561656
}

compiler/rustc_trait_selection/src/solve/canonicalize.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,14 +300,20 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'_, 'tcx> {
300300
ty::Placeholder(placeholder) => match self.canonicalize_mode {
301301
CanonicalizeMode::Input => CanonicalVarKind::PlaceholderTy(ty::Placeholder {
302302
universe: placeholder.universe,
303-
name: BoundTyKind::Anon(self.variables.len() as u32),
303+
bound: ty::BoundTy {
304+
var: ty::BoundVar::from_usize(self.variables.len()),
305+
kind: ty::BoundTyKind::Anon(self.variables.len() as u32),
306+
},
304307
}),
305308
CanonicalizeMode::Response { .. } => CanonicalVarKind::PlaceholderTy(placeholder),
306309
},
307310
ty::Param(_) => match self.canonicalize_mode {
308311
CanonicalizeMode::Input => CanonicalVarKind::PlaceholderTy(ty::Placeholder {
309312
universe: ty::UniverseIndex::ROOT,
310-
name: ty::BoundTyKind::Anon(self.variables.len() as u32),
313+
bound: ty::BoundTy {
314+
var: ty::BoundVar::from_usize(self.variables.len()),
315+
kind: ty::BoundTyKind::Anon(self.variables.len() as u32),
316+
},
311317
}),
312318
CanonicalizeMode::Response { .. } => bug!("param ty in response: {t:?}"),
313319
},
@@ -373,7 +379,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'_, 'tcx> {
373379
CanonicalizeMode::Input => CanonicalVarKind::PlaceholderConst(
374380
ty::Placeholder {
375381
universe: placeholder.universe,
376-
name: ty::BoundVar::from(self.variables.len()),
382+
bound: ty::BoundVar::from(self.variables.len()),
377383
},
378384
c.ty(),
379385
),
@@ -385,7 +391,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'_, 'tcx> {
385391
CanonicalizeMode::Input => CanonicalVarKind::PlaceholderConst(
386392
ty::Placeholder {
387393
universe: ty::UniverseIndex::ROOT,
388-
name: ty::BoundVar::from(self.variables.len()),
394+
bound: ty::BoundVar::from(self.variables.len()),
389395
},
390396
c.ty(),
391397
),

0 commit comments

Comments
 (0)