Skip to content

Commit

Permalink
tweak "make mut" spans (No. 3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ezrashaw committed Apr 20, 2023
1 parent b6616b6 commit 9329bb5
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 39 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,10 @@ fn suggest_ampmut<'tcx>(
{
let span = span.with_lo(span.lo() + BytePos(ws_pos as u32)).shrink_to_lo();
(true, span, " mut".to_owned())
} else if binding_exists {
// shrink the span to just after the `&` in `&variable`
let span = span.with_lo(span.lo() + BytePos(1)).shrink_to_lo();
(true, span, "mut ".to_owned())
} else {
let ty_mut = local_decl.ty.builtin_deref(true).unwrap();
assert_eq!(ty_mut.mutbl, hir::Mutability::Not);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ LL | *s.pointer += 1;
|
help: consider changing this to be a mutable reference
|
LL | fn a(s: &mut S<'_>) {
| ~~~~~~~~~~
LL | fn a(s: &mut S) {
| +++

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

error: aborting due to 2 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ LL | let x: &mut isize = &mut **t0;
|
help: consider changing this to be a mutable reference
|
LL | fn foo4(t0: &mut &mut isize) {
| ~~~~~~~~~~~~~~~
LL | fn foo4(t0: &mut &mut isize) {
| +++

error: aborting due to 3 previous errors

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/borrowck/borrowck-reborrow-from-mut.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ LL | let _bar1 = &mut foo.bar1;
help: consider changing this to be a mutable reference
|
LL | fn borrow_mut_from_imm(foo: &mut Foo) {
| ~~~~~~~~
| +++

error: aborting due to 11 previous errors

Expand Down
24 changes: 12 additions & 12 deletions tests/ui/borrowck/mutability-errors.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | *x = (1,);
help: consider changing this to be a mutable reference
|
LL | fn named_ref(x: &mut (i32,)) {
| ~~~~~~~~~~~
| +++

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

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

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

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

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

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

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

error[E0594]: cannot assign to data in a `*const` pointer
--> $DIR/mutability-errors.rs:30:5
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/did_you_mean/issue-38147-4.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ LL | f.s.push('x');
|
help: consider changing this to be a mutable reference
|
LL | fn f(x: usize, f: &mut Foo<'_>) {
| ~~~~~~~~~~~~
LL | fn f(x: usize, f: &mut Foo) {
| +++

error: aborting due to previous error

Expand Down
10 changes: 5 additions & 5 deletions tests/ui/did_you_mean/issue-39544.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ LL | let _ = &mut other.x;
help: consider changing this to be a mutable reference
|
LL | fn foo1(&self, other: &mut Z) {
| ~~~~~~
| +++

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

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

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

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

error[E0594]: cannot assign to `*x.0`, which is behind a `&` reference
--> $DIR/issue-39544.rs:48:5
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/nll/issue-57989.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | *x = 0;
help: consider changing this to be a mutable reference
|
LL | fn f(x: &mut i32) {
| ~~~~~~~~
| +++

error[E0506]: cannot assign to `*x` because it is borrowed
--> $DIR/issue-57989.rs:5:5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ LL | &mut x.y
help: consider changing this to be a mutable reference
|
LL | fn deref_extend_mut_field1(x: &mut Own<Point>) -> &mut isize {
| ~~~~~~~~~~~~~~~
| +++

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

error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
--> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:129:6
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/span/borrowck-call-is-borrow-issue-12224.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ LL | (*f)();
help: consider changing this to be a mutable reference
|
LL | fn test2<F>(f: &mut F) where F: FnMut() {
| ~~~~~~
| +++

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

error[E0507]: cannot move out of `f`, a captured variable in an `FnMut` closure
--> $DIR/borrowck-call-is-borrow-issue-12224.rs:57:13
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | x.h();
help: consider changing this to be a mutable reference
|
LL | fn b(x: &mut Foo) {
| ~~~~~~~~
| +++

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/span/borrowck-fn-in-const-b.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | x.push(format!("this is broken"));
help: consider changing this to be a mutable reference
|
LL | fn broken(x: &mut Vec<String>) {
| ~~~~~~~~~~~~~~~~
| +++

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/span/borrowck-object-mutability.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | x.borrowed_mut();
help: consider changing this to be a mutable reference
|
LL | fn borrowed_receiver(x: &mut dyn Foo) {
| ~~~~~~~~~~~~
| +++

error[E0596]: cannot borrow `*x` as mutable, as `x` is not declared as mutable
--> $DIR/borrowck-object-mutability.rs:18:5
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/span/mut-arg-hint.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | a.push_str("bar");
help: consider changing this to be a mutable reference
|
LL | fn foo(mut a: &mut String) {
| ~~~~~~~~~~~
| +++

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

error: aborting due to 3 previous errors

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/suggestions/issue-68049-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ LL | *input = self.0;
|
help: consider changing that to be a mutable reference
|
LL | fn example(&self, input: &mut i32); // should suggest here
| ~~~~~~~~
LL | fn example(&self, input: mut ); // should suggest here
| ~~~

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

0 comments on commit 9329bb5

Please sign in to comment.