about summary refs log tree commit diff
path: root/tests/ui/destructuring-assignment
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-12-08 19:54:46 +0000
committerMichael Goulet <michael@errs.io>2023-12-08 19:55:07 +0000
commitd473bdfdc3a2c377afd873abd4ace4244af80766 (patch)
tree2d81dc0a2064a125b1f2cb86eae4679fa2e7758e /tests/ui/destructuring-assignment
parentae612bedcbfc7098d1711eb35bc7ca994eb17a4c (diff)
downloadrust-d473bdfdc3a2c377afd873abd4ace4244af80766.tar.gz
rust-d473bdfdc3a2c377afd873abd4ace4244af80766.zip
Support bare unit structs in destructuring assignments
Diffstat (limited to 'tests/ui/destructuring-assignment')
-rw-r--r--tests/ui/destructuring-assignment/bad-expr-lhs.rs2
-rw-r--r--tests/ui/destructuring-assignment/bad-expr-lhs.stderr10
-rw-r--r--tests/ui/destructuring-assignment/non-exhaustive-destructure.rs4
-rw-r--r--tests/ui/destructuring-assignment/non-exhaustive-destructure.stderr17
-rw-r--r--tests/ui/destructuring-assignment/struct-or-enum-variant-path.rs6
5 files changed, 28 insertions, 11 deletions
diff --git a/tests/ui/destructuring-assignment/bad-expr-lhs.rs b/tests/ui/destructuring-assignment/bad-expr-lhs.rs
index 53794783a3c..90e1ac19943 100644
--- a/tests/ui/destructuring-assignment/bad-expr-lhs.rs
+++ b/tests/ui/destructuring-assignment/bad-expr-lhs.rs
@@ -4,6 +4,4 @@ fn main() {
     (1, 2) = (3, 4);
     //~^ ERROR invalid left-hand side of assignment
     //~| ERROR invalid left-hand side of assignment
-
-    None = Some(3); //~ ERROR invalid left-hand side of assignment
 }
diff --git a/tests/ui/destructuring-assignment/bad-expr-lhs.stderr b/tests/ui/destructuring-assignment/bad-expr-lhs.stderr
index d2986747480..2916d6d9f11 100644
--- a/tests/ui/destructuring-assignment/bad-expr-lhs.stderr
+++ b/tests/ui/destructuring-assignment/bad-expr-lhs.stderr
@@ -30,15 +30,7 @@ LL |     (1, 2) = (3, 4);
    |         |
    |         cannot assign to this expression
 
-error[E0070]: invalid left-hand side of assignment
-  --> $DIR/bad-expr-lhs.rs:8:10
-   |
-LL |     None = Some(3);
-   |     ---- ^
-   |     |
-   |     cannot assign to this expression
-
-error: aborting due to 5 previous errors
+error: aborting due to 4 previous errors
 
 Some errors have detailed explanations: E0067, E0070.
 For more information about an error, try `rustc --explain E0067`.
diff --git a/tests/ui/destructuring-assignment/non-exhaustive-destructure.rs b/tests/ui/destructuring-assignment/non-exhaustive-destructure.rs
new file mode 100644
index 00000000000..39939f2bad6
--- /dev/null
+++ b/tests/ui/destructuring-assignment/non-exhaustive-destructure.rs
@@ -0,0 +1,4 @@
+fn main() {
+    None = Some(3);
+    //~^ ERROR refutable pattern in local binding
+}
diff --git a/tests/ui/destructuring-assignment/non-exhaustive-destructure.stderr b/tests/ui/destructuring-assignment/non-exhaustive-destructure.stderr
new file mode 100644
index 00000000000..b9ceaa4af7b
--- /dev/null
+++ b/tests/ui/destructuring-assignment/non-exhaustive-destructure.stderr
@@ -0,0 +1,17 @@
+error[E0005]: refutable pattern in local binding
+  --> $DIR/non-exhaustive-destructure.rs:2:5
+   |
+LL |     None = Some(3);
+   |     ^^^^ pattern `Some(_)` not covered
+   |
+   = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
+   = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
+   = note: the matched value is of type `Option<i32>`
+help: you might want to use `if let` to ignore the variant that isn't matched
+   |
+LL |     if None = Some(3) { todo!() };
+   |     ++                +++++++++++
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0005`.
diff --git a/tests/ui/destructuring-assignment/struct-or-enum-variant-path.rs b/tests/ui/destructuring-assignment/struct-or-enum-variant-path.rs
index 8da7f90c524..f82e029983b 100644
--- a/tests/ui/destructuring-assignment/struct-or-enum-variant-path.rs
+++ b/tests/ui/destructuring-assignment/struct-or-enum-variant-path.rs
@@ -11,17 +11,22 @@ type A = E;
 fn main() {
     let mut a;
 
+    S = S;
     (S, a) = (S, ());
 
+    E::V = E::V;
     (E::V, a) = (E::V, ());
 
+    <E>::V = E::V;
     (<E>::V, a) = (E::V, ());
+    A::V = A::V;
     (A::V, a) = (E::V, ());
 }
 
 impl S {
     fn check() {
         let a;
+        Self = S;
         (Self, a) = (S, ());
     }
 }
@@ -29,6 +34,7 @@ impl S {
 impl E {
     fn check() {
         let a;
+        Self::V = E::V;
         (Self::V, a) = (E::V, ());
     }
 }