From 0a19f4f1b4a12bd50032249be4c9298284c08e3c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 4 Mar 2019 16:38:54 +0300 Subject: allow aliases in underscores this helps with use foo::Trait as _; syntax --- crates/ra_parser/src/grammar.rs | 4 +++- crates/ra_parser/src/grammar/items/use_item.rs | 1 + .../tests/data/parser/inline/ok/0043_use_alias.rs | 1 + .../tests/data/parser/inline/ok/0043_use_alias.txt | 17 ++++++++++++++++- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs index f94702e97..c9941fe93 100644 --- a/crates/ra_parser/src/grammar.rs +++ b/crates/ra_parser/src/grammar.rs @@ -129,7 +129,9 @@ fn opt_alias(p: &mut Parser) { if p.at(AS_KW) { let m = p.start(); p.bump(); - name(p); + if !p.eat(UNDERSCORE) { + name(p); + } m.complete(p, ALIAS); } } diff --git a/crates/ra_parser/src/grammar/items/use_item.rs b/crates/ra_parser/src/grammar/items/use_item.rs index 5111d37eb..b36612726 100644 --- a/crates/ra_parser/src/grammar/items/use_item.rs +++ b/crates/ra_parser/src/grammar/items/use_item.rs @@ -76,6 +76,7 @@ fn use_tree(p: &mut Parser) { // yet::another::path, // running::out::of::synonyms::for_::different::* // }; + // use Trait as _; opt_alias(p); } COLONCOLON => { diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0043_use_alias.rs b/crates/ra_syntax/tests/data/parser/inline/ok/0043_use_alias.rs index 544caa020..9be50f877 100644 --- a/crates/ra_syntax/tests/data/parser/inline/ok/0043_use_alias.rs +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0043_use_alias.rs @@ -5,3 +5,4 @@ use some::{ yet::another::path, running::out::of::synonyms::for_::different::* }; +use Trait as _; diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0043_use_alias.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0043_use_alias.txt index 8ef0ecbc6..0c8dec81d 100644 --- a/crates/ra_syntax/tests/data/parser/inline/ok/0043_use_alias.txt +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0043_use_alias.txt @@ -1,4 +1,4 @@ -SOURCE_FILE@[0; 182) +SOURCE_FILE@[0; 198) USE_ITEM@[0; 28) USE_KW@[0; 3) WHITESPACE@[3; 4) @@ -121,3 +121,18 @@ SOURCE_FILE@[0; 182) R_CURLY@[179; 180) SEMI@[180; 181) WHITESPACE@[181; 182) + USE_ITEM@[182; 197) + USE_KW@[182; 185) + WHITESPACE@[185; 186) + USE_TREE@[186; 196) + PATH@[186; 191) + PATH_SEGMENT@[186; 191) + NAME_REF@[186; 191) + IDENT@[186; 191) "Trait" + WHITESPACE@[191; 192) + ALIAS@[192; 196) + AS_KW@[192; 194) + WHITESPACE@[194; 195) + UNDERSCORE@[195; 196) + SEMI@[196; 197) + WHITESPACE@[197; 198) -- cgit v1.2.3