This code compiles and works perfectly fine:
use rocket::{get, uri};
#[get("/test/<x>")]
pub fn endpoint(x: i32) -> &'static str {
let _x = x;
"x"
}
fn main() {
let x = 123;
let query = uri!(endpoint(x = x));
println!("{}", query)
}
Cargo.toml
:
[package]
name = "dd"
version = "0.1.0"
edition = "2021"
[dependencies]
rocket = "0.5.0-rc"
But when I run cargo clippy
, it fails with:
error: redundant redefinition of a binding
--> src/main.rs:10:9
|
10 | let x = 123;
| ^
11 | let query = uri!(endpoint(x = x));
| ^
|
= help: remove the redefinition of `x`
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_locals
= note: `#[deny(clippy::redundant_locals)]` on by default
error: could not compile `dd` (bin "dd") due to previous error
And the error doesn't really seem to make sense.
Renaming the x
binding resolves the issue.
Could this be a bug in clippy, or is it a problem with the uri!
macro? Or the code above, maybe?
Relevant info:
- this lint
redundant_locals
was only introduced in 1.73, the problem did not exist in 1.72, - maybe rocket is at fault here (problem in the macro), but I would expect the clippy error to refer to the macro, not the caller.