]> git.lizzy.rs Git - rust.git/commitdiff
Make attrs be a child of the let statement
authorDJMcNab <36049421+DJMcNab@users.noreply.github.com>
Sat, 26 Jan 2019 22:02:23 +0000 (22:02 +0000)
committerDJMcNab <36049421+DJMcNab@users.noreply.github.com>
Sat, 26 Jan 2019 22:02:23 +0000 (22:02 +0000)
crates/ra_syntax/src/grammar/expressions.rs
crates/ra_syntax/src/grammar/items.rs
crates/ra_syntax/tests/data/parser/ok/0044_let_attrs.txt

index 0b2f7b11695b2048f817dc5a5d53c025accd280e..8dd9587d0135298ab96569a97c43e28c5bb579ca 100644 (file)
@@ -45,7 +45,10 @@ pub(crate) fn block(p: &mut Parser) {
 
     while !p.at(EOF) && !p.at(R_CURLY) {
         match p.current() {
-            LET_KW => let_stmt(p),
+            LET_KW => {
+                let m = p.start();
+                let_stmt(p, m)
+            }
             // test nocontentexpr
             // fn foo(){
             //     ;;;some_expr();;;;{;;;};;;;Ok(())
@@ -54,8 +57,9 @@ pub(crate) fn block(p: &mut Parser) {
             _ => {
                 // test block_items
                 // fn a() { fn b() {} }
-                let has_attrs = p.at(POUND);
                 let m = p.start();
+                let has_attrs = p.at(POUND);
+                attributes::outer_attributes(p);
                 match items::maybe_item(p, items::ItemFlavor::Mod) {
                     items::MaybeItem::Item(kind) => {
                         m.complete(p, kind);
@@ -68,10 +72,10 @@ pub(crate) fn block(p: &mut Parser) {
                     // fn foo() { pub 92; } //FIXME
                     items::MaybeItem::None => {
                         if has_attrs {
-                            m.abandon(p);
                             if p.at(LET_KW) {
-                                let_stmt(p);
+                                let_stmt(p, m);
                             } else {
+                                m.abandon(p);
                                 p.error("expected a let statement");
                             }
                         } else {
@@ -116,9 +120,8 @@ pub(crate) fn block(p: &mut Parser) {
     //     let c = 92;
     //     let d: i32 = 92;
     // }
-    fn let_stmt(p: &mut Parser) {
+    fn let_stmt(p: &mut Parser, m: Marker) {
         assert!(p.at(LET_KW));
-        let m = p.start();
         p.bump();
         patterns::pattern(p);
         if p.at(COLON) {
index 265e84570d519469a20a10315a0ac1db414fd02a..18039cd3f8daa3b22ac0efd53a38ba0eef9ee152 100644 (file)
@@ -36,6 +36,7 @@ pub(super) enum ItemFlavor {
 
 pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemFlavor) {
     let m = p.start();
+    attributes::outer_attributes(p);
     match maybe_item(p, flavor) {
         MaybeItem::Item(kind) => {
             m.complete(p, kind);
@@ -79,7 +80,6 @@ pub(super) enum MaybeItem {
 }
 
 pub(super) fn maybe_item(p: &mut Parser, flavor: ItemFlavor) -> MaybeItem {
-    attributes::outer_attributes(p);
     opt_visibility(p);
     if let Some(kind) = items_without_modifiers(p) {
         return MaybeItem::Item(kind);
index b3f37dd96fc002eccd9ab932fcc707031da5811e..1f52f699b3fd84a0639c6026f5c121daf3e026a4 100644 (file)
@@ -13,22 +13,22 @@ SOURCE_FILE@[0; 166)
     BLOCK@[71; 165)
       L_CURLY@[71; 72)
       WHITESPACE@[72; 77)
-      ATTR@[77; 106)
-        POUND@[77; 78)
-        TOKEN_TREE@[78; 106)
-          L_BRACK@[78; 79)
-          IDENT@[79; 82) "cfg"
-          TOKEN_TREE@[82; 105)
-            L_PAREN@[82; 83)
-            IDENT@[83; 90) "feature"
-            WHITESPACE@[90; 91)
-            EQ@[91; 92)
-            WHITESPACE@[92; 93)
-            STRING@[93; 104)
-            R_PAREN@[104; 105)
-          R_BRACK@[105; 106)
-      WHITESPACE@[106; 111)
-      LET_STMT@[111; 163)
+      LET_STMT@[77; 163)
+        ATTR@[77; 106)
+          POUND@[77; 78)
+          TOKEN_TREE@[78; 106)
+            L_BRACK@[78; 79)
+            IDENT@[79; 82) "cfg"
+            TOKEN_TREE@[82; 105)
+              L_PAREN@[82; 83)
+              IDENT@[83; 90) "feature"
+              WHITESPACE@[90; 91)
+              EQ@[91; 92)
+              WHITESPACE@[92; 93)
+              STRING@[93; 104)
+              R_PAREN@[104; 105)
+            R_BRACK@[105; 106)
+        WHITESPACE@[106; 111)
         LET_KW@[111; 114)
         WHITESPACE@[114; 115)
         BIND_PAT@[115; 124)