Skip to content

Commit 5c4af97

Browse files
author
Keegan McAllister
committed
---
yaml --- r: 114564 b: refs/heads/master c: fd40d0c h: refs/heads/master v: v3
1 parent 259c63d commit 5c4af97

File tree

4 files changed

+102
-1
lines changed

4 files changed

+102
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 55776f28221e3da7dd31c2c6c5e05f7a9a31381f
2+
refs/heads/master: fd40d0cf5b873ebc94b64fb1abcf2e14fd38dcf7
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: ec0258a381b88b5574e3f8ce72ae553ac3a574b7
55
refs/heads/try: 7c6c492fb2af9a85f21ff952942df3523b22fd17

trunk/src/test/compile-fail/macro-incomplete-parse.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,16 @@ macro_rules! ignored_expr {
2222
() => ( 1, 2 ) //~ ERROR macro expansion ignores token `,`
2323
}
2424

25+
macro_rules! ignored_pat {
26+
() => ( 1, 2 ) //~ ERROR macro expansion ignores token `,`
27+
}
28+
2529
ignored_item!()
2630

2731
fn main() {
2832
ignored_expr!()
33+
match 1 {
34+
ignored_pat!() => (),
35+
_ => (),
36+
}
2937
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(macro_rules)]
12+
13+
macro_rules! foo ( () => ( x ) )
14+
15+
fn main() {
16+
let foo!() = 2;
17+
x + 1; //~ ERROR unresolved name `x`
18+
}

trunk/src/test/run-pass/macro-pat.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(macro_rules)]
12+
13+
macro_rules! mypat(
14+
() => (
15+
Some('y')
16+
)
17+
)
18+
19+
macro_rules! char_x(
20+
() => (
21+
'x'
22+
)
23+
)
24+
25+
macro_rules! some(
26+
($x:pat) => (
27+
Some($x)
28+
)
29+
)
30+
31+
macro_rules! indirect(
32+
() => (
33+
some!(char_x!())
34+
)
35+
)
36+
37+
macro_rules! ident_pat(
38+
($x:ident) => (
39+
$x
40+
)
41+
)
42+
43+
fn f(c: Option<char>) -> uint {
44+
match c {
45+
Some('x') => 1,
46+
mypat!() => 2,
47+
_ => 3,
48+
}
49+
}
50+
51+
pub fn main() {
52+
assert_eq!(1, f(Some('x')));
53+
assert_eq!(2, f(Some('y')));
54+
assert_eq!(3, f(None));
55+
56+
assert_eq!(1, match Some('x') {
57+
Some(char_x!()) => 1,
58+
_ => 2,
59+
});
60+
61+
assert_eq!(1, match Some('x') {
62+
some!(char_x!()) => 1,
63+
_ => 2,
64+
});
65+
66+
assert_eq!(1, match Some('x') {
67+
indirect!() => 1,
68+
_ => 2,
69+
});
70+
71+
assert_eq!(3, {
72+
let ident_pat!(x) = 2;
73+
x+1
74+
});
75+
}

0 commit comments

Comments
 (0)