]> git.lizzy.rs Git - rust.git/blobdiff - crates/parser/src/grammar/items.rs
Wrap remaining self/super/crate in Name{Ref}
[rust.git] / crates / parser / src / grammar / items.rs
index 8999829b437fa9e029d433d258eb000751f40527..1d894e907be280a3d3afcdf09072e01634a044ec 100644 (file)
@@ -27,19 +27,19 @@ pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) {
 }
 
 pub(super) const ITEM_RECOVERY_SET: TokenSet = TokenSet::new(&[
-    FN_KW,
-    STRUCT_KW,
-    ENUM_KW,
-    IMPL_KW,
-    TRAIT_KW,
-    CONST_KW,
-    STATIC_KW,
-    LET_KW,
-    MOD_KW,
-    PUB_KW,
-    CRATE_KW,
-    USE_KW,
-    MACRO_KW,
+    T![fn],
+    T![struct],
+    T![enum],
+    T![impl],
+    T![trait],
+    T![const],
+    T![static],
+    T![let],
+    T![mod],
+    T![pub],
+    T![crate],
+    T![use],
+    T![macro],
     T![;],
 ]);
 
@@ -96,7 +96,10 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> {
     let mut has_mods = false;
 
     // modifiers
-    has_mods |= p.eat(T![const]);
+    if p.at(T![const]) && p.nth(1) != T!['{'] {
+        p.eat(T![const]);
+        has_mods = true;
+    }
 
     // test_err async_without_semicolon
     // fn foo() { let _ = async {} }
@@ -167,7 +170,7 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> {
             m.complete(p, TRAIT);
         }
 
-        T![const] => {
+        T![const] if p.nth(1) != T!['{'] => {
             consts::konst(p, m);
         }
 
@@ -267,7 +270,9 @@ fn extern_crate(p: &mut Parser, m: Marker) {
     p.bump(T![crate]);
 
     if p.at(T![self]) {
+        let m = p.start();
         p.bump(T![self]);
+        m.complete(p, NAME_REF);
     } else {
         name_ref(p);
     }
@@ -386,10 +391,15 @@ fn macro_rules(p: &mut Parser, m: Marker) {
     }
 
     match p.current() {
-        T!['{'] => {
+        // test macro_rules_non_brace
+        // macro_rules! m ( ($i:ident) => {} );
+        // macro_rules! m [ ($i:ident) => {} ];
+        T!['['] | T!['('] => {
             token_tree(p);
+            p.expect(T![;]);
         }
-        _ => p.error("expected `{`"),
+        T!['{'] => token_tree(p),
+        _ => p.error("expected `{`, `[`, `(`"),
     }
     m.complete(p, MACRO_RULES);
 }