Skip to content

Commit ccc2fd9

Browse files
Use DefId instead of Span in BrAnon to avoid stable hashing collisions
1 parent 5b82ea7 commit ccc2fd9

File tree

7 files changed

+24
-25
lines changed

7 files changed

+24
-25
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
214214

215215
fn re_infer(&self, def: Option<&ty::GenericParamDef>, span: Span) -> Option<ty::Region<'tcx>> {
216216
let v = match def {
217-
Some(def) => infer::EarlyBoundRegion(span, def.name),
217+
Some(def) => infer::EarlyBoundRegion(span, def.def_id),
218218
None => infer::MiscVariable(span),
219219
};
220220
Some(self.next_region_var(v))

compiler/rustc_hir_typeck/src/generator_interior/mod.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ pub fn resolve_interior<'a, 'tcx>(
228228
// typeck had previously found constraints that would cause them to be related.
229229

230230
let mut counter = 0;
231-
let mut mk_bound_region = |span| {
232-
let kind = ty::BrAnon(counter, span);
231+
let mut mk_bound_region = |def_id| {
232+
let kind = ty::BrAnon(counter, def_id);
233233
let var = ty::BoundVar::from_u32(counter);
234234
counter += 1;
235235
ty::BoundRegion { var, kind }
@@ -240,22 +240,18 @@ pub fn resolve_interior<'a, 'tcx>(
240240
ty::ReVar(vid) => {
241241
let origin = fcx.region_var_origin(vid);
242242
match origin {
243-
RegionVariableOrigin::EarlyBoundRegion(span, _) => {
244-
mk_bound_region(Some(span))
243+
RegionVariableOrigin::EarlyBoundRegion(_, def_id) => {
244+
mk_bound_region(Some(def_id))
245245
}
246246
_ => mk_bound_region(None),
247247
}
248248
}
249249
// FIXME: these should use `BrNamed`
250-
ty::ReEarlyBound(region) => {
251-
mk_bound_region(Some(fcx.tcx.def_span(region.def_id)))
252-
}
250+
ty::ReEarlyBound(region) => mk_bound_region(Some(region.def_id)),
253251
ty::ReLateBound(_, ty::BoundRegion { kind, .. })
254252
| ty::ReFree(ty::FreeRegion { bound_region: kind, .. }) => match kind {
255-
ty::BoundRegionKind::BrAnon(_, span) => mk_bound_region(span),
256-
ty::BoundRegionKind::BrNamed(def_id, _) => {
257-
mk_bound_region(Some(fcx.tcx.def_span(def_id)))
258-
}
253+
ty::BoundRegionKind::BrAnon(_, def_id) => mk_bound_region(def_id),
254+
ty::BoundRegionKind::BrNamed(def_id, _) => mk_bound_region(Some(def_id)),
259255
ty::BoundRegionKind::BrEnv => mk_bound_region(None),
260256
},
261257
_ => mk_bound_region(None),

compiler/rustc_infer/src/errors/note_and_explain.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ impl<'a> DescriptionCtx<'a> {
8989
};
9090
me.span = Some(sp);
9191
}
92-
ty::BrAnon(idx, span) => {
92+
ty::BrAnon(idx, def_id) => {
9393
me.kind = "anon_num_here";
9494
me.num_arg = idx+1;
95-
me.span = match span {
96-
Some(_) => span,
95+
me.span = match def_id {
96+
Some(def_id) => Some(tcx.def_span(def_id)),
9797
None => Some(tcx.def_span(scope)),
9898
}
9999
},

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,10 @@ fn msg_span_from_early_bound_and_free_regions<'tcx>(
211211
};
212212
(text, sp)
213213
}
214-
ty::BrAnon(idx, span) => (
214+
ty::BrAnon(idx, def_id) => (
215215
format!("the anonymous lifetime #{} defined here", idx + 1),
216-
match span {
217-
Some(span) => span,
216+
match def_id {
217+
Some(def_id) => tcx.def_span(def_id),
218218
None => tcx.def_span(scope)
219219
}
220220
),
@@ -3048,7 +3048,9 @@ impl<'tcx> InferCtxt<'tcx> {
30483048
br_string(br),
30493049
self.tcx.associated_item(def_id).name
30503050
),
3051-
infer::EarlyBoundRegion(_, name) => format!(" for lifetime parameter `{}`", name),
3051+
infer::EarlyBoundRegion(_, def_id) => {
3052+
format!(" for lifetime parameter `{}`", self.tcx.item_name(def_id))
3053+
}
30523054
infer::UpvarRegion(ref upvar_id, _) => {
30533055
let var_name = self.tcx.hir().name(upvar_id.var_path.hir_id);
30543056
format!(" for capture of `{}` by closure", var_name)

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
2222
ty::BrNamed(def_id, symbol) => {
2323
(Some(self.tcx().def_span(def_id)), Some(symbol))
2424
}
25-
ty::BrAnon(_, span) => (*span, None),
25+
ty::BrAnon(_, Some(def_id)) => (Some(self.tcx().def_span(def_id)), None),
26+
ty::BrAnon(_, None) => (None, None),
2627
ty::BrEnv => (None, None),
2728
};
2829
let (sup_span, sup_symbol) = match sup_name {
2930
ty::BrNamed(def_id, symbol) => {
3031
(Some(self.tcx().def_span(def_id)), Some(symbol))
3132
}
32-
ty::BrAnon(_, span) => (*span, None),
33+
ty::BrAnon(_, Some(def_id)) => (Some(self.tcx().def_span(def_id)), None),
34+
ty::BrAnon(_, None) => (None, None),
3335
ty::BrEnv => (None, None),
3436
};
3537
match (sub_span, sup_span, sub_symbol, sup_symbol) {

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use rustc_middle::ty::visit::TypeVisitable;
3333
pub use rustc_middle::ty::IntVarValue;
3434
use rustc_middle::ty::{self, GenericParamDefKind, InferConst, Ty, TyCtxt};
3535
use rustc_middle::ty::{ConstVid, FloatVid, IntVid, TyVid};
36-
use rustc_span::symbol::Symbol;
3736
use rustc_span::{Span, DUMMY_SP};
3837

3938
use std::cell::{Cell, RefCell};
@@ -470,7 +469,7 @@ pub enum RegionVariableOrigin {
470469
Coercion(Span),
471470

472471
/// Region variables created as the values for early-bound regions
473-
EarlyBoundRegion(Span, Symbol),
472+
EarlyBoundRegion(Span, DefId),
474473

475474
/// Region variables created for bound regions
476475
/// in a function or method that is called
@@ -1181,7 +1180,7 @@ impl<'tcx> InferCtxt<'tcx> {
11811180
GenericParamDefKind::Lifetime => {
11821181
// Create a region inference variable for the given
11831182
// region parameter definition.
1184-
self.next_region_var(EarlyBoundRegion(span, param.name)).into()
1183+
self.next_region_var(EarlyBoundRegion(span, param.def_id)).into()
11851184
}
11861185
GenericParamDefKind::Type { .. } => {
11871186
// Create a type inference variable for the given

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub struct FreeRegion {
5959
#[derive(HashStable)]
6060
pub enum BoundRegionKind {
6161
/// An anonymous region parameter for a given fn (&T)
62-
BrAnon(u32, Option<Span>),
62+
BrAnon(u32, Option<DefId>),
6363

6464
/// Named region parameters for functions (a in &'a T)
6565
///

0 commit comments

Comments
 (0)