]> git.lizzy.rs Git - rust.git/commitdiff
Add tests
authorNadrieril <nadrieril+git@gmail.com>
Sat, 2 Jan 2021 22:38:18 +0000 (22:38 +0000)
committerNadrieril <nadrieril+git@gmail.com>
Sun, 24 Jan 2021 20:28:28 +0000 (20:28 +0000)
src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.rs
src/test/ui/or-patterns/exhaustiveness-unreachable-pattern.stderr
src/test/ui/pattern/usefulness/issue-80501-or-pat-and-macro.rs [new file with mode: 0644]
src/test/ui/pattern/usefulness/issue-80501-or-pat-and-macro.stderr [new file with mode: 0644]

index 184ffa85c40e28b56beade40e73710bc7d598d5d..f51ba683cab2bd91a7728ef8bd28f58df522bbb9 100644 (file)
@@ -48,6 +48,22 @@ fn main() {
         (1 | 1,) => {} //~ ERROR unreachable
         _ => {}
     }
+    match 0 {
+        (0 | 1) | 1 => {} //~ ERROR unreachable
+        _ => {}
+    }
+    match 0 {
+        0 | (0 | 0) => {}
+        //~^ ERROR unreachable
+        _ => {}
+    }
+    match None {
+        // There is only one error that correctly points to the whole subpattern
+        Some(0) |
+            Some( //~ ERROR unreachable
+                0 | 0) => {}
+        _ => {}
+    }
     match [0; 2] {
         [0
             | 0 //~ ERROR unreachable
index 8b1003b5514a680b91ed77a1793205c610d9c10d..f61e7f2281afc86d7a0fa8cc3a27e9f601a6c25b 100644 (file)
@@ -77,58 +77,77 @@ LL |         (1 | 1,) => {}
    |              ^
 
 error: unreachable pattern
-  --> $DIR/exhaustiveness-unreachable-pattern.rs:53:15
+  --> $DIR/exhaustiveness-unreachable-pattern.rs:52:19
+   |
+LL |         (0 | 1) | 1 => {}
+   |                   ^
+
+error: unreachable pattern
+  --> $DIR/exhaustiveness-unreachable-pattern.rs:56:14
+   |
+LL |         0 | (0 | 0) => {}
+   |              ^^^^^
+
+error: unreachable pattern
+  --> $DIR/exhaustiveness-unreachable-pattern.rs:63:13
+   |
+LL | /             Some(
+LL | |                 0 | 0) => {}
+   | |______________________^
+
+error: unreachable pattern
+  --> $DIR/exhaustiveness-unreachable-pattern.rs:69:15
    |
 LL |             | 0
    |               ^
 
 error: unreachable pattern
-  --> $DIR/exhaustiveness-unreachable-pattern.rs:55:15
+  --> $DIR/exhaustiveness-unreachable-pattern.rs:71:15
    |
 LL |             | 0] => {}
    |               ^
 
 error: unreachable pattern
-  --> $DIR/exhaustiveness-unreachable-pattern.rs:63:10
+  --> $DIR/exhaustiveness-unreachable-pattern.rs:79:10
    |
 LL |         [1
    |          ^
 
 error: unreachable pattern
-  --> $DIR/exhaustiveness-unreachable-pattern.rs:75:10
+  --> $DIR/exhaustiveness-unreachable-pattern.rs:91:10
    |
 LL |         [true
    |          ^^^^
 
 error: unreachable pattern
-  --> $DIR/exhaustiveness-unreachable-pattern.rs:82:36
+  --> $DIR/exhaustiveness-unreachable-pattern.rs:98:36
    |
 LL |         (true | false, None | Some(true
    |                                    ^^^^
 
 error: unreachable pattern
-  --> $DIR/exhaustiveness-unreachable-pattern.rs:98:14
+  --> $DIR/exhaustiveness-unreachable-pattern.rs:114:14
    |
 LL |         Some(0
    |              ^
 
 error: unreachable pattern
-  --> $DIR/exhaustiveness-unreachable-pattern.rs:117:19
+  --> $DIR/exhaustiveness-unreachable-pattern.rs:133:19
    |
 LL |                 | false) => {}
    |                   ^^^^^
 
 error: unreachable pattern
-  --> $DIR/exhaustiveness-unreachable-pattern.rs:125:15
+  --> $DIR/exhaustiveness-unreachable-pattern.rs:141:15
    |
 LL |             | true) => {}
    |               ^^^^
 
 error: unreachable pattern
-  --> $DIR/exhaustiveness-unreachable-pattern.rs:131:15
+  --> $DIR/exhaustiveness-unreachable-pattern.rs:147:15
    |
 LL |             | true,
    |               ^^^^
 
-error: aborting due to 21 previous errors
+error: aborting due to 24 previous errors
 
diff --git a/src/test/ui/pattern/usefulness/issue-80501-or-pat-and-macro.rs b/src/test/ui/pattern/usefulness/issue-80501-or-pat-and-macro.rs
new file mode 100644 (file)
index 0000000..483edce
--- /dev/null
@@ -0,0 +1,27 @@
+#![deny(unreachable_patterns)]
+//~^ NOTE: lint level is defined here
+pub enum TypeCtor {
+    Slice,
+    Array,
+}
+
+pub struct ApplicationTy(TypeCtor);
+
+macro_rules! ty_app {
+    ($ctor:pat) => {
+        ApplicationTy($ctor) //~ ERROR unreachable pattern
+    };
+}
+
+fn _foo(ty: ApplicationTy) {
+    match ty {
+        ty_app!(TypeCtor::Array) | ty_app!(TypeCtor::Slice) => {} //~ NOTE: in this expansion
+    }
+
+    // same as above, with the macro expanded
+    match ty {
+        ApplicationTy(TypeCtor::Array) | ApplicationTy(TypeCtor::Slice) => {}
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/pattern/usefulness/issue-80501-or-pat-and-macro.stderr b/src/test/ui/pattern/usefulness/issue-80501-or-pat-and-macro.stderr
new file mode 100644 (file)
index 0000000..9d12b4a
--- /dev/null
@@ -0,0 +1,18 @@
+error: unreachable pattern
+  --> $DIR/issue-80501-or-pat-and-macro.rs:12:9
+   |
+LL |         ApplicationTy($ctor)
+   |         ^^^^^^^^^^^^^^^^^^^^
+...
+LL |         ty_app!(TypeCtor::Array) | ty_app!(TypeCtor::Slice) => {}
+   |                                    ------------------------ in this macro invocation
+   |
+note: the lint level is defined here
+  --> $DIR/issue-80501-or-pat-and-macro.rs:1:9
+   |
+LL | #![deny(unreachable_patterns)]
+   |         ^^^^^^^^^^^^^^^^^^^^
+   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to previous error
+