move_from,
..
} => {
- let mut suggest_change_head_expr = false;
- match move_from {
+ let try_remove_deref = match move_from {
Place::Projection(box PlaceProjection {
elem: ProjectionElem::Deref,
..
- }) => {
- // This is false for (e.g.) index expressions `a[b]`,
- // which roughly desugar to `*Index::index(&a, b)` or
- // `*IndexMut::index_mut(&mut a, b)`.
- if snippet.starts_with('*') {
- err.span_suggestion(
- span,
- "consider removing this dereference operator",
- (&snippet[1..]).to_owned(),
- );
- suggest_change_head_expr = true;
- }
- }
- _ => {
- err.span_suggestion(
- span,
- "consider using a reference instead",
- format!("&{}", snippet),
- );
- suggest_change_head_expr = true;
- }
+ }) => true,
+ _ => false,
+ };
+ if try_remove_deref && snippet.starts_with('*') {
+ // This is false for (e.g.) index expressions `a[b]`,
+ // which roughly desugar to `*Index::index(&a, b)` or
+ // `*IndexMut::index_mut(&mut a, b)`.
+ err.span_suggestion(
+ span,
+ "consider removing this dereference operator",
+ snippet[1..].to_owned(),
+ );
+ } else {
+ err.span_suggestion(
+ span,
+ "consider using a reference instead",
+ format!("&{}", snippet),
+ );
}
+
binds_to.sort();
binds_to.dedup();
- if !suggest_change_head_expr {
- self.add_move_error_suggestions(err, &binds_to);
- }
self.add_move_error_labels(err, &binds_to);
}
GroupedMoveError::MovesFromValue { mut binds_to, .. } => {
--> $DIR/dont-suggest-ref.rs:111:17
|
LL | let X(_t) = vs_[0];
- | -- ^^^^^^ cannot move out of borrowed content
- | |
+ | -- ^^^^^^
+ | | |
+ | | cannot move out of borrowed content
+ | | help: consider using a reference instead: `&vs_[0]`
| data moved here
|
note: move occurs because _t has type `Y`, which does not implement the `Copy` trait
--> $DIR/dont-suggest-ref.rs:115:30
|
LL | if let Either::One(_t) = vr[0] { }
- | -- ^^^^^ cannot move out of borrowed content
- | |
+ | -- ^^^^^
+ | | |
+ | | cannot move out of borrowed content
+ | | help: consider using a reference instead: `&vr[0]`
| data moved here
|
note: move occurs because _t has type `X`, which does not implement the `Copy` trait
--> $DIR/dont-suggest-ref.rs:119:33
|
LL | while let Either::One(_t) = vr[0] { }
- | -- ^^^^^ cannot move out of borrowed content
- | |
+ | -- ^^^^^
+ | | |
+ | | cannot move out of borrowed content
+ | | help: consider using a reference instead: `&vr[0]`
| data moved here
|
note: move occurs because _t has type `X`, which does not implement the `Copy` trait
--> $DIR/dont-suggest-ref.rs:123:11
|
LL | match vr[0] {
- | ^^^^^ cannot move out of borrowed content
+ | ^^^^^
+ | |
+ | cannot move out of borrowed content
+ | help: consider using a reference instead: `&vr[0]`
...
LL | Either::One(_t)
| -- data moved here
--> $DIR/dont-suggest-ref.rs:130:11
|
LL | match vr[0] {
- | ^^^^^ cannot move out of borrowed content
+ | ^^^^^
+ | |
+ | cannot move out of borrowed content
+ | help: consider using a reference instead: `&vr[0]`
...
LL | Either::One(_t) => (),
| -- data moved here
--> $DIR/dont-suggest-ref.rs:139:17
|
LL | let X(_t) = vsm[0];
- | -- ^^^^^^ cannot move out of borrowed content
- | |
+ | -- ^^^^^^
+ | | |
+ | | cannot move out of borrowed content
+ | | help: consider using a reference instead: `&vsm[0]`
| data moved here
|
note: move occurs because _t has type `Y`, which does not implement the `Copy` trait
--> $DIR/dont-suggest-ref.rs:143:30
|
LL | if let Either::One(_t) = vrm[0] { }
- | -- ^^^^^^ cannot move out of borrowed content
- | |
+ | -- ^^^^^^
+ | | |
+ | | cannot move out of borrowed content
+ | | help: consider using a reference instead: `&vrm[0]`
| data moved here
|
note: move occurs because _t has type `X`, which does not implement the `Copy` trait
--> $DIR/dont-suggest-ref.rs:147:33
|
LL | while let Either::One(_t) = vrm[0] { }
- | -- ^^^^^^ cannot move out of borrowed content
- | |
+ | -- ^^^^^^
+ | | |
+ | | cannot move out of borrowed content
+ | | help: consider using a reference instead: `&vrm[0]`
| data moved here
|
note: move occurs because _t has type `X`, which does not implement the `Copy` trait
--> $DIR/dont-suggest-ref.rs:151:11
|
LL | match vrm[0] {
- | ^^^^^^ cannot move out of borrowed content
+ | ^^^^^^
+ | |
+ | cannot move out of borrowed content
+ | help: consider using a reference instead: `&vrm[0]`
...
LL | Either::One(_t)
| -- data moved here
--> $DIR/dont-suggest-ref.rs:158:11
|
LL | match vrm[0] {
- | ^^^^^^ cannot move out of borrowed content
+ | ^^^^^^
+ | |
+ | cannot move out of borrowed content
+ | help: consider using a reference instead: `&vrm[0]`
...
LL | Either::One(_t) => (),
| -- data moved here
--> $DIR/dont-suggest-ref.rs:166:11
|
LL | match vrm[0] {
- | ^^^^^^ cannot move out of borrowed content
+ | ^^^^^^
+ | |
+ | cannot move out of borrowed content
+ | help: consider using a reference instead: `&vrm[0]`
...
LL | Either::One(_t) => (),
| -- data moved here