@@ -3276,7 +3276,7 @@ impl<'a, G: EmissionGuarantee> LintDiagnostic<'a, G> for MismatchedLifetimeSynta
32763276 diag. subdiagnostic ( s) ;
32773277
32783278 for mut s in suggestions {
3279- s. make_tool_only ( ) ;
3279+ s. make_optional_alternative ( ) ;
32803280 diag. subdiagnostic ( s) ;
32813281 }
32823282 }
@@ -3287,56 +3287,74 @@ impl<'a, G: EmissionGuarantee> LintDiagnostic<'a, G> for MismatchedLifetimeSynta
32873287pub ( crate ) enum MismatchedLifetimeSyntaxesSuggestion {
32883288 Implicit {
32893289 suggestions : Vec < Span > ,
3290- tool_only : bool ,
3290+ optional_alternative : bool ,
32913291 } ,
32923292
32933293 Mixed {
32943294 implicit_suggestions : Vec < Span > ,
32953295 explicit_anonymous_suggestions : Vec < ( Span , String ) > ,
3296- tool_only : bool ,
3296+ optional_alternative : bool ,
32973297 } ,
32983298
32993299 Explicit {
33003300 lifetime_name : String ,
33013301 suggestions : Vec < ( Span , String ) > ,
3302- tool_only : bool ,
3302+ optional_alternative : bool ,
33033303 } ,
33043304}
33053305
33063306impl MismatchedLifetimeSyntaxesSuggestion {
3307- fn make_tool_only ( & mut self ) {
3307+ fn make_optional_alternative ( & mut self ) {
33083308 use MismatchedLifetimeSyntaxesSuggestion :: * ;
33093309
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 ,
33143314 } ;
33153315
3316- * tool_only = true ;
3316+ * optional_alternative = true ;
33173317 }
33183318}
33193319
33203320impl Subdiagnostic for MismatchedLifetimeSyntaxesSuggestion {
33213321 fn add_to_diag < G : EmissionGuarantee > ( self , diag : & mut Diag < ' _ , G > ) {
33223322 use MismatchedLifetimeSyntaxesSuggestion :: * ;
33233323
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+ }
33263340 } ;
33273341
33283342 match self {
3329- Implicit { suggestions, tool_only } => {
3343+ Implicit { suggestions, optional_alternative } => {
33303344 let suggestions = suggestions. into_iter ( ) . map ( |s| ( s, String :: new ( ) ) ) . collect ( ) ;
33313345 diag. multipart_suggestion_with_style (
33323346 fluent:: lint_mismatched_lifetime_syntaxes_suggestion_implicit,
33333347 suggestions,
3334- Applicability :: MaybeIncorrect ,
3335- style ( tool_only ) ,
3348+ applicability ( optional_alternative ) ,
3349+ style ( optional_alternative ) ,
33363350 ) ;
33373351 }
33383352
3339- Mixed { implicit_suggestions, explicit_anonymous_suggestions, tool_only } => {
3353+ Mixed {
3354+ implicit_suggestions,
3355+ explicit_anonymous_suggestions,
3356+ optional_alternative,
3357+ } => {
33403358 let message = if implicit_suggestions. is_empty ( ) {
33413359 fluent:: lint_mismatched_lifetime_syntaxes_suggestion_mixed_only_paths
33423360 } else {
@@ -3352,12 +3370,12 @@ impl Subdiagnostic for MismatchedLifetimeSyntaxesSuggestion {
33523370 diag. multipart_suggestion_with_style (
33533371 message,
33543372 suggestions,
3355- Applicability :: MaybeIncorrect ,
3356- style ( tool_only ) ,
3373+ applicability ( optional_alternative ) ,
3374+ style ( optional_alternative ) ,
33573375 ) ;
33583376 }
33593377
3360- Explicit { lifetime_name, suggestions, tool_only } => {
3378+ Explicit { lifetime_name, suggestions, optional_alternative } => {
33613379 diag. arg ( "lifetime_name" , lifetime_name) ;
33623380 let msg = diag. eagerly_translate (
33633381 fluent:: lint_mismatched_lifetime_syntaxes_suggestion_explicit,
@@ -3366,8 +3384,8 @@ impl Subdiagnostic for MismatchedLifetimeSyntaxesSuggestion {
33663384 diag. multipart_suggestion_with_style (
33673385 msg,
33683386 suggestions,
3369- Applicability :: MaybeIncorrect ,
3370- style ( tool_only ) ,
3387+ applicability ( optional_alternative ) ,
3388+ style ( optional_alternative ) ,
33713389 ) ;
33723390 }
33733391 }
0 commit comments