Skip to content

Commit 43cc08b

Browse files
committed
span_suggestion
1 parent d49cc46 commit 43cc08b

File tree

6 files changed

+28
-11
lines changed

6 files changed

+28
-11
lines changed

src/librustc_borrowck/borrowck/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1202,9 +1202,10 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
12021202
} else {
12031203
snippet
12041204
};
1205-
db.span_label(
1205+
db.span_suggestion(
12061206
let_span,
1207-
format!("consider changing this to `{}`", replace_str)
1207+
"use a mutable reference instead",
1208+
replace_str,
12081209
);
12091210
};
12101211
}

src/test/ui/nll/issue-51244.rs

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

src/test/ui/suggestions/issue-51244.nll.stderr renamed to src/test/ui/nll/issue-51244.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
error[E0594]: cannot assign to data in a `&` reference
2-
--> $DIR/issue-51244.rs:13:5
2+
--> $DIR/issue-51244.rs:15:5
33
|
44
LL | let ref my_ref @ _ = 0;
55
| -------------- help: consider changing this to be a mutable reference: `&mut ef my_ref @ _`
6-
LL | *my_ref = 0; //~ ERROR cannot assign to immutable borrowed content `*my_ref` [E0594]
6+
LL | *my_ref = 0; //~ ERROR cannot assign to data in a `&` reference [E0594]
77
| ^^^^^^^^^^^
88

99
error: aborting due to previous error

src/test/ui/rfc-2005-default-binding-mode/enum.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@ error[E0594]: cannot assign to immutable borrowed content `*x`
22
--> $DIR/enum.rs:19:5
33
|
44
LL | let Wrap(x) = &Wrap(3);
5-
| - consider changing this to `x`
5+
| - help: use a mutable reference instead: `x`
66
LL | *x += 1; //~ ERROR cannot assign to immutable
77
| ^^^^^^^ cannot borrow as mutable
88

99
error[E0594]: cannot assign to immutable borrowed content `*x`
1010
--> $DIR/enum.rs:23:9
1111
|
1212
LL | if let Some(x) = &Some(3) {
13-
| - consider changing this to `x`
13+
| - help: use a mutable reference instead: `x`
1414
LL | *x += 1; //~ ERROR cannot assign to immutable
1515
| ^^^^^^^ cannot borrow as mutable
1616

1717
error[E0594]: cannot assign to immutable borrowed content `*x`
1818
--> $DIR/enum.rs:29:9
1919
|
2020
LL | while let Some(x) = &Some(3) {
21-
| - consider changing this to `x`
21+
| - help: use a mutable reference instead: `x`
2222
LL | *x += 1; //~ ERROR cannot assign to immutable
2323
| ^^^^^^^ cannot borrow as mutable
2424

src/test/ui/rfc-2005-default-binding-mode/explicit-mut.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@ error[E0594]: cannot assign to immutable borrowed content `*n`
22
--> $DIR/explicit-mut.rs:17:13
33
|
44
LL | Some(n) => {
5-
| - consider changing this to `n`
5+
| - help: use a mutable reference instead: `n`
66
LL | *n += 1; //~ ERROR cannot assign to immutable
77
| ^^^^^^^ cannot borrow as mutable
88

99
error[E0594]: cannot assign to immutable borrowed content `*n`
1010
--> $DIR/explicit-mut.rs:25:13
1111
|
1212
LL | Some(n) => {
13-
| - consider changing this to `n`
13+
| - help: use a mutable reference instead: `n`
1414
LL | *n += 1; //~ ERROR cannot assign to immutable
1515
| ^^^^^^^ cannot borrow as mutable
1616

1717
error[E0594]: cannot assign to immutable borrowed content `*n`
1818
--> $DIR/explicit-mut.rs:33:13
1919
|
2020
LL | Some(n) => {
21-
| - consider changing this to `n`
21+
| - help: use a mutable reference instead: `n`
2222
LL | *n += 1; //~ ERROR cannot assign to immutable
2323
| ^^^^^^^ cannot borrow as mutable
2424

src/test/ui/suggestions/issue-51244.stderr

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

0 commit comments

Comments
 (0)