about summary refs log tree commit diff
path: root/src/test/ui/pattern
diff options
context:
space:
mode:
authorCaio <c410.f3r@gmail.com>2021-01-16 15:54:05 -0300
committerCaio <c410.f3r@gmail.com>2021-01-16 19:46:54 -0300
commitad35979c50366d6b0fbcda99215f1c4e926e5dab (patch)
tree8bc4fd6168831ee45cf114456cc70d4cf49266d8 /src/test/ui/pattern
parent63a83c5f55801b17b77adf690db397d17c706c48 (diff)
downloadrust-ad35979c50366d6b0fbcda99215f1c4e926e5dab.tar.gz
rust-ad35979c50366d6b0fbcda99215f1c4e926e5dab.zip
Move some tests to more reasonable directories - 2
Address comments

Update limits
Diffstat (limited to 'src/test/ui/pattern')
-rw-r--r--src/test/ui/pattern/issue-12582.rs21
-rw-r--r--src/test/ui/pattern/issue-14221.rs21
-rw-r--r--src/test/ui/pattern/issue-14221.stderr32
-rw-r--r--src/test/ui/pattern/issue-22546.rs52
-rw-r--r--src/test/ui/pattern/issue-6449.rs44
-rw-r--r--src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.rs21
-rw-r--r--src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr33
-rw-r--r--src/test/ui/pattern/size-and-align.rs20
8 files changed, 244 insertions, 0 deletions
diff --git a/src/test/ui/pattern/issue-12582.rs b/src/test/ui/pattern/issue-12582.rs
new file mode 100644
index 00000000000..f3366704e63
--- /dev/null
+++ b/src/test/ui/pattern/issue-12582.rs
@@ -0,0 +1,21 @@
+// run-pass
+
+pub fn main() {
+    let x = 1;
+    let y = 2;
+
+    assert_eq!(3, match (x, y) {
+        (1, 1) => 1,
+        (2, 2) => 2,
+        (1..=2, 2) => 3,
+        _ => 4,
+    });
+
+    // nested tuple
+    assert_eq!(3, match ((x, y),) {
+        ((1, 1),) => 1,
+        ((2, 2),) => 2,
+        ((1..=2, 2),) => 3,
+        _ => 4,
+    });
+}
diff --git a/src/test/ui/pattern/issue-14221.rs b/src/test/ui/pattern/issue-14221.rs
new file mode 100644
index 00000000000..282c4111369
--- /dev/null
+++ b/src/test/ui/pattern/issue-14221.rs
@@ -0,0 +1,21 @@
+#![deny(unreachable_patterns)]
+#![allow(unused_variables)]
+#![allow(non_snake_case)]
+
+pub enum E {
+    A,
+    B,
+}
+
+pub mod b {
+    pub fn key(e: ::E) -> &'static str {
+        match e {
+            A => "A",
+//~^ WARN pattern binding `A` is named the same as one of the variants of the type `E`
+            B => "B", //~ ERROR: unreachable pattern
+//~^ WARN pattern binding `B` is named the same as one of the variants of the type `E`
+        }
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/pattern/issue-14221.stderr b/src/test/ui/pattern/issue-14221.stderr
new file mode 100644
index 00000000000..fc8ae1ed7b5
--- /dev/null
+++ b/src/test/ui/pattern/issue-14221.stderr
@@ -0,0 +1,32 @@
+warning[E0170]: pattern binding `A` is named the same as one of the variants of the type `E`
+  --> $DIR/issue-14221.rs:13:13
+   |
+LL |             A => "A",
+   |             ^ help: to match on the variant, qualify the path: `E::A`
+   |
+   = note: `#[warn(bindings_with_variant_name)]` on by default
+
+warning[E0170]: pattern binding `B` is named the same as one of the variants of the type `E`
+  --> $DIR/issue-14221.rs:15:13
+   |
+LL |             B => "B",
+   |             ^ help: to match on the variant, qualify the path: `E::B`
+
+error: unreachable pattern
+  --> $DIR/issue-14221.rs:15:13
+   |
+LL |             A => "A",
+   |             - matches any value
+LL |
+LL |             B => "B",
+   |             ^ unreachable pattern
+   |
+note: the lint level is defined here
+  --> $DIR/issue-14221.rs:1:9
+   |
+LL | #![deny(unreachable_patterns)]
+   |         ^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error; 2 warnings emitted
+
+For more information about this error, try `rustc --explain E0170`.
diff --git a/src/test/ui/pattern/issue-22546.rs b/src/test/ui/pattern/issue-22546.rs
new file mode 100644
index 00000000000..c26e457f9e4
--- /dev/null
+++ b/src/test/ui/pattern/issue-22546.rs
@@ -0,0 +1,52 @@
+// run-pass
+#![allow(unused_variables)]
+// Parsing patterns with paths with type parameters (issue #22544)
+
+use std::default::Default;
+
+#[derive(Default)]
+pub struct Foo<T>(T, T);
+
+impl<T: ::std::fmt::Display> Foo<T> {
+    fn foo(&self) {
+        match *self {
+            Foo::<T>(ref x, ref y) => println!("Goodbye, World! {} {}", x, y)
+        }
+    }
+}
+
+trait Tr {
+    type U;
+}
+
+impl<T> Tr for Foo<T> {
+    type U = T;
+}
+
+struct Wrapper<T> {
+    value: T
+}
+
+fn main() {
+    let Foo::<i32>(a, b) = Default::default();
+
+    let f = Foo(2,3);
+    f.foo();
+
+    let w = Wrapper { value: Foo(10u8, 11u8) };
+    match w {
+        Wrapper::<Foo<u8>> { value: Foo(10, 11) } => {},
+        ::Wrapper::<<Foo<_> as Tr>::U> { value: Foo::<u8>(11, 16) } => { panic!() },
+        _ => { panic!() }
+    }
+
+    if let None::<u8> = Some(8) {
+        panic!();
+    }
+    if let None::<u8> { .. } = Some(8) {
+        panic!();
+    }
+    if let Option::None::<u8> { .. } = Some(8) {
+        panic!();
+    }
+}
diff --git a/src/test/ui/pattern/issue-6449.rs b/src/test/ui/pattern/issue-6449.rs
new file mode 100644
index 00000000000..bfd4c123208
--- /dev/null
+++ b/src/test/ui/pattern/issue-6449.rs
@@ -0,0 +1,44 @@
+// run-pass
+#![allow(dead_code)]
+
+enum Foo {
+    Bar(isize),
+    Baz,
+}
+
+enum Other {
+    Other1(Foo),
+    Other2(Foo, Foo),
+}
+
+fn main() {
+    match Foo::Baz {
+        ::Foo::Bar(3) => panic!(),
+        ::Foo::Bar(_) if false => panic!(),
+        ::Foo::Bar(..) if false => panic!(),
+        ::Foo::Bar(_n) => panic!(),
+        ::Foo::Baz => {}
+    }
+    match Foo::Bar(3) {
+        ::Foo::Bar(3) => {}
+        ::Foo::Bar(_) if false => panic!(),
+        ::Foo::Bar(..) if false => panic!(),
+        ::Foo::Bar(_n) => panic!(),
+        ::Foo::Baz => panic!(),
+    }
+    match Foo::Bar(4) {
+        ::Foo::Bar(3) => panic!(),
+        ::Foo::Bar(_) if false => panic!(),
+        ::Foo::Bar(..) if false => panic!(),
+        ::Foo::Bar(n) => assert_eq!(n, 4),
+        ::Foo::Baz => panic!(),
+    }
+
+    match Other::Other1(Foo::Baz) {
+        ::Other::Other1(::Foo::Baz) => {}
+        ::Other::Other1(::Foo::Bar(_)) => {}
+        ::Other::Other2(::Foo::Baz, ::Foo::Bar(_)) => {}
+        ::Other::Other2(::Foo::Bar(..), ::Foo::Baz) => {}
+        ::Other::Other2(..) => {}
+    }
+}
diff --git a/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.rs b/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.rs
new file mode 100644
index 00000000000..a3023ee906d
--- /dev/null
+++ b/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.rs
@@ -0,0 +1,21 @@
+// Regression test for #67037.
+//
+// In type checking patterns, E0023 occurs when the tuple pattern and the expected
+// tuple pattern have different number of fields. For example, as below, `P()`,
+// the tuple struct pattern, has 0 fields, but requires 1 field.
+//
+// In emitting E0023, we try to see if this is a case of e.g., `Some(a, b, c)` but where
+// the scrutinee was of type `Some((a, b, c))`, and suggest that parenthesis be added.
+//
+// However, we did not account for the expected type being different than the tuple pattern type.
+// This caused an issue when the tuple pattern type (`P<T>`) was generic.
+// Specifically, we tried deriving the 0th field's type using the `substs` of the expected type.
+// When attempting to substitute `T`, there was no such substitution, so "out of range" occurred.
+
+struct U {} // 0 type parameters offered
+struct P<T>(T); // 1 type parameter wanted
+
+fn main() {
+    let P() = U {}; //~ ERROR mismatched types
+    //~^ ERROR this pattern has 0 fields, but the corresponding tuple struct has 1 field
+}
diff --git a/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr b/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr
new file mode 100644
index 00000000000..9bdbf0bf9f4
--- /dev/null
+++ b/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr
@@ -0,0 +1,33 @@
+error[E0308]: mismatched types
+  --> $DIR/issue-67037-pat-tup-scrut-ty-diff-less-fields.rs:19:9
+   |
+LL |     let P() = U {};
+   |         ^^^   ---- this expression has type `U`
+   |         |
+   |         expected struct `U`, found struct `P`
+   |
+   = note: expected struct `U`
+              found struct `P<_>`
+
+error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has 1 field
+  --> $DIR/issue-67037-pat-tup-scrut-ty-diff-less-fields.rs:19:9
+   |
+LL | struct P<T>(T); // 1 type parameter wanted
+   | --------------- tuple struct defined here
+...
+LL |     let P() = U {};
+   |         ^^^ expected 1 field, found 0
+   |
+help: use `_` to explicitly ignore each field
+   |
+LL |     let P(_) = U {};
+   |           ^
+help: use `..` to ignore all fields
+   |
+LL |     let P(..) = U {};
+   |           ^^
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0023, E0308.
+For more information about an error, try `rustc --explain E0023`.
diff --git a/src/test/ui/pattern/size-and-align.rs b/src/test/ui/pattern/size-and-align.rs
new file mode 100644
index 00000000000..a32b5de7292
--- /dev/null
+++ b/src/test/ui/pattern/size-and-align.rs
@@ -0,0 +1,20 @@
+// run-pass
+
+#![allow(non_camel_case_types)]
+enum clam<T> { a(T, isize), b, }
+
+fn uhoh<T>(v: Vec<clam<T>> ) {
+    match v[1] {
+      clam::a::<T>(ref _t, ref u) => {
+          println!("incorrect");
+          println!("{}", u);
+          panic!();
+      }
+      clam::b::<T> => { println!("correct"); }
+    }
+}
+
+pub fn main() {
+    let v: Vec<clam<isize>> = vec![clam::b::<isize>, clam::b::<isize>, clam::a::<isize>(42, 17)];
+    uhoh::<isize>(v);
+}