Skip to content

Commit 098a24f

Browse files
committed
Auto merge of rust-lang#139598 - compiler-errors:no-bound-var-symbol, r=<try>
Remove `Symbol` from `Named` variant of `BoundRegionKind`/`LateParamRegionKind` r? `@ghost`
2 parents 48f89e7 + dba712a commit 098a24f

File tree

35 files changed

+289
-313
lines changed

35 files changed

+289
-313
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -4184,7 +4184,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
41844184
// anything.
41854185
let return_ty = sig.output();
41864186
match return_ty.skip_binder().kind() {
4187-
ty::Ref(return_region, _, _) if return_region.has_name() && !is_closure => {
4187+
ty::Ref(return_region, _, _)
4188+
if return_region.has_name(self.infcx.tcx) && !is_closure =>
4189+
{
41884190
// This is case 1 from above, return type is a named reference so we need to
41894191
// search for relevant arguments.
41904192
let mut arguments = Vec::new();

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
851851
return;
852852
};
853853

854-
let lifetime = if f.has_name() { fr_name.name } else { kw::UnderscoreLifetime };
854+
let lifetime =
855+
if f.has_name(self.infcx.tcx) { fr_name.name } else { kw::UnderscoreLifetime };
855856

856857
let arg = match param.param.pat.simple_ident() {
857858
Some(simple_ident) => format!("argument `{simple_ident}`"),

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -300,16 +300,11 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
300300
}
301301

302302
ty::ReLateParam(late_param) => match late_param.kind {
303-
ty::LateParamRegionKind::Named(region_def_id, name) => {
303+
ty::LateParamRegionKind::Named(region_def_id) => {
304304
// Get the span to point to, even if we don't use the name.
305305
let span = tcx.hir_span_if_local(region_def_id).unwrap_or(DUMMY_SP);
306-
debug!(
307-
"bound region named: {:?}, is_named: {:?}",
308-
name,
309-
late_param.kind.is_named()
310-
);
311306

312-
if late_param.kind.is_named() {
307+
if let Some(name) = late_param.kind.get_name(tcx) {
313308
// A named region that is actually named.
314309
Some(RegionName {
315310
name,
@@ -368,7 +363,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
368363
})
369364
}
370365

371-
ty::LateParamRegionKind::Anon(_) => None,
366+
ty::LateParamRegionKind::Anon(_) | ty::LateParamRegionKind::NamedAnon(_, _) => None,
372367
},
373368

374369
ty::ReBound(..)

compiler/rustc_borrowck/src/nll.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,13 @@ pub(super) fn dump_nll_mir<'tcx>(
235235
// Also dump the region constraint graph as a graphviz file.
236236
let _: io::Result<()> = try {
237237
let mut file = create_dump_file(tcx, "regioncx.all.dot", false, "nll", &0, body)?;
238-
regioncx.dump_graphviz_raw_constraints(&mut file)?;
238+
regioncx.dump_graphviz_raw_constraints(tcx, &mut file)?;
239239
};
240240

241241
// Also dump the region constraint SCC graph as a graphviz file.
242242
let _: io::Result<()> = try {
243243
let mut file = create_dump_file(tcx, "regioncx.scc.dot", false, "nll", &0, body)?;
244-
regioncx.dump_graphviz_scc_constraints(&mut file)?;
244+
regioncx.dump_graphviz_scc_constraints(tcx, &mut file)?;
245245
};
246246
}
247247

compiler/rustc_borrowck/src/polonius/dump.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,15 @@ fn emit_polonius_dump<'tcx>(
116116
writeln!(out, "<div>")?;
117117
writeln!(out, "NLL regions")?;
118118
writeln!(out, "<pre class='mermaid'>")?;
119-
emit_mermaid_nll_regions(regioncx, out)?;
119+
emit_mermaid_nll_regions(tcx, regioncx, out)?;
120120
writeln!(out, "</pre>")?;
121121
writeln!(out, "</div>")?;
122122

123123
// Section 5: mermaid visualization of the NLL SCC graph.
124124
writeln!(out, "<div>")?;
125125
writeln!(out, "NLL SCCs")?;
126126
writeln!(out, "<pre class='mermaid'>")?;
127-
emit_mermaid_nll_sccs(regioncx, out)?;
127+
emit_mermaid_nll_sccs(tcx, regioncx, out)?;
128128
writeln!(out, "</pre>")?;
129129
writeln!(out, "</div>")?;
130130

@@ -306,9 +306,10 @@ fn emit_mermaid_cfg(body: &Body<'_>, out: &mut dyn io::Write) -> io::Result<()>
306306
}
307307

308308
/// Emits a region's label: index, universe, external name.
309-
fn render_region(
309+
fn render_region<'tcx>(
310+
tcx: TyCtxt<'tcx>,
310311
region: RegionVid,
311-
regioncx: &RegionInferenceContext<'_>,
312+
regioncx: &RegionInferenceContext<'tcx>,
312313
out: &mut dyn io::Write,
313314
) -> io::Result<()> {
314315
let def = regioncx.region_definition(region);
@@ -318,7 +319,7 @@ fn render_region(
318319
if !universe.is_root() {
319320
write!(out, "/{universe:?}")?;
320321
}
321-
if let Some(name) = def.external_name.and_then(|e| e.get_name()) {
322+
if let Some(name) = def.external_name.and_then(|e| e.get_name(tcx)) {
322323
write!(out, " ({name})")?;
323324
}
324325
Ok(())
@@ -327,6 +328,7 @@ fn render_region(
327328
/// Emits a mermaid flowchart of the NLL regions and the outlives constraints between them, similar
328329
/// to the graphviz version.
329330
fn emit_mermaid_nll_regions<'tcx>(
331+
tcx: TyCtxt<'tcx>,
330332
regioncx: &RegionInferenceContext<'tcx>,
331333
out: &mut dyn io::Write,
332334
) -> io::Result<()> {
@@ -336,7 +338,7 @@ fn emit_mermaid_nll_regions<'tcx>(
336338
// Emit the region nodes.
337339
for region in regioncx.definitions.indices() {
338340
write!(out, "{}[\"", region.as_usize())?;
339-
render_region(region, regioncx, out)?;
341+
render_region(tcx, region, regioncx, out)?;
340342
writeln!(out, "\"]")?;
341343
}
342344

@@ -378,6 +380,7 @@ fn emit_mermaid_nll_regions<'tcx>(
378380
/// Emits a mermaid flowchart of the NLL SCCs and the outlives constraints between them, similar
379381
/// to the graphviz version.
380382
fn emit_mermaid_nll_sccs<'tcx>(
383+
tcx: TyCtxt<'tcx>,
381384
regioncx: &RegionInferenceContext<'tcx>,
382385
out: &mut dyn io::Write,
383386
) -> io::Result<()> {
@@ -395,7 +398,7 @@ fn emit_mermaid_nll_sccs<'tcx>(
395398
// The node label: the regions contained in the SCC.
396399
write!(out, "{scc}[\"SCC({scc}) = {{", scc = scc.as_usize())?;
397400
for (idx, &region) in regions.iter().enumerate() {
398-
render_region(region, regioncx, out)?;
401+
render_region(tcx, region, regioncx, out)?;
399402
if idx < regions.len() - 1 {
400403
write!(out, ",")?;
401404
}

compiler/rustc_borrowck/src/region_infer/graphviz.rs

+25-9
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,15 @@ fn render_universe(u: UniverseIndex) -> String {
2626
format!("/{:?}", u)
2727
}
2828

29-
fn render_region_vid(rvid: RegionVid, regioncx: &RegionInferenceContext<'_>) -> String {
29+
fn render_region_vid<'tcx>(
30+
tcx: TyCtxt<'tcx>,
31+
rvid: RegionVid,
32+
regioncx: &RegionInferenceContext<'tcx>,
33+
) -> String {
3034
let universe_str = render_universe(regioncx.region_definition(rvid).universe);
3135

3236
let external_name_str = if let Some(external_name) =
33-
regioncx.region_definition(rvid).external_name.and_then(|e| e.get_name())
37+
regioncx.region_definition(rvid).external_name.and_then(|e| e.get_name(tcx))
3438
{
3539
format!(" ({external_name})")
3640
} else {
@@ -42,12 +46,20 @@ fn render_region_vid(rvid: RegionVid, regioncx: &RegionInferenceContext<'_>) ->
4246

4347
impl<'tcx> RegionInferenceContext<'tcx> {
4448
/// Write out the region constraint graph.
45-
pub(crate) fn dump_graphviz_raw_constraints(&self, mut w: &mut dyn Write) -> io::Result<()> {
46-
dot::render(&RawConstraints { regioncx: self }, &mut w)
49+
pub(crate) fn dump_graphviz_raw_constraints(
50+
&self,
51+
tcx: TyCtxt<'tcx>,
52+
mut w: &mut dyn Write,
53+
) -> io::Result<()> {
54+
dot::render(&RawConstraints { tcx, regioncx: self }, &mut w)
4755
}
4856

4957
/// Write out the region constraint SCC graph.
50-
pub(crate) fn dump_graphviz_scc_constraints(&self, mut w: &mut dyn Write) -> io::Result<()> {
58+
pub(crate) fn dump_graphviz_scc_constraints(
59+
&self,
60+
tcx: TyCtxt<'tcx>,
61+
mut w: &mut dyn Write,
62+
) -> io::Result<()> {
5163
let mut nodes_per_scc: IndexVec<ConstraintSccIndex, _> =
5264
self.constraint_sccs.all_sccs().map(|_| Vec::new()).collect();
5365

@@ -56,11 +68,12 @@ impl<'tcx> RegionInferenceContext<'tcx> {
5668
nodes_per_scc[scc].push(region);
5769
}
5870

59-
dot::render(&SccConstraints { regioncx: self, nodes_per_scc }, &mut w)
71+
dot::render(&SccConstraints { tcx, regioncx: self, nodes_per_scc }, &mut w)
6072
}
6173
}
6274

6375
struct RawConstraints<'a, 'tcx> {
76+
tcx: TyCtxt<'tcx>,
6477
regioncx: &'a RegionInferenceContext<'tcx>,
6578
}
6679

@@ -78,7 +91,7 @@ impl<'a, 'this, 'tcx> dot::Labeller<'this> for RawConstraints<'a, 'tcx> {
7891
Some(dot::LabelText::LabelStr(Cow::Borrowed("box")))
7992
}
8093
fn node_label(&'this self, n: &RegionVid) -> dot::LabelText<'this> {
81-
dot::LabelText::LabelStr(render_region_vid(*n, self.regioncx).into())
94+
dot::LabelText::LabelStr(render_region_vid(self.tcx, *n, self.regioncx).into())
8295
}
8396
fn edge_label(&'this self, e: &OutlivesConstraint<'tcx>) -> dot::LabelText<'this> {
8497
dot::LabelText::LabelStr(render_outlives_constraint(e).into())
@@ -110,6 +123,7 @@ impl<'a, 'this, 'tcx> dot::GraphWalk<'this> for RawConstraints<'a, 'tcx> {
110123
}
111124

112125
struct SccConstraints<'a, 'tcx> {
126+
tcx: TyCtxt<'tcx>,
113127
regioncx: &'a RegionInferenceContext<'tcx>,
114128
nodes_per_scc: IndexVec<ConstraintSccIndex, Vec<RegionVid>>,
115129
}
@@ -128,8 +142,10 @@ impl<'a, 'this, 'tcx> dot::Labeller<'this> for SccConstraints<'a, 'tcx> {
128142
Some(dot::LabelText::LabelStr(Cow::Borrowed("box")))
129143
}
130144
fn node_label(&'this self, n: &ConstraintSccIndex) -> dot::LabelText<'this> {
131-
let nodes_str =
132-
self.nodes_per_scc[*n].iter().map(|n| render_region_vid(*n, self.regioncx)).join(", ");
145+
let nodes_str = self.nodes_per_scc[*n]
146+
.iter()
147+
.map(|n| render_region_vid(self.tcx, *n, self.regioncx))
148+
.join(", ");
133149
dot::LabelText::LabelStr(format!("SCC({n}) = {{{nodes_str}}}", n = n.as_usize()).into())
134150
}
135151
}

compiler/rustc_borrowck/src/type_check/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
800800
let region_ctxt_fn = || {
801801
let reg_info = match br.kind {
802802
ty::BoundRegionKind::Anon => sym::anon,
803-
ty::BoundRegionKind::Named(_, name) => name,
803+
ty::BoundRegionKind::NamedAnon(name) => name,
804+
ty::BoundRegionKind::Named(def_id) => tcx.item_name(def_id),
804805
ty::BoundRegionKind::ClosureEnv => sym::env,
805806
};
806807

compiler/rustc_borrowck/src/type_check/relate_tys.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
215215
if let Some(ex_reg_var) = reg_map.get(&br) {
216216
*ex_reg_var
217217
} else {
218-
let ex_reg_var = self.next_existential_region_var(true, br.kind.get_name());
218+
let ex_reg_var =
219+
self.next_existential_region_var(true, br.kind.get_name(infcx.infcx.tcx));
219220
debug!(?ex_reg_var);
220221
reg_map.insert(br, ex_reg_var);
221222

@@ -263,7 +264,8 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
263264

264265
let reg_info = match placeholder.bound.kind {
265266
ty::BoundRegionKind::Anon => sym::anon,
266-
ty::BoundRegionKind::Named(_, name) => name,
267+
ty::BoundRegionKind::NamedAnon(name) => name,
268+
ty::BoundRegionKind::Named(def_id) => self.type_checker.tcx().item_name(def_id),
267269
ty::BoundRegionKind::ClosureEnv => sym::env,
268270
};
269271

compiler/rustc_borrowck/src/universal_regions.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
493493
|r| {
494494
debug!(?r);
495495
let region_vid = {
496-
let name = r.get_name_or_anon();
496+
let name = r.get_name_or_anon(self.infcx.tcx);
497497
self.infcx.next_nll_region_var(FR, || RegionCtxt::LateBound(name))
498498
};
499499

@@ -519,7 +519,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
519519
let kind = ty::LateParamRegionKind::from_bound(ty::BoundVar::from_usize(idx), kind);
520520
let r = ty::Region::new_late_param(self.infcx.tcx, self.mir_def.to_def_id(), kind);
521521
let region_vid = {
522-
let name = r.get_name_or_anon();
522+
let name = r.get_name_or_anon(self.infcx.tcx);
523523
self.infcx.next_nll_region_var(FR, || RegionCtxt::LateBound(name))
524524
};
525525

@@ -857,7 +857,7 @@ impl<'tcx> BorrowckInferCtxt<'tcx> {
857857
T: TypeFoldable<TyCtxt<'tcx>>,
858858
{
859859
fold_regions(self.infcx.tcx, value, |region, _depth| {
860-
let name = region.get_name_or_anon();
860+
let name = region.get_name_or_anon(self.infcx.tcx);
861861
debug!(?region, ?name);
862862

863863
self.next_nll_region_var(origin, || RegionCtxt::Free(name))

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2270,7 +2270,7 @@ fn param_env_with_gat_bounds<'tcx>(
22702270
.into()
22712271
}
22722272
GenericParamDefKind::Lifetime => {
2273-
let kind = ty::BoundRegionKind::Named(param.def_id, param.name);
2273+
let kind = ty::BoundRegionKind::Named(param.def_id);
22742274
let bound_var = ty::BoundVariableKind::Region(kind);
22752275
bound_vars.push(bound_var);
22762276
ty::Region::new_bound(

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2408,7 +2408,7 @@ fn lint_redundant_lifetimes<'tcx>(
24082408
lifetimes.push(ty::Region::new_late_param(tcx, owner_id.to_def_id(), kind));
24092409
}
24102410
}
2411-
lifetimes.retain(|candidate| candidate.has_name());
2411+
lifetimes.retain(|candidate| candidate.has_name(tcx));
24122412

24132413
// Keep track of lifetimes which have already been replaced with other lifetimes.
24142414
// This makes sure that if `'a = 'b = 'c`, we don't say `'c` should be replaced by

compiler/rustc_hir_analysis/src/collect.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -638,11 +638,7 @@ fn get_new_lifetime_name<'tcx>(
638638
.collect_referenced_late_bound_regions(poly_trait_ref)
639639
.into_iter()
640640
.filter_map(|lt| {
641-
if let ty::BoundRegionKind::Named(_, name) = lt {
642-
Some(name.as_str().to_string())
643-
} else {
644-
None
645-
}
641+
if let Some(name) = lt.get_name(tcx) { Some(name.as_str().to_string()) } else { None }
646642
})
647643
.chain(generics.params.iter().filter_map(|param| {
648644
if let hir::GenericParamKind::Lifetime { .. } = &param.kind {

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ fn late_arg_as_bound_arg<'tcx>(
280280
let name = tcx.item_name(def_id);
281281
match param.kind {
282282
GenericParamKind::Lifetime { .. } => {
283-
ty::BoundVariableKind::Region(ty::BoundRegionKind::Named(def_id, name))
283+
ty::BoundVariableKind::Region(ty::BoundRegionKind::Named(def_id))
284284
}
285285
GenericParamKind::Type { .. } => {
286286
ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(def_id, name))
@@ -295,7 +295,7 @@ fn late_arg_as_bound_arg<'tcx>(
295295
fn generic_param_def_as_bound_arg(param: &ty::GenericParamDef) -> ty::BoundVariableKind {
296296
match param.kind {
297297
ty::GenericParamDefKind::Lifetime => {
298-
ty::BoundVariableKind::Region(ty::BoundRegionKind::Named(param.def_id, param.name))
298+
ty::BoundVariableKind::Region(ty::BoundRegionKind::Named(param.def_id))
299299
}
300300
ty::GenericParamDefKind::Type { .. } => {
301301
ty::BoundVariableKind::Ty(ty::BoundTyKind::Param(param.def_id, param.name))

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_middle::ty::{
1212
self as ty, IsSuggestable, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
1313
TypeVisitor, Upcast,
1414
};
15-
use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol, kw, sym};
15+
use rustc_span::{ErrorGuaranteed, Ident, Span, kw, sym};
1616
use rustc_trait_selection::traits;
1717
use smallvec::SmallVec;
1818
use tracing::{debug, instrument};
@@ -851,7 +851,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
851851
ty::INNERMOST,
852852
ty::BoundRegion {
853853
var: ty::BoundVar::from_usize(num_bound_vars),
854-
kind: ty::BoundRegionKind::Named(param.def_id, param.name),
854+
kind: ty::BoundRegionKind::Named(param.def_id),
855855
},
856856
)
857857
.into(),
@@ -969,12 +969,12 @@ fn check_assoc_const_binding_type<'tcx>(
969969
ty_note,
970970
}));
971971
}
972-
for (var_def_id, var_name) in collector.vars {
972+
for var_def_id in collector.vars {
973973
guar.get_or_insert(cx.dcx().emit_err(
974974
crate::errors::EscapingBoundVarInTyOfAssocConstBinding {
975975
span: assoc_const.span,
976976
assoc_const,
977-
var_name,
977+
var_name: cx.tcx().item_name(var_def_id),
978978
var_def_kind: tcx.def_descr(var_def_id),
979979
var_defined_here_label: tcx.def_ident_span(var_def_id).unwrap(),
980980
ty_note,
@@ -989,7 +989,7 @@ fn check_assoc_const_binding_type<'tcx>(
989989
struct GenericParamAndBoundVarCollector<'a, 'tcx> {
990990
cx: &'a dyn HirTyLowerer<'tcx>,
991991
params: FxIndexSet<u32>,
992-
vars: FxIndexSet<(DefId, Symbol)>,
992+
vars: FxIndexSet<DefId>,
993993
depth: ty::DebruijnIndex,
994994
}
995995

@@ -1013,7 +1013,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GenericParamAndBoundVarCollector<'_, 't
10131013
}
10141014
ty::Bound(db, bt) if *db >= self.depth => {
10151015
self.vars.insert(match bt.kind {
1016-
ty::BoundTyKind::Param(def_id, name) => (def_id, name),
1016+
ty::BoundTyKind::Param(def_id, _) => def_id,
10171017
ty::BoundTyKind::Anon => {
10181018
let reported = self
10191019
.cx
@@ -1036,8 +1036,10 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GenericParamAndBoundVarCollector<'_, 't
10361036
}
10371037
ty::ReBound(db, br) if db >= self.depth => {
10381038
self.vars.insert(match br.kind {
1039-
ty::BoundRegionKind::Named(def_id, name) => (def_id, name),
1040-
ty::BoundRegionKind::Anon | ty::BoundRegionKind::ClosureEnv => {
1039+
ty::BoundRegionKind::Named(def_id) => def_id,
1040+
ty::BoundRegionKind::Anon
1041+
| ty::BoundRegionKind::NamedAnon(_)
1042+
| ty::BoundRegionKind::ClosureEnv => {
10411043
let guar = self
10421044
.cx
10431045
.dcx()

0 commit comments

Comments
 (0)