From cd0a3c4bcf3ec6e2ff4f7f3c96532cca50ea26a1 Mon Sep 17 00:00:00 2001 From: Yukang Date: Tue, 30 Jun 2026 08:17:50 +0800 Subject: [PATCH] Fix spacing issue for unused parentheses lint --- compiler/rustc_lint/src/unused.rs | 2 +- ...used-parens-trailing-space-issue-158583.rs | 5 +++++ ...-parens-trailing-space-issue-158583.stderr | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tests/ui/lint/unused-parens-trailing-space-issue-158583.rs create mode 100644 tests/ui/lint/unused-parens-trailing-space-issue-158583.stderr diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index dd2cb505cb1bc..5d1b82b0bb48c 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -338,7 +338,7 @@ trait UnusedDelimLint { && !snip.starts_with(' ') { " " - } else if let Ok(snip) = sm.span_to_prev_source(value_span) + } else if let Ok(snip) = sm.span_to_next_source(value_span) && snip.starts_with(|c: char| c.is_alphanumeric()) { " " diff --git a/tests/ui/lint/unused-parens-trailing-space-issue-158583.rs b/tests/ui/lint/unused-parens-trailing-space-issue-158583.rs new file mode 100644 index 0000000000000..d3c70f8769a9c --- /dev/null +++ b/tests/ui/lint/unused-parens-trailing-space-issue-158583.rs @@ -0,0 +1,5 @@ +fn main() { + #[deny(unused_parens)] + let _x = (3 + 6); + //~^ ERROR unnecessary parentheses around assigned value +} diff --git a/tests/ui/lint/unused-parens-trailing-space-issue-158583.stderr b/tests/ui/lint/unused-parens-trailing-space-issue-158583.stderr new file mode 100644 index 0000000000000..200379a5151eb --- /dev/null +++ b/tests/ui/lint/unused-parens-trailing-space-issue-158583.stderr @@ -0,0 +1,19 @@ +error: unnecessary parentheses around assigned value + --> $DIR/unused-parens-trailing-space-issue-158583.rs:3:14 + | +LL | let _x = (3 + 6); + | ^ ^ + | +note: the lint level is defined here + --> $DIR/unused-parens-trailing-space-issue-158583.rs:2:12 + | +LL | #[deny(unused_parens)] + | ^^^^^^^^^^^^^ +help: remove these parentheses + | +LL - let _x = (3 + 6); +LL + let _x = 3 + 6; + | + +error: aborting due to 1 previous error +