From 1c4e05ec2f177dd82c85b015f611650430b2f020 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 17 Feb 2018 16:27:17 +0300 Subject: [PATCH] More correct path type --- src/parser/grammar/types.rs | 9 ++- tests/data/parser/inline/0032_path_type.rs | 4 ++ tests/data/parser/inline/0032_path_type.txt | 70 +++++++++++++++++++++ 3 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 tests/data/parser/inline/0032_path_type.rs create mode 100644 tests/data/parser/inline/0032_path_type.txt diff --git a/src/parser/grammar/types.rs b/src/parser/grammar/types.rs index c25517a5149..bcdc3ef9716 100644 --- a/src/parser/grammar/types.rs +++ b/src/parser/grammar/types.rs @@ -10,7 +10,7 @@ pub(super) fn type_(p: &mut Parser) { UNDERSCORE => placeholder_type(p), FN_KW | UNSAFE_KW | EXTERN_KW => fn_pointer_type(p), FOR_KW => for_type(p), - IDENT => path_type(p), + _ if paths::is_path_start(p) => path_type(p), _ => { p.error("expected type"); } @@ -178,8 +178,13 @@ fn for_type(p: &mut Parser) { m.complete(p, FOR_TYPE); } +// test path_type +// type A = Foo; +// type B = ::Foo; +// type C = self::Foo; +// type D = super::Foo; fn path_type(p: &mut Parser) { - assert!(p.at(IDENT)); + assert!(paths::is_path_start(p)); let m = p.start(); paths::type_path(p); m.complete(p, PATH_TYPE); diff --git a/tests/data/parser/inline/0032_path_type.rs b/tests/data/parser/inline/0032_path_type.rs new file mode 100644 index 00000000000..bf94f32e196 --- /dev/null +++ b/tests/data/parser/inline/0032_path_type.rs @@ -0,0 +1,4 @@ +type A = Foo; +type B = ::Foo; +type C = self::Foo; +type D = super::Foo; diff --git a/tests/data/parser/inline/0032_path_type.txt b/tests/data/parser/inline/0032_path_type.txt new file mode 100644 index 00000000000..1441b8c1387 --- /dev/null +++ b/tests/data/parser/inline/0032_path_type.txt @@ -0,0 +1,70 @@ +FILE@[0; 71) + TYPE_ITEM@[0; 14) + TYPE_KW@[0; 4) + NAME@[4; 7) + WHITESPACE@[4; 5) + IDENT@[5; 6) "A" + WHITESPACE@[6; 7) + EQ@[7; 8) + PATH_TYPE@[8; 12) + PATH@[8; 12) + PATH_SEGMENT@[8; 12) + NAME_REF@[8; 12) + WHITESPACE@[8; 9) + IDENT@[9; 12) "Foo" + SEMI@[12; 13) + WHITESPACE@[13; 14) + TYPE_ITEM@[14; 30) + TYPE_KW@[14; 18) + NAME@[18; 21) + WHITESPACE@[18; 19) + IDENT@[19; 20) "B" + WHITESPACE@[20; 21) + EQ@[21; 22) + PATH_TYPE@[22; 28) + PATH@[22; 28) + PATH_SEGMENT@[22; 28) + WHITESPACE@[22; 23) + COLONCOLON@[23; 25) + NAME_REF@[25; 28) + IDENT@[25; 28) "Foo" + SEMI@[28; 29) + WHITESPACE@[29; 30) + TYPE_ITEM@[30; 50) + TYPE_KW@[30; 34) + NAME@[34; 37) + WHITESPACE@[34; 35) + IDENT@[35; 36) "C" + WHITESPACE@[36; 37) + EQ@[37; 38) + PATH_TYPE@[38; 48) + PATH@[38; 48) + PATH@[38; 43) + PATH_SEGMENT@[38; 43) + WHITESPACE@[38; 39) + SELF_KW@[39; 43) + COLONCOLON@[43; 45) + PATH_SEGMENT@[45; 48) + NAME_REF@[45; 48) + IDENT@[45; 48) "Foo" + SEMI@[48; 49) + WHITESPACE@[49; 50) + TYPE_ITEM@[50; 71) + TYPE_KW@[50; 54) + NAME@[54; 57) + WHITESPACE@[54; 55) + IDENT@[55; 56) "D" + WHITESPACE@[56; 57) + EQ@[57; 58) + PATH_TYPE@[58; 69) + PATH@[58; 69) + PATH@[58; 64) + PATH_SEGMENT@[58; 64) + WHITESPACE@[58; 59) + SUPER_KW@[59; 64) + COLONCOLON@[64; 66) + PATH_SEGMENT@[66; 69) + NAME_REF@[66; 69) + IDENT@[66; 69) "Foo" + SEMI@[69; 70) + WHITESPACE@[70; 71)