Fix &mut removal suggestion

This commit is contained in:
Esteban Küber 2024-07-03 21:02:55 +00:00
parent f63d2bc657
commit 9344779f71
4 changed files with 23 additions and 14 deletions

View File

@ -449,8 +449,8 @@ pub(crate) fn report_mutability_error(
.is_ok_and(|snippet| snippet.starts_with("&mut ")) =>
{
err.span_label(span, format!("cannot {act}"));
err.span_suggestion(
span,
err.span_suggestion_verbose(
span.with_hi(span.lo() + BytePos(5)),
"try removing `&mut` here",
"",
Applicability::MaybeIncorrect,

View File

@ -2,10 +2,13 @@ error[E0596]: cannot borrow `v` as mutable, as it is not declared as mutable
--> $DIR/issue-33819.rs:4:34
|
LL | Some(ref v) => { let a = &mut v; },
| ^^^^^^
| |
| cannot borrow as mutable
| help: try removing `&mut` here
| ^^^^^^ cannot borrow as mutable
|
help: try removing `&mut` here
|
LL - Some(ref v) => { let a = &mut v; },
LL + Some(ref v) => { let a = v; },
|
error: aborting due to 1 previous error

View File

@ -2,10 +2,13 @@ error[E0596]: cannot borrow `key` as mutable, as it is not declared as mutable
--> $DIR/issue-34337.rs:6:9
|
LL | get(&mut key);
| ^^^^^^^^
| |
| cannot borrow as mutable
| help: try removing `&mut` here
| ^^^^^^^^ cannot borrow as mutable
|
help: try removing `&mut` here
|
LL - get(&mut key);
LL + get(key);
|
error: aborting due to 1 previous error

View File

@ -2,10 +2,13 @@ error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
--> $DIR/issue-37139.rs:12:18
|
LL | test(&mut x);
| ^^^^^^
| |
| cannot borrow as mutable
| help: try removing `&mut` here
| ^^^^^^ cannot borrow as mutable
|
help: try removing `&mut` here
|
LL - test(&mut x);
LL + test(x);
|
error: aborting due to 1 previous error