elided_named_lifetimes: add suggestions
This commit is contained in:
parent
e38764d73b
commit
dcfc71310d
23 changed files with 166 additions and 16 deletions
|
@ -7,6 +7,7 @@ use rustc_ast::util::unicode::TEXT_FLOW_CONTROL_CHARS;
|
|||
use rustc_errors::{
|
||||
elided_lifetime_in_path_suggestion, Applicability, Diag, DiagArgValue, LintDiagnostic,
|
||||
};
|
||||
use rustc_hir::MissingLifetimeKind;
|
||||
use rustc_middle::middle::stability;
|
||||
use rustc_session::lint::{BuiltinLintDiag, ElidedLifetimeResolution};
|
||||
use rustc_session::Session;
|
||||
|
@ -14,7 +15,8 @@ use rustc_span::symbol::kw;
|
|||
use rustc_span::BytePos;
|
||||
use tracing::debug;
|
||||
|
||||
use crate::lints;
|
||||
use crate::fluent_generated;
|
||||
use crate::lints::{self, ElidedNamedLifetime};
|
||||
|
||||
mod check_cfg;
|
||||
|
||||
|
@ -442,20 +444,32 @@ pub(super) fn decorate_lint(sess: &Session, diagnostic: BuiltinLintDiag, diag: &
|
|||
BuiltinLintDiag::UnexpectedBuiltinCfg { cfg, cfg_name, controlled_by } => {
|
||||
lints::UnexpectedBuiltinCfg { cfg, cfg_name, controlled_by }.decorate_lint(diag)
|
||||
}
|
||||
BuiltinLintDiag::ElidedNamedLifetimes { elided: (elided, _kind), resolution } => {
|
||||
match resolution {
|
||||
ElidedLifetimeResolution::Static => lints::ElidedNamedLifetime {
|
||||
elided,
|
||||
name: kw::StaticLifetime,
|
||||
named_declaration: None,
|
||||
},
|
||||
ElidedLifetimeResolution::Param(name, declaration) => lints::ElidedNamedLifetime {
|
||||
elided,
|
||||
name,
|
||||
named_declaration: Some(declaration),
|
||||
},
|
||||
}
|
||||
.decorate_lint(diag)
|
||||
BuiltinLintDiag::ElidedNamedLifetimes { elided: (span, kind), resolution } => {
|
||||
let (name, named_declaration) = match resolution {
|
||||
ElidedLifetimeResolution::Static => (kw::StaticLifetime, None),
|
||||
ElidedLifetimeResolution::Param(name, declaration) => (name, Some(declaration)),
|
||||
};
|
||||
ElidedNamedLifetime { span, name, named_declaration }.decorate_lint(diag);
|
||||
|
||||
let (applicability, suggestion) = match kind {
|
||||
MissingLifetimeKind::Underscore => {
|
||||
(Applicability::MachineApplicable, format!("{name}"))
|
||||
}
|
||||
MissingLifetimeKind::Ampersand => {
|
||||
(Applicability::MachineApplicable, format!("&{name} "))
|
||||
}
|
||||
MissingLifetimeKind::Comma => (Applicability::Unspecified, format!("<{name}, ")),
|
||||
MissingLifetimeKind::Brackets => (
|
||||
Applicability::Unspecified,
|
||||
format!("{}<{name}>", sess.source_map().span_to_snippet(span).unwrap()),
|
||||
),
|
||||
};
|
||||
diag.span_suggestion_verbose(
|
||||
span,
|
||||
fluent_generated::lint_elided_named_lifetime_suggestion,
|
||||
suggestion,
|
||||
applicability,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2627,7 +2627,7 @@ pub(crate) struct ElidedLifetimesInPaths {
|
|||
#[diag(lint_elided_named_lifetime)]
|
||||
pub(crate) struct ElidedNamedLifetime {
|
||||
#[label(lint_label_elided)]
|
||||
pub elided: Span,
|
||||
pub span: Span,
|
||||
pub name: Symbol,
|
||||
#[label(lint_label_named)]
|
||||
pub named_declaration: Option<Span>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue