1
Fork 0

span_suggestion

This commit is contained in:
csmoe 2018-06-14 09:12:50 +08:00 committed by ashtneoi
parent 8932684ccc
commit 7a70140ed5
6 changed files with 28 additions and 11 deletions

View file

@ -1215,9 +1215,10 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
} else { } else {
snippet snippet
}; };
db.span_label( db.span_suggestion(
let_span, let_span,
format!("consider changing this to `{}`", replace_str) "use a mutable reference instead",
replace_str,
); );
}; };
} }

View file

@ -0,0 +1,16 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(nll)]
fn main() {
let ref my_ref @ _ = 0;
*my_ref = 0; //~ ERROR cannot assign to data in a `&` reference [E0594]
}

View file

@ -1,9 +1,9 @@
error[E0594]: cannot assign to data in a `&` reference error[E0594]: cannot assign to data in a `&` reference
--> $DIR/issue-51244.rs:13:5 --> $DIR/issue-51244.rs:15:5
| |
LL | let ref my_ref @ _ = 0; LL | let ref my_ref @ _ = 0;
| -------------- help: consider changing this to be a mutable reference: `&mut ef my_ref @ _` | -------------- help: consider changing this to be a mutable reference: `&mut ef my_ref @ _`
LL | *my_ref = 0; //~ ERROR cannot assign to immutable borrowed content `*my_ref` [E0594] LL | *my_ref = 0; //~ ERROR cannot assign to data in a `&` reference [E0594]
| ^^^^^^^^^^^ | ^^^^^^^^^^^
error: aborting due to previous error error: aborting due to previous error

View file

@ -2,7 +2,7 @@ error[E0594]: cannot assign to immutable borrowed content `*x`
--> $DIR/enum.rs:19:5 --> $DIR/enum.rs:19:5
| |
LL | let Wrap(x) = &Wrap(3); LL | let Wrap(x) = &Wrap(3);
| - consider changing this to `x` | - help: use a mutable reference instead: `x`
LL | *x += 1; //~ ERROR cannot assign to immutable LL | *x += 1; //~ ERROR cannot assign to immutable
| ^^^^^^^ cannot borrow as mutable | ^^^^^^^ cannot borrow as mutable
@ -10,7 +10,7 @@ error[E0594]: cannot assign to immutable borrowed content `*x`
--> $DIR/enum.rs:23:9 --> $DIR/enum.rs:23:9
| |
LL | if let Some(x) = &Some(3) { LL | if let Some(x) = &Some(3) {
| - consider changing this to `x` | - help: use a mutable reference instead: `x`
LL | *x += 1; //~ ERROR cannot assign to immutable LL | *x += 1; //~ ERROR cannot assign to immutable
| ^^^^^^^ cannot borrow as mutable | ^^^^^^^ cannot borrow as mutable
@ -18,7 +18,7 @@ error[E0594]: cannot assign to immutable borrowed content `*x`
--> $DIR/enum.rs:29:9 --> $DIR/enum.rs:29:9
| |
LL | while let Some(x) = &Some(3) { LL | while let Some(x) = &Some(3) {
| - consider changing this to `x` | - help: use a mutable reference instead: `x`
LL | *x += 1; //~ ERROR cannot assign to immutable LL | *x += 1; //~ ERROR cannot assign to immutable
| ^^^^^^^ cannot borrow as mutable | ^^^^^^^ cannot borrow as mutable

View file

@ -2,7 +2,7 @@ error[E0594]: cannot assign to immutable borrowed content `*n`
--> $DIR/explicit-mut.rs:17:13 --> $DIR/explicit-mut.rs:17:13
| |
LL | Some(n) => { LL | Some(n) => {
| - consider changing this to `n` | - help: use a mutable reference instead: `n`
LL | *n += 1; //~ ERROR cannot assign to immutable LL | *n += 1; //~ ERROR cannot assign to immutable
| ^^^^^^^ cannot borrow as mutable | ^^^^^^^ cannot borrow as mutable
@ -10,7 +10,7 @@ error[E0594]: cannot assign to immutable borrowed content `*n`
--> $DIR/explicit-mut.rs:25:13 --> $DIR/explicit-mut.rs:25:13
| |
LL | Some(n) => { LL | Some(n) => {
| - consider changing this to `n` | - help: use a mutable reference instead: `n`
LL | *n += 1; //~ ERROR cannot assign to immutable LL | *n += 1; //~ ERROR cannot assign to immutable
| ^^^^^^^ cannot borrow as mutable | ^^^^^^^ cannot borrow as mutable
@ -18,7 +18,7 @@ error[E0594]: cannot assign to immutable borrowed content `*n`
--> $DIR/explicit-mut.rs:33:13 --> $DIR/explicit-mut.rs:33:13
| |
LL | Some(n) => { LL | Some(n) => {
| - consider changing this to `n` | - help: use a mutable reference instead: `n`
LL | *n += 1; //~ ERROR cannot assign to immutable LL | *n += 1; //~ ERROR cannot assign to immutable
| ^^^^^^^ cannot borrow as mutable | ^^^^^^^ cannot borrow as mutable

View file

@ -2,7 +2,7 @@ error[E0594]: cannot assign to immutable borrowed content `*my_ref`
--> $DIR/issue-51244.rs:13:5 --> $DIR/issue-51244.rs:13:5
| |
LL | let ref my_ref @ _ = 0; LL | let ref my_ref @ _ = 0;
| -------------- consider changing this to `ref mut my_ref @ _` | -------------- help: use a mutable reference instead: `ref mut my_ref @ _`
LL | *my_ref = 0; //~ ERROR cannot assign to immutable borrowed content `*my_ref` [E0594] LL | *my_ref = 0; //~ ERROR cannot assign to immutable borrowed content `*my_ref` [E0594]
| ^^^^^^^^^^^ cannot borrow as mutable | ^^^^^^^^^^^ cannot borrow as mutable