Skip to content

Commit aa7a02b

Browse files
committed
resolve: test binding mode consistency for or-patterns.
1 parent 33317c7 commit aa7a02b

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// This test ensures that or patterns require binding mode consistency across arms.
2+
3+
#![feature(or_patterns)]
4+
#![allow(incomplete_features, non_camel_case_types)]
5+
fn main() {
6+
// One level:
7+
let Ok(a) | Err(ref a): Result<&u8, u8> = Ok(&0);
8+
//~^ ERROR variable `a` is bound in inconsistent ways
9+
let Ok(ref mut a) | Err(a): Result<u8, &mut u8> = Ok(0);
10+
//~^ ERROR variable `a` is bound in inconsistent ways
11+
let Ok(ref a) | Err(ref mut a): Result<&u8, &mut u8> = Ok(&0);
12+
//~^ ERROR variable `a` is bound in inconsistent ways
13+
//~| ERROR mismatched types
14+
let Ok((ref a, b)) | Err((ref mut a, ref b)) = Ok((0, &0));
15+
//~^ ERROR variable `a` is bound in inconsistent ways
16+
//~| ERROR variable `b` is bound in inconsistent ways
17+
//~| ERROR mismatched types
18+
19+
// Two levels:
20+
let Ok(Ok(a) | Err(a)) | Err(ref a) = Err(0);
21+
//~^ ERROR variable `a` is bound in inconsistent ways
22+
23+
// Three levels:
24+
let Ok([ Ok((Ok(ref a) | Err(a),)) | Err(a) ]) | Err(a) = Err(&1);
25+
//~^ ERROR variable `a` is bound in inconsistent ways
26+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
error[E0409]: variable `a` is bound in inconsistent ways within the same match arm
2+
--> $DIR/inconsistent-modes.rs:7:25
3+
|
4+
LL | let Ok(a) | Err(ref a): Result<&u8, u8> = Ok(&0);
5+
| - ^ bound in different ways
6+
| |
7+
| first binding
8+
9+
error[E0409]: variable `a` is bound in inconsistent ways within the same match arm
10+
--> $DIR/inconsistent-modes.rs:9:29
11+
|
12+
LL | let Ok(ref mut a) | Err(a): Result<u8, &mut u8> = Ok(0);
13+
| - ^ bound in different ways
14+
| |
15+
| first binding
16+
17+
error[E0409]: variable `a` is bound in inconsistent ways within the same match arm
18+
--> $DIR/inconsistent-modes.rs:11:33
19+
|
20+
LL | let Ok(ref a) | Err(ref mut a): Result<&u8, &mut u8> = Ok(&0);
21+
| - first binding ^ bound in different ways
22+
23+
error[E0409]: variable `a` is bound in inconsistent ways within the same match arm
24+
--> $DIR/inconsistent-modes.rs:14:39
25+
|
26+
LL | let Ok((ref a, b)) | Err((ref mut a, ref b)) = Ok((0, &0));
27+
| - first binding ^ bound in different ways
28+
29+
error[E0409]: variable `b` is bound in inconsistent ways within the same match arm
30+
--> $DIR/inconsistent-modes.rs:14:46
31+
|
32+
LL | let Ok((ref a, b)) | Err((ref mut a, ref b)) = Ok((0, &0));
33+
| - first binding ^ bound in different ways
34+
35+
error[E0409]: variable `a` is bound in inconsistent ways within the same match arm
36+
--> $DIR/inconsistent-modes.rs:20:38
37+
|
38+
LL | let Ok(Ok(a) | Err(a)) | Err(ref a) = Err(0);
39+
| - ^ bound in different ways
40+
| |
41+
| first binding
42+
43+
error[E0409]: variable `a` is bound in inconsistent ways within the same match arm
44+
--> $DIR/inconsistent-modes.rs:24:34
45+
|
46+
LL | let Ok([ Ok((Ok(ref a) | Err(a),)) | Err(a) ]) | Err(a) = Err(&1);
47+
| - ^ bound in different ways
48+
| |
49+
| first binding
50+
51+
error[E0308]: mismatched types
52+
--> $DIR/inconsistent-modes.rs:11:25
53+
|
54+
LL | let Ok(ref a) | Err(ref mut a): Result<&u8, &mut u8> = Ok(&0);
55+
| ^^^^^^^^^ types differ in mutability
56+
|
57+
= note: expected type `&&u8`
58+
found type `&mut &mut u8`
59+
60+
error[E0308]: mismatched types
61+
--> $DIR/inconsistent-modes.rs:14:31
62+
|
63+
LL | let Ok((ref a, b)) | Err((ref mut a, ref b)) = Ok((0, &0));
64+
| ^^^^^^^^^ types differ in mutability
65+
|
66+
= note: expected type `&{integer}`
67+
found type `&mut _`
68+
69+
error: aborting due to 9 previous errors
70+
71+
Some errors have detailed explanations: E0308, E0409.
72+
For more information about an error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)