Skip to content

Commit 9452402

Browse files
committed
Auto merge of rust-lang#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 rust-lang#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

+2-2
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

+8-6
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

+1-1
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

+1-3
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

+2-2
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

+4-4
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

+4-6
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

+3-3
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

+2-3
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

+1-1
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

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

+6-6
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

+5-5
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),
@@ -226,8 +226,8 @@ fn msg_span_from_early_bound_and_free_regions<'tcx>(
226226
};
227227
(text, sp)
228228
}
229-
ty::BrAnon(idx, span) => (
230-
format!("the anonymous lifetime #{} defined here", idx + 1),
229+
ty::BrAnon(span) => (
230+
"the anonymous lifetime as defined here".to_string(),
231231
match span {
232232
Some(span) => span,
233233
None => tcx.def_span(scope)

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

+16-4
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,34 @@ 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 {
2436
ty::BrNamed(def_id, symbol) => {
2537
(Some(self.tcx().def_span(def_id)), Some(symbol))
2638
}
27-
ty::BrAnon(_, span) => (*span, None),
39+
ty::BrAnon(span) => (*span, None),
2840
ty::BrEnv => (None, None),
2941
};
3042
let (sup_span, sup_symbol) = match sup_name {
3143
ty::BrNamed(def_id, symbol) => {
3244
(Some(self.tcx().def_span(def_id)), Some(symbol))
3345
}
34-
ty::BrAnon(_, span) => (*span, None),
46+
ty::BrAnon(span) => (*span, None),
3547
ty::BrEnv => (None, None),
3648
};
3749
let diag = match (sub_span, sup_span, sub_symbol, sup_symbol) {

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

+7-7
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

+10-6
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,
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

+1-1
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

+2-2
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
}

0 commit comments

Comments
 (0)