resolve: test consistent or-patterns being allowed.

This commit is contained in:
Mazdak Farrokhzad 2019-09-03 04:32:50 +02:00
parent aa7a02b029
commit dbe6873387
8 changed files with 132 additions and 38 deletions

View file

@ -1,8 +1,8 @@
// This test ensures that the "already bound identifier in a product pattern"
// correctly accounts for or-patterns.
#![allow(warnings)]
#![feature(or_patterns)]
//~^ WARN the feature `or_patterns` is incomplete
enum E<T> { A(T, T), B(T) }

View file

@ -82,6 +82,14 @@ error[E0416]: identifier `a` is bound more than once in the same pattern
LL | let B(A(a, _) | B(a)) | A(A(a, _) | B(a), A(a, _) | B(a)) = B(B(1));
| ^ used in a pattern more than once
warning: the feature `or_patterns` is incomplete and may cause the compiler to crash
--> $DIR/already-bound-name.rs:4:12
|
LL | #![feature(or_patterns)]
| ^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
error[E0308]: mismatched types
--> $DIR/already-bound-name.rs:33:31
|

View file

@ -0,0 +1,46 @@
// Check that or-patterns with consistent bindings across arms are allowed.
// edition:2018
#![feature(or_patterns)]
//~^ WARN the feature `or_patterns` is incomplete
fn main() {
// One level:
let Ok(a) | Err(a) = Ok(0);
let Ok(ref a) | Err(ref a) = Ok(0);
let Ok(ref mut a) | Err(ref mut a) = Ok(0);
// Two levels:
enum Tri<S, T, U> { V1(S), V2(T), V3(U) }
use Tri::*;
let Ok((V1(a) | V2(a) | V3(a), b)) | Err(Ok((a, b)) | Err((a, b)))
: Result<_, Result<_, _>>
= Ok((V1(1), 1));
let Ok((V1(a) | V2(a) | V3(a), ref b)) | Err(Ok((a, ref b)) | Err((a, ref b)))
: Result<_, Result<_, _>>
= Ok((V1(1), 1));
// Three levels:
let (
a,
Err((ref mut b, ref c, d)) |
Ok((
Ok(
V1((ref c, d)) |
V2((d, ref c)) |
V3((ref c, Ok((_, d)) | Err((d, _))))
) |
Err((ref c, d)),
ref mut b
))
) =
(1, Ok((Ok(V3((1, Ok((1, 1))))), 1)));
// FIXME(or_patterns; Centril | dlrobertson): remove this line below and
// change this test to check-pass once MIR can handle or-patterns with bindings.
let () = 0;
//~^ ERROR mismatched types
}

View file

@ -0,0 +1,20 @@
warning: the feature `or_patterns` is incomplete and may cause the compiler to crash
--> $DIR/consistent-bindings.rs:5:12
|
LL | #![feature(or_patterns)]
| ^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
error[E0308]: mismatched types
--> $DIR/consistent-bindings.rs:44:9
|
LL | let () = 0;
| ^^ expected integer, found ()
|
= note: expected type `{integer}`
found type `()`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.

View file

