-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-borrow-checkerArea: The borrow checkerArea: The borrow checkerA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.NLL-diagnosticsWorking towards the "diagnostic parity" goalWorking towards the "diagnostic parity" goalT-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.
Milestone
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
A-borrow-checkerArea: The borrow checkerArea: The borrow checkerA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.NLL-diagnosticsWorking towards the "diagnostic parity" goalWorking towards the "diagnostic parity" goalT-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.