]> git.lizzy.rs Git - rust.git/commitdiff
Enable fall through past $:lifetime matcher
authorDavid Tolnay <dtolnay@gmail.com>
Sun, 10 Jun 2018 21:26:26 +0000 (14:26 -0700)
committerDavid Tolnay <dtolnay@gmail.com>
Sun, 10 Jun 2018 21:39:16 +0000 (14:39 -0700)
src/libsyntax/ext/tt/macro_parser.rs
src/test/compile-fail/macro-non-lifetime.rs
src/test/run-pass/macro-first-set.rs

index b53d94db27eabfb60ebdc3c379033445c17131d1..fe458fa9977a5552f6c1d6f6f9f862dbf614e8df 100644 (file)
@@ -827,6 +827,14 @@ fn may_be_ident(nt: &token::Nonterminal) -> bool {
             Token::Interpolated(ref nt) => may_be_ident(&nt.0),
             _ => false,
         },
+        "lifetime" => match *token {
+            Token::Lifetime(_) => true,
+            Token::Interpolated(ref nt) => match nt.0 {
+                token::NtLifetime(_) | token::NtTT(_) => true,
+                _ => false,
+            },
+            _ => false,
+        },
         _ => match *token {
             token::CloseDelim(_) => false,
             _ => true,
index a2706e83229e5bfdddee3a008f113ef870e2d288..647d7aaa759c31969232fbf5d7a60223e6619c2f 100644 (file)
@@ -16,5 +16,5 @@ macro_rules! m { ($x:lifetime) => { } }
 
 fn main() {
     m!(a);
-    //~^ ERROR expected a lifetime, found `a`
+    //~^ ERROR no rules expected the token `a`
 }
index 99e5d22fb476e9d8b96c13a4bf3fbefdd749ffa2..c371a33257f4e3fe373e81a9b6b78dd232d8d263 100644 (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 ==========================================================
 
 macro_rules! test_block {
@@ -234,6 +268,14 @@ macro_rules! test_meta_block {
 
 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() {
@@ -241,5 +283,6 @@ fn main() {
     test_40569();
     test_35650();
     test_24189();
+    test_51477();
 }