From 0af727da91e7ff3c8ed5518cb7e005e8d4f939b0 Mon Sep 17 00:00:00 2001 From: John Renner Date: Mon, 27 Apr 2020 10:02:47 -0700 Subject: Validate the location of `crate` in paths --- .../parser/err/0040_illegal_crate_kw_location.rast | 76 ++++++++++++++++++++++ .../parser/err/0040_illegal_crate_kw_location.rs | 4 ++ 2 files changed, 80 insertions(+) create mode 100644 crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rast create mode 100644 crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rs (limited to 'crates/ra_syntax/test_data/parser/err') diff --git a/crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rast b/crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rast new file mode 100644 index 000000000..8306f7361 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rast @@ -0,0 +1,76 @@ +SOURCE_FILE@0..83 + USE_ITEM@0..12 + USE_KW@0..3 "use" + WHITESPACE@3..4 " " + USE_TREE@4..11 + PATH@4..11 + PATH_SEGMENT@4..11 + COLON2@4..6 "::" + CRATE_KW@6..11 "crate" + SEMICOLON@11..12 ";" + WHITESPACE@12..13 "\n" + USE_ITEM@13..39 + USE_KW@13..16 "use" + WHITESPACE@16..17 " " + USE_TREE@17..38 + USE_TREE_LIST@17..38 + L_CURLY@17..18 "{" + USE_TREE@18..23 + PATH@18..23 + PATH_SEGMENT@18..23 + CRATE_KW@18..23 "crate" + COMMA@23..24 "," + WHITESPACE@24..25 " " + USE_TREE@25..37 + PATH@25..28 + PATH_SEGMENT@25..28 + NAME_REF@25..28 + IDENT@25..28 "foo" + COLON2@28..30 "::" + USE_TREE_LIST@30..37 + L_CURLY@30..31 "{" + USE_TREE@31..36 + PATH@31..36 + PATH_SEGMENT@31..36 + CRATE_KW@31..36 "crate" + R_CURLY@36..37 "}" + R_CURLY@37..38 "}" + SEMICOLON@38..39 ";" + WHITESPACE@39..40 "\n" + USE_ITEM@40..57 + USE_KW@40..43 "use" + WHITESPACE@43..44 " " + USE_TREE@44..56 + PATH@44..56 + PATH@44..49 + PATH_SEGMENT@44..49 + NAME_REF@44..49 + IDENT@44..49 "hello" + COLON2@49..51 "::" + PATH_SEGMENT@51..56 + CRATE_KW@51..56 "crate" + SEMICOLON@56..57 ";" + WHITESPACE@57..58 "\n" + USE_ITEM@58..82 + USE_KW@58..61 "use" + WHITESPACE@61..62 " " + USE_TREE@62..81 + PATH@62..81 + PATH@62..74 + PATH@62..67 + PATH_SEGMENT@62..67 + NAME_REF@62..67 + IDENT@62..67 "hello" + COLON2@67..69 "::" + PATH_SEGMENT@69..74 + CRATE_KW@69..74 "crate" + COLON2@74..76 "::" + PATH_SEGMENT@76..81 + NAME_REF@76..81 + IDENT@76..81 "there" + SEMICOLON@81..82 ";" + WHITESPACE@82..83 "\n" +error 6..11: The `crate` keyword is only allowed as the first segment of a path +error 31..36: The `crate` keyword is only allowed as the first segment of a path +error 51..56: The `crate` keyword is only allowed as the first segment of a path +error 69..74: The `crate` keyword is only allowed as the first segment of a path diff --git a/crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rs b/crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rs new file mode 100644 index 000000000..bead4c0b6 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rs @@ -0,0 +1,4 @@ +use ::crate; +use {crate, foo::{crate}}; +use hello::crate; +use hello::crate::there; -- cgit v1.2.3 From 513a3615f6d462852c0135dc4ac30a2086e25c5a Mon Sep 17 00:00:00 2001 From: John Renner Date: Thu, 30 Apr 2020 10:41:24 -0700 Subject: Report invalid, nested, multi-segment crate-paths Specifically, things like: use foo::{crate::bar}; Are now being caught, when before we only caught: use foo::{crate}; --- .../parser/err/0040_illegal_crate_kw_location.rast | 113 ++++++++++++--------- .../parser/err/0040_illegal_crate_kw_location.rs | 2 +- 2 files changed, 65 insertions(+), 50 deletions(-) (limited to 'crates/ra_syntax/test_data/parser/err') diff --git a/crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rast b/crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rast index 8306f7361..d2a549273 100644 --- a/crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rast +++ b/crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rast @@ -1,4 +1,4 @@ -SOURCE_FILE@0..83 +SOURCE_FILE@0..98 USE_ITEM@0..12 USE_KW@0..3 "use" WHITESPACE@3..4 " " @@ -9,11 +9,11 @@ SOURCE_FILE@0..83 CRATE_KW@6..11 "crate" SEMICOLON@11..12 ";" WHITESPACE@12..13 "\n" - USE_ITEM@13..39 + USE_ITEM@13..54 USE_KW@13..16 "use" WHITESPACE@16..17 " " - USE_TREE@17..38 - USE_TREE_LIST@17..38 + USE_TREE@17..53 + USE_TREE_LIST@17..53 L_CURLY@17..18 "{" USE_TREE@18..23 PATH@18..23 @@ -21,56 +21,71 @@ SOURCE_FILE@0..83 CRATE_KW@18..23 "crate" COMMA@23..24 "," WHITESPACE@24..25 " " - USE_TREE@25..37 + USE_TREE@25..52 PATH@25..28 PATH_SEGMENT@25..28 NAME_REF@25..28 IDENT@25..28 "foo" COLON2@28..30 "::" - USE_TREE_LIST@30..37 + USE_TREE_LIST@30..52 L_CURLY@30..31 "{" - USE_TREE@31..36 - PATH@31..36 - PATH_SEGMENT@31..36 - CRATE_KW@31..36 "crate" - R_CURLY@36..37 "}" - R_CURLY@37..38 "}" - SEMICOLON@38..39 ";" - WHITESPACE@39..40 "\n" - USE_ITEM@40..57 - USE_KW@40..43 "use" - WHITESPACE@43..44 " " - USE_TREE@44..56 - PATH@44..56 - PATH@44..49 - PATH_SEGMENT@44..49 - NAME_REF@44..49 - IDENT@44..49 "hello" - COLON2@49..51 "::" - PATH_SEGMENT@51..56 - CRATE_KW@51..56 "crate" - SEMICOLON@56..57 ";" - WHITESPACE@57..58 "\n" - USE_ITEM@58..82 - USE_KW@58..61 "use" - WHITESPACE@61..62 " " - USE_TREE@62..81 - PATH@62..81 - PATH@62..74 - PATH@62..67 - PATH_SEGMENT@62..67 - NAME_REF@62..67 - IDENT@62..67 "hello" - COLON2@67..69 "::" - PATH_SEGMENT@69..74 - CRATE_KW@69..74 "crate" - COLON2@74..76 "::" - PATH_SEGMENT@76..81 - NAME_REF@76..81 - IDENT@76..81 "there" - SEMICOLON@81..82 ";" - WHITESPACE@82..83 "\n" + USE_TREE@31..51 + PATH@31..51 + PATH@31..46 + PATH@31..41 + PATH@31..36 + PATH_SEGMENT@31..36 + CRATE_KW@31..36 "crate" + COLON2@36..38 "::" + PATH_SEGMENT@38..41 + NAME_REF@38..41 + IDENT@38..41 "foo" + COLON2@41..43 "::" + PATH_SEGMENT@43..46 + NAME_REF@43..46 + IDENT@43..46 "bar" + COLON2@46..48 "::" + PATH_SEGMENT@48..51 + NAME_REF@48..51 + IDENT@48..51 "baz" + R_CURLY@51..52 "}" + R_CURLY@52..53 "}" + SEMICOLON@53..54 ";" + WHITESPACE@54..55 "\n" + USE_ITEM@55..72 + USE_KW@55..58 "use" + WHITESPACE@58..59 " " + USE_TREE@59..71 + PATH@59..71 + PATH@59..64 + PATH_SEGMENT@59..64 + NAME_REF@59..64 + IDENT@59..64 "hello" + COLON2@64..66 "::" + PATH_SEGMENT@66..71 + CRATE_KW@66..71 "crate" + SEMICOLON@71..72 ";" + WHITESPACE@72..73 "\n" + USE_ITEM@73..97 + USE_KW@73..76 "use" + WHITESPACE@76..77 " " + USE_TREE@77..96 + PATH@77..96 + PATH@77..89 + PATH@77..82 + PATH_SEGMENT@77..82 + NAME_REF@77..82 + IDENT@77..82 "hello" + COLON2@82..84 "::" + PATH_SEGMENT@84..89 + CRATE_KW@84..89 "crate" + COLON2@89..91 "::" + PATH_SEGMENT@91..96 + NAME_REF@91..96 + IDENT@91..96 "there" + SEMICOLON@96..97 ";" + WHITESPACE@97..98 "\n" error 6..11: The `crate` keyword is only allowed as the first segment of a path error 31..36: The `crate` keyword is only allowed as the first segment of a path -error 51..56: The `crate` keyword is only allowed as the first segment of a path -error 69..74: The `crate` keyword is only allowed as the first segment of a path +error 66..71: The `crate` keyword is only allowed as the first segment of a path +error 84..89: The `crate` keyword is only allowed as the first segment of a path diff --git a/crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rs b/crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rs index bead4c0b6..508def2c7 100644 --- a/crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rs +++ b/crates/ra_syntax/test_data/parser/err/0040_illegal_crate_kw_location.rs @@ -1,4 +1,4 @@ use ::crate; -use {crate, foo::{crate}}; +use {crate, foo::{crate::foo::bar::baz}}; use hello::crate; use hello::crate::there; -- cgit v1.2.3