about summary refs log tree commit diff
path: root/src/test/ui
diff options
context:
space:
mode:
authorNadrieril <nadrieril+git@gmail.com>2020-11-01 01:58:48 +0000
committerNadrieril <nadrieril+git@gmail.com>2020-11-01 02:04:42 +0000
commit4cd30197eb126727b791a1c845c5ec47dbd3b1de (patch)
tree0b3e2d94cf67c154f2c3b92b7a51737fe3a9accd /src/test/ui
parenta53fb30e3bf2655b0563da6d561c23cda5f3ec11 (diff)
Fix #78549
Before #78430, string literals worked because `specialize_constructor`
didn't actually care too much which constructor was passed to it unless
needed. Since then, string literals are special cased and a bit hacky. I
did not anticipate patterns for the `&str` type other than string
literals, hence this bug. This makes string literals less hacky.
Diffstat (limited to 'src/test/ui')
-rw-r--r--src/test/ui/issues/issue-30240.rs4
-rw-r--r--src/test/ui/issues/issue-30240.stderr8
-rw-r--r--src/test/ui/pattern/usefulness/issue-78549-ref-pat-and-str.rs25
3 files changed, 31 insertions, 6 deletions
diff --git a/src/test/ui/issues/issue-30240.rs b/src/test/ui/issues/issue-30240.rs
index 8075532c37d..a0c0d1626ec 100644
--- a/src/test/ui/issues/issue-30240.rs
+++ b/src/test/ui/issues/issue-30240.rs
@@ -1,9 +1,9 @@
 fn main() {
-    match "world" { //~ ERROR non-exhaustive patterns: `_`
+    match "world" { //~ ERROR non-exhaustive patterns: `&_`
         "hello" => {}
     }
 
-    match "world" { //~ ERROR non-exhaustive patterns: `_`
+    match "world" { //~ ERROR non-exhaustive patterns: `&_`
         ref _x if false => {}
         "hello" => {}
     }
diff --git a/src/test/ui/issues/issue-30240.stderr b/src/test/ui/issues/issue-30240.stderr
index 71a8bcb50cd..a2c58d6e051 100644
--- a/src/test/ui/issues/issue-30240.stderr
+++ b/src/test/ui/issues/issue-30240.stderr
@@ -1,17 +1,17 @@
-error[E0004]: non-exhaustive patterns: `_` not covered
+error[E0004]: non-exhaustive patterns: `&_` not covered
   --> $DIR/issue-30240.rs:2:11
    |
 LL |     match "world" {
-   |           ^^^^^^^ pattern `_` not covered
+   |           ^^^^^^^ pattern `&_` not covered
    |
    = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
    = note: the matched value is of type `&str`
 
-error[E0004]: non-exhaustive patterns: `_` not covered
+error[E0004]: non-exhaustive patterns: `&_` not covered
   --> $DIR/issue-30240.rs:6:11
    |
 LL |     match "world" {
-   |           ^^^^^^^ pattern `_` not covered
+   |           ^^^^^^^ pattern `&_` not covered
    |
    = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
    = note: the matched value is of type `&str`
diff --git a/src/test/ui/pattern/usefulness/issue-78549-ref-pat-and-str.rs b/src/test/ui/pattern/usefulness/issue-78549-ref-pat-and-str.rs
new file mode 100644
index 00000000000..2879caf2c4c
--- /dev/null
+++ b/src/test/ui/pattern/usefulness/issue-78549-ref-pat-and-str.rs
@@ -0,0 +1,25 @@
+// check-pass
+// From https://github.com/rust-lang/rust/issues/78549
+
+fn main() {
+    match "foo" {
+        "foo" => {},
+        &_ => {},
+    }
+
+    match "foo" {
+        &_ => {},
+        "foo" => {},
+    }
+
+    match ("foo", 0, "bar") {
+        (&_, 0, &_) => {},
+        ("foo", _, "bar") => {},
+        (&_, _, &_) => {},
+    }
+
+    match (&"foo", "bar") {
+        (&"foo", &_) => {},
+        (&&_, &_) => {},
+    }
+}