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