Skip to content

Commit

Permalink
Auto merge of #54977 - estebank:macro-arg-parse, r=<try>
Browse files Browse the repository at this point in the history
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>>;
}
```

Fix #25274.
  • Loading branch information
bors committed Oct 10, 2018
2 parents 5af0bb8 + c77a0cf commit 4021bd0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/libsyntax/ext/tt/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,8 @@ fn is_in_follow(tok: &quoted::TokenTree, frag: &str) -> Result<bool, (String, &'
"path" | "ty" => match *tok {
TokenTree::Token(_, ref tok) => match *tok {
OpenDelim(token::DelimToken::Brace) | OpenDelim(token::DelimToken::Bracket) |
Comma | FatArrow | Colon | Eq | Gt | Semi | BinOp(token::Or) => Ok(true),
Comma | FatArrow | Colon | Eq | Gt | BinOp(token::Shr) | Semi |
BinOp(token::Or) => Ok(true),
Ident(i, false) if i.name == "as" || i.name == "where" => Ok(true),
_ => Ok(false)
},
Expand Down
16 changes: 16 additions & 0 deletions src/test/run-pass/macros/issue-25274.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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>>;
}

fn main() {
println!("{}", fun(0).unwrap());
}

0 comments on commit 4021bd0

Please sign in to comment.