-
Notifications
You must be signed in to change notification settings - Fork 14k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.Category: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-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
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)
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.Category: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-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.