@@ -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,49 @@ 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) ]
26302627 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+ match kind {
2643+ MissingLifetimeKind :: Underscore => diag. span_suggestion_verbose (
2644+ span,
2645+ fluent:: lint_suggestion,
2646+ format ! ( "{name}" ) ,
2647+ Applicability :: MachineApplicable ,
2648+ ) ,
2649+ MissingLifetimeKind :: Ampersand => diag. span_suggestion_verbose (
2650+ span. shrink_to_hi ( ) ,
2651+ fluent:: lint_suggestion,
2652+ format ! ( "{name} " ) ,
2653+ Applicability :: MachineApplicable ,
2654+ ) ,
2655+ MissingLifetimeKind :: Comma => diag. span_suggestion_verbose (
2656+ span. shrink_to_hi ( ) ,
2657+ fluent:: lint_suggestion,
2658+ format ! ( "{name}, " ) ,
2659+ Applicability :: MachineApplicable ,
2660+ ) ,
2661+ MissingLifetimeKind :: Brackets => diag. span_suggestion_verbose (
2662+ span. shrink_to_hi ( ) ,
2663+ fluent:: lint_suggestion,
2664+ format ! ( "<{name}>" ) ,
2665+ Applicability :: MachineApplicable ,
2666+ ) ,
2667+ } ;
2668+ }
26342669}
26352670
26362671#[ derive( LintDiagnostic ) ]
0 commit comments