about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorfrancorbacho <francorbacho@proton.me>2023-10-05 15:46:34 +0200
committerfrancorbacho <francorbacho@proton.me>2023-10-05 16:11:31 +0200
commitc8ee7db6ea272b42e90602007807be6c2191f96b (patch)
treebae892a09b1ed076fe05a28a80bcfb93e34b6701 /compiler
parent38b01828328014708feb48f9cdc065460e651098 (diff)
downloadrust-c8ee7db6ea272b42e90602007807be6c2191f96b.tar.gz
rust-c8ee7db6ea272b42e90602007807be6c2191f96b.zip
Only give autofix suggestion when no named args are present
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_builtin_macros/src/errors.rs2
-rw-r--r--compiler/rustc_builtin_macros/src/format.rs8
2 files changed, 8 insertions, 2 deletions
diff --git a/compiler/rustc_builtin_macros/src/errors.rs b/compiler/rustc_builtin_macros/src/errors.rs
index 7a8ec5cfdf3..fde4270334b 100644
--- a/compiler/rustc_builtin_macros/src/errors.rs
+++ b/compiler/rustc_builtin_macros/src/errors.rs
@@ -657,7 +657,7 @@ pub(crate) struct FormatRedundantArgs {
     pub(crate) note: MultiSpan,
 
     #[subdiagnostic]
-    pub(crate) sugg: FormatRedundantArgsSugg,
+    pub(crate) sugg: Option<FormatRedundantArgsSugg>,
 }
 
 #[derive(Subdiagnostic)]
diff --git a/compiler/rustc_builtin_macros/src/format.rs b/compiler/rustc_builtin_macros/src/format.rs
index e08fded01fb..7c78be17653 100644
--- a/compiler/rustc_builtin_macros/src/format.rs
+++ b/compiler/rustc_builtin_macros/src/format.rs
@@ -767,11 +767,17 @@ fn report_redundant_format_arguments<'a>(
             suggestion_spans.push(span);
         }
 
+        let sugg = if args.named_args().len() == 0 {
+            Some(errors::FormatRedundantArgsSugg { spans: suggestion_spans })
+        } else {
+            None
+        };
+
         return Some(ecx.create_err(errors::FormatRedundantArgs {
             n: args_spans.len(),
             span: MultiSpan::from(args_spans),
             note: multispan,
-            sugg: errors::FormatRedundantArgsSugg { spans: suggestion_spans },
+            sugg,
         }));
     }