-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-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-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.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
This code:
fn f(x: &mut u32) { }
fn main() {
let x = 3;
f(&mut x);
}
produces a helpful error message:
error: cannot borrow immutable local variable `x` as mutable
--> <anon>:5:12
|
4 | let x = 3;
| - use `mut x` here to make mutable
5 | f(&mut x);
| ^ cannot borrow mutably
But the analogous code using a Box
:
fn f(x: &mut u32) { }
fn main() {
let x = Box::new(3);
f(&mut *x);
}
gives an error which doesn't point at the binding x
:
error: cannot borrow immutable `Box` content `*x` as mutable
--> <anon>:5:12
|
5 | f(&mut *x);
| ^^
wagenet
Metadata
Metadata
Assignees
Labels
A-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-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.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.