Closed
Description
Currently, when you try to access an immutable local, AST borrowck suggests that you should change it to mut x
, for example:
fn main() {
let x = 0;
x = 1;
std::mem::replace(&mut x, 2);
}
warning: value assigned to `x` is never read
--> src/main.rs:2:9
|
2 | let x = 0;
| ^
|
= note: #[warn(unused_assignments)] on by default
error[E0596]: cannot borrow immutable local variable `x` as mutable
--> src/main.rs:4:28
|
2 | let x = 0;
| - consider changing this to `mut x` <---- THIS NOTE
3 | x = 1;
4 | std::mem::replace(&mut x, 2);
| ^ cannot borrow mutably
error[E0384]: cannot assign twice to immutable variable `x`
--> src/main.rs:3:5
|
2 | let x = 0;
| - first assignment to `x`
3 | x = 1;
| ^^^^^ cannot assign twice to immutable variable
error: aborting due to 2 previous errors
MIR borrowck should be doing this too.
FIXME: I should write mentor notes
Metadata
Metadata
Assignees
Labels
Area: The borrow checkerArea: Messages for errors, warnings, and lintsCategory: An issue proposing an enhancement or a PR with one.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Working towards the "diagnostic parity" goalRelevant to the compiler team, which will review and decide on the PR/issue.