Skip to content

Commit 22a08f9

Browse files
committed
update tests
1 parent 243ae7d commit 22a08f9

File tree

3 files changed

+104
-30
lines changed

3 files changed

+104
-30
lines changed
Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
1-
// run-pass
2-
31
//#![feature(or_patterns)]
42

5-
macro_rules! foo {
6-
($orpat:pat, $val:expr) => {
7-
match $val {
8-
x @ ($orpat) => x,
9-
_ => 0xDEADBEEF,
10-
}
11-
};
12-
($nonor:pat | $val:expr, 3) => {
13-
match $val {
14-
x @ ($orpat) => x,
15-
_ => 0xDEADBEEF,
16-
}
17-
};
18-
}
19-
203
macro_rules! bar {
214
($nonor:pat |) => {};
225
}
@@ -26,15 +9,16 @@ macro_rules! baz {
269
}
2710

2811
fn main() {
29-
// Test ambiguity.
30-
foo!(1 | 2, 3); //~ERROR: multiple matchers
31-
3212
// Leading vert not allowed in pat<no_top_alt>
33-
bar!(1 | 2 | 3 |); // ok
3413
bar!(|1| 2 | 3 |); //~ERROR: no rules expected
35-
bar!(1 | 2 | 3); //~ERROR: unexpected end
14+
15+
// Top-level or-patterns not allowed in pat<no_top_alt>
16+
bar!(1 | 2 | 3 |); //~ERROR: no rules expected
17+
bar!(1 | 2 | 3); //~ERROR: no rules expected
18+
bar!((1 | 2 | 3)); //~ERROR: unexpected end
19+
bar!((1 | 2 | 3) |); // ok
3620

3721
baz!(1 | 2 | 3); // ok
3822
baz!(|1| 2 | 3); // ok
39-
baz!(|1| 2 | 3 |); //~ERROR: no rules expected
23+
baz!(|1| 2 | 3 |); //~ERROR: expected pattern
4024
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
error: no rules expected the token `|`
2+
--> $DIR/or-pattern-macro-pat-fallback.rs:13:10
3+
|
4+
LL | macro_rules! bar {
5+
| ---------------- when calling this macro
6+
...
7+
LL | bar!(|1| 2 | 3 |);
8+
| ^ no rules expected this token in macro call
9+
10+
error: no rules expected the token `2`
11+
--> $DIR/or-pattern-macro-pat-fallback.rs:16:14
12+
|
13+
LL | macro_rules! bar {
14+
| ---------------- when calling this macro
15+
...
16+
LL | bar!(1 | 2 | 3 |);
17+
| ^ no rules expected this token in macro call
18+
19+
error: no rules expected the token `2`
20+
--> $DIR/or-pattern-macro-pat-fallback.rs:17:14
21+
|
22+
LL | macro_rules! bar {
23+
| ---------------- when calling this macro
24+
...
25+
LL | bar!(1 | 2 | 3);
26+
| ^ no rules expected this token in macro call
27+
28+
error: unexpected end of macro invocation
29+
--> $DIR/or-pattern-macro-pat-fallback.rs:18:21
30+
|
31+
LL | macro_rules! bar {
32+
| ---------------- when calling this macro
33+
...
34+
LL | bar!((1 | 2 | 3));
35+
| ^ missing tokens in macro arguments
36+
37+
error: expected pattern, found `<eof>`
38+
--> $DIR/or-pattern-macro-pat-fallback.rs:23:20
39+
|
40+
LL | ($nonor:pat) => {};
41+
| ---------- while parsing argument for this `pat` macro fragment
42+
...
43+
LL | baz!(|1| 2 | 3 |);
44+
| - ^ expected pattern
45+
| |
46+
| while parsing this or-pattern starting here
47+
48+
error: aborting due to 5 previous errors
49+

src/test/ui/pattern/or-pattern-macro-pat.rs

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ macro_rules! foo {
1616
($orpat:pat, $val:expr) => {
1717
match $val {
1818
x @ ($orpat) => x, // leading vert would not be allowed in $orpat
19-
_ => B(0xDEADBEEF),
19+
_ => B(0xDEADBEEFu64),
2020
}
2121
};
2222
}
@@ -25,16 +25,16 @@ macro_rules! bar {
2525
($orpat:pat, $val:expr) => {
2626
match $val {
2727
$orpat => 42, // leading vert allowed here
28-
_ => 0xDEADBEEF,
28+
_ => 0xDEADBEEFu64,
2929
}
3030
};
3131
}
3232

3333
macro_rules! quux {
3434
($orpat1:pat | $orpat2:pat, $val:expr) => {
3535
match $val {
36-
x @ ($orpat1) => x,
37-
_ => B(0xDEADBEEF),
36+
$orpat1 => $val,
37+
_ => B(0xDEADBEEFu64),
3838
}
3939
};
4040
}
@@ -43,13 +43,46 @@ macro_rules! baz {
4343
($orpat:pat, $val:expr) => {
4444
match $val {
4545
$orpat => 42,
46-
_ => 0xDEADBEEF,
46+
_ => 0xDEADBEEFu64,
4747
}
4848
};
4949
($nonor:pat | $val:expr, C) => {
5050
match $val {
5151
x @ ($orpat) => x,
52-
_ => 0xDEADBEEF,
52+
_ => 0xDEADBEEFu64,
53+
}
54+
};
55+
}
56+
57+
macro_rules! foo2a {
58+
($orpat:pat, $val:expr) => {
59+
match $val {
60+
x @ ($orpat) => x,
61+
_ => 0xDEADBEEFu64,
62+
}
63+
};
64+
}
65+
66+
macro_rules! foo2b {
67+
($nonor:pat | $val:expr, 2) => {
68+
match $val {
69+
x @ $nonor => x,
70+
_ => 0xDEADBEEFu64,
71+
}
72+
};
73+
}
74+
75+
macro_rules! foo2 {
76+
($orpat:pat, $val:expr) => {
77+
match $val {
78+
x @ ($orpat) => x,
79+
_ => 0xDEADBEEFu64,
80+
}
81+
};
82+
($nonor:pat | $val:expr, 2) => {
83+
match $val {
84+
x @ $nonor => x,
85+
_ => 0xDEADBEEFu64,
5386
}
5487
};
5588
}
@@ -69,5 +102,13 @@ fn main() {
69102

70103
// Or-separator fallback.
71104
let y = quux!(C | D, D);
72-
assert_eq!(y, B(0xDEADBEEF));
105+
assert_eq!(y, B(0xDEADBEEFu64));
106+
107+
// Test tricky ambiguous case.
108+
let y = foo2a!(1 | 2, 2);
109+
assert_eq!(y, 2);
110+
let y = foo2b!(1 | 2, 2);
111+
assert_eq!(y, 0xDEADBEEFu64);
112+
let y = foo2!(1 | 2, 2);
113+
assert_eq!(y, 2);
73114
}

0 commit comments

Comments
 (0)