Do not suggest borrowing binding in pattern in let else

Fix #104838.
This commit is contained in:
Esteban Küber 2022-12-08 09:31:57 -08:00
parent e46416eed6
commit 4f7c257fd8
4 changed files with 15 additions and 14 deletions

View File

@ -231,7 +231,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
remainder_span, remainder_span,
pattern, pattern,
None, None,
Some((None, initializer_span)), Some((Some(&destination), initializer_span)),
); );
this.visit_primary_bindings( this.visit_primary_bindings(
pattern, pattern,

View File

@ -32,15 +32,19 @@ LL + if let E::Bar(identifier) = &s.x {
| |
error[E0507]: cannot move out of a shared reference error[E0507]: cannot move out of a shared reference
--> $DIR/by-move-pattern-binding.rs:25:17 --> $DIR/by-move-pattern-binding.rs:25:31
| |
LL | let &E::Bar(identifier) = &s.x else { LL | let &E::Bar(identifier) = &s.x else {
| ^^^^^^^^^^ move occurs because value has type `String`, which does not implement the `Copy` trait | ---------- ^^^^
| |
| data moved here
| move occurs because `identifier` has type `String`, which does not implement the `Copy` trait
| |
help: consider borrowing here help: consider removing the borrow
|
LL - let &E::Bar(identifier) = &s.x else {
LL + let E::Bar(identifier) = &s.x else {
| |
LL | let &E::Bar(&identifier) = &s.x else {
| +
error: aborting due to 3 previous errors error: aborting due to 3 previous errors

View File

@ -319,7 +319,6 @@ struct Testing {
fn testing(a: &Testing) { fn testing(a: &Testing) {
let Some(_s) = a.a else { let Some(_s) = a.a else {
//~^ ERROR cannot move //~^ ERROR cannot move
//~| HELP consider borrowing
return; return;
}; };
} }

View File

@ -902,15 +902,13 @@ LL | fn f4((&mut X(_t),): (&mut X,)) { }
| move occurs because `_t` has type `Y`, which does not implement the `Copy` trait | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait
error[E0507]: cannot move out of `a.a` as enum variant `Some` which is behind a shared reference error[E0507]: cannot move out of `a.a` as enum variant `Some` which is behind a shared reference
--> $DIR/simple.rs:320:14 --> $DIR/simple.rs:320:20
| |
LL | let Some(_s) = a.a else { LL | let Some(_s) = a.a else {
| ^^ move occurs because `a.a.0` has type `String`, which does not implement the `Copy` trait | -- ^^^
| | |
help: consider borrowing here | data moved here
| | move occurs because `_s` has type `String`, which does not implement the `Copy` trait
LL | let Some(&_s) = a.a else {
| +
error: aborting due to 61 previous errors error: aborting due to 61 previous errors