@@ -9,7 +9,7 @@ use rustc_errors::{
99} ;
1010use rustc_hir:: def:: Namespace ;
1111use rustc_hir:: def_id:: DefId ;
12- use rustc_hir:: { self as hir} ;
12+ use rustc_hir:: { self as hir, MissingLifetimeKind } ;
1313use rustc_macros:: { LintDiagnostic , Subdiagnostic } ;
1414use rustc_middle:: ty:: inhabitedness:: InhabitedPredicate ;
1515use rustc_middle:: ty:: { Clause , PolyExistentialTraitRef , Ty , TyCtxt } ;
@@ -2623,14 +2623,56 @@ pub(crate) struct ElidedLifetimesInPaths {
26232623 pub subdiag : ElidedLifetimeInPathSubdiag ,
26242624}
26252625
2626- #[ derive( LintDiagnostic ) ]
2627- #[ diag( lint_elided_named_lifetime) ]
26282626pub ( crate ) struct ElidedNamedLifetime {
2629- # [ label ( lint_label_elided ) ]
2630- pub elided : Span ,
2627+ pub span : Span ,
2628+ pub kind : MissingLifetimeKind ,
26312629 pub name : Symbol ,
2632- #[ label( lint_label_named) ]
2633- pub named_declaration : Option < Span > ,
2630+ pub declaration : Option < Span > ,
2631+ }
2632+
2633+ impl < G : EmissionGuarantee > LintDiagnostic < ' _ , G > for ElidedNamedLifetime {
2634+ fn decorate_lint ( self , diag : & mut rustc_errors:: Diag < ' _ , G > ) {
2635+ let Self { span, kind, name, declaration } = self ;
2636+ diag. primary_message ( fluent:: lint_elided_named_lifetime) ;
2637+ diag. arg ( "name" , name) ;
2638+ diag. span_label ( span, fluent:: lint_label_elided) ;
2639+ if let Some ( declaration) = declaration {
2640+ diag. span_label ( declaration, fluent:: lint_label_named) ;
2641+ }
2642+ // FIXME(GrigorenkoPV): this `if` and `return` should be removed,
2643+ // but currently this lint's suggestions can conflict with those of `clippy::needless_lifetimes`:
2644+ // https://github.com/rust-lang/rust/pull/129840#issuecomment-2323349119
2645+ // HACK: `'static` suggestions will never sonflict, emit only those for now.
2646+ if name != rustc_span:: symbol:: kw:: StaticLifetime {
2647+ return ;
2648+ }
2649+ match kind {
2650+ MissingLifetimeKind :: Underscore => diag. span_suggestion_verbose (
2651+ span,
2652+ fluent:: lint_suggestion,
2653+ format ! ( "{name}" ) ,
2654+ Applicability :: MachineApplicable ,
2655+ ) ,
2656+ MissingLifetimeKind :: Ampersand => diag. span_suggestion_verbose (
2657+ span. shrink_to_hi ( ) ,
2658+ fluent:: lint_suggestion,
2659+ format ! ( "{name} " ) ,
2660+ Applicability :: MachineApplicable ,
2661+ ) ,
2662+ MissingLifetimeKind :: Comma => diag. span_suggestion_verbose (
2663+ span. shrink_to_hi ( ) ,
2664+ fluent:: lint_suggestion,
2665+ format ! ( "{name}, " ) ,
2666+ Applicability :: MachineApplicable ,
2667+ ) ,
2668+ MissingLifetimeKind :: Brackets => diag. span_suggestion_verbose (
2669+ span. shrink_to_hi ( ) ,
2670+ fluent:: lint_suggestion,
2671+ format ! ( "<{name}>" ) ,
2672+ Applicability :: MachineApplicable ,
2673+ ) ,
2674+ } ;
2675+ }
26342676}
26352677
26362678#[ derive( LintDiagnostic ) ]
0 commit comments