-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
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.P-lowLow priorityLow 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.WG-diagnosticsWorking group: DiagnosticsWorking group: Diagnostics
Description
let mut mem_buffer : &[u8] = &b"foo"[..];
let mut reader = &mut mem_buffer as &std::io::Read;
let mut read_buffer = [0u8, 10];
reader.read(&mut read_buffer);
reports
error[E0596]: cannot borrow immutable borrowed content `*reader` as mutable
--> src/main.rs:5:5
|
5 | reader.read(&mut read_buffer);
| ^^^^^^ cannot borrow as mutable
Which is correct, but the fix is to modify the creation of the reader
variable. While this case is easy, it's probably less so in the general case. Possible avenues of improvement:
- The easy way this error message can be improved is to mention that the type is
&T
, but should be&mut T
. - If there are explicit type annotations on the variable, a note should point to it
- If the variable's type is inferred, a note should point to its initializer and maybe even do some primitive checks that can lead the developer towards the solution.
estebank
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.P-lowLow priorityLow 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.WG-diagnosticsWorking group: DiagnosticsWorking group: Diagnostics