mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-21 22:34:05 +00:00
elided_named_lifetimes: unify lint def & pass MissingLifetimeKind
This commit is contained in:
parent
a3af2085cc
commit
e38764d73b
@ -8,7 +8,7 @@ use rustc_errors::{
|
||||
elided_lifetime_in_path_suggestion, Applicability, Diag, DiagArgValue, LintDiagnostic,
|
||||
};
|
||||
use rustc_middle::middle::stability;
|
||||
use rustc_session::lint::BuiltinLintDiag;
|
||||
use rustc_session::lint::{BuiltinLintDiag, ElidedLifetimeResolution};
|
||||
use rustc_session::Session;
|
||||
use rustc_span::symbol::kw;
|
||||
use rustc_span::BytePos;
|
||||
@ -442,15 +442,18 @@ 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::ElidedIsStatic { elided } => {
|
||||
lints::ElidedNamedLifetime { elided, name: kw::StaticLifetime, named_declaration: None }
|
||||
.decorate_lint(diag)
|
||||
}
|
||||
BuiltinLintDiag::ElidedIsParam { elided, param: (param_name, param_span) } => {
|
||||
lints::ElidedNamedLifetime {
|
||||
elided,
|
||||
name: param_name,
|
||||
named_declaration: Some(param_span),
|
||||
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)
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ use rustc_data_structures::stable_hasher::{
|
||||
};
|
||||
use rustc_error_messages::{DiagMessage, MultiSpan};
|
||||
use rustc_hir::def::Namespace;
|
||||
use rustc_hir::{HashStableContext, HirId};
|
||||
use rustc_hir::{HashStableContext, HirId, MissingLifetimeKind};
|
||||
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
|
||||
use rustc_span::edition::Edition;
|
||||
use rustc_span::symbol::{Ident, MacroRulesNormalizedIdent};
|
||||
@ -556,6 +556,12 @@ pub enum DeprecatedSinceKind {
|
||||
InVersion(String),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ElidedLifetimeResolution {
|
||||
Static,
|
||||
Param(Symbol, Span),
|
||||
}
|
||||
|
||||
// This could be a closure, but then implementing derive trait
|
||||
// becomes hacky (and it gets allocated).
|
||||
#[derive(Debug)]
|
||||
@ -568,12 +574,9 @@ pub enum BuiltinLintDiag {
|
||||
},
|
||||
MacroExpandedMacroExportsAccessedByAbsolutePaths(Span),
|
||||
ElidedLifetimesInPaths(usize, Span, bool, Span),
|
||||
ElidedIsStatic {
|
||||
elided: Span,
|
||||
},
|
||||
ElidedIsParam {
|
||||
elided: Span,
|
||||
param: (Symbol, Span),
|
||||
ElidedNamedLifetimes {
|
||||
elided: (Span, MissingLifetimeKind),
|
||||
resolution: ElidedLifetimeResolution,
|
||||
},
|
||||
UnknownCrateTypes {
|
||||
span: Span,
|
||||
|
@ -2062,7 +2062,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
lint::builtin::ELIDED_NAMED_LIFETIMES,
|
||||
missing.id_for_lint,
|
||||
missing.span,
|
||||
BuiltinLintDiag::ElidedIsStatic { elided: missing.span },
|
||||
BuiltinLintDiag::ElidedNamedLifetimes {
|
||||
elided: (missing.span, missing.kind),
|
||||
resolution: lint::ElidedLifetimeResolution::Static,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -2072,9 +2075,12 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||
lint::builtin::ELIDED_NAMED_LIFETIMES,
|
||||
missing.id_for_lint,
|
||||
missing.span,
|
||||
BuiltinLintDiag::ElidedIsParam {
|
||||
elided: missing.span,
|
||||
param: (tcx.item_name(param.into()), tcx.source_span(param)),
|
||||
BuiltinLintDiag::ElidedNamedLifetimes {
|
||||
elided: (missing.span, missing.kind),
|
||||
resolution: lint::ElidedLifetimeResolution::Param(
|
||||
tcx.item_name(param.into()),
|
||||
tcx.source_span(param),
|
||||
),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user