-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)L-false-positiveLint: False positive (should not have fired).Lint: False positive (should not have fired).L-unused_parensLint: unused_parensLint: unused_parensT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Code
macro_rules! wrap {
($name:ident $arg:expr) => {
$name($arg);
};
}
fn main() {
wrap!(unary(routine()));
}
fn unary(_: ()) {}
fn routine() {}
Current output
warning: unnecessary parentheses around function argument
--> src/main.rs:8:16
|
8 | wrap!(unary(routine()));
| ^ ^
|
= note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
|
8 - wrap!(unary(routine()));
8 + wrap!(unaryroutine());
|
Desired output
(this section left empty, lint should not trigger)
Rationale and extra context
This:
wrap!(unary(routine()))
expands to:
unary((routine()))
Where the parentheses are indeed overkill.
Hence the lint would somehow need to look at the original span to see if it's necessary.
I see 3 paths forward from this:
- Do not trigger the lint.
- Introduce a new lint that suggests inserting a space before the parentheses for clarity.
- Introduce a new lint that does 2. but also suggests removing the parens in one go.
Point 1. is probably the easiest forward, the other ones probably require the information necessary for 1. anyway.
Other cases
// The argument can be actually anything, it is not necessary for it to be a function call
// It'll just be appended to the ident
macro_rules! wrap {
($name:ident $arg:expr) => {
$name($arg);
};
}
fn main() {
wrap!(unary(0));
}
fn unary<T>(_: T) {}
Rust Version
$ rustc --version --verbose
rustc 1.87.0-nightly (f5a1ef712 2025-03-07)
binary: rustc
commit-hash: f5a1ef7121ad661b5a21a1d02941c8064d54ee0b
commit-date: 2025-03-07
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0
Anything else?
Thank you all for your work. <3
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)L-false-positiveLint: False positive (should not have fired).Lint: False positive (should not have fired).L-unused_parensLint: unused_parensLint: unused_parensT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.