Rollup merge of #54977 - estebank:macro-arg-parse, r=pnkfelix
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.
This commit is contained in:
@@ -905,7 +905,8 @@ fn is_in_follow(tok: "ed::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)
|
||||
},
|
||||
|
||||
16
src/test/run-pass/macros/issue-25274.rs
Normal file
16
src/test/run-pass/macros/issue-25274.rs
Normal file
@@ -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());
|
||||
}
|
||||
Reference in New Issue
Block a user