diff --git a/crates/ra_assists/src/handlers/auto_import.rs b/crates/ra_assists/src/handlers/auto_import.rs index 947be3b9b4a..01e7b7a44cb 100644 --- a/crates/ra_assists/src/handlers/auto_import.rs +++ b/crates/ra_assists/src/handlers/auto_import.rs @@ -92,7 +92,7 @@ fn for_method_call(method_call: ast::MethodCallExpr, ctx: &AssistContext) -> Opt fn for_regular_path(path_under_caret: ast::Path, ctx: &AssistContext) -> Option { let syntax_under_caret = path_under_caret.syntax().to_owned(); - if syntax_under_caret.ancestors().find_map(ast::UseItem::cast).is_some() { + if syntax_under_caret.ancestors().find_map(ast::Use::cast).is_some() { return None; } diff --git a/crates/ra_assists/src/handlers/merge_imports.rs b/crates/ra_assists/src/handlers/merge_imports.rs index 1beccb61c09..c775fe25c52 100644 --- a/crates/ra_assists/src/handlers/merge_imports.rs +++ b/crates/ra_assists/src/handlers/merge_imports.rs @@ -28,7 +28,7 @@ pub(crate) fn merge_imports(acc: &mut Assists, ctx: &AssistContext) -> Option<() let mut rewriter = SyntaxRewriter::default(); let mut offset = ctx.offset(); - if let Some(use_item) = tree.syntax().parent().and_then(ast::UseItem::cast) { + if let Some(use_item) = tree.syntax().parent().and_then(ast::Use::cast) { let (merged, to_delete) = next_prev() .filter_map(|dir| neighbor(&use_item, dir)) .filter_map(|it| Some((it.clone(), it.use_tree()?))) diff --git a/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs b/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs index 3d51faa5430..53496ede150 100644 --- a/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs +++ b/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs @@ -25,7 +25,7 @@ pub(crate) fn replace_qualified_name_with_use( ) -> Option<()> { let path: ast::Path = ctx.find_node_at_offset()?; // We don't want to mess with use statements - if path.syntax().ancestors().find_map(ast::UseItem::cast).is_some() { + if path.syntax().ancestors().find_map(ast::Use::cast).is_some() { return None; } @@ -85,7 +85,7 @@ fn shorten_paths(rewriter: &mut SyntaxRewriter<'static>, node: SyntaxNode, path: match child { // Don't modify `use` items, as this can break the `use` item when injecting a new // import into the use tree. - ast::UseItem(_it) => continue, + ast::Use(_it) => continue, // Don't descend into submodules, they don't have the same `use` items in scope. ast::Module(_it) => continue, diff --git a/crates/ra_assists/src/utils/insert_use.rs b/crates/ra_assists/src/utils/insert_use.rs index c05027eff1b..617afe2e945 100644 --- a/crates/ra_assists/src/utils/insert_use.rs +++ b/crates/ra_assists/src/utils/insert_use.rs @@ -225,7 +225,7 @@ fn walk_use_tree_for_best_action( current_use_tree .syntax() .ancestors() - .find_map(ast::UseItem::cast) + .find_map(ast::Use::cast) .map(|it| it.syntax().clone()), true, ); @@ -254,7 +254,7 @@ fn walk_use_tree_for_best_action( current_use_tree .syntax() .ancestors() - .find_map(ast::UseItem::cast) + .find_map(ast::Use::cast) .map(|it| it.syntax().clone()), true, ), @@ -304,7 +304,7 @@ fn walk_use_tree_for_best_action( current_use_tree .syntax() .ancestors() - .find_map(ast::UseItem::cast) + .find_map(ast::Use::cast) .map(|it| it.syntax().clone()), true, ); @@ -377,7 +377,7 @@ fn best_action_for_target( let mut storage = Vec::with_capacity(16); // this should be the only allocation let best_action = container .children() - .filter_map(ast::UseItem::cast) + .filter_map(ast::Use::cast) .filter_map(|it| it.use_tree()) .map(|u| walk_use_tree_for_best_action(&mut storage, None, u, target)) .fold(None, |best, a| match best { diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index bfd574c5dcc..5c57d8bde3b 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -670,7 +670,7 @@ fn collect_block_items(&mut self, block: &ast::BlockExpr) { } ast::Item::ExternBlock(_) => return None, // FIXME: collect from extern blocks ast::Item::ImplDef(_) - | ast::Item::UseItem(_) + | ast::Item::Use(_) | ast::Item::ExternCrate(_) | ast::Item::Module(_) | ast::Item::MacroCall(_) => return None, diff --git a/crates/ra_hir_def/src/item_tree.rs b/crates/ra_hir_def/src/item_tree.rs index 4db7b2793f8..0bab9c6d8b0 100644 --- a/crates/ra_hir_def/src/item_tree.rs +++ b/crates/ra_hir_def/src/item_tree.rs @@ -411,7 +411,7 @@ fn index(&self, index: Idx<$typ>) -> &Self::Output { } mod_items! { - Import in imports -> ast::UseItem, + Import in imports -> ast::Use, ExternCrate in extern_crates -> ast::ExternCrate, Function in functions -> ast::FnDef, Struct in structs -> ast::StructDef, @@ -482,7 +482,7 @@ pub struct Import { pub is_prelude: bool, /// AST ID of the `use` or `extern crate` item this import was derived from. Note that many /// `Import`s can map to the same `use` item. - pub ast_id: FileAstId, + pub ast_id: FileAstId, } #[derive(Debug, Clone, Eq, PartialEq)] diff --git a/crates/ra_hir_def/src/item_tree/lower.rs b/crates/ra_hir_def/src/item_tree/lower.rs index 8a36de31182..8bd0362dce8 100644 --- a/crates/ra_hir_def/src/item_tree/lower.rs +++ b/crates/ra_hir_def/src/item_tree/lower.rs @@ -95,7 +95,7 @@ fn lower_mod_item(&mut self, item: &ast::Item, inner: bool) -> Option ast::Item::TraitDef(_) | ast::Item::ImplDef(_) | ast::Item::ExternBlock(_) => {} // These don't have inner items. - ast::Item::Module(_) | ast::Item::ExternCrate(_) | ast::Item::UseItem(_) => {} + ast::Item::Module(_) | ast::Item::ExternCrate(_) | ast::Item::Use(_) => {} }; let attrs = Attrs::new(item, &self.hygiene); @@ -110,7 +110,7 @@ fn lower_mod_item(&mut self, item: &ast::Item, inner: bool) -> Option ast::Item::Module(ast) => self.lower_module(ast).map(Into::into), ast::Item::TraitDef(ast) => self.lower_trait(ast).map(Into::into), ast::Item::ImplDef(ast) => self.lower_impl(ast).map(Into::into), - ast::Item::UseItem(ast) => Some(ModItems( + ast::Item::Use(ast) => Some(ModItems( self.lower_use(ast).into_iter().map(Into::into).collect::>(), )), ast::Item::ExternCrate(ast) => self.lower_extern_crate(ast).map(Into::into), @@ -469,7 +469,7 @@ fn lower_impl(&mut self, impl_def: &ast::ImplDef) -> Option Some(id(self.data().impls.alloc(res))) } - fn lower_use(&mut self, use_item: &ast::UseItem) -> Vec> { + fn lower_use(&mut self, use_item: &ast::Use) -> Vec> { // FIXME: cfg_attr let is_prelude = use_item.has_atom_attr("prelude_import"); let visibility = self.lower_visibility(use_item); diff --git a/crates/ra_hir_def/src/path.rs b/crates/ra_hir_def/src/path.rs index 190d6d98d4b..68b9f89c375 100644 --- a/crates/ra_hir_def/src/path.rs +++ b/crates/ra_hir_def/src/path.rs @@ -67,7 +67,7 @@ pub(crate) fn from_tt_ident(ident: &tt::Ident) -> ModPath { /// Calls `cb` with all paths, represented by this use item. pub(crate) fn expand_use_item( - item_src: InFile, + item_src: InFile, hygiene: &Hygiene, mut cb: impl FnMut(ModPath, &ast::UseTree, /* is_glob */ bool, Option), ) { diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index c84d43d7733..cc55f6dd6ba 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -36,7 +36,7 @@ pub(crate) struct CompletionContext<'a> { pub(super) expected_type: Option, pub(super) name_ref_syntax: Option, pub(super) function_syntax: Option, - pub(super) use_item_syntax: Option, + pub(super) use_item_syntax: Option, pub(super) record_lit_syntax: Option, pub(super) record_pat_syntax: Option, pub(super) record_field_syntax: Option, @@ -343,7 +343,7 @@ fn classify_name_ref( } self.use_item_syntax = - self.sema.ancestors_with_macros(self.token.parent()).find_map(ast::UseItem::cast); + self.sema.ancestors_with_macros(self.token.parent()).find_map(ast::Use::cast); self.function_syntax = self .sema diff --git a/crates/ra_ide/src/folding_ranges.rs b/crates/ra_ide/src/folding_ranges.rs index 315808890bc..bad0791463d 100644 --- a/crates/ra_ide/src/folding_ranges.rs +++ b/crates/ra_ide/src/folding_ranges.rs @@ -58,7 +58,7 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec { } NodeOrToken::Node(node) => { // Fold groups of imports - if node.kind() == USE_ITEM && !visited_imports.contains(&node) { + if node.kind() == USE && !visited_imports.contains(&node) { if let Some(range) = contiguous_range_for_group(&node, &mut visited_imports) { res.push(Fold { range, kind: FoldKind::Imports }) } @@ -83,7 +83,7 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec { fn fold_kind(kind: SyntaxKind) -> Option { match kind { COMMENT => Some(FoldKind::Comment), - USE_ITEM => Some(FoldKind::Imports), + USE => Some(FoldKind::Imports), ARG_LIST | PARAM_LIST => Some(FoldKind::ArgList), RECORD_FIELD_DEF_LIST | RECORD_FIELD_PAT_LIST diff --git a/crates/ra_parser/src/grammar/items/use_item.rs b/crates/ra_parser/src/grammar/items/use_item.rs index 3a0c7a31a85..8e836a77e1d 100644 --- a/crates/ra_parser/src/grammar/items/use_item.rs +++ b/crates/ra_parser/src/grammar/items/use_item.rs @@ -7,7 +7,7 @@ pub(super) fn use_item(p: &mut Parser, m: Marker) { p.bump(T![use]); use_tree(p, true); p.expect(T![;]); - m.complete(p, USE_ITEM); + m.complete(p, USE); } /// Parse a use 'tree', such as `some::path` in `use some::path;` diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs index 116b58858f7..4f35e0baa58 100644 --- a/crates/ra_parser/src/syntax_kind/generated.rs +++ b/crates/ra_parser/src/syntax_kind/generated.rs @@ -130,7 +130,7 @@ pub enum SyntaxKind { RET_TYPE, EXTERN_CRATE, MODULE, - USE_ITEM, + USE, STATIC_DEF, CONST_DEF, TRAIT_DEF, diff --git a/crates/ra_ssr/src/search.rs b/crates/ra_ssr/src/search.rs index 0f512cb62d0..213dc494fff 100644 --- a/crates/ra_ssr/src/search.rs +++ b/crates/ra_ssr/src/search.rs @@ -237,7 +237,7 @@ fn is_search_permitted(node: &SyntaxNode) -> bool { // and the code is `use foo::{baz, bar}`, we'll match `bar`, since it resolves to `foo::bar`. // However we'll then replace just the part we matched `bar`. We probably need to instead remove // `bar` and insert a new use declaration. - node.kind() != SyntaxKind::USE_ITEM + node.kind() != SyntaxKind::USE } impl UsageCache { diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs index 2e958fa2310..6ebe10ff65e 100644 --- a/crates/ra_syntax/src/ast/edit.rs +++ b/crates/ra_syntax/src/ast/edit.rs @@ -262,9 +262,9 @@ fn _with_type_args(&self, type_args: ast::TypeArgList, turbo: bool) -> ast::Path } } -impl ast::UseItem { +impl ast::Use { #[must_use] - pub fn with_use_tree(&self, use_tree: ast::UseTree) -> ast::UseItem { + pub fn with_use_tree(&self, use_tree: ast::UseTree) -> ast::Use { if let Some(old) = self.use_tree() { return self.replace_descendant(old, use_tree); } diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index 9d8127a3d41..be657699ff5 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -213,12 +213,12 @@ pub fn record_field_def_list(&self) -> Option { } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct UseItem { +pub struct Use { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for UseItem {} -impl ast::VisibilityOwner for UseItem {} -impl UseItem { +impl ast::AttrsOwner for Use {} +impl ast::VisibilityOwner for Use {} +impl Use { pub fn use_token(&self) -> Option { support::token(&self.syntax, T![use]) } pub fn use_tree(&self) -> Option { support::child(&self.syntax) } pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } @@ -1283,7 +1283,7 @@ pub enum Item { TraitDef(TraitDef), TypeAliasDef(TypeAliasDef), UnionDef(UnionDef), - UseItem(UseItem), + Use(Use), } impl ast::AttrsOwner for Item {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1562,8 +1562,8 @@ fn cast(syntax: SyntaxNode) -> Option { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for UseItem { - fn can_cast(kind: SyntaxKind) -> bool { kind == USE_ITEM } +impl AstNode for Use { + fn can_cast(kind: SyntaxKind) -> bool { kind == USE } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -2811,15 +2811,16 @@ fn from(node: TypeAliasDef) -> Item { Item::TypeAliasDef(node) } impl From for Item { fn from(node: UnionDef) -> Item { Item::UnionDef(node) } } -impl From for Item { - fn from(node: UseItem) -> Item { Item::UseItem(node) } +impl From for Item { + fn from(node: Use) -> Item { Item::Use(node) } } impl AstNode for Item { fn can_cast(kind: SyntaxKind) -> bool { match kind { CONST_DEF | ENUM_DEF | EXTERN_BLOCK | EXTERN_CRATE | FN_DEF | IMPL_DEF | MACRO_CALL - | MODULE | STATIC_DEF | STRUCT_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | UNION_DEF - | USE_ITEM => true, + | MODULE | STATIC_DEF | STRUCT_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | UNION_DEF | USE => { + true + } _ => false, } } @@ -2838,7 +2839,7 @@ fn cast(syntax: SyntaxNode) -> Option { TRAIT_DEF => Item::TraitDef(TraitDef { syntax }), TYPE_ALIAS_DEF => Item::TypeAliasDef(TypeAliasDef { syntax }), UNION_DEF => Item::UnionDef(UnionDef { syntax }), - USE_ITEM => Item::UseItem(UseItem { syntax }), + USE => Item::Use(Use { syntax }), _ => return None, }; Some(res) @@ -2858,7 +2859,7 @@ fn syntax(&self) -> &SyntaxNode { Item::TraitDef(it) => &it.syntax, Item::TypeAliasDef(it) => &it.syntax, Item::UnionDef(it) => &it.syntax, - Item::UseItem(it) => &it.syntax, + Item::Use(it) => &it.syntax, } } } @@ -3531,7 +3532,7 @@ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for UseItem { +impl std::fmt::Display for Use { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 2b05ed2d4a2..0ff69bc2d1d 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs @@ -60,7 +60,7 @@ pub fn use_tree_list(use_trees: impl IntoIterator) -> ast:: ast_from_text(&format!("use {{{}}};", use_trees)) } -pub fn use_item(use_tree: ast::UseTree) -> ast::UseItem { +pub fn use_item(use_tree: ast::UseTree) -> ast::Use { ast_from_text(&format!("use {};", use_tree)) } diff --git a/xtask/src/ast_src.rs b/xtask/src/ast_src.rs index 083727c5cd3..3a58217c479 100644 --- a/xtask/src/ast_src.rs +++ b/xtask/src/ast_src.rs @@ -100,7 +100,7 @@ pub(crate) struct KindsSrc<'a> { "RET_TYPE", "EXTERN_CRATE", "MODULE", - "USE_ITEM", + "USE", "STATIC_DEF", "CONST_DEF", "TRAIT_DEF", diff --git a/xtask/src/codegen/rust.ungram b/xtask/src/codegen/rust.ungram index 2ba68457fd8..449b0242fb4 100644 --- a/xtask/src/codegen/rust.ungram +++ b/xtask/src/codegen/rust.ungram @@ -17,7 +17,7 @@ Item = | TraitDef | TypeAliasDef | UnionDef -| UseItem +| Use Module = Attr* Visibility? 'mod' Name @@ -32,7 +32,7 @@ ExternCrate = Rename = 'as' (Name | '_') -UseItem = +Use = Attr* Visibility? 'use' UseTree ';' UseTree =