or_patterns: harden bindings test

This commit is contained in:
Mazdak Farrokhzad 2020-02-05 05:03:37 +01:00
parent c9290dceee
commit 6509db8443
2 changed files with 245 additions and 7 deletions

View file

@ -1,4 +1,68 @@
enum Blah { A(isize, isize, usize), B(isize, isize) }
// 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() { match Blah::A(1, 1, 2) { Blah::A(_, x, y) | Blah::B(x, y) => { } } }
//~^ ERROR mismatched types
#![feature(or_patterns)]
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
}

View file

@ -1,9 +1,183 @@
error[E0308]: mismatched types
--> $DIR/or-pattern-mismatch.rs:3:68
--> $DIR/or-pattern-mismatch.rs:13:39
|
LL | fn main() { match Blah::A(1, 1, 2) { Blah::A(_, x, y) | Blah::B(x, y) => { } } }
| ---------------- this expression has type `Blah` ^ expected `usize`, found `isize`
LL | match Blah::A(1, 1, 2) {
| ---------------- this expression has type `main::Blah`
LL | Blah::A(_, x, y) | Blah::B(x, y) => {}
| ^ expected `usize`, found `isize`
error: aborting due to previous error
error[E0308]: mismatched types
--> $DIR/or-pattern-mismatch.rs:17:44
|
LL | match Some(Blah::A(1, 1, 2)) {
| ---------------------- this expression has type `std::option::Option<main::Blah>`
LL | Some(Blah::A(_, x, y) | Blah::B(x, y)) => {}
| ^ expected `usize`, found `isize`
error[E0308]: mismatched types
--> $DIR/or-pattern-mismatch.rs:21:19
|
LL | match (0u8, 1u16) {
| ----------- this expression has type `(u8, u16)`
LL | (x, y) | (y, x) => {}
| ^ expected `u16`, found `u8`
error[E0308]: mismatched types
--> $DIR/or-pattern-mismatch.rs:21:22
|
LL | match (0u8, 1u16) {
| ----------- this expression has type `(u8, u16)`
LL | (x, y) | (y, x) => {}
| ^ expected `u8`, found `u16`
error[E0308]: mismatched types
--> $DIR/or-pattern-mismatch.rs:26:41
|
LL | match Some((0u8, Some((1u16, 2u32)))) {
| ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>`
LL | Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x)))) => {}
| ^ expected `u16`, found `u8`
error[E0308]: mismatched types
--> $DIR/or-pattern-mismatch.rs:26:50
|
LL | match Some((0u8, Some((1u16, 2u32)))) {
| ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>`
LL | Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x)))) => {}
| ^ expected `u8`, found `u16`
error[E0308]: mismatched types
--> $DIR/or-pattern-mismatch.rs:26:59
|
LL | match Some((0u8, Some((1u16, 2u32)))) {
| ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>`
LL | Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x)))) => {}
| ^ expected `u32`, found `u16`
error[E0308]: mismatched types
--> $DIR/or-pattern-mismatch.rs:26:62
|
LL | match Some((0u8, Some((1u16, 2u32)))) {
| ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>`
LL | Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x)))) => {}
| ^ expected `u8`, found `u32`
error[E0308]: mismatched types
--> $DIR/or-pattern-mismatch.rs:34:42
|
LL | if let Blah::A(_, x, y) | Blah::B(x, y) = Blah::A(1, 1, 2) {
| ^ ---------------- this expression has type `main::Blah`
| |
| expected `usize`, found `isize`
error[E0308]: mismatched types
--> $DIR/or-pattern-mismatch.rs:38:47
|
LL | if let Some(Blah::A(_, x, y) | Blah::B(x, y)) = Some(Blah::A(1, 1, 2)) {
| ^ ---------------------- this expression has type `std::option::Option<main::Blah>`
| |
| expected `usize`, found `isize`
error[E0308]: mismatched types
--> $DIR/or-pattern-mismatch.rs:42:22
|
LL | if let (x, y) | (y, x) = (0u8, 1u16) {
| ^ ----------- this expression has type `(u8, u16)`
| |
| expected `u16`, found `u8`
error[E0308]: mismatched types
--> $DIR/or-pattern-mismatch.rs:42:25
|
LL | if let (x, y) | (y, x) = (0u8, 1u16) {
| ^ ----------- this expression has type `(u8, u16)`
| |
| expected `u8`, found `u16`
error[E0308]: mismatched types
--> $DIR/or-pattern-mismatch.rs:47:44
|
LL | if let Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x))))
| ^ expected `u16`, found `u8`
...
LL | = Some((0u8, Some((1u16, 2u32))))
| ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>`
error[E0308]: mismatched types
--> $DIR/or-pattern-mismatch.rs:47:53
|
LL | if let Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x))))
| ^ expected `u8`, found `u16`
...
LL | = Some((0u8, Some((1u16, 2u32))))
| ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>`
error[E0308]: mismatched types
--> $DIR/or-pattern-mismatch.rs:47:62
|
LL | if let Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x))))
| ^ expected `u32`, found `u16`
...
LL | = Some((0u8, Some((1u16, 2u32))))
| ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>`
error[E0308]: mismatched types
--> $DIR/or-pattern-mismatch.rs:47:65
|
LL | if let Some((x, Some((y, z)))) | Some((y, Some((x, z) | (z, x))))
| ^ expected `u8`, found `u32`
...
LL | = Some((0u8, Some((1u16, 2u32))))
| ------------------------------- this expression has type `std::option::Option<(u8, std::option::Option<(u16, u32)>)>`
error[E0308]: mismatched types
--> $DIR/or-pattern-mismatch.rs:55:39
|
LL | let Blah::A(_, x, y) | Blah::B(x, y) = Blah::A(1, 1, 2);
| ^ ---------------- this expression has type `main::Blah`
| |
| expected `usize`, found `isize`
error[E0308]: mismatched types
--> $DIR/or-pattern-mismatch.rs:58:19
|
LL | let (x, y) | (y, x) = (0u8, 1u16);
| ^ ----------- this expression has type `(u8, u16)`
| |
| expected `u16`, found `u8`
error[E0308]: mismatched types
--> $DIR/or-pattern-mismatch.rs:58:22
|
LL | let (x, y) | (y, x) = (0u8, 1u16);
| ^ ----------- this expression has type `(u8, u16)`
| |
| expected `u8`, found `u16`
error[E0308]: mismatched types
--> $DIR/or-pattern-mismatch.rs:62:42
|
LL | fn f1((Blah::A(_, x, y) | Blah::B(x, y)): Blah) {}
| ^ ---- expected due to this
| |
| expected `usize`, found `isize`
error[E0308]: mismatched types
--> $DIR/or-pattern-mismatch.rs:65:22
|
LL | fn f2(((x, y) | (y, x)): (u8, u16)) {}
| ^ --------- expected due to this
| |
| expected `u16`, found `u8`
error[E0308]: mismatched types
--> $DIR/or-pattern-mismatch.rs:65:25
|
LL | fn f2(((x, y) | (y, x)): (u8, u16)) {}
| ^ --------- expected due to this
| |
| expected `u8`, found `u16`
error: aborting due to 22 previous errors
For more information about this error, try `rustc --explain E0308`.