- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lints
Description
The following snippet:
fn main() {
    let ref my_ref @ _ = 0;
    *my_ref = 0
}Produces the following output:
error[E0594]: cannot assign to immutable borrowed content `*my_ref`
 --> src/main.rs:3:5
  |
2 |     let ref my_ref @ _ = 0;
  |         -------------- consider changing this to `ref mut my_ref mut @ _`
3 |     *my_ref = 0
  |     ^^^^^^^^^^^ cannot borrow as mutable
Note that the label suggests invalid syntax. I believe this happens due to the text replacement in the following code:
rust/src/librustc_borrowck/borrowck/mod.rs
Lines 1210 to 1219 in e38554c
| ty::BindByReference(..) => { | |
| let snippet = self.tcx.sess.codemap().span_to_snippet(let_span); | |
| if let Ok(snippet) = snippet { | |
| db.span_label( | |
| let_span, | |
| format!("consider changing this to `{}`", | |
| snippet.replace("ref ", "ref mut ")) | |
| ); | |
| } | |
| } | 
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lints