Skip to content

Commit db61426

Browse files
committed
elided_named_lifetimes: unify lint def & pass MissingLifetimeKind
1 parent a9b959a commit db61426

File tree

3 files changed

+33
-21
lines changed

3 files changed

+33
-21
lines changed

compiler/rustc_lint/src/context/diagnostics.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_errors::{
88
elided_lifetime_in_path_suggestion, Applicability, Diag, DiagArgValue, LintDiagnostic,
99
};
1010
use rustc_middle::middle::stability;
11-
use rustc_session::lint::BuiltinLintDiag;
11+
use rustc_session::lint::{BuiltinLintDiag, ElidedLifetimeResolution};
1212
use rustc_session::Session;
1313
use rustc_span::symbol::kw;
1414
use rustc_span::BytePos;
@@ -442,15 +442,18 @@ pub(super) fn decorate_lint(sess: &Session, diagnostic: BuiltinLintDiag, diag: &
442442
BuiltinLintDiag::UnexpectedBuiltinCfg { cfg, cfg_name, controlled_by } => {
443443
lints::UnexpectedBuiltinCfg { cfg, cfg_name, controlled_by }.decorate_lint(diag)
444444
}
445-
BuiltinLintDiag::ElidedIsStatic { elided } => {
446-
lints::ElidedNamedLifetime { elided, name: kw::StaticLifetime, named_declaration: None }
447-
.decorate_lint(diag)
448-
}
449-
BuiltinLintDiag::ElidedIsParam { elided, param: (param_name, param_span) } => {
450-
lints::ElidedNamedLifetime {
451-
elided,
452-
name: param_name,
453-
named_declaration: Some(param_span),
445+
BuiltinLintDiag::ElidedNamedLifetimes { elided: (elided, _kind), resolution } => {
446+
match resolution {
447+
ElidedLifetimeResolution::Static => lints::ElidedNamedLifetime {
448+
elided,
449+
name: kw::StaticLifetime,
450+
named_declaration: None,
451+
},
452+
ElidedLifetimeResolution::Param(name, declaration) => lints::ElidedNamedLifetime {
453+
elided,
454+
name,
455+
named_declaration: Some(declaration),
456+
},
454457
}
455458
.decorate_lint(diag)
456459
}

compiler/rustc_lint_defs/src/lib.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_data_structures::stable_hasher::{
1010
};
1111
use rustc_error_messages::{DiagMessage, MultiSpan};
1212
use rustc_hir::def::Namespace;
13-
use rustc_hir::{HashStableContext, HirId};
13+
use rustc_hir::{HashStableContext, HirId, MissingLifetimeKind};
1414
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
1515
use rustc_span::edition::Edition;
1616
use rustc_span::symbol::{Ident, MacroRulesNormalizedIdent};
@@ -577,6 +577,12 @@ pub enum DeprecatedSinceKind {
577577
InVersion(String),
578578
}
579579

580+
#[derive(Debug)]
581+
pub enum ElidedLifetimeResolution {
582+
Static,
583+
Param(Symbol, Span),
584+
}
585+
580586
// This could be a closure, but then implementing derive trait
581587
// becomes hacky (and it gets allocated).
582588
#[derive(Debug)]
@@ -589,12 +595,9 @@ pub enum BuiltinLintDiag {
589595
},
590596
MacroExpandedMacroExportsAccessedByAbsolutePaths(Span),
591597
ElidedLifetimesInPaths(usize, Span, bool, Span),
592-
ElidedIsStatic {
593-
elided: Span,
594-
},
595-
ElidedIsParam {
596-
elided: Span,
597-
param: (Symbol, Span),
598+
ElidedNamedLifetimes {
599+
elided: (Span, MissingLifetimeKind),
600+
resolution: ElidedLifetimeResolution,
598601
},
599602
UnknownCrateTypes {
600603
span: Span,

compiler/rustc_resolve/src/late.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -2062,7 +2062,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
20622062
lint::builtin::ELIDED_NAMED_LIFETIMES,
20632063
missing.id_for_lint,
20642064
missing.span,
2065-
BuiltinLintDiag::ElidedIsStatic { elided: missing.span },
2065+
BuiltinLintDiag::ElidedNamedLifetimes {
2066+
elided: (missing.span, missing.kind),
2067+
resolution: lint::ElidedLifetimeResolution::Static,
2068+
},
20662069
);
20672070
}
20682071
}
@@ -2072,9 +2075,12 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
20722075
lint::builtin::ELIDED_NAMED_LIFETIMES,
20732076
missing.id_for_lint,
20742077
missing.span,
2075-
BuiltinLintDiag::ElidedIsParam {
2076-
elided: missing.span,
2077-
param: (tcx.item_name(param.into()), tcx.source_span(param)),
2078+
BuiltinLintDiag::ElidedNamedLifetimes {
2079+
elided: (missing.span, missing.kind),
2080+
resolution: lint::ElidedLifetimeResolution::Param(
2081+
tcx.item_name(param.into()),
2082+
tcx.source_span(param),
2083+
),
20782084
},
20792085
);
20802086
}

0 commit comments

Comments
 (0)