-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-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
Given the following code:
macro_rules! foo {
($($a:ident)? ; $num:expr) => { {
let mut x = 0;
$(
x += $a;
)?
assert_eq!(x, $num);
} }
}
pub fn main() {
let a = 1;
// accept 0 or 1 repetitions
foo!( ; 0);
foo!(a ; 1);
}The current output is:
warning: variable does not need to be mutable
--> src/main.rs:3:13
|
3 | let mut x = 0;
| ----^
| |
| help: remove this `mut`
...
17 | foo!( ; 0);
| ---------- in this macro invocation
|
cargo fix should perhaps not cross macro boundaries?
It will remove the mut inside the macro and the code will no longer work
The following errors were reported:
error[E0384]: cannot assign twice to immutable variable `x`
--> src/main.rs:6:13
|
3 | let x = 0;
| -
| |
| first assignment to `x`
| help: consider making this binding mutable: `mut x`
...
6 | x += $a;
| ^^^^^^^ cannot assign twice to immutable variable
...
18 | foo!(a ; 1);
| ----------- in this macro invocation
|
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error
For more information about this error, try `rustc --explain E0384`.
Original diagnostics will follow.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-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.