]> git.lizzy.rs Git - rust.git/commitdiff
parser: fix parsing of macro call inside generic args
authorcynecx <me@cynecx.net>
Wed, 6 Oct 2021 20:10:50 +0000 (22:10 +0200)
committercynecx <me@cynecx.net>
Wed, 6 Oct 2021 20:41:35 +0000 (22:41 +0200)
Cargo.lock
crates/parser/src/grammar/generic_args.rs
crates/syntax/test_data/parser/inline/ok/0194_macro_inside_generic_arg.rast [new file with mode: 0644]
crates/syntax/test_data/parser/inline/ok/0194_macro_inside_generic_arg.rs [new file with mode: 0644]

index 9ad34f71605a57551910fe6f15c733fec9ce5919..e414d39b8d71a38270d834a2d6a641fdd42105dd 100644 (file)
@@ -1761,9 +1761,9 @@ dependencies = [
 
 [[package]]
 name = "ungrammar"
-version = "1.14.5"
+version = "1.14.6"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "395e988af2480b8a8118ad1d5f1f790197d332e3e2585231f742949b63080ef5"
+checksum = "fb1cd6666863b2ff36bab1ced85c4b5e651638705f306f3cfad0a367f85ea715"
 
 [[package]]
 name = "unicase"
index b47912d07d493da2bdf3dc177af3bde583260ceb..1148c6c35c59211c1e92bd52c5d0bdb4e7f56ece 100644 (file)
@@ -32,7 +32,10 @@ fn generic_arg(p: &mut Parser) {
         k if k.is_literal() => const_arg(p),
         // test associated_type_bounds
         // fn print_all<T: Iterator<Item, Item::Item, Item::<true>, Item: Display, Item<'a> = Item>>(printables: T) {}
-        IDENT if [T![<], T![=], T![:]].contains(&p.nth(1)) => {
+
+        // test macro_inside_generic_arg
+        // type A = Foo<syn::Token![_]>;
+        IDENT if [T![<], T![=], T![:]].contains(&p.nth(1)) && !p.nth_at(1, T![::]) => {
             let m = p.start();
             name_ref(p);
             opt_generic_arg_list(p, false);
diff --git a/crates/syntax/test_data/parser/inline/ok/0194_macro_inside_generic_arg.rast b/crates/syntax/test_data/parser/inline/ok/0194_macro_inside_generic_arg.rast
new file mode 100644 (file)
index 0000000..37306ba
--- /dev/null
@@ -0,0 +1,36 @@
+SOURCE_FILE@0..30
+  TYPE_ALIAS@0..29
+    TYPE_KW@0..4 "type"
+    WHITESPACE@4..5 " "
+    NAME@5..6
+      IDENT@5..6 "A"
+    WHITESPACE@6..7 " "
+    EQ@7..8 "="
+    WHITESPACE@8..9 " "
+    PATH_TYPE@9..28
+      PATH@9..28
+        PATH_SEGMENT@9..28
+          NAME_REF@9..12
+            IDENT@9..12 "Foo"
+          GENERIC_ARG_LIST@12..28
+            L_ANGLE@12..13 "<"
+            TYPE_ARG@13..27
+              MACRO_TYPE@13..27
+                MACRO_CALL@13..27
+                  PATH@13..23
+                    PATH@13..16
+                      PATH_SEGMENT@13..16
+                        NAME_REF@13..16
+                          IDENT@13..16 "syn"
+                    COLON2@16..18 "::"
+                    PATH_SEGMENT@18..23
+                      NAME_REF@18..23
+                        IDENT@18..23 "Token"
+                  BANG@23..24 "!"
+                  TOKEN_TREE@24..27
+                    L_BRACK@24..25 "["
+                    UNDERSCORE@25..26 "_"
+                    R_BRACK@26..27 "]"
+            R_ANGLE@27..28 ">"
+    SEMICOLON@28..29 ";"
+  WHITESPACE@29..30 "\n"
diff --git a/crates/syntax/test_data/parser/inline/ok/0194_macro_inside_generic_arg.rs b/crates/syntax/test_data/parser/inline/ok/0194_macro_inside_generic_arg.rs
new file mode 100644 (file)
index 0000000..8d43a53
--- /dev/null
@@ -0,0 +1 @@
+type A = Foo<syn::Token![_]>;