@@ -3292,7 +3292,7 @@ impl<'a, G: EmissionGuarantee> LintDiagnostic<'a, G> for MismatchedLifetimeSynta
32923292 diag. subdiagnostic ( s) ;
32933293
32943294 for mut s in suggestions {
3295- s. make_tool_only ( ) ;
3295+ s. make_optional_alternative ( ) ;
32963296 diag. subdiagnostic ( s) ;
32973297 }
32983298 }
@@ -3303,56 +3303,74 @@ impl<'a, G: EmissionGuarantee> LintDiagnostic<'a, G> for MismatchedLifetimeSynta
33033303pub ( crate ) enum MismatchedLifetimeSyntaxesSuggestion {
33043304 Implicit {
33053305 suggestions : Vec < Span > ,
3306- tool_only : bool ,
3306+ optional_alternative : bool ,
33073307 } ,
33083308
33093309 Mixed {
33103310 implicit_suggestions : Vec < Span > ,
33113311 explicit_anonymous_suggestions : Vec < ( Span , String ) > ,
3312- tool_only : bool ,
3312+ optional_alternative : bool ,
33133313 } ,
33143314
33153315 Explicit {
33163316 lifetime_name : String ,
33173317 suggestions : Vec < ( Span , String ) > ,
3318- tool_only : bool ,
3318+ optional_alternative : bool ,
33193319 } ,
33203320}
33213321
33223322impl MismatchedLifetimeSyntaxesSuggestion {
3323- fn make_tool_only ( & mut self ) {
3323+ fn make_optional_alternative ( & mut self ) {
33243324 use MismatchedLifetimeSyntaxesSuggestion :: * ;
33253325
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 ,
33303330 } ;
33313331
3332- * tool_only = true ;
3332+ * optional_alternative = true ;
33333333 }
33343334}
33353335
33363336impl Subdiagnostic for MismatchedLifetimeSyntaxesSuggestion {
33373337 fn add_to_diag < G : EmissionGuarantee > ( self , diag : & mut Diag < ' _ , G > ) {
33383338 use MismatchedLifetimeSyntaxesSuggestion :: * ;
33393339
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+ }
33423356 } ;
33433357
33443358 match self {
3345- Implicit { suggestions, tool_only } => {
3359+ Implicit { suggestions, optional_alternative } => {
33463360 let suggestions = suggestions. into_iter ( ) . map ( |s| ( s, String :: new ( ) ) ) . collect ( ) ;
33473361 diag. multipart_suggestion_with_style (
33483362 fluent:: lint_mismatched_lifetime_syntaxes_suggestion_implicit,
33493363 suggestions,
3350- Applicability :: MaybeIncorrect ,
3351- style ( tool_only ) ,
3364+ applicability ( optional_alternative ) ,
3365+ style ( optional_alternative ) ,
33523366 ) ;
33533367 }
33543368
3355- Mixed { implicit_suggestions, explicit_anonymous_suggestions, tool_only } => {
3369+ Mixed {
3370+ implicit_suggestions,
3371+ explicit_anonymous_suggestions,
3372+ optional_alternative,
3373+ } => {
33563374 let message = if implicit_suggestions. is_empty ( ) {
33573375 fluent:: lint_mismatched_lifetime_syntaxes_suggestion_mixed_only_paths
33583376 } else {
@@ -3368,12 +3386,12 @@ impl Subdiagnostic for MismatchedLifetimeSyntaxesSuggestion {
33683386 diag. multipart_suggestion_with_style (
33693387 message,
33703388 suggestions,
3371- Applicability :: MaybeIncorrect ,
3372- style ( tool_only ) ,
3389+ applicability ( optional_alternative ) ,
3390+ style ( optional_alternative ) ,
33733391 ) ;
33743392 }
33753393
3376- Explicit { lifetime_name, suggestions, tool_only } => {
3394+ Explicit { lifetime_name, suggestions, optional_alternative } => {
33773395 diag. arg ( "lifetime_name" , lifetime_name) ;
33783396 let msg = diag. eagerly_translate (
33793397 fluent:: lint_mismatched_lifetime_syntaxes_suggestion_explicit,
@@ -3382,8 +3400,8 @@ impl Subdiagnostic for MismatchedLifetimeSyntaxesSuggestion {
33823400 diag. multipart_suggestion_with_style (
33833401 msg,
33843402 suggestions,
3385- Applicability :: MaybeIncorrect ,
3386- style ( tool_only ) ,
3403+ applicability ( optional_alternative ) ,
3404+ style ( optional_alternative ) ,
33873405 ) ;
33883406 }
33893407 }
0 commit comments