about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorxizheyin <xizheyin@smail.nju.edu.cn>2025-06-17 22:48:58 +0800
committerxizheyin <xizheyin@smail.nju.edu.cn>2025-06-18 00:36:51 +0800
commit72fbf3ea6163d739dfa6c15312e3a7433b1fcb67 (patch)
tree2e0cd6f4f726cde8719164d70be15de506ee1ba1 /compiler
parent1ab8ff57d6fe41af9f22c75cbf41d07130bb3d60 (diff)
Dont suggest remove semi inside macro expansion for redundant semi lint
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_lint/messages.ftl3
-rw-r--r--compiler/rustc_lint/src/lints.rs12
-rw-r--r--compiler/rustc_lint/src/redundant_semicolon.rs13
3 files changed, 21 insertions, 7 deletions
diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl
index 46ae4146528..f92f8307808 100644
--- a/compiler/rustc_lint/messages.ftl
+++ b/compiler/rustc_lint/messages.ftl
@@ -738,7 +738,8 @@ lint_redundant_semicolons =
         [true] semicolons
         *[false] semicolon
     }
-    .suggestion = remove {$multiple ->
+
+lint_redundant_semicolons_suggestion = remove {$multiple_semicolons ->
         [true] these semicolons
         *[false] this semicolon
     }
diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs
index 3d17dfbc451..0b8c68404f1 100644
--- a/compiler/rustc_lint/src/lints.rs
+++ b/compiler/rustc_lint/src/lints.rs
@@ -1538,8 +1538,16 @@ pub(crate) struct PassByValueDiag {
 #[diag(lint_redundant_semicolons)]
 pub(crate) struct RedundantSemicolonsDiag {
     pub multiple: bool,
-    #[suggestion(code = "", applicability = "maybe-incorrect")]
-    pub suggestion: Span,
+    #[subdiagnostic]
+    pub suggestion: Option<RedundantSemicolonsSuggestion>,
+}
+
+#[derive(Subdiagnostic)]
+#[suggestion(lint_redundant_semicolons_suggestion, code = "", applicability = "maybe-incorrect")]
+pub(crate) struct RedundantSemicolonsSuggestion {
+    pub multiple_semicolons: bool,
+    #[primary_span]
+    pub span: Span,
 }
 
 // traits.rs
diff --git a/compiler/rustc_lint/src/redundant_semicolon.rs b/compiler/rustc_lint/src/redundant_semicolon.rs
index b43e4938b73..f6d2fbe4261 100644
--- a/compiler/rustc_lint/src/redundant_semicolon.rs
+++ b/compiler/rustc_lint/src/redundant_semicolon.rs
@@ -2,7 +2,7 @@ use rustc_ast::{Block, StmtKind};
 use rustc_session::{declare_lint, declare_lint_pass};
 use rustc_span::Span;
 
-use crate::lints::RedundantSemicolonsDiag;
+use crate::lints::{RedundantSemicolonsDiag, RedundantSemicolonsSuggestion};
 use crate::{EarlyContext, EarlyLintPass, LintContext};
 
 declare_lint! {
@@ -44,16 +44,21 @@ impl EarlyLintPass for RedundantSemicolons {
 
 fn maybe_lint_redundant_semis(cx: &EarlyContext<'_>, seq: &mut Option<(Span, bool)>) {
     if let Some((span, multiple)) = seq.take() {
-        // FIXME: Find a better way of ignoring the trailing
-        // semicolon from macro expansion
         if span == rustc_span::DUMMY_SP {
             return;
         }
 
+        // Ignore redundant semicolons inside macro expansion.(issue #142143)
+        let suggestion = if span.from_expansion() {
+            None
+        } else {
+            Some(RedundantSemicolonsSuggestion { multiple_semicolons: multiple, span })
+        };
+
         cx.emit_span_lint(
             REDUNDANT_SEMICOLONS,
             span,
-            RedundantSemicolonsDiag { multiple, suggestion: span },
+            RedundantSemicolonsDiag { multiple, suggestion },
         );
     }
 }