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

Lines changed: 6 additions & 26 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 5 additions & 5 deletions
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
| -

0 commit comments

Comments
 (0)