summaryrefslogtreecommitdiffstats
path: root/src/test/ui/or-patterns/or-patterns-binding-type-mismatch.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/ui/or-patterns/or-patterns-binding-type-mismatch.rs')
-rw-r--r--src/test/ui/or-patterns/or-patterns-binding-type-mismatch.rs66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/test/ui/or-patterns/or-patterns-binding-type-mismatch.rs b/src/test/ui/or-patterns/or-patterns-binding-type-mismatch.rs
new file mode 100644
index 000000000..fa470de7f
--- /dev/null
+++ b/src/test/ui/or-patterns/or-patterns-binding-type-mismatch.rs
@@ -0,0 +1,66 @@
+// Here we test type checking of bindings when combined with or-patterns.
+// Specifically, we ensure that introducing bindings of different types result in type errors.
+
+fn main() {
+ enum Blah {
+ A(isize, isize, usize),
+ B(isize, isize),
+ }
+
+ match Blah::A(1, 1, 2) {
+ Blah::A(_, x, y) | Blah::B(x, y) => {} //~ ERROR mismatched types
+ }
+
+ match Some(Blah::A(1, 1, 2)) {
+ Some(Blah::A(_, x, y) | Blah::B(x, y)) => {} //~ ERROR mismatched types
+ }
+
+ match (0u8, 1u16) {
+ (x, y) | (y, x) => {} //~ ERROR mismatched types
+ //~^ ERROR mismatched types
+ }
+
+ match Some((0u8, Some((1u16, 2u32)))) {
+ Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x)))) => {}
+ //~^ ERROR mismatched types
+ //~| ERROR mismatched types
+ //~| ERROR mismatched types
+ //~| ERROR mismatched types
+ _ => {}
+ }
+
+ if let Blah::A(_, x, y) | Blah::B(x, y) = Blah::A(1, 1, 2) {
+ //~^ ERROR mismatched types
+ }
+
+ if let Some(Blah::A(_, x, y) | Blah::B(x, y)) = Some(Blah::A(1, 1, 2)) {
+ //~^ ERROR mismatched types
+ }
+
+ if let (x, y) | (y, x) = (0u8, 1u16) {
+ //~^ ERROR mismatched types
+ //~| ERROR mismatched types
+ }
+
+ if let Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x))))
+ //~^ ERROR mismatched types
+ //~| ERROR mismatched types
+ //~| ERROR mismatched types
+ //~| ERROR mismatched types
+ = Some((0u8, Some((1u16, 2u32))))
+ {}
+
+ let (Blah::A(_, x, y) | Blah::B(x, y)) = Blah::A(1, 1, 2);
+ //~^ ERROR mismatched types
+
+ let ((x, y) | (y, x)) = (0u8, 1u16);
+ //~^ ERROR mismatched types
+ //~| ERROR mismatched types
+
+ fn f1((Blah::A(_, x, y) | Blah::B(x, y)): Blah) {}
+ //~^ ERROR mismatched types
+
+ fn f2(((x, y) | (y, x)): (u8, u16)) {}
+ //~^ ERROR mismatched types
+ //~| ERROR mismatched types
+}