Skip to content

Commit c77a0cf

Browse files
committed
Accept Option<Box<$t:ty>> in macro argument
Given the following code, compile successfuly: ``` macro_rules! test { ( fn fun() -> Option<Box<$t:ty>>; ) => { fn fun(x: $t) -> Option<Box<$t>> { Some(Box::new(x)) } } } test! { fn fun() -> Option<Box<i32>>; } ```
1 parent e1041c6 commit c77a0cf

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/libsyntax/ext/tt/macro_rules.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,8 @@ fn is_in_follow(tok: &quoted::TokenTree, frag: &str) -> Result<bool, (String, &'
902902
"path" | "ty" => match *tok {
903903
TokenTree::Token(_, ref tok) => match *tok {
904904
OpenDelim(token::DelimToken::Brace) | OpenDelim(token::DelimToken::Bracket) |
905-
Comma | FatArrow | Colon | Eq | Gt | Semi | BinOp(token::Or) => Ok(true),
905+
Comma | FatArrow | Colon | Eq | Gt | BinOp(token::Shr) | Semi |
906+
BinOp(token::Or) => Ok(true),
906907
Ident(i, false) if i.name == "as" || i.name == "where" => Ok(true),
907908
_ => Ok(false)
908909
},
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
macro_rules! test {
2+
(
3+
fn fun() -> Option<Box<$t:ty>>;
4+
) => {
5+
fn fun(x: $t) -> Option<Box<$t>>
6+
{ Some(Box::new(x)) }
7+
}
8+
}
9+
10+
test! {
11+
fn fun() -> Option<Box<i32>>;
12+
}
13+
14+
fn main() {
15+
println!("{}", fun(0).unwrap());
16+
}

0 commit comments

Comments
 (0)