Skip to content

Commit dbe6873

Browse files
committed
resolve: test consistent or-patterns being allowed.
1 parent aa7a02b commit dbe6873

8 files changed

+132
-38
lines changed

src/test/ui/or-patterns/already-bound-name.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// This test ensures that the "already bound identifier in a product pattern"
22
// correctly accounts for or-patterns.
33

4-
#![allow(warnings)]
54
#![feature(or_patterns)]
5+
//~^ WARN the feature `or_patterns` is incomplete
66

77
enum E<T> { A(T, T), B(T) }
88

src/test/ui/or-patterns/already-bound-name.stderr

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ error[E0416]: identifier `a` is bound more than once in the same pattern
8282
LL | let B(A(a, _) | B(a)) | A(A(a, _) | B(a), A(a, _) | B(a)) = B(B(1));
8383
| ^ used in a pattern more than once
8484

85+
warning: the feature `or_patterns` is incomplete and may cause the compiler to crash
86+
--> $DIR/already-bound-name.rs:4:12
87+
|
88+
LL | #![feature(or_patterns)]
89+
| ^^^^^^^^^^^
90+
|
91+
= note: `#[warn(incomplete_features)]` on by default
92+
8593
error[E0308]: mismatched types
8694
--> $DIR/already-bound-name.rs:33:31
8795
|
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Check that or-patterns with consistent bindings across arms are allowed.
2+
3+
// edition:2018
4+
5+
#![feature(or_patterns)]
6+
//~^ WARN the feature `or_patterns` is incomplete
7+
8+
fn main() {
9+
// One level:
10+
let Ok(a) | Err(a) = Ok(0);
11+
let Ok(ref a) | Err(ref a) = Ok(0);
12+
let Ok(ref mut a) | Err(ref mut a) = Ok(0);
13+
14+
// Two levels:
15+
enum Tri<S, T, U> { V1(S), V2(T), V3(U) }
16+
use Tri::*;
17+
18+
let Ok((V1(a) | V2(a) | V3(a), b)) | Err(Ok((a, b)) | Err((a, b)))
19+
: Result<_, Result<_, _>>
20+
= Ok((V1(1), 1));
21+
22+
let Ok((V1(a) | V2(a) | V3(a), ref b)) | Err(Ok((a, ref b)) | Err((a, ref b)))
23+
: Result<_, Result<_, _>>
24+
= Ok((V1(1), 1));
25+
26+
// Three levels:
27+
let (
28+
a,
29+
Err((ref mut b, ref c, d)) |
30+
Ok((
31+
Ok(
32+
V1((ref c, d)) |
33+
V2((d, ref c)) |
34+
V3((ref c, Ok((_, d)) | Err((d, _))))
35+
) |
36+
Err((ref c, d)),
37+
ref mut b
38+
))
39+
) =
40+
(1, Ok((Ok(V3((1, Ok((1, 1))))), 1)));
41+
42+
// FIXME(or_patterns; Centril | dlrobertson): remove this line below and
43+
// change this test to check-pass once MIR can handle or-patterns with bindings.
44+
let () = 0;
45+
//~^ ERROR mismatched types
46+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
warning: the feature `or_patterns` is incomplete and may cause the compiler to crash
2+
--> $DIR/consistent-bindings.rs:5:12
3+
|
4+
LL | #![feature(or_patterns)]
5+
| ^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
9+
error[E0308]: mismatched types
10+
--> $DIR/consistent-bindings.rs:44:9
11+
|
12+
LL | let () = 0;
13+
| ^^ expected integer, found ()
14+
|
15+
= note: expected type `{integer}`
16+
found type `()`
17+
18+
error: aborting due to previous error
19+
20+
For more information about this error, try `rustc --explain E0308`.

src/test/ui/or-patterns/inconsistent-modes.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// This test ensures that or patterns require binding mode consistency across arms.
22

33
#![feature(or_patterns)]
4-
#![allow(incomplete_features, non_camel_case_types)]
4+
//~^ WARN the feature `or_patterns` is incomplete
5+
6+
#![allow(non_camel_case_types)]
57
fn main() {
68
// One level:
79
let Ok(a) | Err(ref a): Result<&u8, u8> = Ok(&0);

src/test/ui/or-patterns/inconsistent-modes.stderr

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,63 @@
11
error[E0409]: variable `a` is bound in inconsistent ways within the same match arm
2-
--> $DIR/inconsistent-modes.rs:7:25
2+
--> $DIR/inconsistent-modes.rs:9:25
33
|
44
LL | let Ok(a) | Err(ref a): Result<&u8, u8> = Ok(&0);
55
| - ^ bound in different ways
66
| |
77
| first binding
88

99
error[E0409]: variable `a` is bound in inconsistent ways within the same match arm
10-
--> $DIR/inconsistent-modes.rs:9:29
10+
--> $DIR/inconsistent-modes.rs:11:29
1111
|
1212
LL | let Ok(ref mut a) | Err(a): Result<u8, &mut u8> = Ok(0);
1313
| - ^ bound in different ways
1414
| |
1515
| first binding
1616

1717
error[E0409]: variable `a` is bound in inconsistent ways within the same match arm
18-
--> $DIR/inconsistent-modes.rs:11:33
18+
--> $DIR/inconsistent-modes.rs:13:33
1919
|
2020
LL | let Ok(ref a) | Err(ref mut a): Result<&u8, &mut u8> = Ok(&0);
2121
| - first binding ^ bound in different ways
2222

2323
error[E0409]: variable `a` is bound in inconsistent ways within the same match arm
24-
--> $DIR/inconsistent-modes.rs:14:39
24+
--> $DIR/inconsistent-modes.rs:16:39
2525
|
2626
LL | let Ok((ref a, b)) | Err((ref mut a, ref b)) = Ok((0, &0));
2727
| - first binding ^ bound in different ways
2828

2929
error[E0409]: variable `b` is bound in inconsistent ways within the same match arm
30-
--> $DIR/inconsistent-modes.rs:14:46
30+
--> $DIR/inconsistent-modes.rs:16:46
3131
|
3232
LL | let Ok((ref a, b)) | Err((ref mut a, ref b)) = Ok((0, &0));
3333
| - first binding ^ bound in different ways
3434

3535
error[E0409]: variable `a` is bound in inconsistent ways within the same match arm
36-
--> $DIR/inconsistent-modes.rs:20:38
36+
--> $DIR/inconsistent-modes.rs:22:38
3737
|
3838
LL | let Ok(Ok(a) | Err(a)) | Err(ref a) = Err(0);
3939
| - ^ bound in different ways
4040
| |
4141
| first binding
4242

4343
error[E0409]: variable `a` is bound in inconsistent ways within the same match arm
44-
--> $DIR/inconsistent-modes.rs:24:34
44+
--> $DIR/inconsistent-modes.rs:26:34
4545
|
4646
LL | let Ok([ Ok((Ok(ref a) | Err(a),)) | Err(a) ]) | Err(a) = Err(&1);
4747
| - ^ bound in different ways
4848
| |
4949
| first binding
5050

51+
warning: the feature `or_patterns` is incomplete and may cause the compiler to crash
52+
--> $DIR/inconsistent-modes.rs:3:12
53+
|
54+
LL | #![feature(or_patterns)]
55+
| ^^^^^^^^^^^
56+
|
57+
= note: `#[warn(incomplete_features)]` on by default
58+
5159
error[E0308]: mismatched types
52-
--> $DIR/inconsistent-modes.rs:11:25
60+
--> $DIR/inconsistent-modes.rs:13:25
5361
|
5462
LL | let Ok(ref a) | Err(ref mut a): Result<&u8, &mut u8> = Ok(&0);
5563
| ^^^^^^^^^ types differ in mutability
@@ -58,7 +66,7 @@ LL | let Ok(ref a) | Err(ref mut a): Result<&u8, &mut u8> = Ok(&0);
5866
found type `&mut &mut u8`
5967

6068
error[E0308]: mismatched types
61-
--> $DIR/inconsistent-modes.rs:14:31
69+
--> $DIR/inconsistent-modes.rs:16:31
6270
|
6371
LL | let Ok((ref a, b)) | Err((ref mut a, ref b)) = Ok((0, &0));
6472
| ^^^^^^^^^ types differ in mutability

src/test/ui/or-patterns/missing-bindings.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
// edition:2018
44

55
#![feature(or_patterns)]
6-
#![allow(incomplete_features, non_camel_case_types)]
6+
//~^ WARN the feature `or_patterns` is incomplete
7+
8+
#![allow(non_camel_case_types)]
79

810
fn main() {}
911

0 commit comments

Comments
 (0)