Skip to content

Commit

Permalink
Fix issue rust-lang#125143
Browse files Browse the repository at this point in the history
 - More than one unnamed lifetimes gave incorrect spans when lookup
   was done by name (since they both had name "'_"). Use DefId instead
   to get correct spans.
  • Loading branch information
bovinebuddha committed May 17, 2024
1 parent 2d89cee commit 4ee2fce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,10 @@ impl<'hir> Generics<'hir> {
self.params.iter().find(|&param| name == param.name.ident().name)
}

pub fn get_with_def_id(&self, id: DefId) -> Option<&GenericParam<'hir>> {
self.params.iter().find(|&param| id.index == param.def_id.local_def_index)
}

/// If there are generic parameters, return where to introduce a new one.
pub fn span_for_lifetime_suggestion(&self) -> Option<Span> {
if let Some(first) = self.params.first()
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,10 @@ fn msg_span_from_named_region<'tcx>(
match *region {
ty::ReEarlyParam(ref br) => {
let scope = region.free_region_binding_scope(tcx).expect_local();
let span = if let Some(param) =
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(br.name))
let span = if let Some(param) = tcx
.hir()
.get_generics(scope)
.and_then(|generics| generics.get_with_def_id(br.def_id))
{
param.span
} else {
Expand Down

0 comments on commit 4ee2fce

Please sign in to comment.