Skip to content

Commit 9329bb5

Browse files
committed
tweak "make mut" spans (No. 3)
1 parent b6616b6 commit 9329bb5

15 files changed

+43
-39
lines changed

Diff for: compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,10 @@ fn suggest_ampmut<'tcx>(
12631263
{
12641264
let span = span.with_lo(span.lo() + BytePos(ws_pos as u32)).shrink_to_lo();
12651265
(true, span, " mut".to_owned())
1266+
} else if binding_exists {
1267+
// shrink the span to just after the `&` in `&variable`
1268+
let span = span.with_lo(span.lo() + BytePos(1)).shrink_to_lo();
1269+
(true, span, "mut ".to_owned())
12661270
} else {
12671271
let ty_mut = local_decl.ty.builtin_deref(true).unwrap();
12681272
assert_eq!(ty_mut.mutbl, hir::Mutability::Not);

Diff for: tests/ui/borrowck/borrowck-assign-to-andmut-in-aliasable-loc.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ LL | *s.pointer += 1;
66
|
77
help: consider changing this to be a mutable reference
88
|
9-
LL | fn a(s: &mut S<'_>) {
10-
| ~~~~~~~~~~
9+
LL | fn a(s: &mut S) {
10+
| +++
1111

1212
error[E0594]: cannot assign to `*s.pointer`, which is behind a `&` reference
1313
--> $DIR/borrowck-assign-to-andmut-in-aliasable-loc.rs:17:5
@@ -17,8 +17,8 @@ LL | *s.pointer += 1;
1717
|
1818
help: consider changing this to be a mutable reference
1919
|
20-
LL | fn c(s: &mut &mut S<'_>) {
21-
| ~~~~~~~~~~~~~~~
20+
LL | fn c(s: &mut &mut S) {
21+
| +++
2222

2323
error: aborting due to 2 previous errors
2424

Diff for: tests/ui/borrowck/borrowck-borrow-mut-base-ptr-in-aliasable-loc.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ LL | let x: &mut isize = &mut **t0;
2727
|
2828
help: consider changing this to be a mutable reference
2929
|
30-
LL | fn foo4(t0: &mut &mut isize) {
31-
| ~~~~~~~~~~~~~~~
30+
LL | fn foo4(t0: &mut &mut isize) {
31+
| +++
3232

3333
error: aborting due to 3 previous errors
3434

Diff for: tests/ui/borrowck/borrowck-reborrow-from-mut.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ LL | let _bar1 = &mut foo.bar1;
111111
help: consider changing this to be a mutable reference
112112
|
113113
LL | fn borrow_mut_from_imm(foo: &mut Foo) {
114-
| ~~~~~~~~
114+
| +++
115115

116116
error: aborting due to 11 previous errors
117117

Diff for: tests/ui/borrowck/mutability-errors.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | *x = (1,);
77
help: consider changing this to be a mutable reference
88
|
99
LL | fn named_ref(x: &mut (i32,)) {
10-
| ~~~~~~~~~~~
10+
| +++
1111

1212
error[E0594]: cannot assign to `x.0`, which is behind a `&` reference
1313
--> $DIR/mutability-errors.rs:10:5
@@ -18,7 +18,7 @@ LL | x.0 = 1;
1818
help: consider changing this to be a mutable reference
1919
|
2020
LL | fn named_ref(x: &mut (i32,)) {
21-
| ~~~~~~~~~~~
21+
| +++
2222

2323
error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference
2424
--> $DIR/mutability-errors.rs:11:5
@@ -29,7 +29,7 @@ LL | &mut *x;
2929
help: consider changing this to be a mutable reference
3030
|
3131
LL | fn named_ref(x: &mut (i32,)) {
32-
| ~~~~~~~~~~~
32+
| +++
3333

3434
error[E0596]: cannot borrow `x.0` as mutable, as it is behind a `&` reference
3535
--> $DIR/mutability-errors.rs:12:5
@@ -40,7 +40,7 @@ LL | &mut x.0;
4040
help: consider changing this to be a mutable reference
4141
|
4242
LL | fn named_ref(x: &mut (i32,)) {
43-
| ~~~~~~~~~~~
43+
| +++
4444

4545
error[E0594]: cannot assign to data in a `&` reference
4646
--> $DIR/mutability-errors.rs:16:5
@@ -74,8 +74,8 @@ LL | *x = (1,);
7474
|
7575
help: consider changing this to be a mutable pointer
7676
|
77-
LL | unsafe fn named_ptr(x: *mut (i32,)) {
78-
| ~~~~~~~~~~~
77+
LL | unsafe fn named_ptr(x: *mut const (i32,)) {
78+
| +++
7979

8080
error[E0594]: cannot assign to `x.0`, which is behind a `*const` pointer
8181
--> $DIR/mutability-errors.rs:24:5
@@ -85,8 +85,8 @@ LL | (*x).0 = 1;
8585
|
8686
help: consider changing this to be a mutable pointer
8787
|
88-
LL | unsafe fn named_ptr(x: *mut (i32,)) {
89-
| ~~~~~~~~~~~
88+
LL | unsafe fn named_ptr(x: *mut const (i32,)) {
89+
| +++
9090

9191
error[E0596]: cannot borrow `*x` as mutable, as it is behind a `*const` pointer
9292
--> $DIR/mutability-errors.rs:25:5
@@ -96,8 +96,8 @@ LL | &mut *x;
9696
|
9797
help: consider changing this to be a mutable pointer
9898
|
99-
LL | unsafe fn named_ptr(x: *mut (i32,)) {
100-
| ~~~~~~~~~~~
99+
LL | unsafe fn named_ptr(x: *mut const (i32,)) {
100+
| +++
101101

102102
error[E0596]: cannot borrow `x.0` as mutable, as it is behind a `*const` pointer
103103
--> $DIR/mutability-errors.rs:26:5
@@ -107,8 +107,8 @@ LL | &mut (*x).0;
107107
|
108108
help: consider changing this to be a mutable pointer
109109
|
110-
LL | unsafe fn named_ptr(x: *mut (i32,)) {
111-
| ~~~~~~~~~~~
110+
LL | unsafe fn named_ptr(x: *mut const (i32,)) {
111+
| +++
112112

113113
error[E0594]: cannot assign to data in a `*const` pointer
114114
--> $DIR/mutability-errors.rs:30:5

Diff for: tests/ui/did_you_mean/issue-38147-4.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ LL | f.s.push('x');
66
|
77
help: consider changing this to be a mutable reference
88
|
9-
LL | fn f(x: usize, f: &mut Foo<'_>) {
10-
| ~~~~~~~~~~~~
9+
LL | fn f(x: usize, f: &mut Foo) {
10+
| +++
1111

1212
error: aborting due to previous error
1313

Diff for: tests/ui/did_you_mean/issue-39544.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ LL | let _ = &mut other.x;
4040
help: consider changing this to be a mutable reference
4141
|
4242
LL | fn foo1(&self, other: &mut Z) {
43-
| ~~~~~~
43+
| +++
4444

4545
error[E0596]: cannot borrow `self.x` as mutable, as it is behind a `&` reference
4646
--> $DIR/issue-39544.rs:25:17
@@ -62,7 +62,7 @@ LL | let _ = &mut other.x;
6262
help: consider changing this to be a mutable reference
6363
|
6464
LL | fn foo2<'a>(&'a self, other: &mut Z) {
65-
| ~~~~~~
65+
| +++
6666

6767
error[E0596]: cannot borrow `self.x` as mutable, as it is behind a `&` reference
6868
--> $DIR/issue-39544.rs:30:17
@@ -84,7 +84,7 @@ LL | let _ = &mut other.x;
8484
help: consider changing this to be a mutable reference
8585
|
8686
LL | fn foo3<'a>(self: &'a Self, other: &mut Z) {
87-
| ~~~~~~
87+
| +++
8888

8989
error[E0596]: cannot borrow `other.x` as mutable, as it is behind a `&` reference
9090
--> $DIR/issue-39544.rs:35:17
@@ -95,7 +95,7 @@ LL | let _ = &mut other.x;
9595
help: consider changing this to be a mutable reference
9696
|
9797
LL | fn foo4(other: &mut Z) {
98-
| ~~~~~~
98+
| +++
9999

100100
error[E0596]: cannot borrow `z.x` as mutable, as `z` is not declared as mutable
101101
--> $DIR/issue-39544.rs:41:13
@@ -117,7 +117,7 @@ LL | let _ = &mut w.x;
117117
help: consider changing this to be a mutable reference
118118
|
119119
LL | pub fn with_arg(z: Z, w: &mut Z) {
120-
| ~~~~~~
120+
| +++
121121

122122
error[E0594]: cannot assign to `*x.0`, which is behind a `&` reference
123123
--> $DIR/issue-39544.rs:48:5

Diff for: tests/ui/nll/issue-57989.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | *x = 0;
77
help: consider changing this to be a mutable reference
88
|
99
LL | fn f(x: &mut i32) {
10-
| ~~~~~~~~
10+
| +++
1111

1212
error[E0506]: cannot assign to `*x` because it is borrowed
1313
--> $DIR/issue-57989.rs:5:5

Diff for: tests/ui/span/borrowck-borrow-overloaded-auto-deref-mut.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ LL | &mut x.y
1818
help: consider changing this to be a mutable reference
1919
|
2020
LL | fn deref_extend_mut_field1(x: &mut Own<Point>) -> &mut isize {
21-
| ~~~~~~~~~~~~~~~
21+
| +++
2222

2323
error[E0499]: cannot borrow `*x` as mutable more than once at a time
2424
--> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:78:19
@@ -82,7 +82,7 @@ LL | x.y_mut()
8282
help: consider changing this to be a mutable reference
8383
|
8484
LL | fn deref_extend_mut_method1(x: &mut Own<Point>) -> &mut isize {
85-
| ~~~~~~~~~~~~~~~
85+
| +++
8686

8787
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
8888
--> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:129:6

Diff for: tests/ui/span/borrowck-call-is-borrow-issue-12224.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ LL | (*f)();
1919
help: consider changing this to be a mutable reference
2020
|
2121
LL | fn test2<F>(f: &mut F) where F: FnMut() {
22-
| ~~~~~~
22+
| +++
2323

2424
error[E0596]: cannot borrow `f.f` as mutable, as it is behind a `&` reference
2525
--> $DIR/borrowck-call-is-borrow-issue-12224.rs:34:5
@@ -29,8 +29,8 @@ LL | f.f.call_mut(())
2929
|
3030
help: consider changing this to be a mutable reference
3131
|
32-
LL | fn test4(f: &mut Test<'_>) {
33-
| ~~~~~~~~~~~~~
32+
LL | fn test4(f: &mut Test) {
33+
| +++
3434

3535
error[E0507]: cannot move out of `f`, a captured variable in an `FnMut` closure
3636
--> $DIR/borrowck-call-is-borrow-issue-12224.rs:57:13

Diff for: tests/ui/span/borrowck-call-method-from-mut-aliasable.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | x.h();
77
help: consider changing this to be a mutable reference
88
|
99
LL | fn b(x: &mut Foo) {
10-
| ~~~~~~~~
10+
| +++
1111

1212
error: aborting due to previous error
1313

Diff for: tests/ui/span/borrowck-fn-in-const-b.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | x.push(format!("this is broken"));
77
help: consider changing this to be a mutable reference
88
|
99
LL | fn broken(x: &mut Vec<String>) {
10-
| ~~~~~~~~~~~~~~~~
10+
| +++
1111

1212
error: aborting due to previous error
1313

Diff for: tests/ui/span/borrowck-object-mutability.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | x.borrowed_mut();
77
help: consider changing this to be a mutable reference
88
|
99
LL | fn borrowed_receiver(x: &mut dyn Foo) {
10-
| ~~~~~~~~~~~~
10+
| +++
1111

1212
error[E0596]: cannot borrow `*x` as mutable, as `x` is not declared as mutable
1313
--> $DIR/borrowck-object-mutability.rs:18:5

Diff for: tests/ui/span/mut-arg-hint.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | a.push_str("bar");
77
help: consider changing this to be a mutable reference
88
|
99
LL | fn foo(mut a: &mut String) {
10-
| ~~~~~~~~~~~
10+
| +++
1111

1212
error[E0596]: cannot borrow `*a` as mutable, as it is behind a `&` reference
1313
--> $DIR/mut-arg-hint.rs:8:5
@@ -29,7 +29,7 @@ LL | a.push_str("foo");
2929
help: consider changing this to be a mutable reference
3030
|
3131
LL | pub fn foo(mut a: &mut String) {
32-
| ~~~~~~~~~~~
32+
| +++
3333

3434
error: aborting due to 3 previous errors
3535

Diff for: tests/ui/suggestions/issue-68049-2.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ LL | *input = self.0;
66
|
77
help: consider changing that to be a mutable reference
88
|
9-
LL | fn example(&self, input: &mut i32); // should suggest here
10-
| ~~~~~~~~
9+
LL | fn example(&self, input: mut ); // should suggest here
10+
| ~~~
1111

1212
error[E0594]: cannot assign to `self.0`, which is behind a `&` reference
1313
--> $DIR/issue-68049-2.rs:17:5

0 commit comments

Comments
 (0)