5583: Rename Rename r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-07-30 10:01:43 +00:00 committed by GitHub
commit dc49f88f17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 34 additions and 30 deletions

View file

@ -215,7 +215,7 @@ fn walk_use_tree_for_best_action(
let prev_len = current_path_segments.len(); let prev_len = current_path_segments.len();
let tree_list = current_use_tree.use_tree_list(); let tree_list = current_use_tree.use_tree_list();
let alias = current_use_tree.alias(); let alias = current_use_tree.rename();
let path = match current_use_tree.path() { let path = match current_use_tree.path() {
Some(path) => path, Some(path) => path,

View file

@ -501,7 +501,7 @@ impl Ctx {
extern_crate: &ast::ExternCrateItem, extern_crate: &ast::ExternCrateItem,
) -> Option<FileItemTreeId<ExternCrate>> { ) -> Option<FileItemTreeId<ExternCrate>> {
let path = ModPath::from_name_ref(&extern_crate.name_ref()?); let path = ModPath::from_name_ref(&extern_crate.name_ref()?);
let alias = extern_crate.alias().map(|a| { let alias = extern_crate.rename().map(|a| {
a.name().map(|it| it.as_name()).map_or(ImportAlias::Underscore, ImportAlias::Alias) a.name().map(|it| it.as_name()).map_or(ImportAlias::Underscore, ImportAlias::Alias)
}); });
let visibility = self.lower_visibility(extern_crate); let visibility = self.lower_visibility(extern_crate);

View file

@ -31,7 +31,7 @@ pub(crate) fn lower_use_tree(
lower_use_tree(prefix.clone(), child_tree, hygiene, cb); lower_use_tree(prefix.clone(), child_tree, hygiene, cb);
} }
} else { } else {
let alias = tree.alias().map(|a| { let alias = tree.rename().map(|a| {
a.name().map(|it| it.as_name()).map_or(ImportAlias::Underscore, ImportAlias::Alias) a.name().map(|it| it.as_name()).map_or(ImportAlias::Underscore, ImportAlias::Alias)
}); });
let is_glob = tree.star_token().is_some(); let is_glob = tree.star_token().is_some();

View file

@ -119,7 +119,7 @@ pub fn classify_name(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Option
match_ast! { match_ast! {
match parent { match parent {
ast::Alias(it) => { ast::Rename(it) => {
let use_tree = it.syntax().parent().and_then(ast::UseTree::cast)?; let use_tree = it.syntax().parent().and_then(ast::UseTree::cast)?;
let path = use_tree.path()?; let path = use_tree.path()?;
let path_segment = path.segment()?; let path_segment = path.segment()?;

View file

@ -224,7 +224,7 @@ fn opt_alias(p: &mut Parser) {
if !p.eat(T![_]) { if !p.eat(T![_]) {
name(p); name(p);
} }
m.complete(p, ALIAS); m.complete(p, RENAME);
} }
} }

View file

@ -221,7 +221,7 @@ pub enum SyntaxKind {
PATH, PATH,
PATH_SEGMENT, PATH_SEGMENT,
LITERAL, LITERAL,
ALIAS, RENAME,
VISIBILITY, VISIBILITY,
WHERE_CLAUSE, WHERE_CLAUSE,
WHERE_PRED, WHERE_PRED,

View file

@ -317,8 +317,12 @@ impl ast::UseTree {
Some(it) => it, Some(it) => it,
None => return self.clone(), None => return self.clone(),
}; };
let use_tree = let use_tree = make::use_tree(
make::use_tree(suffix, self.use_tree_list(), self.alias(), self.star_token().is_some()); suffix,
self.use_tree_list(),
self.rename(),
self.star_token().is_some(),
);
let nested = make::use_tree_list(iter::once(use_tree)); let nested = make::use_tree_list(iter::once(use_tree));
return make::use_tree(prefix.clone(), Some(nested), None, false); return make::use_tree(prefix.clone(), Some(nested), None, false);

View file

@ -75,7 +75,7 @@ impl ExternCrateItem {
pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) } pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) }
pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) } pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) }
pub fn alias(&self) -> Option<Alias> { support::child(&self.syntax) } pub fn rename(&self) -> Option<Rename> { support::child(&self.syntax) }
pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
} }
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
@ -1178,7 +1178,7 @@ impl UseTree {
pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) } pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) }
pub fn star_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![*]) } pub fn star_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![*]) }
pub fn use_tree_list(&self) -> Option<UseTreeList> { support::child(&self.syntax) } pub fn use_tree_list(&self) -> Option<UseTreeList> { support::child(&self.syntax) }
pub fn alias(&self) -> Option<Alias> { support::child(&self.syntax) } pub fn rename(&self) -> Option<Rename> { support::child(&self.syntax) }
} }
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct UseTreeList { pub struct UseTreeList {
@ -1190,11 +1190,11 @@ impl UseTreeList {
pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
} }
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Alias { pub struct Rename {
pub(crate) syntax: SyntaxNode, pub(crate) syntax: SyntaxNode,
} }
impl ast::NameOwner for Alias {} impl ast::NameOwner for Rename {}
impl Alias { impl Rename {
pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) } pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) }
} }
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
@ -2683,8 +2683,8 @@ impl AstNode for UseTreeList {
} }
fn syntax(&self) -> &SyntaxNode { &self.syntax } fn syntax(&self) -> &SyntaxNode { &self.syntax }
} }
impl AstNode for Alias { impl AstNode for Rename {
fn can_cast(kind: SyntaxKind) -> bool { kind == ALIAS } fn can_cast(kind: SyntaxKind) -> bool { kind == RENAME }
fn cast(syntax: SyntaxNode) -> Option<Self> { fn cast(syntax: SyntaxNode) -> Option<Self> {
if Self::can_cast(syntax.kind()) { if Self::can_cast(syntax.kind()) {
Some(Self { syntax }) Some(Self { syntax })
@ -4040,7 +4040,7 @@ impl std::fmt::Display for UseTreeList {
std::fmt::Display::fmt(self.syntax(), f) std::fmt::Display::fmt(self.syntax(), f)
} }
} }
impl std::fmt::Display for Alias { impl std::fmt::Display for Rename {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.syntax(), f) std::fmt::Display::fmt(self.syntax(), f)
} }

View file

@ -37,7 +37,7 @@ fn path_from_text(text: &str) -> ast::Path {
pub fn use_tree( pub fn use_tree(
path: ast::Path, path: ast::Path,
use_tree_list: Option<ast::UseTreeList>, use_tree_list: Option<ast::UseTreeList>,
alias: Option<ast::Alias>, alias: Option<ast::Rename>,
add_star: bool, add_star: bool,
) -> ast::UseTree { ) -> ast::UseTree {
let mut buf = "use ".to_string(); let mut buf = "use ".to_string();

View file

@ -13,7 +13,7 @@ SOURCE_FILE@0..198
NAME_REF@10..14 NAME_REF@10..14
IDENT@10..14 "path" IDENT@10..14 "path"
WHITESPACE@14..15 " " WHITESPACE@14..15 " "
ALIAS@15..27 RENAME@15..27
AS_KW@15..17 "as" AS_KW@15..17 "as"
WHITESPACE@17..18 " " WHITESPACE@17..18 " "
NAME@18..27 NAME@18..27
@ -43,7 +43,7 @@ SOURCE_FILE@0..198
NAME_REF@49..53 NAME_REF@49..53
IDENT@49..53 "path" IDENT@49..53 "path"
WHITESPACE@53..54 " " WHITESPACE@53..54 " "
ALIAS@54..72 RENAME@54..72
AS_KW@54..56 "as" AS_KW@54..56 "as"
WHITESPACE@56..57 " " WHITESPACE@56..57 " "
NAME@57..72 NAME@57..72
@ -61,7 +61,7 @@ SOURCE_FILE@0..198
NAME_REF@86..90 NAME_REF@86..90
IDENT@86..90 "path" IDENT@86..90 "path"
WHITESPACE@90..91 " " WHITESPACE@90..91 " "
ALIAS@91..108 RENAME@91..108
AS_KW@91..93 "as" AS_KW@91..93 "as"
WHITESPACE@93..94 " " WHITESPACE@93..94 " "
NAME@94..108 NAME@94..108
@ -130,7 +130,7 @@ SOURCE_FILE@0..198
NAME_REF@186..191 NAME_REF@186..191
IDENT@186..191 "Trait" IDENT@186..191 "Trait"
WHITESPACE@191..192 " " WHITESPACE@191..192 " "
ALIAS@192..196 RENAME@192..196
AS_KW@192..194 "as" AS_KW@192..194 "as"
WHITESPACE@194..195 " " WHITESPACE@194..195 " "
UNDERSCORE@195..196 "_" UNDERSCORE@195..196 "_"

View file

@ -16,7 +16,7 @@ SOURCE_FILE@0..69
NAME_REF@31..34 NAME_REF@31..34
IDENT@31..34 "foo" IDENT@31..34 "foo"
WHITESPACE@34..35 " " WHITESPACE@34..35 " "
ALIAS@35..41 RENAME@35..41
AS_KW@35..37 "as" AS_KW@35..37 "as"
WHITESPACE@37..38 " " WHITESPACE@37..38 " "
NAME@38..41 NAME@38..41
@ -30,7 +30,7 @@ SOURCE_FILE@0..69
WHITESPACE@55..56 " " WHITESPACE@55..56 " "
SELF_KW@56..60 "self" SELF_KW@56..60 "self"
WHITESPACE@60..61 " " WHITESPACE@60..61 " "
ALIAS@61..67 RENAME@61..67
AS_KW@61..63 "as" AS_KW@61..63 "as"
WHITESPACE@63..64 " " WHITESPACE@63..64 " "
NAME@64..67 NAME@64..67

View file

@ -8,7 +8,7 @@ SOURCE_FILE@0..55
NAME_REF@4..7 NAME_REF@4..7
IDENT@4..7 "foo" IDENT@4..7 "foo"
WHITESPACE@7..8 " " WHITESPACE@7..8 " "
ALIAS@8..14 RENAME@8..14
AS_KW@8..10 "as" AS_KW@8..10 "as"
WHITESPACE@10..11 " " WHITESPACE@10..11 " "
NAME@11..14 NAME@11..14
@ -32,7 +32,7 @@ SOURCE_FILE@0..55
NAME_REF@26..27 NAME_REF@26..27
IDENT@26..27 "a" IDENT@26..27 "a"
WHITESPACE@27..28 " " WHITESPACE@27..28 " "
ALIAS@28..32 RENAME@28..32
AS_KW@28..30 "as" AS_KW@28..30 "as"
WHITESPACE@30..31 " " WHITESPACE@30..31 " "
NAME@31..32 NAME@31..32
@ -55,7 +55,7 @@ SOURCE_FILE@0..55
NAME_REF@44..47 NAME_REF@44..47
IDENT@44..47 "foo" IDENT@44..47 "foo"
WHITESPACE@47..48 " " WHITESPACE@47..48 " "
ALIAS@48..52 RENAME@48..52
AS_KW@48..50 "as" AS_KW@48..50 "as"
WHITESPACE@50..51 " " WHITESPACE@50..51 " "
NAME@51..52 NAME@51..52

View file

@ -194,7 +194,7 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc {
"PATH", "PATH",
"PATH_SEGMENT", "PATH_SEGMENT",
"LITERAL", "LITERAL",
"ALIAS", "RENAME",
"VISIBILITY", "VISIBILITY",
"WHERE_CLAUSE", "WHERE_CLAUSE",
"WHERE_PRED", "WHERE_PRED",

View file

@ -396,16 +396,16 @@ UseItem =
Attr* Visibility? 'use' UseTree ';' Attr* Visibility? 'use' UseTree ';'
UseTree = UseTree =
Path ('::' ('*' | UseTreeList)) Alias? Path ('::' ('*' | UseTreeList)) Rename?
UseTreeList = UseTreeList =
'{' UseTree* '}' '{' UseTree* '}'
Alias = Rename =
'as' Name 'as' Name
ExternCrateItem = ExternCrateItem =
Attr* Visibility? 'extern' 'crate' (NameRef | 'self') Alias? ';' Attr* Visibility? 'extern' 'crate' (NameRef | 'self') Rename? ';'
Path = Path =
(qualifier:Path '::')? segment:PathSegment (qualifier:Path '::')? segment:PathSegment