about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2022-12-08 09:31:57 -0800
committerEsteban Küber <esteban@kuber.com.ar>2022-12-13 10:06:13 -0800
commit4f7c257fd8421392cbe4b1502985d9829cbed37e (patch)
treebfa8ab2bada17b54e13e809894427f92b6b5f3e3
parente46416eed689655b9d395cb2fb7089bb7ec8aa9c (diff)
Do not suggest borrowing binding in pattern in let else
Fix #104838.
-rw-r--r--compiler/rustc_mir_build/src/build/block.rs2
-rw-r--r--src/test/ui/by-move-pattern-binding.stderr14
-rw-r--r--src/test/ui/suggestions/dont-suggest-ref/simple.rs1
-rw-r--r--src/test/ui/suggestions/dont-suggest-ref/simple.stderr12
4 files changed, 15 insertions, 14 deletions
diff --git a/compiler/rustc_mir_build/src/build/block.rs b/compiler/rustc_mir_build/src/build/block.rs
index 49d7136a2f1..7b19acf7073 100644
--- a/compiler/rustc_mir_build/src/build/block.rs
+++ b/compiler/rustc_mir_build/src/build/block.rs
@@ -231,7 +231,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
                                         remainder_span,
                                         pattern,
                                         None,
-                                        Some((None, initializer_span)),
+                                        Some((Some(&destination), initializer_span)),
                                     );
                                     this.visit_primary_bindings(
                                         pattern,
diff --git a/src/test/ui/by-move-pattern-binding.stderr b/src/test/ui/by-move-pattern-binding.stderr
index bf1e61fe554..203e37dc387 100644
--- a/src/test/ui/by-move-pattern-binding.stderr
+++ b/src/test/ui/by-move-pattern-binding.stderr
@@ -32,15 +32,19 @@ LL +     if let E::Bar(identifier) = &s.x {
    |
 
 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 {
-   |                 ^^^^^^^^^^ 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 removing the borrow
    |
-help: consider borrowing here
+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
 
diff --git a/src/test/ui/suggestions/dont-suggest-ref/simple.rs b/src/test/ui/suggestions/dont-suggest-ref/simple.rs
index aa47ac4725a..1de612abbcd 100644
--- a/src/test/ui/suggestions/dont-suggest-ref/simple.rs
+++ b/src/test/ui/suggestions/dont-suggest-ref/simple.rs
@@ -319,7 +319,6 @@ struct Testing {
 fn testing(a: &Testing) {
     let Some(_s) = a.a else {
         //~^ ERROR cannot move
-        //~| HELP consider borrowing
         return;
     };
 }
diff --git a/src/test/ui/suggestions/dont-suggest-ref/simple.stderr b/src/test/ui/suggestions/dont-suggest-ref/simple.stderr
index decc57379e7..400eee83311 100644
--- a/src/test/ui/suggestions/dont-suggest-ref/simple.stderr
+++ b/src/test/ui/suggestions/dont-suggest-ref/simple.stderr
@@ -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
 
 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 {
-   |              ^^ move occurs because `a.a.0` has type `String`, which does not implement the `Copy` trait
-   |
-help: consider borrowing here
-   |
-LL |     let Some(&_s) = a.a else {
-   |              +
+   |              --    ^^^
+   |              |
+   |              data moved here
+   |              move occurs because `_s` has type `String`, which does not implement the `Copy` trait
 
 error: aborting due to 61 previous errors