Skip to content

Commit 9344779

Browse files
committed
Fix &mut removal suggestion
1 parent f63d2bc commit 9344779

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
449449
.is_ok_and(|snippet| snippet.starts_with("&mut ")) =>
450450
{
451451
err.span_label(span, format!("cannot {act}"));
452-
err.span_suggestion(
453-
span,
452+
err.span_suggestion_verbose(
453+
span.with_hi(span.lo() + BytePos(5)),
454454
"try removing `&mut` here",
455455
"",
456456
Applicability::MaybeIncorrect,

tests/ui/borrowck/issue-33819.stderr

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ error[E0596]: cannot borrow `v` as mutable, as it is not declared as mutable
22
--> $DIR/issue-33819.rs:4:34
33
|
44
LL | Some(ref v) => { let a = &mut v; },
5-
| ^^^^^^
6-
| |
7-
| cannot borrow as mutable
8-
| help: try removing `&mut` here
5+
| ^^^^^^ cannot borrow as mutable
6+
|
7+
help: try removing `&mut` here
8+
|
9+
LL - Some(ref v) => { let a = &mut v; },
10+
LL + Some(ref v) => { let a = v; },
11+
|
912

1013
error: aborting due to 1 previous error
1114

tests/ui/did_you_mean/issue-34337.stderr

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ error[E0596]: cannot borrow `key` as mutable, as it is not declared as mutable
22
--> $DIR/issue-34337.rs:6:9
33
|
44
LL | get(&mut key);
5-
| ^^^^^^^^
6-
| |
7-
| cannot borrow as mutable
8-
| help: try removing `&mut` here
5+
| ^^^^^^^^ cannot borrow as mutable
6+
|
7+
help: try removing `&mut` here
8+
|
9+
LL - get(&mut key);
10+
LL + get(key);
11+
|
912

1013
error: aborting due to 1 previous error
1114

tests/ui/did_you_mean/issue-37139.stderr

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
22
--> $DIR/issue-37139.rs:12:18
33
|
44
LL | test(&mut x);
5-
| ^^^^^^
6-
| |
7-
| cannot borrow as mutable
8-
| help: try removing `&mut` here
5+
| ^^^^^^ cannot borrow as mutable
6+
|
7+
help: try removing `&mut` here
8+
|
9+
LL - test(&mut x);
10+
LL + test(x);
11+
|
912

1013
error: aborting due to 1 previous error
1114

0 commit comments

Comments
 (0)