@@ -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 } ;
@@ -2611,14 +2611,49 @@ pub(crate) struct ElidedLifetimesInPaths {
26112611 pub subdiag : ElidedLifetimeInPathSubdiag ,
26122612}
26132613
2614- #[ derive( LintDiagnostic ) ]
2615- #[ diag( lint_elided_named_lifetime) ]
26162614pub ( crate ) struct ElidedNamedLifetime {
2617- #[ label( lint_label_elided) ]
26182615 pub span : Span ,
2616+ pub kind : MissingLifetimeKind ,
26192617 pub name : Symbol ,
2620- #[ label( lint_label_named) ]
2621- pub named_declaration : Option < Span > ,
2618+ pub declaration : Option < Span > ,
2619+ }
2620+
2621+ impl < G : EmissionGuarantee > LintDiagnostic < ' _ , G > for ElidedNamedLifetime {
2622+ fn decorate_lint ( self , diag : & mut rustc_errors:: Diag < ' _ , G > ) {
2623+ let Self { span, kind, name, declaration } = self ;
2624+ diag. primary_message ( fluent:: lint_elided_named_lifetime) ;
2625+ diag. arg ( "name" , name) ;
2626+ diag. span_label ( span, fluent:: lint_label_elided) ;
2627+ if let Some ( declaration) = declaration {
2628+ diag. span_label ( declaration, fluent:: lint_label_named) ;
2629+ }
2630+ match kind {
2631+ MissingLifetimeKind :: Underscore => diag. span_suggestion_verbose (
2632+ span,
2633+ fluent:: lint_suggestion,
2634+ format ! ( "{name}" ) ,
2635+ Applicability :: MachineApplicable ,
2636+ ) ,
2637+ MissingLifetimeKind :: Ampersand => diag. span_suggestion_verbose (
2638+ span. shrink_to_hi ( ) ,
2639+ fluent:: lint_suggestion,
2640+ format ! ( "{name} " ) ,
2641+ Applicability :: MachineApplicable ,
2642+ ) ,
2643+ MissingLifetimeKind :: Comma => diag. span_suggestion_verbose (
2644+ span. shrink_to_hi ( ) ,
2645+ fluent:: lint_suggestion,
2646+ format ! ( "{name}, " ) ,
2647+ Applicability :: MachineApplicable ,
2648+ ) ,
2649+ MissingLifetimeKind :: Brackets => diag. span_suggestion_verbose (
2650+ span. shrink_to_hi ( ) ,
2651+ fluent:: lint_suggestion,
2652+ format ! ( "<{name}>" ) ,
2653+ Applicability :: MachineApplicable ,
2654+ ) ,
2655+ } ;
2656+ }
26222657}
26232658
26242659#[ derive( LintDiagnostic ) ]
0 commit comments