Closed
Description
Summary
Though after macro expansion the closure seems redundant, the closure is required for the macro invocation.
Lint Name
redundant_closure_call
Reproducer
I tried this code:
macro_rules! m {
($closure:expr) => {
$closure(1)
};
}
fn main() {
m!(|x| println!("{x}"));
}
I saw this happen:
warning: try not to call a closure in the expression where it is declared
--> src/main.rs:3:9
|
3 | $closure(1)
| ^^^^^^^^^^^
...
8 | m!(|x| println!("{x}"));
| ----------------------- in this macro invocation
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_call
= note: `#[warn(clippy::redundant_closure_call)]` on by default
= note: this warning originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
I expected to see this happen:
No warning.
Version
rustc 1.73.0-nightly (32303b219 2023-07-29)
binary: rustc
commit-hash: 32303b219d4dffa447aa606bc11c7a648f44a862
commit-date: 2023-07-29
host: x86_64-unknown-linux-gnu
release: 1.73.0-nightly
LLVM version: 16.0.5
Additional Labels
No response