Auto merge of #121587 - ShoyuVanilla:fix-issue-121267, r=TaKO8Ki
Fix bad span for explicit lifetime suggestions
Fixes #121267
Current explicit lifetime suggestions are not showing correct spans for some lifetimes - e.g. elided lifetime generic parameters;
This should be done correctly regarding elided lifetime kind like the following code
43fdd4916d/compiler/rustc_resolve/src/late/diagnostics.rs (L3015-L3044)
This commit is contained in:
commit
6e1f7b538a
11 changed files with 167 additions and 83 deletions
|
@ -810,6 +810,8 @@ pub enum LifetimeRes {
|
|||
param: NodeId,
|
||||
/// Id of the introducing place. See `Param`.
|
||||
binder: NodeId,
|
||||
/// Kind of elided lifetime
|
||||
kind: hir::MissingLifetimeKind,
|
||||
},
|
||||
/// This variant is used for anonymous lifetimes that we did not resolve during
|
||||
/// late resolution. Those lifetimes will be inferred by typechecking.
|
||||
|
|
|
@ -456,6 +456,18 @@ impl GenericBound<'_> {
|
|||
|
||||
pub type GenericBounds<'hir> = &'hir [GenericBound<'hir>];
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable_Generic, Debug)]
|
||||
pub enum MissingLifetimeKind {
|
||||
/// An explicit `'_`.
|
||||
Underscore,
|
||||
/// An elided lifetime `&' ty`.
|
||||
Ampersand,
|
||||
/// An elided lifetime in brackets with written brackets.
|
||||
Comma,
|
||||
/// An elided lifetime with elided brackets.
|
||||
Brackets,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, HashStable_Generic)]
|
||||
pub enum LifetimeParamKind {
|
||||
// Indicates that the lifetime definition was explicitly declared (e.g., in
|
||||
|
@ -464,7 +476,7 @@ pub enum LifetimeParamKind {
|
|||
|
||||
// Indication that the lifetime was elided (e.g., in both cases in
|
||||
// `fn foo(x: &u8) -> &'_ u8 { x }`).
|
||||
Elided,
|
||||
Elided(MissingLifetimeKind),
|
||||
|
||||
// Indication that the lifetime name was somehow in error.
|
||||
Error,
|
||||
|
@ -512,7 +524,7 @@ impl<'hir> GenericParam<'hir> {
|
|||
///
|
||||
/// See `lifetime_to_generic_param` in `rustc_ast_lowering` for more information.
|
||||
pub fn is_elided_lifetime(&self) -> bool {
|
||||
matches!(self.kind, GenericParamKind::Lifetime { kind: LifetimeParamKind::Elided })
|
||||
matches!(self.kind, GenericParamKind::Lifetime { kind: LifetimeParamKind::Elided(_) })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue