Closed
Description
Problem
Consider the following src/main.rs
file in a cargo package:
macro_rules! make_var {
($struct:ident, $var:ident) => {
let $var = $struct.$var;
};
}
#[allow(unused)]
struct MyStruct {
var: i32,
}
fn main() {
let s = MyStruct { var: 42 };
make_var!(s, var);
}
Cargo will warn that var
is not used. Upon running cargo fix
, cargo will change the second parameter from var
to _var
, making the compilation fail. Even worse, if MyStruct
contained a field _var
then cargo fix
would change the variable without producing any warning.
Steps
- Initialize a new cargo binary project with the above snippet in
main.rs
- Run
cargo fix
(presumably with--allow-dirty
)
Possible Solution(s)
No response
Notes
No response
Version
cargo 1.73.0 (9c4383fb5 2023-08-26)