Enable fall through past $:lifetime matcher

This commit is contained in:
David Tolnay 2018-06-10 14:26:26 -07:00
parent cabb679bf1
commit 987020846c
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82
3 changed files with 52 additions and 1 deletions

View file

@ -827,6 +827,14 @@ fn may_begin_with(name: &str, token: &Token) -> bool {
Token::Interpolated(ref nt) => may_be_ident(&nt.0), Token::Interpolated(ref nt) => may_be_ident(&nt.0),
_ => false, _ => false,
}, },
"lifetime" => match *token {
Token::Lifetime(_) => true,
Token::Interpolated(ref nt) => match nt.0 {
token::NtLifetime(_) | token::NtTT(_) => true,
_ => false,
},
_ => false,
},
_ => match *token { _ => match *token {
token::CloseDelim(_) => false, token::CloseDelim(_) => false,
_ => true, _ => true,

View file

@ -16,5 +16,5 @@ macro_rules! m { ($x:lifetime) => { } }
fn main() { fn main() {
m!(a); m!(a);
//~^ ERROR expected a lifetime, found `a` //~^ ERROR no rules expected the token `a`
} }

View file

@ -199,6 +199,40 @@ fn test_24189() {
//}}} //}}}
//{{{ issue 50903 ==============================================================
macro_rules! foo_50903 {
($($lif:lifetime ,)* #) => {};
}
foo_50903!('a, 'b, #);
foo_50903!('a, #);
foo_50903!(#);
//}}}
//{{{ issue 51477 ==============================================================
macro_rules! foo_51477 {
($lifetime:lifetime) => {
"last token is lifetime"
};
($other:tt) => {
"last token is other"
};
($first:tt $($rest:tt)*) => {
foo_51477!($($rest)*)
};
}
fn test_51477() {
assert_eq!("last token is lifetime", foo_51477!('a));
assert_eq!("last token is other", foo_51477!(@));
assert_eq!("last token is lifetime", foo_51477!(@ {} 'a));
}
//}}}
//{{{ some more tests ========================================================== //{{{ some more tests ==========================================================
macro_rules! test_block { macro_rules! test_block {
@ -234,6 +268,14 @@ macro_rules! test_meta_block {
test_meta_block!(windows {}); test_meta_block!(windows {});
macro_rules! test_lifetime {
(1. $($l:lifetime)* $($b:block)*) => {};
(2. $($b:block)* $($l:lifetime)*) => {};
}
test_lifetime!(1. 'a 'b {} {});
test_lifetime!(2. {} {} 'a 'b);
//}}} //}}}
fn main() { fn main() {
@ -241,5 +283,6 @@ fn main() {
test_40569(); test_40569();
test_35650(); test_35650();
test_24189(); test_24189();
test_51477();
} }