tweak "make mut" spans (No. 3)

This commit is contained in:
Ezra Shaw 2023-04-19 19:50:08 +12:00 committed by Ezra Shaw
parent 9624d2b08e
commit 57c6a3183c
No known key found for this signature in database
GPG key ID: 5156CF5845150B0D
15 changed files with 43 additions and 39 deletions

View file

@ -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);

View file

@ -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
@ -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

View file

@ -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

View file

@ -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

View file

@ -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
@ -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
@ -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
@ -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
@ -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
@ -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
@ -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
@ -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

View file

@ -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

View file

@ -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
@ -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
@ -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
@ -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
@ -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

View file

@ -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

View file

@ -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
@ -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

View file

@ -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
@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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
@ -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

View file

@ -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