@@ -7,14 +7,16 @@ use rustc_ast::util::unicode::TEXT_FLOW_CONTROL_CHARS;
7
7
use rustc_errors:: {
8
8
elided_lifetime_in_path_suggestion, Applicability , Diag , DiagArgValue , LintDiagnostic ,
9
9
} ;
10
+ use rustc_hir:: MissingLifetimeKind ;
10
11
use rustc_middle:: middle:: stability;
11
12
use rustc_session:: lint:: { BuiltinLintDiag , ElidedLifetimeResolution } ;
12
13
use rustc_session:: Session ;
13
14
use rustc_span:: symbol:: kw;
14
15
use rustc_span:: BytePos ;
15
16
use tracing:: debug;
16
17
17
- use crate :: lints;
18
+ use crate :: fluent_generated;
19
+ use crate :: lints:: { self , ElidedNamedLifetime } ;
18
20
19
21
mod check_cfg;
20
22
@@ -442,20 +444,32 @@ pub(super) fn decorate_lint(sess: &Session, diagnostic: BuiltinLintDiag, diag: &
442
444
BuiltinLintDiag :: UnexpectedBuiltinCfg { cfg, cfg_name, controlled_by } => {
443
445
lints:: UnexpectedBuiltinCfg { cfg, cfg_name, controlled_by } . decorate_lint ( diag)
444
446
}
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
+ ) ;
459
473
}
460
474
}
461
475
}
0 commit comments