Skip to content

Commit 9452402

Browse files
committed
Auto merge of #110036 - jackh726:placeholder_boundvar, r=nnethercote
Remove u32 on BrAnon and BoundTyKind::Anon in favor of BoundVar on Placeholder types r? `@nnethercote` Better alternative to #110025
2 parents da14081 + f08f154 commit 9452402

Some content is hidden

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

47 files changed

+204
-200
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/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,9 +1342,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
13421342

13431343
let region_ctxt_fn = || {
13441344
let reg_info = match br.kind {
1345-
ty::BoundRegionKind::BrAnon(_, Some(span)) => {
1346-
BoundRegionInfo::Span(span)
1347-
}
1345+
ty::BoundRegionKind::BrAnon(Some(span)) => BoundRegionInfo::Span(span),
13481346
ty::BoundRegionKind::BrAnon(..) => {
13491347
BoundRegionInfo::Name(Symbol::intern("anon"))
13501348
}

compiler/rustc_borrowck/src/type_check/relate_tys.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ 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 {
127-
ty::BoundRegionKind::BrAnon(_, Some(span)) => BoundRegionInfo::Span(span),
126+
let reg_info = match placeholder.bound.kind {
127+
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),
130130
ty::BoundRegionKind::BrEnv => BoundRegionInfo::Name(Symbol::intern("env")),

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_hir_analysis/src/check/intrinsic.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,14 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
139139
let name_str = intrinsic_name.as_str();
140140

141141
let bound_vars = tcx.mk_bound_variable_kinds(&[
142-
ty::BoundVariableKind::Region(ty::BrAnon(0, None)),
142+
ty::BoundVariableKind::Region(ty::BrAnon(None)),
143143
ty::BoundVariableKind::Region(ty::BrEnv),
144144
]);
145145
let mk_va_list_ty = |mutbl| {
146146
tcx.lang_items().va_list().map(|did| {
147147
let region = tcx.mk_re_late_bound(
148148
ty::INNERMOST,
149-
ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(0, None) },
149+
ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(None) },
150150
);
151151
let env_region = tcx.mk_re_late_bound(
152152
ty::INNERMOST,
@@ -387,8 +387,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
387387
);
388388
let discriminant_def_id = assoc_items[0];
389389

390-
let br =
391-
ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(0, None) };
390+
let br = ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(None) };
392391
(
393392
1,
394393
vec![tcx.mk_imm_ref(tcx.mk_re_late_bound(ty::INNERMOST, br), param(0))],
@@ -440,8 +439,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
440439
sym::nontemporal_store => (1, vec![tcx.mk_mut_ptr(param(0)), param(0)], tcx.mk_unit()),
441440

442441
sym::raw_eq => {
443-
let br =
444-
ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(0, None) };
442+
let br = ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(None) };
445443
let param_ty = tcx.mk_imm_ref(tcx.mk_re_late_bound(ty::INNERMOST, br), param(0));
446444
(1, vec![param_ty; 2], tcx.types.bool)
447445
}

compiler/rustc_hir_typeck/src/generator_interior/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ pub fn resolve_interior<'a, 'tcx>(
240240

241241
let mut counter = 0;
242242
let mut mk_bound_region = |span| {
243-
let kind = ty::BrAnon(counter, span);
243+
let kind = ty::BrAnon(span);
244244
let var = ty::BoundVar::from_u32(counter);
245245
counter += 1;
246246
ty::BoundRegion { var, kind }
@@ -263,7 +263,7 @@ pub fn resolve_interior<'a, 'tcx>(
263263
}
264264
ty::ReLateBound(_, ty::BoundRegion { kind, .. })
265265
| ty::ReFree(ty::FreeRegion { bound_region: kind, .. }) => match kind {
266-
ty::BoundRegionKind::BrAnon(_, span) => mk_bound_region(span),
266+
ty::BoundRegionKind::BrAnon(span) => mk_bound_region(span),
267267
ty::BoundRegionKind::BrNamed(def_id, _) => {
268268
mk_bound_region(Some(fcx.tcx.def_span(def_id)))
269269
}
@@ -294,7 +294,7 @@ pub fn resolve_interior<'a, 'tcx>(
294294
FnMutDelegate {
295295
regions: &mut |br| {
296296
let kind = match br.kind {
297-
ty::BrAnon(_, span) => ty::BrAnon(counter, span),
297+
ty::BrAnon(span) => ty::BrAnon(span),
298298
_ => br.kind,
299299
};
300300
let var = ty::BoundVar::from_usize(bound_vars.len());

compiler/rustc_infer/src/errors/note_and_explain.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,8 @@ impl<'a> DescriptionCtx<'a> {
9090
};
9191
me.span = Some(sp);
9292
}
93-
ty::BrAnon(idx, span) => {
94-
me.kind = "anon_num_here";
95-
me.num_arg = idx+1;
93+
ty::BrAnon(span) => {
94+
me.kind = "defined_here";
9695
me.span = match span {
9796
Some(_) => span,
9897
None => Some(tcx.def_span(scope)),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
772772
r: ty::Region<'tcx>,
773773
) -> ty::Region<'tcx> {
774774
let var = self.canonical_var(info, r.into());
775-
let br = ty::BoundRegion { var, kind: ty::BrAnon(var.as_u32(), None) };
775+
let br = ty::BoundRegion { var, kind: ty::BrAnon(None) };
776776
self.interner().mk_re_late_bound(self.binder_index, br)
777777
}
778778

0 commit comments

Comments
 (0)