-
Notifications
You must be signed in to change notification settings - Fork 13.7k
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-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.Call for participation: Hard difficulty. Experience needed to fix: A lot.P-highHigh priorityHigh priorityT-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
struct Foo { a: usize }
fn main() {
let mut x = std::rc::Rc::new(Foo { a: 1 });
x.a += 1;
let mut y = &(Foo { a: 1 });
y.a += 1;
}
<anon>:4:5: 4:13 error: cannot assign to immutable field
<anon>:4 x.a += 1;
^~~~~~~~
<anon>:7:5: 7:13 error: cannot assign to immutable field `y.a`
<anon>:7 y.a += 1;
^~~~~~~~
Gives no indication that the field is immutable because it is stored inside an Rc
/&
. These example are somewhat obvious, since the initialiser is directly above, but it's certainly possible to be matching deep inside some data structure and meet this error even though there are mut
s on all the appropriate variables.
The error message could include: "note: this field is immutable because it is being accessed via an &
reference [created by the autoderef of a Rc
]".
jalexvig, PENGUINLIONG, lwiklendt and dustinfreeman
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-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.Call for participation: Hard difficulty. Experience needed to fix: A lot.P-highHigh priorityHigh priorityT-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.