@ -1,7 +1,9 @@
// This test ensures that or patterns require binding mode consistency across arms.
#![feature(or_patterns)]
#![allow(incomplete_features, non_camel_case_types)]
//~^ WARN the feature `or_patterns` is incomplete
#![allow(non_camel_case_types)]
fn main() {
// One level:
let Ok(a) | Err(ref a): Result<&u8, u8> = Ok(&0);

View file

@ -1,5 +1,5 @@
error[E0409]: variable `a` is bound in inconsistent ways within the same match arm
--> $DIR/inconsistent-modes.rs:7:25
--> $DIR/inconsistent-modes.rs:9:25
|
LL | let Ok(a) | Err(ref a): Result<&u8, u8> = Ok(&0);
| - ^ bound in different ways
@ -7,7 +7,7 @@ LL | let Ok(a) | Err(ref a): Result<&u8, u8> = Ok(&0);
| first binding
error[E0409]: variable `a` is bound in inconsistent ways within the same match arm
--> $DIR/inconsistent-modes.rs:9:29
--> $DIR/inconsistent-modes.rs:11:29
|
LL | let Ok(ref mut a) | Err(a): Result<u8, &mut u8> = Ok(0);
| - ^ bound in different ways
@ -15,25 +15,25 @@ LL | let Ok(ref mut a) | Err(a): Result<u8, &mut u8> = Ok(0);
| first binding
error[E0409]: variable `a` is bound in inconsistent ways within the same match arm
--> $DIR/inconsistent-modes.rs:11:33
--> $DIR/inconsistent-modes.rs:13:33
|
LL | let Ok(ref a) | Err(ref mut a): Result<&u8, &mut u8> = Ok(&0);
| - first binding ^ bound in different ways
error[E0409]: variable `a` is bound in inconsistent ways within the same match arm
--> $DIR/inconsistent-modes.rs:14:39
--> $DIR/inconsistent-modes.rs:16:39
|
LL | let Ok((ref a, b)) | Err((ref mut a, ref b)) = Ok((0, &0));
| - first binding ^ bound in different ways
error[E0409]: variable `b` is bound in inconsistent ways within the same match arm
--> $DIR/inconsistent-modes.rs:14:46
--> $DIR/inconsistent-modes.rs:16:46
|
LL | let Ok((ref a, b)) | Err((ref mut a, ref b)) = Ok((0, &0));
| - first binding ^ bound in different ways
error[E0409]: variable `a` is bound in inconsistent ways within the same match arm
--> $DIR/inconsistent-modes.rs:20:38
--> $DIR/inconsistent-modes.rs:22:38
|
LL | let Ok(Ok(a) | Err(a)) | Err(ref a) = Err(0);
| - ^ bound in different ways
@ -41,15 +41,23 @@ LL | let Ok(Ok(a) | Err(a)) | Err(ref a) = Err(0);
| first binding
error[E0409]: variable `a` is bound in inconsistent ways within the same match arm
--> $DIR/inconsistent-modes.rs:24:34
--> $DIR/inconsistent-modes.rs:26:34
|
LL | let Ok([ Ok((Ok(ref a) | Err(a),)) | Err(a) ]) | Err(a) = Err(&1);
| - ^ bound in different ways
| |
| first binding
warning: the feature `or_patterns` is incomplete and may cause the compiler to crash
--> $DIR/inconsistent-modes.rs:3:12
|
LL | #![feature(or_patterns)]
| ^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
error[E0308]: mismatched types
--> $DIR/inconsistent-modes.rs:11:25
--> $DIR/inconsistent-modes.rs:13:25
|
LL | let Ok(ref a) | Err(ref mut a): Result<&u8, &mut u8> = Ok(&0);
| ^^^^^^^^^ types differ in mutability
@ -58,7 +66,7 @@ LL | let Ok(ref a) | Err(ref mut a): Result<&u8, &mut u8> = Ok(&0);
found type `&mut &mut u8`
error[E0308]: mismatched types
--> $DIR/inconsistent-modes.rs:14:31
--> $DIR/inconsistent-modes.rs:16:31
|
LL | let Ok((ref a, b)) | Err((ref mut a, ref b)) = Ok((0, &0));
| ^^^^^^^^^ types differ in mutability

View file

@ -3,7 +3,9 @@
// edition:2018
#![feature(or_patterns)]
#![allow(incomplete_features, non_camel_case_types)]
//~^ WARN the feature `or_patterns` is incomplete
#![allow(non_camel_case_types)]
fn main() {}

View file

@ -1,5 +1,5 @@
error[E0408]: variable `beta` is not bound in all patterns
--> $DIR/missing-bindings.rs:20:9
--> $DIR/missing-bindings.rs:22:9
|
LL | let alpha | beta | charlie = alpha;
| ^^^^^ ---- ^^^^^^^ pattern doesn't bind `beta`
@ -8,7 +8,7 @@ LL | let alpha | beta | charlie = alpha;
| pattern doesn't bind `beta`
error[E0408]: variable `beta` is not bound in all patterns
--> $DIR/missing-bindings.rs:22:14
--> $DIR/missing-bindings.rs:24:14
|
LL | Some(alpha | beta) => {}
| ^^^^^ ---- variable not in all patterns
@ -16,7 +16,7 @@ LL | Some(alpha | beta) => {}
| pattern doesn't bind `beta`
error[E0408]: variable `a` is not bound in all patterns
--> $DIR/missing-bindings.rs:34:19
--> $DIR/missing-bindings.rs:36:19
|
LL | let A(a, _) | _ = X;
| - ^ pattern doesn't bind `a`
@ -24,7 +24,7 @@ LL | let A(a, _) | _ = X;
| variable not in all patterns
error[E0408]: variable `a` is not bound in all patterns
--> $DIR/missing-bindings.rs:35:9
--> $DIR/missing-bindings.rs:37:9
|
LL | let _ | B(a) = X;
| ^ - variable not in all patterns
@ -32,7 +32,7 @@ LL | let _ | B(a) = X;
| pattern doesn't bind `a`
error[E0408]: variable `a` is not bound in all patterns
--> $DIR/missing-bindings.rs:36:9
--> $DIR/missing-bindings.rs:38:9
|
LL | let A(..) | B(a) = X;
| ^^^^^ - variable not in all patterns
@ -40,7 +40,7 @@ LL | let A(..) | B(a) = X;
| pattern doesn't bind `a`
error[E0408]: variable `a` is not bound in all patterns
--> $DIR/missing-bindings.rs:37:19
--> $DIR/missing-bindings.rs:39:19
|
LL | let A(a, _) | B(_) = X;
| - ^^^^ pattern doesn't bind `a`
@ -48,7 +48,7 @@ LL | let A(a, _) | B(_) = X;
| variable not in all patterns
error[E0408]: variable `a` is not bound in all patterns
--> $DIR/missing-bindings.rs:38:19
--> $DIR/missing-bindings.rs:40:19
|
LL | let A(_, a) | B(_) = X;
| - ^^^^ pattern doesn't bind `a`
@ -56,7 +56,7 @@ LL | let A(_, a) | B(_) = X;
| variable not in all patterns
error[E0408]: variable `b` is not bound in all patterns
--> $DIR/missing-bindings.rs:39:19
--> $DIR/missing-bindings.rs:41:19
|
LL | let A(a, b) | B(a) = X;
| - ^^^^ pattern doesn't bind `b`
@ -64,7 +64,7 @@ LL | let A(a, b) | B(a) = X;
| variable not in all patterns
error[E0408]: variable `a` is not bound in all patterns
--> $DIR/missing-bindings.rs:43:9
--> $DIR/missing-bindings.rs:45:9
|
LL | let A(A(..) | B(_), _) | B(a) = Y;
| ^^^^^^^^^^^^^^^^^^ - variable not in all patterns
@ -72,7 +72,7 @@ LL | let A(A(..) | B(_), _) | B(a) = Y;
| pattern doesn't bind `a`
error[E0408]: variable `a` is not bound in all patterns
--> $DIR/missing-bindings.rs:44:11
--> $DIR/missing-bindings.rs:46:11
|
LL | let A(A(..) | B(a), _) | B(A(a, _) | B(a)) = Y;
| ^^^^^ - variable not in all patterns
@ -80,7 +80,7 @@ LL | let A(A(..) | B(a), _) | B(A(a, _) | B(a)) = Y;
| pattern doesn't bind `a`
error[E0408]: variable `a` is not bound in all patterns
--> $DIR/missing-bindings.rs:46:21
--> $DIR/missing-bindings.rs:48:21
|
LL | let A(A(a, b) | B(c), d) | B(e) = Y;
| - ^^^^ pattern doesn't bind `a`
@ -88,7 +88,7 @@ LL | let A(A(a, b) | B(c), d) | B(e) = Y;
| variable not in all patterns
error[E0408]: variable `b` is not bound in all patterns
--> $DIR/missing-bindings.rs:46:21
--> $DIR/missing-bindings.rs:48:21
|
LL | let A(A(a, b) | B(c), d) | B(e) = Y;
| - ^^^^ pattern doesn't bind `b`
@ -96,7 +96,7 @@ LL | let A(A(a, b) | B(c), d) | B(e) = Y;
| variable not in all patterns
error[E0408]: variable `c` is not bound in all patterns
--> $DIR/missing-bindings.rs:46:11
--> $DIR/missing-bindings.rs:48:11
|
LL | let A(A(a, b) | B(c), d) | B(e) = Y;
| ^^^^^^^ - variable not in all patterns
@ -104,7 +104,7 @@ LL | let A(A(a, b) | B(c), d) | B(e) = Y;
| pattern doesn't bind `c`
error[E0408]: variable `a` is not bound in all patterns
--> $DIR/missing-bindings.rs:46:32
--> $DIR/missing-bindings.rs:48:32
|
LL | let A(A(a, b) | B(c), d) | B(e) = Y;
| - ^^^^ pattern doesn't bind `a`
@ -112,7 +112,7 @@ LL | let A(A(a, b) | B(c), d) | B(e) = Y;
| variable not in all patterns
error[E0408]: variable `b` is not bound in all patterns
--> $DIR/missing-bindings.rs:46:32
--> $DIR/missing-bindings.rs:48:32
|
LL | let A(A(a, b) | B(c), d) | B(e) = Y;
| - ^^^^ pattern doesn't bind `b`
@ -120,7 +120,7 @@ LL | let A(A(a, b) | B(c), d) | B(e) = Y;
| variable not in all patterns
error[E0408]: variable `c` is not bound in all patterns
--> $DIR/missing-bindings.rs:46:32
--> $DIR/missing-bindings.rs:48:32
|
LL | let A(A(a, b) | B(c), d) | B(e) = Y;
| - ^^^^ pattern doesn't bind `c`
@ -128,7 +128,7 @@ LL | let A(A(a, b) | B(c), d) | B(e) = Y;
| variable not in all patterns
error[E0408]: variable `d` is not bound in all patterns
--> $DIR/missing-bindings.rs:46:32
--> $DIR/missing-bindings.rs:48:32
|
LL | let A(A(a, b) | B(c), d) | B(e) = Y;
| - ^^^^ pattern doesn't bind `d`
@ -136,7 +136,7 @@ LL | let A(A(a, b) | B(c), d) | B(e) = Y;
| variable not in all patterns
error[E0408]: variable `e` is not bound in all patterns
--> $DIR/missing-bindings.rs:46:9
--> $DIR/missing-bindings.rs:48:9
|
LL | let A(A(a, b) | B(c), d) | B(e) = Y;
| ^^^^^^^^^^^^^^^^^^^^ - variable not in all patterns
@ -144,7 +144,7 @@ LL | let A(A(a, b) | B(c), d) | B(e) = Y;
| pattern doesn't bind `e`
error[E0408]: variable `a` is not bound in all patterns
--> $DIR/missing-bindings.rs:62:29
--> $DIR/missing-bindings.rs:64:29
|
LL | Ok(a) | Err(_),
| - ^^^^^^ pattern doesn't bind `a`
@ -152,7 +152,7 @@ LL | Ok(a) | Err(_),
| variable not in all patterns
error[E0408]: variable `a` is not bound in all patterns
--> $DIR/missing-bindings.rs:70:21
--> $DIR/missing-bindings.rs:72:21
|
LL | A(_, a) |
| - variable not in all patterns
@ -160,7 +160,7 @@ LL | B(b),
| ^^^^ pattern doesn't bind `a`
error[E0408]: variable `b` is not bound in all patterns
--> $DIR/missing-bindings.rs:69:21
--> $DIR/missing-bindings.rs:71:21
|
LL | A(_, a) |
| ^^^^^^^ pattern doesn't bind `b`
@ -168,7 +168,7 @@ LL | B(b),
| - variable not in all patterns
error[E0408]: variable `a` is not bound in all patterns
--> $DIR/missing-bindings.rs:73:17
--> $DIR/missing-bindings.rs:75:17
|
LL | A(_, a) |
| - variable not in all patterns
@ -177,7 +177,7 @@ LL | B(_)
| ^^^^ pattern doesn't bind `a`
error[E0408]: variable `b` is not bound in all patterns
--> $DIR/missing-bindings.rs:73:17
--> $DIR/missing-bindings.rs:75:17
|
LL | B(b),
| - variable not in all patterns
@ -186,7 +186,7 @@ LL | B(_)
| ^^^^ pattern doesn't bind `b`
error[E0408]: variable `a` is not bound in all patterns
--> $DIR/missing-bindings.rs:77:13
--> $DIR/missing-bindings.rs:79:13
|
LL | B(Ok(a) | Err(a))
| - variable not in all patterns
@ -198,7 +198,7 @@ LL | V3(c),
| ^^^^^ pattern doesn't bind `a`
error[E0408]: variable `b` is not bound in all patterns
--> $DIR/missing-bindings.rs:58:13
--> $DIR/missing-bindings.rs:60:13
|
LL | / V1(
LL | |
@ -216,7 +216,7 @@ LL | V3(c),
| ^^^^^ pattern doesn't bind `b`
error[E0408]: variable `c` is not bound in all patterns
--> $DIR/missing-bindings.rs:58:13
--> $DIR/missing-bindings.rs:60:13
|
LL | / V1(
LL | |
@ -237,6 +237,14 @@ LL | | ) |
LL | V3(c),
| - variable not in all patterns
warning: the feature `or_patterns` is incomplete and may cause the compiler to crash
--> $DIR/missing-bindings.rs:5:12
|
LL | #![feature(or_patterns)]
| ^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
error: aborting due to 26 previous errors
For more information about this error, try `rustc --explain E0408`.