Skip to content

Commit 32dc5a0

Browse files
committed
Auto merge of #54157 - euclio:structured-suggestion, r=estebank
use structured suggestion for "missing mut" label Fixes #54133 for both NLL and non-NLL. r? @estebank I'm not super happy with the existing wording here, since it's now a suggestion. I wonder if the message would work better as something like "help: make binding mutable: `mut foo`"? Also, are the `HELP` and `SUGGESTION` comments necessary?
2 parents f481987 + d871b8a commit 32dc5a0

File tree

77 files changed

+179
-164
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+179
-164
lines changed

src/librustc_borrowck/borrowck/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use rustc_data_structures::sync::Lrc;
4545
use std::hash::{Hash, Hasher};
4646
use syntax::ast;
4747
use syntax_pos::{MultiSpan, Span};
48-
use errors::{DiagnosticBuilder, DiagnosticId};
48+
use errors::{Applicability, DiagnosticBuilder, DiagnosticId};
4949

5050
use rustc::hir;
5151
use rustc::hir::intravisit::{self, Visitor};
@@ -1299,9 +1299,11 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
12991299
snippet
13001300
);
13011301
} else {
1302-
db.span_label(
1302+
db.span_suggestion_with_applicability(
13031303
let_span,
1304-
format!("consider changing this to `mut {}`", snippet),
1304+
"make this binding mutable",
1305+
format!("mut {}", snippet),
1306+
Applicability::MachineApplicable,
13051307
);
13061308
}
13071309
}

src/librustc_mir/borrow_check/error_reporting.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc::mir::{ProjectionElem, Rvalue, Statement, StatementKind};
1717
use rustc::ty;
1818
use rustc_data_structures::fx::FxHashSet;
1919
use rustc_data_structures::sync::Lrc;
20-
use rustc_errors::DiagnosticBuilder;
20+
use rustc_errors::{Applicability, DiagnosticBuilder};
2121
use syntax_pos::Span;
2222

2323
use super::borrow_set::BorrowData;
@@ -702,9 +702,11 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
702702
if let Some(decl) = local_decl {
703703
if let Some(name) = decl.name {
704704
if decl.can_be_made_mutable() {
705-
err.span_label(
705+
err.span_suggestion_with_applicability(
706706
decl.source_info.span,
707-
format!("consider changing this to `mut {}`", name),
707+
"make this binding mutable",
708+
format!("mut {}", name),
709+
Applicability::MachineApplicable,
708710
);
709711
}
710712
}

src/test/ui/E0596.ast.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0596]: cannot borrow immutable local variable `x` as mutable
22
--> $DIR/E0596.rs:16:18
33
|
44
LL | let x = 1;
5-
| - consider changing this to `mut x`
5+
| - help: make this binding mutable: `mut x`
66
LL | let y = &mut x; //[ast]~ ERROR [E0596]
77
| ^ cannot borrow mutably
88

src/test/ui/asm/asm-out-assign-imm.nll.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0384]: cannot assign twice to immutable variable `x`
22
--> $DIR/asm-out-assign-imm.rs:34:9
33
|
44
LL | let x: isize;
5-
| - consider changing this to `mut x`
5+
| - help: make this binding mutable: `mut x`
66
LL | x = 1;
77
| ----- first assignment to `x`
88
...

src/test/ui/assign-imm-local-twice.ast.nll.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
error[E0384]: cannot assign twice to immutable variable `v`
2-
--> $DIR/assign-imm-local-twice.rs:20:5
2+
--> $DIR/assign-imm-local-twice.rs:21:5
33
|
44
LL | let v: isize;
5-
| - consider changing this to `mut v`
6-
LL | //[mir]~^ NOTE consider changing this to `mut v`
5+
| - help: make this binding mutable: `mut v`
6+
...
77
LL | v = 1; //[ast]~ NOTE first assignment
88
| ----- first assignment to `v`
99
...

src/test/ui/assign-imm-local-twice.ast.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0384]: cannot assign twice to immutable variable `v`
2-
--> $DIR/assign-imm-local-twice.rs:20:5
2+
--> $DIR/assign-imm-local-twice.rs:21:5
33
|
44
LL | v = 1; //[ast]~ NOTE first assignment
55
| ----- first assignment to `v`

src/test/ui/assign-imm-local-twice.mir.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
error[E0384]: cannot assign twice to immutable variable `v`
2-
--> $DIR/assign-imm-local-twice.rs:20:5
2+
--> $DIR/assign-imm-local-twice.rs:21:5
33
|
44
LL | let v: isize;
5-
| - consider changing this to `mut v`
6-
LL | //[mir]~^ NOTE consider changing this to `mut v`
5+
| - help: make this binding mutable: `mut v`
6+
...
77
LL | v = 1; //[ast]~ NOTE first assignment
88
| ----- first assignment to `v`
99
...

src/test/ui/assign-imm-local-twice.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414
fn test() {
1515
let v: isize;
16-
//[mir]~^ NOTE consider changing this to `mut v`
16+
//[mir]~^ HELP make this binding mutable
17+
//[mir]~| SUGGESTION mut v
1718
v = 1; //[ast]~ NOTE first assignment
1819
//[mir]~^ NOTE first assignment
1920
println!("v={}", v);

src/test/ui/augmented-assignments.nll.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ LL | | x; //~ value moved here
1515
| borrow later used here
1616

1717
error[E0596]: cannot borrow `y` as mutable, as it is not declared as mutable
18-
--> $DIR/augmented-assignments.rs:30:5
18+
--> $DIR/augmented-assignments.rs:31:5
1919
|
2020
LL | let y = Int(2);
2121
| - help: consider changing this to be mutable: `mut y`
22-
LL | //~^ consider changing this to `mut y`
22+
...
2323
LL | y //~ error: cannot borrow immutable local variable `y` as mutable
2424
| ^ cannot borrow as mutable
2525

src/test/ui/augmented-assignments.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ fn main() {
2626
x; //~ value moved here
2727

2828
let y = Int(2);
29-
//~^ consider changing this to `mut y`
29+
//~^ HELP make this binding mutable
30+
//~| SUGGESTION mut y
3031
y //~ error: cannot borrow immutable local variable `y` as mutable
3132
//~| cannot borrow
3233
+=

0 commit comments

Comments
 (0)