@@ -7,14 +7,16 @@ use rustc_ast::util::unicode::TEXT_FLOW_CONTROL_CHARS;
77use rustc_errors:: {
88 elided_lifetime_in_path_suggestion, Applicability , Diag , DiagArgValue , LintDiagnostic ,
99} ;
10+ use rustc_hir:: MissingLifetimeKind ;
1011use rustc_middle:: middle:: stability;
1112use rustc_session:: lint:: { BuiltinLintDiag , ElidedLifetimeResolution } ;
1213use rustc_session:: Session ;
1314use rustc_span:: symbol:: kw;
1415use rustc_span:: BytePos ;
1516use tracing:: debug;
1617
17- use crate :: lints;
18+ use crate :: fluent_generated;
19+ use crate :: lints:: { self , ElidedNamedLifetime } ;
1820
1921mod check_cfg;
2022
@@ -442,20 +444,32 @@ pub(super) fn decorate_lint(sess: &Session, diagnostic: BuiltinLintDiag, diag: &
442444 BuiltinLintDiag :: UnexpectedBuiltinCfg { cfg, cfg_name, controlled_by } => {
443445 lints:: UnexpectedBuiltinCfg { cfg, cfg_name, controlled_by } . decorate_lint ( diag)
444446 }
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- } ,
457- }
458- . decorate_lint ( diag)
447+ BuiltinLintDiag :: ElidedNamedLifetimes { elided : ( span, kind) , resolution } => {
448+ let ( name, named_declaration) = match resolution {
449+ ElidedLifetimeResolution :: Static => ( kw:: StaticLifetime , None ) ,
450+ ElidedLifetimeResolution :: Param ( name, declaration) => ( name, Some ( declaration) ) ,
451+ } ;
452+ ElidedNamedLifetime { span, name, named_declaration } . decorate_lint ( diag) ;
453+
454+ let ( applicability, suggestion) = match kind {
455+ MissingLifetimeKind :: Underscore => {
456+ ( Applicability :: MachineApplicable , format ! ( "{name}" ) )
457+ }
458+ MissingLifetimeKind :: Ampersand => {
459+ ( Applicability :: MachineApplicable , format ! ( "&{name} " ) )
460+ }
461+ MissingLifetimeKind :: Comma => ( Applicability :: Unspecified , format ! ( "<{name}, " ) ) ,
462+ MissingLifetimeKind :: Brackets => (
463+ Applicability :: Unspecified ,
464+ format ! ( "{}<{name}>" , sess. source_map( ) . span_to_snippet( span) . unwrap( ) ) ,
465+ ) ,
466+ } ;
467+ diag. span_suggestion_verbose (
468+ span,
469+ fluent_generated:: lint_elided_named_lifetime_suggestion,
470+ suggestion,
471+ applicability,
472+ ) ;
459473 }
460474 }
461475}
0 commit comments