Skip to content

Commit b9439eb

Browse files
committedDec 29, 2022
Use verbose suggestions for mutability errors
·
1.91.01.68.0
1 parent 92c1937 commit b9439eb

34 files changed

+338
-181
lines changed
 

‎compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs‎

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
333333
let local_decl = &self.body.local_decls[local];
334334
assert_eq!(local_decl.mutability, Mutability::Not);
335335

336-
err.span_label(span, format!("cannot {ACT}", ACT = act));
336+
err.span_label(span, format!("cannot {act}"));
337337
err.span_suggestion(
338338
local_decl.source_info.span,
339339
"consider changing this to be mutable",
@@ -357,7 +357,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
357357

358358
let captured_place = &self.upvars[upvar_index.index()].place;
359359

360-
err.span_label(span, format!("cannot {ACT}", ACT = act));
360+
err.span_label(span, format!("cannot {act}"));
361361

362362
let upvar_hir_id = captured_place.get_root_variable();
363363

@@ -397,7 +397,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
397397
.span_to_snippet(span)
398398
.map_or(false, |snippet| snippet.starts_with("&mut ")) =>
399399
{
400-
err.span_label(span, format!("cannot {ACT}", ACT = act));
400+
err.span_label(span, format!("cannot {act}"));
401401
err.span_suggestion(
402402
span,
403403
"try removing `&mut` here",
@@ -409,7 +409,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
409409
PlaceRef { local, projection: [ProjectionElem::Deref] }
410410
if self.body.local_decls[local].is_ref_for_guard() =>
411411
{
412-
err.span_label(span, format!("cannot {ACT}", ACT = act));
412+
err.span_label(span, format!("cannot {act}"));
413413
err.note(
414414
"variables bound in patterns are immutable until the end of the pattern guard",
415415
);
@@ -537,7 +537,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
537537
Some((true, err_help_span, suggested_code)) => {
538538
let (is_trait_sig, local_trait) = self.is_error_in_trait(local);
539539
if !is_trait_sig {
540-
err.span_suggestion(
540+
err.span_suggestion_verbose(
541541
err_help_span,
542542
&format!(
543543
"consider changing this to be a mutable {pointer_desc}"
@@ -546,7 +546,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
546546
Applicability::MachineApplicable,
547547
);
548548
} else if let Some(x) = local_trait {
549-
err.span_suggestion(
549+
err.span_suggestion_verbose(
550550
x,
551551
&format!(
552552
"consider changing that to be a mutable {pointer_desc}"
@@ -569,24 +569,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
569569
err.span_label(
570570
span,
571571
format!(
572-
"`{NAME}` is a `{SIGIL}` {DESC}, \
573-
so the data it refers to cannot be {ACTED_ON}",
574-
NAME = name,
575-
SIGIL = pointer_sigil,
576-
DESC = pointer_desc,
577-
ACTED_ON = acted_on
572+
"`{name}` is a `{pointer_sigil}` {pointer_desc}, \
573+
so the data it refers to cannot be {acted_on}",
578574
),
579575
);
580576
}
581577
_ => {
582578
err.span_label(
583579
span,
584-
format!(
585-
"cannot {ACT} through `{SIGIL}` {DESC}",
586-
ACT = act,
587-
SIGIL = pointer_sigil,
588-
DESC = pointer_desc
589-
),
580+
format!("cannot {act} through `{pointer_sigil}` {pointer_desc}"),
590581
);
591582
}
592583
}
@@ -605,13 +596,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
605596
Some(BorrowedContentSource::OverloadedDeref(ty)) => {
606597
err.help(&format!(
607598
"trait `DerefMut` is required to modify through a dereference, \
608-
but it is not implemented for `{ty}`",
599+
but it is not implemented for `{ty}`",
609600
));
610601
}
611602
Some(BorrowedContentSource::OverloadedIndex(ty)) => {
612603
err.help(&format!(
613604
"trait `IndexMut` is required to modify indexed content, \
614-
but it is not implemented for `{ty}`",
605+
but it is not implemented for `{ty}`",
615606
));
616607
self.suggest_map_index_mut_alternatives(ty, &mut err, span);
617608
}
@@ -620,7 +611,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
620611
}
621612

622613
_ => {
623-
err.span_label(span, format!("cannot {ACT}", ACT = act));
614+
err.span_label(span, format!("cannot {act}"));
624615
}
625616
}
626617

‎src/test/ui/array-slice-vec/slice-mut-2.stderr‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference
22
--> $DIR/slice-mut-2.rs:7:18
33
|
4-
LL | let x: &[isize] = &[1, 2, 3, 4, 5];
5-
| ---------------- help: consider changing this to be a mutable reference: `&mut [1, 2, 3, 4, 5]`
6-
...
74
LL | let _ = &mut x[2..4];
85
| ^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
6+
|
7+
help: consider changing this to be a mutable reference
8+
|
9+
LL | let x: &[isize] = &mut [1, 2, 3, 4, 5];
10+
| ~~~~~~~~~~~~~~~~~~~~
911

1012
error: aborting due to previous error
1113

‎src/test/ui/borrowck/borrow-raw-address-of-deref-mutability.stderr‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference
22
--> $DIR/borrow-raw-address-of-deref-mutability.rs:8:13
33
|
4-
LL | let x = &0;
5-
| -- help: consider changing this to be a mutable reference: `&mut 0`
6-
LL |
74
LL | let q = &raw mut *x;
85
| ^^^^^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
6+
|
7+
help: consider changing this to be a mutable reference
8+
|
9+
LL | let x = &mut 0;
10+
| ~~~~~~
911

1012
error[E0596]: cannot borrow `*x` as mutable, as it is behind a `*const` pointer
1113
--> $DIR/borrow-raw-address-of-deref-mutability.rs:14:13
1214
|
13-
LL | let x = &0 as *const i32;
14-
| -- help: consider changing this to be a mutable pointer: `&mut 0`
15-
LL |
1615
LL | let q = &raw mut *x;
1716
| ^^^^^^^^^^^ `x` is a `*const` pointer, so the data it refers to cannot be borrowed as mutable
17+
|
18+
help: consider changing this to be a mutable pointer
19+
|
20+
LL | let x = &mut 0 as *const i32;
21+
| ~~~~~~
1822

1923
error: aborting due to 2 previous errors
2024

‎src/test/ui/borrowck/borrowck-access-permissions.stderr‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,35 @@ LL | let _y1 = &mut *box_x;
2525
error[E0596]: cannot borrow `*ref_x` as mutable, as it is behind a `&` reference
2626
--> $DIR/borrowck-access-permissions.rs:30:19
2727
|
28-
LL | let ref_x = &x;
29-
| -- help: consider changing this to be a mutable reference: `&mut x`
30-
...
3128
LL | let _y1 = &mut *ref_x;
3229
| ^^^^^^^^^^^ `ref_x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
30+
|
31+
help: consider changing this to be a mutable reference
32+
|
33+
LL | let ref_x = &mut x;
34+
| ~~~~~~
3335

3436
error[E0596]: cannot borrow `*ptr_x` as mutable, as it is behind a `*const` pointer
3537
--> $DIR/borrowck-access-permissions.rs:39:23
3638
|
37-
LL | let ptr_x : *const _ = &x;
38-
| -- help: consider changing this to be a mutable pointer: `&mut x`
39-
...
4039
LL | let _y1 = &mut *ptr_x;
4140
| ^^^^^^^^^^^ `ptr_x` is a `*const` pointer, so the data it refers to cannot be borrowed as mutable
41+
|
42+
help: consider changing this to be a mutable pointer
43+
|
44+
LL | let ptr_x : *const _ = &mut x;
45+
| ~~~~~~
4246

4347
error[E0596]: cannot borrow `*foo_ref.f` as mutable, as it is behind a `&` reference
4448
--> $DIR/borrowck-access-permissions.rs:48:18
4549
|
46-
LL | let foo_ref = &foo;
47-
| ---- help: consider changing this to be a mutable reference: `&mut foo`
4850
LL | let _y = &mut *foo_ref.f;
4951
| ^^^^^^^^^^^^^^^ `foo_ref` is a `&` reference, so the data it refers to cannot be borrowed as mutable
52+
|
53+
help: consider changing this to be a mutable reference
54+
|
55+
LL | let foo_ref = &mut foo;
56+
| ~~~~~~~~
5057

5158
error: aborting due to 6 previous errors
5259

‎src/test/ui/borrowck/borrowck-assign-to-andmut-in-aliasable-loc.stderr‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
error[E0594]: cannot assign to `*s.pointer`, which is behind a `&` reference
22
--> $DIR/borrowck-assign-to-andmut-in-aliasable-loc.rs:9:5
33
|
4-
LL | fn a(s: &S) {
5-
| -- help: consider changing this to be a mutable reference: `&mut S<'_>`
64
LL | *s.pointer += 1;
75
| ^^^^^^^^^^^^^^^ `s` is a `&` reference, so the data it refers to cannot be written
6+
|
7+
help: consider changing this to be a mutable reference
8+
|
9+
LL | fn a(s: &mut S<'_>) {
10+
| ~~~~~~~~~~
811

912
error[E0594]: cannot assign to `*s.pointer`, which is behind a `&` reference
1013
--> $DIR/borrowck-assign-to-andmut-in-aliasable-loc.rs:17:5
1114
|
12-
LL | fn c(s: & &mut S) {
13-
| -------- help: consider changing this to be a mutable reference: `&mut &mut S<'_>`
1415
LL | *s.pointer += 1;
1516
| ^^^^^^^^^^^^^^^ `s` is a `&` reference, so the data it refers to cannot be written
17+
|
18+
help: consider changing this to be a mutable reference
19+
|
20+
LL | fn c(s: &mut &mut S<'_>) {
21+
| ~~~~~~~~~~~~~~~
1622

1723
error: aborting due to 2 previous errors
1824

‎src/test/ui/borrowck/borrowck-borrow-mut-base-ptr-in-aliasable-loc.stderr‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ LL | **t1 = 22;
2020
error[E0596]: cannot borrow `**t0` as mutable, as it is behind a `&` reference
2121
--> $DIR/borrowck-borrow-mut-base-ptr-in-aliasable-loc.rs:19:26
2222
|
23-
LL | fn foo4(t0: & &mut isize) {
24-
| ------------ help: consider changing this to be a mutable reference: `&mut &mut isize`
2523
LL | let x: &mut isize = &mut **t0;
2624
| ^^^^^^^^^ `t0` is a `&` reference, so the data it refers to cannot be borrowed as mutable
25+
|
26+
help: consider changing this to be a mutable reference
27+
|
28+
LL | fn foo4(t0: &mut &mut isize) {
29+
| ~~~~~~~~~~~~~~~
2730

2831
error: aborting due to 3 previous errors
2932

‎src/test/ui/borrowck/borrowck-issue-14498.stderr‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
error[E0594]: cannot assign to `***p`, which is behind a `&` reference
22
--> $DIR/borrowck-issue-14498.rs:16:5
33
|
4-
LL | let p = &y;
5-
| -- help: consider changing this to be a mutable reference: `&mut y`
64
LL | ***p = 2;
75
| ^^^^^^^^ `p` is a `&` reference, so the data it refers to cannot be written
6+
|
7+
help: consider changing this to be a mutable reference
8+
|
9+
LL | let p = &mut y;
10+
| ~~~~~~
811

912
error[E0506]: cannot assign to `**y` because it is borrowed
1013
--> $DIR/borrowck-issue-14498.rs:25:5

‎src/test/ui/borrowck/borrowck-reborrow-from-mut.stderr‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,13 @@ LL | use_imm(_bar1);
105105
error[E0596]: cannot borrow `foo.bar1` as mutable, as it is behind a `&` reference
106106
--> $DIR/borrowck-reborrow-from-mut.rs:88:17
107107
|
108-
LL | fn borrow_mut_from_imm(foo: &Foo) {
109-
| ---- help: consider changing this to be a mutable reference: `&mut Foo`
110108
LL | let _bar1 = &mut foo.bar1;
111109
| ^^^^^^^^^^^^^ `foo` is a `&` reference, so the data it refers to cannot be borrowed as mutable
110+
|
111+
help: consider changing this to be a mutable reference
112+
|
113+
LL | fn borrow_mut_from_imm(foo: &mut Foo) {
114+
| ~~~~~~~~
112115

113116
error: aborting due to 11 previous errors
114117

‎src/test/ui/borrowck/issue-85765.stderr‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ LL | rofl.push(Vec::new());
1010
error[E0594]: cannot assign to `*r`, which is behind a `&` reference
1111
--> $DIR/issue-85765.rs:12:5
1212
|
13-
LL | let r = &mutvar;
14-
| ------- help: consider changing this to be a mutable reference: `&mut mutvar`
15-
LL |
1613
LL | *r = 0;
1714
| ^^^^^^ `r` is a `&` reference, so the data it refers to cannot be written
15+
|
16+
help: consider changing this to be a mutable reference
17+
|
18+
LL | let r = &mut mutvar;
19+
| ~~~~~~~~~~~
1820

1921
error[E0594]: cannot assign to `*x`, which is behind a `&` reference
2022
--> $DIR/issue-85765.rs:19:5

‎src/test/ui/borrowck/issue-93093.stderr‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
error[E0594]: cannot assign to `self.foo`, which is behind a `&` reference
22
--> $DIR/issue-93093.rs:8:9
33
|
4-
LL | async fn bar(&self) {
5-
| ----- help: consider changing this to be a mutable reference: `&mut self`
6-
LL |
74
LL | self.foo += 1;
85
| ^^^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be written
6+
|
7+
help: consider changing this to be a mutable reference
8+
|
9+
LL | async fn bar(&mut self) {
10+
| ~~~~~~~~~
911

1012
error: aborting due to previous error
1113

‎src/test/ui/borrowck/mutability-errors.stderr‎

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,46 @@
11
error[E0594]: cannot assign to `*x`, which is behind a `&` reference
22
--> $DIR/mutability-errors.rs:9:5
33
|
4-
LL | fn named_ref(x: &(i32,)) {
5-
| ------- help: consider changing this to be a mutable reference: `&mut (i32,)`
64
LL | *x = (1,);
75
| ^^^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be written
6+
|
7+
help: consider changing this to be a mutable reference
8+
|
9+
LL | fn named_ref(x: &mut (i32,)) {
10+
| ~~~~~~~~~~~
811

912
error[E0594]: cannot assign to `x.0`, which is behind a `&` reference
1013
--> $DIR/mutability-errors.rs:10:5
1114
|
12-
LL | fn named_ref(x: &(i32,)) {
13-
| ------- help: consider changing this to be a mutable reference: `&mut (i32,)`
14-
LL | *x = (1,);
1515
LL | x.0 = 1;
1616
| ^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be written
17+
|
18+
help: consider changing this to be a mutable reference
19+
|
20+
LL | fn named_ref(x: &mut (i32,)) {
21+
| ~~~~~~~~~~~
1722

1823
error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference
1924
--> $DIR/mutability-errors.rs:11:5
2025
|
21-
LL | fn named_ref(x: &(i32,)) {
22-
| ------- help: consider changing this to be a mutable reference: `&mut (i32,)`
23-
...
2426
LL | &mut *x;
2527
| ^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
28+
|
29+
help: consider changing this to be a mutable reference
30+
|
31+
LL | fn named_ref(x: &mut (i32,)) {
32+
| ~~~~~~~~~~~
2633

2734
error[E0596]: cannot borrow `x.0` as mutable, as it is behind a `&` reference
2835
--> $DIR/mutability-errors.rs:12:5
2936
|
30-
LL | fn named_ref(x: &(i32,)) {
31-
| ------- help: consider changing this to be a mutable reference: `&mut (i32,)`
32-
...
3337
LL | &mut x.0;
3438
| ^^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
39+
|
40+
help: consider changing this to be a mutable reference
41+
|
42+
LL | fn named_ref(x: &mut (i32,)) {
43+
| ~~~~~~~~~~~
3544

3645
error[E0594]: cannot assign to data in a `&` reference
3746
--> $DIR/mutability-errors.rs:16:5
@@ -60,37 +69,46 @@ LL | &mut f().0;
6069
error[E0594]: cannot assign to `*x`, which is behind a `*const` pointer
6170
--> $DIR/mutability-errors.rs:23:5
6271
|
63-
LL | unsafe fn named_ptr(x: *const (i32,)) {
64-
| ------------- help: consider changing this to be a mutable pointer: `*mut (i32,)`
6572
LL | *x = (1,);
6673
| ^^^^^^^^^ `x` is a `*const` pointer, so the data it refers to cannot be written
74+
|
75+
help: consider changing this to be a mutable pointer
76+
|
77+
LL | unsafe fn named_ptr(x: *mut (i32,)) {
78+
| ~~~~~~~~~~~
6779

6880
error[E0594]: cannot assign to `x.0`, which is behind a `*const` pointer
6981
--> $DIR/mutability-errors.rs:24:5
7082
|
71-
LL | unsafe fn named_ptr(x: *const (i32,)) {
72-
| ------------- help: consider changing this to be a mutable pointer: `*mut (i32,)`
73-
LL | *x = (1,);
7483
LL | (*x).0 = 1;
7584
| ^^^^^^^^^^ `x` is a `*const` pointer, so the data it refers to cannot be written
85+
|
86+
help: consider changing this to be a mutable pointer
87+
|
88+
LL | unsafe fn named_ptr(x: *mut (i32,)) {
89+
| ~~~~~~~~~~~
7690

7791
error[E0596]: cannot borrow `*x` as mutable, as it is behind a `*const` pointer
7892
--> $DIR/mutability-errors.rs:25:5
7993
|
80-
LL | unsafe fn named_ptr(x: *const (i32,)) {
81-
| ------------- help: consider changing this to be a mutable pointer: `*mut (i32,)`
82-
...
8394
LL | &mut *x;
8495
| ^^^^^^^ `x` is a `*const` pointer, so the data it refers to cannot be borrowed as mutable
96+
|
97+
help: consider changing this to be a mutable pointer
98+
|
99+
LL | unsafe fn named_ptr(x: *mut (i32,)) {
100+
| ~~~~~~~~~~~
85101

86102
error[E0596]: cannot borrow `x.0` as mutable, as it is behind a `*const` pointer
87103
--> $DIR/mutability-errors.rs:26:5
88104
|
89-
LL | unsafe fn named_ptr(x: *const (i32,)) {
90-
| ------------- help: consider changing this to be a mutable pointer: `*mut (i32,)`
91-
...
92105
LL | &mut (*x).0;
93106
| ^^^^^^^^^^^ `x` is a `*const` pointer, so the data it refers to cannot be borrowed as mutable
107+
|
108+
help: consider changing this to be a mutable pointer
109+
|
110+
LL | unsafe fn named_ptr(x: *mut (i32,)) {
111+
| ~~~~~~~~~~~
94112

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

‎src/test/ui/closures/2229_closure_analysis/diagnostics/mut_ref.stderr‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
error[E0596]: cannot borrow `**ref_mref_x` as mutable, as it is behind a `&` reference
22
--> $DIR/mut_ref.rs:12:13
33
|
4-
LL | let ref_mref_x = &mref_x;
5-
| ------- help: consider changing this to be a mutable reference: `&mut mref_x`
6-
LL |
74
LL | let c = || {
85
| ^^ `ref_mref_x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
96
LL |
107
LL | **ref_mref_x = y;
118
| ------------ mutable borrow occurs due to use of `**ref_mref_x` in closure
9+
|
10+
help: consider changing this to be a mutable reference
11+
|
12+
LL | let ref_mref_x = &mut mref_x;
13+
| ~~~~~~~~~~~
1214

1315
error[E0596]: cannot borrow `**mref_ref_x` as mutable, as it is behind a `&` reference
1416
--> $DIR/mut_ref.rs:26:13

‎src/test/ui/did_you_mean/issue-38147-1.stderr‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
error[E0596]: cannot borrow `*self.s` as mutable, as it is behind a `&` reference
22
--> $DIR/issue-38147-1.rs:17:9
33
|
4-
LL | fn f(&self) {
5-
| ----- help: consider changing this to be a mutable reference: `&mut self`
64
LL | self.s.push('x');
75
| ^^^^^^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be borrowed as mutable
6+
|
7+
help: consider changing this to be a mutable reference
8+
|
9+
LL | fn f(&mut self) {
10+
| ~~~~~~~~~
811

912
error: aborting due to previous error
1013

‎src/test/ui/did_you_mean/issue-38147-4.stderr‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
error[E0596]: cannot borrow `*f.s` as mutable, as it is behind a `&` reference
22
--> $DIR/issue-38147-4.rs:6:5
33
|
4-
LL | fn f(x: usize, f: &Foo) {
5-
| ---- help: consider changing this to be a mutable reference: `&mut Foo<'_>`
64
LL | f.s.push('x');
75
| ^^^^^^^^^^^^^ `f` is a `&` reference, so the data it refers to cannot be borrowed as mutable
6+
|
7+
help: consider changing this to be a mutable reference
8+
|
9+
LL | fn f(x: usize, f: &mut Foo<'_>) {
10+
| ~~~~~~~~~~~~
811

912
error: aborting due to previous error
1013

‎src/test/ui/did_you_mean/issue-39544.stderr‎

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,69 +9,90 @@ LL | let _ = &mut z.x;
99
error[E0596]: cannot borrow `self.x` as mutable, as it is behind a `&` reference
1010
--> $DIR/issue-39544.rs:16:17
1111
|
12-
LL | fn foo<'z>(&'z self) {
13-
| -------- help: consider changing this to be a mutable reference: `&'z mut self`
1412
LL | let _ = &mut self.x;
1513
| ^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be borrowed as mutable
14+
|
15+
help: consider changing this to be a mutable reference
16+
|
17+
LL | fn foo<'z>(&'z mut self) {
18+
| ~~~~~~~~~~~~
1619

1720
error[E0596]: cannot borrow `self.x` as mutable, as it is behind a `&` reference
1821
--> $DIR/issue-39544.rs:20:17
1922
|
20-
LL | fn foo1(&self, other: &Z) {
21-
| ----- help: consider changing this to be a mutable reference: `&mut self`
2223
LL | let _ = &mut self.x;
2324
| ^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be borrowed as mutable
25+
|
26+
help: consider changing this to be a mutable reference
27+
|
28+
LL | fn foo1(&mut self, other: &Z) {
29+
| ~~~~~~~~~
2430

2531
error[E0596]: cannot borrow `other.x` as mutable, as it is behind a `&` reference
2632
--> $DIR/issue-39544.rs:21:17
2733
|
28-
LL | fn foo1(&self, other: &Z) {
29-
| -- help: consider changing this to be a mutable reference: `&mut Z`
30-
LL | let _ = &mut self.x;
3134
LL | let _ = &mut other.x;
3235
| ^^^^^^^^^^^^ `other` is a `&` reference, so the data it refers to cannot be borrowed as mutable
36+
|
37+
help: consider changing this to be a mutable reference
38+
|
39+
LL | fn foo1(&self, other: &mut Z) {
40+
| ~~~~~~
3341

3442
error[E0596]: cannot borrow `self.x` as mutable, as it is behind a `&` reference
3543
--> $DIR/issue-39544.rs:25:17
3644
|
37-
LL | fn foo2<'a>(&'a self, other: &Z) {
38-
| -------- help: consider changing this to be a mutable reference: `&'a mut self`
3945
LL | let _ = &mut self.x;
4046
| ^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be borrowed as mutable
47+
|
48+
help: consider changing this to be a mutable reference
49+
|
50+
LL | fn foo2<'a>(&'a mut self, other: &Z) {
51+
| ~~~~~~~~~~~~
4152

4253
error[E0596]: cannot borrow `other.x` as mutable, as it is behind a `&` reference
4354
--> $DIR/issue-39544.rs:26:17
4455
|
45-
LL | fn foo2<'a>(&'a self, other: &Z) {
46-
| -- help: consider changing this to be a mutable reference: `&mut Z`
47-
LL | let _ = &mut self.x;
4856
LL | let _ = &mut other.x;
4957
| ^^^^^^^^^^^^ `other` is a `&` reference, so the data it refers to cannot be borrowed as mutable
58+
|
59+
help: consider changing this to be a mutable reference
60+
|
61+
LL | fn foo2<'a>(&'a self, other: &mut Z) {
62+
| ~~~~~~
5063

5164
error[E0596]: cannot borrow `self.x` as mutable, as it is behind a `&` reference
5265
--> $DIR/issue-39544.rs:30:17
5366
|
54-
LL | fn foo3<'a>(self: &'a Self, other: &Z) {
55-
| -------- help: consider changing this to be a mutable reference: `&'a mut Self`
5667
LL | let _ = &mut self.x;
5768
| ^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be borrowed as mutable
69+
|
70+
help: consider changing this to be a mutable reference
71+
|
72+
LL | fn foo3<'a>(self: &'a mut Self, other: &Z) {
73+
| ~~~~~~~~~~~~
5874

5975
error[E0596]: cannot borrow `other.x` as mutable, as it is behind a `&` reference
6076
--> $DIR/issue-39544.rs:31:17
6177
|
62-
LL | fn foo3<'a>(self: &'a Self, other: &Z) {
63-
| -- help: consider changing this to be a mutable reference: `&mut Z`
64-
LL | let _ = &mut self.x;
6578
LL | let _ = &mut other.x;
6679
| ^^^^^^^^^^^^ `other` is a `&` reference, so the data it refers to cannot be borrowed as mutable
80+
|
81+
help: consider changing this to be a mutable reference
82+
|
83+
LL | fn foo3<'a>(self: &'a Self, other: &mut Z) {
84+
| ~~~~~~
6785

6886
error[E0596]: cannot borrow `other.x` as mutable, as it is behind a `&` reference
6987
--> $DIR/issue-39544.rs:35:17
7088
|
71-
LL | fn foo4(other: &Z) {
72-
| -- help: consider changing this to be a mutable reference: `&mut Z`
7389
LL | let _ = &mut other.x;
7490
| ^^^^^^^^^^^^ `other` is a `&` reference, so the data it refers to cannot be borrowed as mutable
91+
|
92+
help: consider changing this to be a mutable reference
93+
|
94+
LL | fn foo4(other: &mut Z) {
95+
| ~~~~~~
7596

7697
error[E0596]: cannot borrow `z.x` as mutable, as `z` is not declared as mutable
7798
--> $DIR/issue-39544.rs:41:13
@@ -84,11 +105,13 @@ LL | let _ = &mut z.x;
84105
error[E0596]: cannot borrow `w.x` as mutable, as it is behind a `&` reference
85106
--> $DIR/issue-39544.rs:42:13
86107
|
87-
LL | pub fn with_arg(z: Z, w: &Z) {
88-
| -- help: consider changing this to be a mutable reference: `&mut Z`
89-
LL | let _ = &mut z.x;
90108
LL | let _ = &mut w.x;
91109
| ^^^^^^^^ `w` is a `&` reference, so the data it refers to cannot be borrowed as mutable
110+
|
111+
help: consider changing this to be a mutable reference
112+
|
113+
LL | pub fn with_arg(z: Z, w: &mut Z) {
114+
| ~~~~~~
92115

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

‎src/test/ui/did_you_mean/issue-40823.stderr‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
error[E0596]: cannot borrow `*buf` as mutable, as it is behind a `&` reference
22
--> $DIR/issue-40823.rs:3:5
33
|
4-
LL | let mut buf = &[1, 2, 3, 4];
5-
| ------------- help: consider changing this to be a mutable reference: `&mut [1, 2, 3, 4]`
64
LL | buf.iter_mut();
75
| ^^^^^^^^^^^^^^ `buf` is a `&` reference, so the data it refers to cannot be borrowed as mutable
6+
|
7+
help: consider changing this to be a mutable reference
8+
|
9+
LL | let mut buf = &mut [1, 2, 3, 4];
10+
| ~~~~~~~~~~~~~~~~~
811

912
error: aborting due to previous error
1013

‎src/test/ui/error-codes/E0389.stderr‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
error[E0594]: cannot assign to `fancy_ref.num`, which is behind a `&` reference
22
--> $DIR/E0389.rs:8:5
33
|
4-
LL | let fancy_ref = &(&mut fancy);
5-
| ------------- help: consider changing this to be a mutable reference: `&mut (&mut fancy)`
64
LL | fancy_ref.num = 6;
75
| ^^^^^^^^^^^^^^^^^ `fancy_ref` is a `&` reference, so the data it refers to cannot be written
6+
|
7+
help: consider changing this to be a mutable reference
8+
|
9+
LL | let fancy_ref = &mut (&mut fancy);
10+
| ~~~~~~~~~~~~~~~~~
811

912
error: aborting due to previous error
1013

‎src/test/ui/issues/issue-51515.stderr‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
error[E0594]: cannot assign to `*foo`, which is behind a `&` reference
22
--> $DIR/issue-51515.rs:5:5
33
|
4-
LL | let foo = &16;
5-
| --- help: consider changing this to be a mutable reference: `&mut 16`
6-
...
74
LL | *foo = 32;
85
| ^^^^^^^^^ `foo` is a `&` reference, so the data it refers to cannot be written
6+
|
7+
help: consider changing this to be a mutable reference
8+
|
9+
LL | let foo = &mut 16;
10+
| ~~~~~~~
911

1012
error[E0594]: cannot assign to `*bar`, which is behind a `&` reference
1113
--> $DIR/issue-51515.rs:8:5

‎src/test/ui/issues/issue-61623.stderr‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
error[E0596]: cannot borrow `*x.1` as mutable, as it is behind a `&` reference
22
--> $DIR/issue-61623.rs:6:19
33
|
4-
LL | fn f3<'a>(x: &'a ((), &'a mut ())) {
5-
| -------------------- help: consider changing this to be a mutable reference: `&'a mut ((), &'a mut ())`
64
LL | f2(|| x.0, f1(x.1))
75
| ^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
6+
|
7+
help: consider changing this to be a mutable reference
8+
|
9+
LL | fn f3<'a>(x: &'a mut ((), &'a mut ())) {
10+
| ~~~~~~~~~~~~~~~~~~~~~~~~
811

912
error: aborting due to previous error
1013

‎src/test/ui/mut/mutable-class-fields-2.stderr‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
error[E0594]: cannot assign to `self.how_hungry`, which is behind a `&` reference
22
--> $DIR/mutable-class-fields-2.rs:9:5
33
|
4-
LL | pub fn eat(&self) {
5-
| ----- help: consider changing this to be a mutable reference: `&mut self`
64
LL | self.how_hungry -= 5;
75
| ^^^^^^^^^^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be written
6+
|
7+
help: consider changing this to be a mutable reference
8+
|
9+
LL | pub fn eat(&mut self) {
10+
| ~~~~~~~~~
811

912
error: aborting due to previous error
1013

‎src/test/ui/nll/issue-47388.stderr‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
error[E0594]: cannot assign to `fancy_ref.num`, which is behind a `&` reference
22
--> $DIR/issue-47388.rs:8:5
33
|
4-
LL | let fancy_ref = &(&mut fancy);
5-
| ------------- help: consider changing this to be a mutable reference: `&mut (&mut fancy)`
64
LL | fancy_ref.num = 6;
75
| ^^^^^^^^^^^^^^^^^ `fancy_ref` is a `&` reference, so the data it refers to cannot be written
6+
|
7+
help: consider changing this to be a mutable reference
8+
|
9+
LL | let fancy_ref = &mut (&mut fancy);
10+
| ~~~~~~~~~~~~~~~~~
811

912
error: aborting due to previous error
1013

‎src/test/ui/nll/issue-51244.stderr‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
error[E0594]: cannot assign to `*my_ref`, which is behind a `&` reference
22
--> $DIR/issue-51244.rs:3:5
33
|
4-
LL | let ref my_ref @ _ = 0;
5-
| ---------- help: consider changing this to be a mutable reference: `ref mut my_ref`
64
LL | *my_ref = 0;
75
| ^^^^^^^^^^^ `my_ref` is a `&` reference, so the data it refers to cannot be written
6+
|
7+
help: consider changing this to be a mutable reference
8+
|
9+
LL | let ref mut my_ref @ _ = 0;
10+
| ~~~~~~~~~~~~~~
811

912
error: aborting due to previous error
1013

‎src/test/ui/nll/issue-57989.stderr‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
error[E0594]: cannot assign to `*x`, which is behind a `&` reference
22
--> $DIR/issue-57989.rs:5:5
33
|
4-
LL | fn f(x: &i32) {
5-
| ---- help: consider changing this to be a mutable reference: `&mut i32`
6-
LL | let g = &x;
74
LL | *x = 0;
85
| ^^^^^^ `x` is a `&` reference, so the data it refers to cannot be written
6+
|
7+
help: consider changing this to be a mutable reference
8+
|
9+
LL | fn f(x: &mut i32) {
10+
| ~~~~~~~~
911

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

‎src/test/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.stderr‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,24 @@ LL | *_x0 = U;
104104
error[E0594]: cannot assign to `*_x0`, which is behind a `&` reference
105105
--> $DIR/borrowck-move-ref-pattern.rs:26:5
106106
|
107-
LL | let (ref _x0, _x1, ref _x2, ..) = tup;
108-
| ------- help: consider changing this to be a mutable reference: `ref mut _x0`
109-
...
110107
LL | *_x0 = U;
111108
| ^^^^^^^^ `_x0` is a `&` reference, so the data it refers to cannot be written
109+
|
110+
help: consider changing this to be a mutable reference
111+
|
112+
LL | let (ref mut _x0, _x1, ref _x2, ..) = tup;
113+
| ~~~~~~~~~~~
112114

113115
error[E0594]: cannot assign to `*_x2`, which is behind a `&` reference
114116
--> $DIR/borrowck-move-ref-pattern.rs:27:5
115117
|
116-
LL | let (ref _x0, _x1, ref _x2, ..) = tup;
117-
| ------- help: consider changing this to be a mutable reference: `ref mut _x2`
118-
...
119118
LL | *_x2 = U;
120119
| ^^^^^^^^ `_x2` is a `&` reference, so the data it refers to cannot be written
120+
|
121+
help: consider changing this to be a mutable reference
122+
|
123+
LL | let (ref _x0, _x1, ref mut _x2, ..) = tup;
124+
| ~~~~~~~~~~~
121125

122126
error[E0382]: use of moved value: `tup.1`
123127
--> $DIR/borrowck-move-ref-pattern.rs:28:10

‎src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.stderr‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ LL | let __isize = &mut x.y;
99
error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference
1010
--> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:65:10
1111
|
12-
LL | fn deref_extend_mut_field1(x: &Own<Point>) -> &mut isize {
13-
| ----------- help: consider changing this to be a mutable reference: `&mut Own<Point>`
1412
LL | &mut x.y
1513
| ^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
14+
|
15+
help: consider changing this to be a mutable reference
16+
|
17+
LL | fn deref_extend_mut_field1(x: &mut Own<Point>) -> &mut isize {
18+
| ~~~~~~~~~~~~~~~
1619

1720
error[E0499]: cannot borrow `*x` as mutable more than once at a time
1821
--> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:78:19
@@ -35,10 +38,13 @@ LL | x.y = 3;
3538
error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference
3639
--> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:92:5
3740
|
38-
LL | fn assign_field2<'a>(x: &'a Own<Point>) {
39-
| -------------- help: consider changing this to be a mutable reference: `&'a mut Own<Point>`
4041
LL | x.y = 3;
4142
| ^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
43+
|
44+
help: consider changing this to be a mutable reference
45+
|
46+
LL | fn assign_field2<'a>(x: &'a mut Own<Point>) {
47+
| ~~~~~~~~~~~~~~~~~~
4248

4349
error[E0499]: cannot borrow `*x` as mutable more than once at a time
4450
--> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:101:5
@@ -61,10 +67,13 @@ LL | x.set(0, 0);
6167
error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference
6268
--> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:121:5
6369
|
64-
LL | fn deref_extend_mut_method1(x: &Own<Point>) -> &mut isize {
65-
| ----------- help: consider changing this to be a mutable reference: `&mut Own<Point>`
6670
LL | x.y_mut()
6771
| ^^^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
72+
|
73+
help: consider changing this to be a mutable reference
74+
|
75+
LL | fn deref_extend_mut_method1(x: &mut Own<Point>) -> &mut isize {
76+
| ~~~~~~~~~~~~~~~
6877

6978
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
7079
--> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:129:6
@@ -77,10 +86,13 @@ LL | *x.y_mut() = 3;
7786
error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference
7887
--> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:133:6
7988
|
80-
LL | fn assign_method2<'a>(x: &'a Own<Point>) {
81-
| -------------- help: consider changing this to be a mutable reference: `&'a mut Own<Point>`
8289
LL | *x.y_mut() = 3;
8390
| ^^^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
91+
|
92+
help: consider changing this to be a mutable reference
93+
|
94+
LL | fn assign_method2<'a>(x: &'a mut Own<Point>) {
95+
| ~~~~~~~~~~~~~~~~~~
8496

8597
error: aborting due to 10 previous errors
8698

‎src/test/ui/span/borrowck-borrow-overloaded-deref-mut.stderr‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ LL | let __isize = &mut *x;
99
error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference
1010
--> $DIR/borrowck-borrow-overloaded-deref-mut.rs:41:11
1111
|
12-
LL | fn deref_extend_mut1<'a>(x: &'a Own<isize>) -> &'a mut isize {
13-
| -------------- help: consider changing this to be a mutable reference: `&'a mut Own<isize>`
1412
LL | &mut **x
1513
| ^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
14+
|
15+
help: consider changing this to be a mutable reference
16+
|
17+
LL | fn deref_extend_mut1<'a>(x: &'a mut Own<isize>) -> &'a mut isize {
18+
| ~~~~~~~~~~~~~~~~~~
1619

1720
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
1821
--> $DIR/borrowck-borrow-overloaded-deref-mut.rs:49:6
@@ -25,10 +28,13 @@ LL | *x = 3;
2528
error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference
2629
--> $DIR/borrowck-borrow-overloaded-deref-mut.rs:53:6
2730
|
28-
LL | fn assign2<'a>(x: &'a Own<isize>) {
29-
| -------------- help: consider changing this to be a mutable reference: `&'a mut Own<isize>`
3031
LL | **x = 3;
3132
| ^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
33+
|
34+
help: consider changing this to be a mutable reference
35+
|
36+
LL | fn assign2<'a>(x: &'a mut Own<isize>) {
37+
| ~~~~~~~~~~~~~~~~~~
3238

3339
error: aborting due to 4 previous errors
3440

‎src/test/ui/span/borrowck-call-is-borrow-issue-12224.stderr‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,24 @@ LL | f((Box::new(|| {})))
1313
error[E0596]: cannot borrow `*f` as mutable, as it is behind a `&` reference
1414
--> $DIR/borrowck-call-is-borrow-issue-12224.rs:25:5
1515
|
16-
LL | fn test2<F>(f: &F) where F: FnMut() {
17-
| -- help: consider changing this to be a mutable reference: `&mut F`
1816
LL | (*f)();
1917
| ^^^^ `f` is a `&` reference, so the data it refers to cannot be borrowed as mutable
18+
|
19+
help: consider changing this to be a mutable reference
20+
|
21+
LL | fn test2<F>(f: &mut F) where F: FnMut() {
22+
| ~~~~~~
2023

2124
error[E0596]: cannot borrow `f.f` as mutable, as it is behind a `&` reference
2225
--> $DIR/borrowck-call-is-borrow-issue-12224.rs:34:5
2326
|
24-
LL | fn test4(f: &Test) {
25-
| ----- help: consider changing this to be a mutable reference: `&mut Test<'_>`
2627
LL | f.f.call_mut(())
2728
| ^^^^^^^^^^^^^^^^ `f` is a `&` reference, so the data it refers to cannot be borrowed as mutable
29+
|
30+
help: consider changing this to be a mutable reference
31+
|
32+
LL | fn test4(f: &mut Test<'_>) {
33+
| ~~~~~~~~~~~~~
2834

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

‎src/test/ui/span/borrowck-call-method-from-mut-aliasable.stderr‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference
22
--> $DIR/borrowck-call-method-from-mut-aliasable.rs:17:5
33
|
4-
LL | fn b(x: &Foo) {
5-
| ---- help: consider changing this to be a mutable reference: `&mut Foo`
6-
LL | x.f();
74
LL | x.h();
85
| ^^^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
6+
|
7+
help: consider changing this to be a mutable reference
8+
|
9+
LL | fn b(x: &mut Foo) {
10+
| ~~~~~~~~
911

1012
error: aborting due to previous error
1113

‎src/test/ui/span/borrowck-fn-in-const-b.stderr‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference
22
--> $DIR/borrowck-fn-in-const-b.rs:7:9
33
|
4-
LL | fn broken(x: &Vec<String>) {
5-
| ------------ help: consider changing this to be a mutable reference: `&mut Vec<String>`
64
LL | x.push(format!("this is broken"));
75
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
6+
|
7+
help: consider changing this to be a mutable reference
8+
|
9+
LL | fn broken(x: &mut Vec<String>) {
10+
| ~~~~~~~~~~~~~~~~
811

912
error: aborting due to previous error
1013

‎src/test/ui/span/borrowck-object-mutability.stderr‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference
22
--> $DIR/borrowck-object-mutability.rs:8:5
33
|
4-
LL | fn borrowed_receiver(x: &dyn Foo) {
5-
| -------- help: consider changing this to be a mutable reference: `&mut dyn Foo`
6-
LL | x.borrowed();
74
LL | x.borrowed_mut();
85
| ^^^^^^^^^^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
6+
|
7+
help: consider changing this to be a mutable reference
8+
|
9+
LL | fn borrowed_receiver(x: &mut dyn Foo) {
10+
| ~~~~~~~~~~~~
911

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

‎src/test/ui/span/mut-arg-hint.stderr‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,35 @@
11
error[E0596]: cannot borrow `*a` as mutable, as it is behind a `&` reference
22
--> $DIR/mut-arg-hint.rs:3:9
33
|
4-
LL | fn foo(mut a: &String) {
5-
| ------- help: consider changing this to be a mutable reference: `&mut String`
64
LL | a.push_str("bar");
75
| ^^^^^^^^^^^^^^^^^ `a` is a `&` reference, so the data it refers to cannot be borrowed as mutable
6+
|
7+
help: consider changing this to be a mutable reference
8+
|
9+
LL | fn foo(mut a: &mut String) {
10+
| ~~~~~~~~~~~
811

912
error[E0596]: cannot borrow `*a` as mutable, as it is behind a `&` reference
1013
--> $DIR/mut-arg-hint.rs:8:5
1114
|
12-
LL | pub fn foo<'a>(mut a: &'a String) {
13-
| ---------- help: consider changing this to be a mutable reference: `&'a mut String`
1415
LL | a.push_str("foo");
1516
| ^^^^^^^^^^^^^^^^^ `a` is a `&` reference, so the data it refers to cannot be borrowed as mutable
17+
|
18+
help: consider changing this to be a mutable reference
19+
|
20+
LL | pub fn foo<'a>(mut a: &'a mut String) {
21+
| ~~~~~~~~~~~~~~
1622

1723
error[E0596]: cannot borrow `*a` as mutable, as it is behind a `&` reference
1824
--> $DIR/mut-arg-hint.rs:15:9
1925
|
20-
LL | pub fn foo(mut a: &String) {
21-
| ------- help: consider changing this to be a mutable reference: `&mut String`
2226
LL | a.push_str("foo");
2327
| ^^^^^^^^^^^^^^^^^ `a` is a `&` reference, so the data it refers to cannot be borrowed as mutable
28+
|
29+
help: consider changing this to be a mutable reference
30+
|
31+
LL | pub fn foo(mut a: &mut String) {
32+
| ~~~~~~~~~~~
2433

2534
error: aborting due to 3 previous errors
2635

‎src/test/ui/suggestions/issue-68049-2.stderr‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
error[E0594]: cannot assign to `*input`, which is behind a `&` reference
22
--> $DIR/issue-68049-2.rs:9:7
33
|
4-
LL | fn example(&self, input: &i32); // should suggest here
5-
| ---- help: consider changing that to be a mutable reference: `&mut i32`
6-
...
74
LL | *input = self.0;
85
| ^^^^^^^^^^^^^^^ `input` is a `&` reference, so the data it refers to cannot be written
6+
|
7+
help: consider changing that to be a mutable reference
8+
|
9+
LL | fn example(&self, input: &mut i32); // should suggest here
10+
| ~~~~~~~~
911

1012
error[E0594]: cannot assign to `self.0`, which is behind a `&` reference
1113
--> $DIR/issue-68049-2.rs:17:5
1214
|
13-
LL | fn example(&self, input: &i32); // should suggest here
14-
| ----- help: consider changing that to be a mutable reference: `&mut self`
15-
...
1615
LL | self.0 += *input;
1716
| ^^^^^^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be written
17+
|
18+
help: consider changing that to be a mutable reference
19+
|
20+
LL | fn example(&mut self, input: &i32); // should suggest here
21+
| ~~~~~~~~~
1822

1923
error: aborting due to 2 previous errors
2024

‎src/test/ui/suggestions/suggest-ref-mut.stderr‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,46 @@
11
error[E0594]: cannot assign to `self.0`, which is behind a `&` reference
22
--> $DIR/suggest-ref-mut.rs:7:9
33
|
4-
LL | fn zap(&self) {
5-
| ----- help: consider changing this to be a mutable reference: `&mut self`
6-
...
74
LL | self.0 = 32;
85
| ^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be written
6+
|
7+
help: consider changing this to be a mutable reference
8+
|
9+
LL | fn zap(&mut self) {
10+
| ~~~~~~~~~
911

1012
error[E0594]: cannot assign to `*foo`, which is behind a `&` reference
1113
--> $DIR/suggest-ref-mut.rs:16:5
1214
|
13-
LL | let ref foo = 16;
14-
| ------- help: consider changing this to be a mutable reference: `ref mut foo`
15-
...
1615
LL | *foo = 32;
1716
| ^^^^^^^^^ `foo` is a `&` reference, so the data it refers to cannot be written
17+
|
18+
help: consider changing this to be a mutable reference
19+
|
20+
LL | let ref mut foo = 16;
21+
| ~~~~~~~~~~~
1822

1923
error[E0594]: cannot assign to `*bar`, which is behind a `&` reference
2024
--> $DIR/suggest-ref-mut.rs:21:9
2125
|
22-
LL | if let Some(ref bar) = Some(16) {
23-
| ------- help: consider changing this to be a mutable reference: `ref mut bar`
24-
...
2526
LL | *bar = 32;
2627
| ^^^^^^^^^ `bar` is a `&` reference, so the data it refers to cannot be written
28+
|
29+
help: consider changing this to be a mutable reference
30+
|
31+
LL | if let Some(ref mut bar) = Some(16) {
32+
| ~~~~~~~~~~~
2733

2834
error[E0594]: cannot assign to `*quo`, which is behind a `&` reference
2935
--> $DIR/suggest-ref-mut.rs:25:22
3036
|
3137
LL | ref quo => { *quo = 32; },
32-
| ------- ^^^^^^^^^ `quo` is a `&` reference, so the data it refers to cannot be written
33-
| |
34-
| help: consider changing this to be a mutable reference: `ref mut quo`
38+
| ^^^^^^^^^ `quo` is a `&` reference, so the data it refers to cannot be written
39+
|
40+
help: consider changing this to be a mutable reference
41+
|
42+
LL | ref mut quo => { *quo = 32; },
43+
| ~~~~~~~~~~~
3544

3645
error: aborting due to 4 previous errors
3746

‎src/test/ui/trivial-bounds/trivial-bounds-inconsistent-copy-reborrow.stderr‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
error[E0596]: cannot borrow `**t` as mutable, as it is behind a `&` reference
22
--> $DIR/trivial-bounds-inconsistent-copy-reborrow.rs:6:5
33
|
4-
LL | fn reborrow_mut<'a>(t: &'a &'a mut i32) -> &'a mut i32 where &'a mut i32: Copy {
5-
| --------------- help: consider changing this to be a mutable reference: `&'a mut &'a mut i32`
64
LL | *t
75
| ^^ `t` is a `&` reference, so the data it refers to cannot be borrowed as mutable
6+
|
7+
help: consider changing this to be a mutable reference
8+
|
9+
LL | fn reborrow_mut<'a>(t: &'a mut &'a mut i32) -> &'a mut i32 where &'a mut i32: Copy {
10+
| ~~~~~~~~~~~~~~~~~~~
811

912
error[E0596]: cannot borrow `**t` as mutable, as it is behind a `&` reference
1013
--> $DIR/trivial-bounds-inconsistent-copy-reborrow.rs:10:6
1114
|
12-
LL | fn copy_reborrow_mut<'a>(t: &'a &'a mut i32) -> &'a mut i32 where &'a mut i32: Copy {
13-
| --------------- help: consider changing this to be a mutable reference: `&'a mut &'a mut i32`
1415
LL | {*t}
1516
| ^^ `t` is a `&` reference, so the data it refers to cannot be borrowed as mutable
17+
|
18+
help: consider changing this to be a mutable reference
19+
|
20+
LL | fn copy_reborrow_mut<'a>(t: &'a mut &'a mut i32) -> &'a mut i32 where &'a mut i32: Copy {
21+
| ~~~~~~~~~~~~~~~~~~~
1622

1723
error: aborting due to 2 previous errors
1824

0 commit comments

Comments
 (0)
Please sign in to comment.