@@ -3292,7 +3292,7 @@ impl<'a, G: EmissionGuarantee> LintDiagnostic<'a, G> for MismatchedLifetimeSynta
3292
3292
diag. subdiagnostic ( s) ;
3293
3293
3294
3294
for mut s in suggestions {
3295
- s. make_tool_only ( ) ;
3295
+ s. make_optional_alternative ( ) ;
3296
3296
diag. subdiagnostic ( s) ;
3297
3297
}
3298
3298
}
@@ -3303,56 +3303,74 @@ impl<'a, G: EmissionGuarantee> LintDiagnostic<'a, G> for MismatchedLifetimeSynta
3303
3303
pub ( crate ) enum MismatchedLifetimeSyntaxesSuggestion {
3304
3304
Implicit {
3305
3305
suggestions : Vec < Span > ,
3306
- tool_only : bool ,
3306
+ optional_alternative : bool ,
3307
3307
} ,
3308
3308
3309
3309
Mixed {
3310
3310
implicit_suggestions : Vec < Span > ,
3311
3311
explicit_anonymous_suggestions : Vec < ( Span , String ) > ,
3312
- tool_only : bool ,
3312
+ optional_alternative : bool ,
3313
3313
} ,
3314
3314
3315
3315
Explicit {
3316
3316
lifetime_name : String ,
3317
3317
suggestions : Vec < ( Span , String ) > ,
3318
- tool_only : bool ,
3318
+ optional_alternative : bool ,
3319
3319
} ,
3320
3320
}
3321
3321
3322
3322
impl MismatchedLifetimeSyntaxesSuggestion {
3323
- fn make_tool_only ( & mut self ) {
3323
+ fn make_optional_alternative ( & mut self ) {
3324
3324
use MismatchedLifetimeSyntaxesSuggestion :: * ;
3325
3325
3326
- let tool_only = match self {
3327
- Implicit { tool_only , .. } | Mixed { tool_only , .. } | Explicit { tool_only , .. } => {
3328
- tool_only
3329
- }
3326
+ let optional_alternative = match self {
3327
+ Implicit { optional_alternative , .. }
3328
+ | Mixed { optional_alternative , .. }
3329
+ | Explicit { optional_alternative , .. } => optional_alternative ,
3330
3330
} ;
3331
3331
3332
- * tool_only = true ;
3332
+ * optional_alternative = true ;
3333
3333
}
3334
3334
}
3335
3335
3336
3336
impl Subdiagnostic for MismatchedLifetimeSyntaxesSuggestion {
3337
3337
fn add_to_diag < G : EmissionGuarantee > ( self , diag : & mut Diag < ' _ , G > ) {
3338
3338
use MismatchedLifetimeSyntaxesSuggestion :: * ;
3339
3339
3340
- let style = |tool_only| {
3341
- if tool_only { SuggestionStyle :: CompletelyHidden } else { SuggestionStyle :: ShowAlways }
3340
+ let style = |optional_alternative| {
3341
+ if optional_alternative {
3342
+ SuggestionStyle :: CompletelyHidden
3343
+ } else {
3344
+ SuggestionStyle :: ShowAlways
3345
+ }
3346
+ } ;
3347
+
3348
+ let applicability = |optional_alternative| {
3349
+ // `cargo fix` can't handle more than one fix for the same issue,
3350
+ // so hide alternative suggestions from it by marking them as maybe-incorrect
3351
+ if optional_alternative {
3352
+ Applicability :: MaybeIncorrect
3353
+ } else {
3354
+ Applicability :: MachineApplicable
3355
+ }
3342
3356
} ;
3343
3357
3344
3358
match self {
3345
- Implicit { suggestions, tool_only } => {
3359
+ Implicit { suggestions, optional_alternative } => {
3346
3360
let suggestions = suggestions. into_iter ( ) . map ( |s| ( s, String :: new ( ) ) ) . collect ( ) ;
3347
3361
diag. multipart_suggestion_with_style (
3348
3362
fluent:: lint_mismatched_lifetime_syntaxes_suggestion_implicit,
3349
3363
suggestions,
3350
- Applicability :: MaybeIncorrect ,
3351
- style ( tool_only ) ,
3364
+ applicability ( optional_alternative ) ,
3365
+ style ( optional_alternative ) ,
3352
3366
) ;
3353
3367
}
3354
3368
3355
- Mixed { implicit_suggestions, explicit_anonymous_suggestions, tool_only } => {
3369
+ Mixed {
3370
+ implicit_suggestions,
3371
+ explicit_anonymous_suggestions,
3372
+ optional_alternative,
3373
+ } => {
3356
3374
let message = if implicit_suggestions. is_empty ( ) {
3357
3375
fluent:: lint_mismatched_lifetime_syntaxes_suggestion_mixed_only_paths
3358
3376
} else {
@@ -3368,12 +3386,12 @@ impl Subdiagnostic for MismatchedLifetimeSyntaxesSuggestion {
3368
3386
diag. multipart_suggestion_with_style (
3369
3387
message,
3370
3388
suggestions,
3371
- Applicability :: MaybeIncorrect ,
3372
- style ( tool_only ) ,
3389
+ applicability ( optional_alternative ) ,
3390
+ style ( optional_alternative ) ,
3373
3391
) ;
3374
3392
}
3375
3393
3376
- Explicit { lifetime_name, suggestions, tool_only } => {
3394
+ Explicit { lifetime_name, suggestions, optional_alternative } => {
3377
3395
diag. arg ( "lifetime_name" , lifetime_name) ;
3378
3396
let msg = diag. eagerly_translate (
3379
3397
fluent:: lint_mismatched_lifetime_syntaxes_suggestion_explicit,
@@ -3382,8 +3400,8 @@ impl Subdiagnostic for MismatchedLifetimeSyntaxesSuggestion {
3382
3400
diag. multipart_suggestion_with_style (
3383
3401
msg,
3384
3402
suggestions,
3385
- Applicability :: MaybeIncorrect ,
3386
- style ( tool_only ) ,
3403
+ applicability ( optional_alternative ) ,
3404
+ style ( optional_alternative ) ,
3387
3405
) ;
3388
3406
}
3389
3407
}
0 commit comments