Skip to content

Commit d3fa451

Browse files
authored
Rollup merge of rust-lang#61332 - kennethbgoodin:borrowck-remove-asterisk-suggestion, r=matthewjasper
Remove asterisk suggestion for move errors in borrowck As per the decision in rust-lang#54985 completely removes the suggestion to add an asterisk when checking move errors. I believe I've preserved the correct behavior with the "consider borrowing here" branch of the original match arm, but I'm not positive on that. This is my first PR to rustc so any feedback is greatly appreciated. Thanks.
2 parents ca1bcfd + de677b9 commit d3fa451

13 files changed

+53
-73
lines changed

src/librustc_mir/borrow_check/move_errors.rs

+6-26
Original file line numberDiff line numberDiff line change
@@ -503,32 +503,12 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
503503
move_from,
504504
..
505505
} => {
506-
let try_remove_deref = match move_from {
507-
Place::Projection(box Projection {
508-
elem: ProjectionElem::Deref,
509-
..
510-
}) => true,
511-
_ => false,
512-
};
513-
if try_remove_deref && snippet.starts_with('*') {
514-
// The snippet doesn't start with `*` in (e.g.) index
515-
// expressions `a[b]`, which roughly desugar to
516-
// `*Index::index(&a, b)` or
517-
// `*IndexMut::index_mut(&mut a, b)`.
518-
err.span_suggestion(
519-
span,
520-
"consider removing the `*`",
521-
snippet[1..].to_owned(),
522-
Applicability::Unspecified,
523-
);
524-
} else {
525-
err.span_suggestion(
526-
span,
527-
"consider borrowing here",
528-
format!("&{}", snippet),
529-
Applicability::Unspecified,
530-
);
531-
}
506+
err.span_suggestion(
507+
span,
508+
"consider borrowing here",
509+
format!("&{}", snippet),
510+
Applicability::Unspecified,
511+
);
532512

533513
if binds_to.is_empty() {
534514
let place_ty = move_from.ty(self.mir, self.infcx.tcx).ty;

src/test/ui/access-mode-in-closures.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | match *s { S(v) => v }
66
| | |
77
| | data moved here
88
| | move occurs because `v` has type `std::vec::Vec<isize>`, which does not implement the `Copy` trait
9-
| help: consider removing the `*`: `s`
9+
| help: consider borrowing here: `&*s`
1010

1111
error: aborting due to previous error
1212

src/test/ui/borrowck/borrowck-issue-2657-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let _b = *y;
55
| ^^
66
| |
77
| move occurs because `*y` has type `std::boxed::Box<i32>`, which does not implement the `Copy` trait
8-
| help: consider removing the `*`: `y`
8+
| help: consider borrowing here: `&*y`
99

1010
error: aborting due to previous error
1111

src/test/ui/borrowck/borrowck-move-error-with-note.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0507]: cannot move out of `f.0` which is behind a shared reference
22
--> $DIR/borrowck-move-error-with-note.rs:11:11
33
|
44
LL | match *f {
5-
| ^^ help: consider removing the `*`: `f`
5+
| ^^ help: consider borrowing here: `&*f`
66
LL | Foo::Foo1(num1,
77
| ---- data moved here
88
LL | num2) => (),

src/test/ui/borrowck/borrowck-move-from-unsafe-ptr.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let y = *x;
55
| ^^
66
| |
77
| move occurs because `*x` has type `std::boxed::Box<isize>`, which does not implement the `Copy` trait
8-
| help: consider removing the `*`: `x`
8+
| help: consider borrowing here: `&*x`
99

1010
error: aborting due to previous error
1111

src/test/ui/borrowck/borrowck-move-out-of-overloaded-deref.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let _x = *Rc::new("hi".to_string());
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
66
| |
77
| move occurs because value has type `std::string::String`, which does not implement the `Copy` trait
8-
| help: consider removing the `*`: `Rc::new("hi".to_string())`
8+
| help: consider borrowing here: `&*Rc::new("hi".to_string())`
99

1010
error: aborting due to previous error
1111

src/test/ui/borrowck/issue-54597-reject-move-out-of-borrow-via-pat.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | *array
55
| ^^^^^^
66
| |
77
| move occurs because `*array` has type `std::vec::Vec<Value>`, which does not implement the `Copy` trait
8-
| help: consider removing the `*`: `array`
8+
| help: consider borrowing here: `&*array`
99

1010
error: aborting due to previous error
1111

src/test/ui/issues/issue-20801.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let a = unsafe { *mut_ref() };
55
| ^^^^^^^^^^
66
| |
77
| move occurs because value has type `T`, which does not implement the `Copy` trait
8-
| help: consider removing the `*`: `mut_ref()`
8+
| help: consider borrowing here: `&*mut_ref()`
99

1010
error[E0507]: cannot move out of a shared reference
1111
--> $DIR/issue-20801.rs:29:22
@@ -14,7 +14,7 @@ LL | let b = unsafe { *imm_ref() };
1414
| ^^^^^^^^^^
1515
| |
1616
| move occurs because value has type `T`, which does not implement the `Copy` trait
17-
| help: consider removing the `*`: `imm_ref()`
17+
| help: consider borrowing here: `&*imm_ref()`
1818

1919
error[E0507]: cannot move out of a raw pointer
2020
--> $DIR/issue-20801.rs:32:22
@@ -23,7 +23,7 @@ LL | let c = unsafe { *mut_ptr() };
2323
| ^^^^^^^^^^
2424
| |
2525
| move occurs because value has type `T`, which does not implement the `Copy` trait
26-
| help: consider removing the `*`: `mut_ptr()`
26+
| help: consider borrowing here: `&*mut_ptr()`
2727

2828
error[E0507]: cannot move out of a raw pointer
2929
--> $DIR/issue-20801.rs:35:22
@@ -32,7 +32,7 @@ LL | let d = unsafe { *const_ptr() };
3232
| ^^^^^^^^^^^^
3333
| |
3434
| move occurs because value has type `T`, which does not implement the `Copy` trait
35-
| help: consider removing the `*`: `const_ptr()`
35+
| help: consider borrowing here: `&*const_ptr()`
3636

3737
error: aborting due to 4 previous errors
3838

src/test/ui/nll/cannot-move-block-spans.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let x = { *r };
55
| ^^
66
| |
77
| move occurs because `*r` has type `std::string::String`, which does not implement the `Copy` trait
8-
| help: consider removing the `*`: `r`
8+
| help: consider borrowing here: `&*r`
99

1010
error[E0507]: cannot move out of `*r` which is behind a shared reference
1111
--> $DIR/cannot-move-block-spans.rs:6:22
@@ -14,7 +14,7 @@ LL | let y = unsafe { *r };
1414
| ^^
1515
| |
1616
| move occurs because `*r` has type `std::string::String`, which does not implement the `Copy` trait
17-
| help: consider removing the `*`: `r`
17+
| help: consider borrowing here: `&*r`
1818

1919
error[E0507]: cannot move out of `*r` which is behind a shared reference
2020
--> $DIR/cannot-move-block-spans.rs:7:26
@@ -23,7 +23,7 @@ LL | let z = loop { break *r; };
2323
| ^^
2424
| |
2525
| move occurs because `*r` has type `std::string::String`, which does not implement the `Copy` trait
26-
| help: consider removing the `*`: `r`
26+
| help: consider borrowing here: `&*r`
2727

2828
error[E0508]: cannot move out of type `[std::string::String; 2]`, a non-copy array
2929
--> $DIR/cannot-move-block-spans.rs:11:15
@@ -62,7 +62,7 @@ LL | let x = { let mut u = 0; u += 1; *r };
6262
| ^^
6363
| |
6464
| move occurs because `*r` has type `std::string::String`, which does not implement the `Copy` trait
65-
| help: consider removing the `*`: `r`
65+
| help: consider borrowing here: `&*r`
6666

6767
error[E0507]: cannot move out of `*r` which is behind a shared reference
6868
--> $DIR/cannot-move-block-spans.rs:18:45
@@ -71,7 +71,7 @@ LL | let y = unsafe { let mut u = 0; u += 1; *r };
7171
| ^^
7272
| |
7373
| move occurs because `*r` has type `std::string::String`, which does not implement the `Copy` trait
74-
| help: consider removing the `*`: `r`
74+
| help: consider borrowing here: `&*r`
7575

7676
error[E0507]: cannot move out of `*r` which is behind a shared reference
7777
--> $DIR/cannot-move-block-spans.rs:19:49
@@ -80,7 +80,7 @@ LL | let z = loop { let mut u = 0; u += 1; break *r; u += 2; };
8080
| ^^
8181
| |
8282
| move occurs because `*r` has type `std::string::String`, which does not implement the `Copy` trait
83-
| help: consider removing the `*`: `r`
83+
| help: consider borrowing here: `&*r`
8484

8585
error: aborting due to 9 previous errors
8686

src/test/ui/nll/move-errors.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let b = *a;
55
| ^^
66
| |
77
| move occurs because `*a` has type `A`, which does not implement the `Copy` trait
8-
| help: consider removing the `*`: `a`
8+
| help: consider borrowing here: `&*a`
99

1010
error[E0508]: cannot move out of type `[A; 1]`, a non-copy array
1111
--> $DIR/move-errors.rs:12:13
@@ -24,7 +24,7 @@ LL | let s = **r;
2424
| ^^^
2525
| |
2626
| move occurs because `**r` has type `A`, which does not implement the `Copy` trait
27-
| help: consider removing the `*`: `*r`
27+
| help: consider borrowing here: `&**r`
2828

2929
error[E0507]: cannot move out of an `Rc`
3030
--> $DIR/move-errors.rs:27:13
@@ -33,7 +33,7 @@ LL | let s = *r;
3333
| ^^
3434
| |
3535
| move occurs because value has type `A`, which does not implement the `Copy` trait
36-
| help: consider removing the `*`: `r`
36+
| help: consider borrowing here: `&*r`
3737

3838
error[E0508]: cannot move out of type `[A; 1]`, a non-copy array
3939
--> $DIR/move-errors.rs:32:13
@@ -49,7 +49,7 @@ error[E0507]: cannot move out of `a.0` which is behind a shared reference
4949
--> $DIR/move-errors.rs:38:16
5050
|
5151
LL | let A(s) = *a;
52-
| - ^^ help: consider removing the `*`: `a`
52+
| - ^^ help: consider borrowing here: `&*a`
5353
| |
5454
| data moved here
5555
| move occurs because `s` has type `std::string::String`, which does not implement the `Copy` trait
@@ -148,7 +148,7 @@ error[E0507]: cannot move out of `x.0` which is behind a shared reference
148148
--> $DIR/move-errors.rs:110:11
149149
|
150150
LL | match *x {
151-
| ^^ help: consider removing the `*`: `x`
151+
| ^^ help: consider borrowing here: `&*x`
152152
LL |
153153
LL | Ok(s) | Err(s) => (),
154154
| -

src/test/ui/std-uncopyable-atomics.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let x = *&x;
55
| ^^^
66
| |
77
| move occurs because value has type `std::sync::atomic::AtomicBool`, which does not implement the `Copy` trait
8-
| help: consider removing the `*`: `&x`
8+
| help: consider borrowing here: `&*&x`
99

1010
error[E0507]: cannot move out of a shared reference
1111
--> $DIR/std-uncopyable-atomics.rs:11:13
@@ -14,7 +14,7 @@ LL | let x = *&x;
1414
| ^^^
1515
| |
1616
| move occurs because value has type `std::sync::atomic::AtomicIsize`, which does not implement the `Copy` trait
17-
| help: consider removing the `*`: `&x`
17+
| help: consider borrowing here: `&*&x`
1818

1919
error[E0507]: cannot move out of a shared reference
2020
--> $DIR/std-uncopyable-atomics.rs:13:13
@@ -23,7 +23,7 @@ LL | let x = *&x;
2323
| ^^^
2424
| |
2525
| move occurs because value has type `std::sync::atomic::AtomicUsize`, which does not implement the `Copy` trait
26-
| help: consider removing the `*`: `&x`
26+
| help: consider borrowing here: `&*&x`
2727

2828
error[E0507]: cannot move out of a shared reference
2929
--> $DIR/std-uncopyable-atomics.rs:15:13
@@ -32,7 +32,7 @@ LL | let x = *&x;
3232
| ^^^
3333
| |
3434
| move occurs because value has type `std::sync::atomic::AtomicPtr<usize>`, which does not implement the `Copy` trait
35-
| help: consider removing the `*`: `&x`
35+
| help: consider borrowing here: `&*&x`
3636

3737
error: aborting due to 4 previous errors
3838

src/test/ui/suggestions/dont-suggest-ref/simple.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,26 @@ pub fn main() {
3737

3838
let X(_t) = *s;
3939
//~^ ERROR cannot move
40-
//~| HELP consider removing the `*`
40+
//~| HELP consider borrowing here
4141
//~| SUGGESTION s
4242
if let Either::One(_t) = *r { }
4343
//~^ ERROR cannot move
44-
//~| HELP consider removing the `*`
44+
//~| HELP consider borrowing here
4545
//~| SUGGESTION r
4646
while let Either::One(_t) = *r { }
4747
//~^ ERROR cannot move
48-
//~| HELP consider removing the `*`
48+
//~| HELP consider borrowing here
4949
//~| SUGGESTION r
5050
match *r {
5151
//~^ ERROR cannot move
52-
//~| HELP consider removing the `*`
52+
//~| HELP consider borrowing here
5353
//~| SUGGESTION r
5454
Either::One(_t)
5555
| Either::Two(_t) => (),
5656
}
5757
match *r {
5858
//~^ ERROR cannot move
59-
//~| HELP consider removing the `*`
59+
//~| HELP consider borrowing here
6060
//~| SUGGESTION r
6161
Either::One(_t) => (),
6262
Either::Two(ref _t) => (),
@@ -65,34 +65,34 @@ pub fn main() {
6565

6666
let X(_t) = *sm;
6767
//~^ ERROR cannot move
68-
//~| HELP consider removing the `*`
68+
//~| HELP consider borrowing here
6969
//~| SUGGESTION sm
7070
if let Either::One(_t) = *rm { }
7171
//~^ ERROR cannot move
72-
//~| HELP consider removing the `*`
72+
//~| HELP consider borrowing here
7373
//~| SUGGESTION rm
7474
while let Either::One(_t) = *rm { }
7575
//~^ ERROR cannot move
76-
//~| HELP consider removing the `*`
76+
//~| HELP consider borrowing here
7777
//~| SUGGESTION rm
7878
match *rm {
7979
//~^ ERROR cannot move
80-
//~| HELP consider removing the `*`
80+
//~| HELP consider borrowing here
8181
//~| SUGGESTION rm
8282
Either::One(_t)
8383
| Either::Two(_t) => (),
8484
}
8585
match *rm {
8686
//~^ ERROR cannot move
87-
//~| HELP consider removing the `*`
87+
//~| HELP consider borrowing here
8888
//~| SUGGESTION rm
8989
Either::One(_t) => (),
9090
Either::Two(ref _t) => (),
9191
// FIXME: should suggest removing `ref` too
9292
}
9393
match *rm {
9494
//~^ ERROR cannot move
95-
//~| HELP consider removing the `*`
95+
//~| HELP consider borrowing here
9696
//~| SUGGESTION rm
9797
Either::One(_t) => (),
9898
Either::Two(ref mut _t) => (),

0 commit comments

Comments
 (0)