From b6ed91a6de846682d91b7196e4fb0c19106d1654 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 27 Sep 2021 12:54:24 +0200 Subject: [PATCH] Rename `*Owner` traits to `Has*` --- crates/hir/src/display.rs | 2 +- crates/hir/src/lib.rs | 2 +- crates/hir/src/semantics.rs | 4 +- crates/hir/src/semantics/source_to_def.rs | 2 +- crates/hir_def/src/adt.rs | 2 +- crates/hir_def/src/attr.rs | 74 ++-- crates/hir_def/src/body.rs | 6 +- crates/hir_def/src/body/lower.rs | 4 +- crates/hir_def/src/child_by_source.rs | 2 +- crates/hir_def/src/generics.rs | 6 +- crates/hir_def/src/item_tree.rs | 2 +- crates/hir_def/src/item_tree/lower.rs | 12 +- crates/hir_def/src/path/lower.rs | 2 +- crates/hir_expand/src/builtin_derive.rs | 2 +- crates/hir_expand/src/builtin_macro.rs | 2 +- crates/hir_expand/src/db.rs | 2 +- crates/hir_expand/src/hygiene.rs | 2 +- crates/hir_expand/src/lib.rs | 2 +- crates/hir_ty/src/diagnostics/decl_check.rs | 2 +- crates/hir_ty/src/tests.rs | 2 +- crates/ide/src/annotations.rs | 4 +- crates/ide/src/display/navigation_target.rs | 10 +- crates/ide/src/file_structure.rs | 8 +- crates/ide/src/fn_references.rs | 2 +- crates/ide/src/folding_ranges.rs | 2 +- crates/ide/src/highlight_related.rs | 2 +- crates/ide/src/inlay_hints.rs | 2 +- crates/ide/src/references.rs | 2 +- crates/ide/src/runnables.rs | 6 +- .../src/handlers/add_lifetime_to_type.rs | 2 +- .../src/handlers/add_missing_match_arms.rs | 2 +- .../src/handlers/change_visibility.rs | 2 +- .../src/handlers/convert_bool_then.rs | 2 +- .../src/handlers/convert_into_to_from.rs | 2 +- .../handlers/convert_iter_for_each_to_for.rs | 2 +- .../convert_tuple_struct_to_named_struct.rs | 2 +- .../src/handlers/convert_while_to_loop.rs | 2 +- .../src/handlers/destructure_tuple_binding.rs | 2 +- .../src/handlers/extract_function.rs | 2 +- .../extract_struct_from_enum_variant.rs | 4 +- .../src/handlers/extract_type_alias.rs | 2 +- .../src/handlers/fix_visibility.rs | 4 +- .../generate_default_from_enum_variant.rs | 2 +- .../src/handlers/generate_default_from_new.rs | 2 +- .../src/handlers/generate_deref.rs | 2 +- .../src/handlers/generate_derive.rs | 2 +- .../src/handlers/generate_enum_is_method.rs | 4 +- .../generate_enum_projection_method.rs | 4 +- .../handlers/generate_from_impl_for_enum.rs | 2 +- .../src/handlers/generate_function.rs | 2 +- .../src/handlers/generate_getter.rs | 2 +- .../ide_assists/src/handlers/generate_impl.rs | 2 +- .../handlers/generate_is_empty_from_len.rs | 2 +- .../ide_assists/src/handlers/generate_new.rs | 2 +- .../src/handlers/generate_setter.rs | 2 +- .../ide_assists/src/handlers/inline_call.rs | 2 +- .../src/handlers/inline_local_variable.rs | 2 +- .../src/handlers/introduce_named_lifetime.rs | 2 +- .../ide_assists/src/handlers/move_bounds.rs | 2 +- .../src/handlers/move_module_to_file.rs | 2 +- .../ide_assists/src/handlers/qualify_path.rs | 2 +- .../src/handlers/remove_unused_param.rs | 2 +- .../ide_assists/src/handlers/reorder_impl.rs | 2 +- .../replace_derive_with_manual_impl.rs | 2 +- .../src/handlers/replace_if_let_with_match.rs | 2 +- crates/ide_assists/src/handlers/sort_items.rs | 4 +- .../ide_assists/src/handlers/toggle_ignore.rs | 2 +- .../ide_assists/src/handlers/unmerge_use.rs | 2 +- crates/ide_assists/src/utils.rs | 2 +- .../src/utils/gen_trait_fn_body.rs | 2 +- crates/ide_assists/src/utils/suggest_name.rs | 2 +- .../src/completions/fn_param.rs | 2 +- crates/ide_completion/src/context.rs | 2 +- crates/ide_completion/src/patterns.rs | 2 +- crates/ide_completion/src/render/const_.rs | 2 +- .../ide_completion/src/render/type_alias.rs | 2 +- crates/ide_db/src/call_info.rs | 2 +- crates/ide_db/src/helpers.rs | 2 +- crates/ide_db/src/helpers/import_assets.rs | 2 +- crates/ide_db/src/helpers/insert_use.rs | 4 +- crates/ide_db/src/helpers/merge_imports.rs | 2 +- crates/ide_db/src/rename.rs | 4 +- crates/ide_db/src/symbol_index.rs | 4 +- crates/ide_db/src/traits.rs | 2 +- .../replace_filter_map_next_with_find_map.rs | 2 +- .../src/handlers/unlinked_file.rs | 2 +- crates/ide_ssr/src/matching.rs | 4 +- crates/mbe/src/benchmark.rs | 2 +- crates/mbe/src/tests.rs | 2 +- crates/syntax/src/ast.rs | 6 +- crates/syntax/src/ast/edit_in_place.rs | 10 +- crates/syntax/src/ast/expr_ext.rs | 2 +- crates/syntax/src/ast/generated/nodes.rs | 368 +++++++++--------- crates/syntax/src/ast/node_ext.rs | 48 +-- crates/syntax/src/ast/traits.rs | 18 +- crates/syntax/src/display.rs | 4 +- crates/syntax/src/lib.rs | 2 +- crates/syntax/src/tests.rs | 2 +- crates/syntax/src/tests/sourcegen_ast.rs | 16 +- crates/syntax/src/validation.rs | 2 +- crates/syntax/src/validation/block.rs | 2 +- 101 files changed, 393 insertions(+), 397 deletions(-) diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs index 4ef7d399de..aa4f25a3b4 100644 --- a/crates/hir/src/display.rs +++ b/crates/hir/src/display.rs @@ -12,7 +12,7 @@ use hir_ty::{ }, Interner, TraitRefExt, WhereClause, }; -use syntax::ast::{self, NameOwner}; +use syntax::ast::{self, HasName}; use crate::{ Adt, Const, ConstParam, Enum, Field, Function, GenericParam, HasCrate, HasVisibility, diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 99ab630a30..879124502a 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -72,7 +72,7 @@ use once_cell::unsync::Lazy; use rustc_hash::FxHashSet; use stdx::{format_to, impl_from}; use syntax::{ - ast::{self, AttrsOwner, NameOwner}, + ast::{self, HasAttrs as _, HasName}, AstNode, AstPtr, SmolStr, SyntaxKind, SyntaxNodePtr, }; use tt::{Ident, Leaf, Literal, TokenTree}; diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index 9de2c32111..ff3384cbe9 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -17,7 +17,7 @@ use rustc_hash::{FxHashMap, FxHashSet}; use smallvec::{smallvec, SmallVec}; use syntax::{ algo::skip_trivia_token, - ast::{self, GenericParamsOwner, LoopBodyOwner}, + ast::{self, HasGenericParams, HasLoopBody}, match_ast, AstNode, Direction, SyntaxNode, SyntaxNodePtr, SyntaxToken, TextRange, TextSize, }; @@ -682,7 +682,7 @@ impl<'db> SemanticsImpl<'db> { fn resolve_lifetime_param(&self, lifetime: &ast::Lifetime) -> Option { let text = lifetime.text(); let lifetime_param = lifetime.syntax().ancestors().find_map(|syn| { - let gpl = ast::AnyGenericParamsOwner::cast(syn)?.generic_param_list()?; + let gpl = ast::AnyHasGenericParams::cast(syn)?.generic_param_list()?; gpl.lifetime_params() .find(|tp| tp.lifetime().as_ref().map(|lt| lt.text()).as_ref() == Some(&text)) })?; diff --git a/crates/hir/src/semantics/source_to_def.rs b/crates/hir/src/semantics/source_to_def.rs index 723c7a1727..20e2481af6 100644 --- a/crates/hir/src/semantics/source_to_def.rs +++ b/crates/hir/src/semantics/source_to_def.rs @@ -100,7 +100,7 @@ use rustc_hash::FxHashMap; use smallvec::SmallVec; use stdx::impl_from; use syntax::{ - ast::{self, NameOwner}, + ast::{self, HasName}, match_ast, AstNode, SyntaxNode, }; diff --git a/crates/hir_def/src/adt.rs b/crates/hir_def/src/adt.rs index 402fb1d8dc..6ba70a2df6 100644 --- a/crates/hir_def/src/adt.rs +++ b/crates/hir_def/src/adt.rs @@ -9,7 +9,7 @@ use hir_expand::{ InFile, }; use la_arena::{Arena, ArenaMap}; -use syntax::ast::{self, NameOwner, VisibilityOwner}; +use syntax::ast::{self, HasName, HasVisibility}; use tt::{Delimiter, DelimiterKind, Leaf, Subtree, TokenTree}; use crate::{ diff --git a/crates/hir_def/src/attr.rs b/crates/hir_def/src/attr.rs index 95516e2e83..03fe46e267 100644 --- a/crates/hir_def/src/attr.rs +++ b/crates/hir_def/src/attr.rs @@ -17,7 +17,7 @@ use la_arena::ArenaMap; use mbe::{syntax_node_to_token_tree, DelimiterKind}; use smallvec::{smallvec, SmallVec}; use syntax::{ - ast::{self, AstNode, AttrsOwner, IsString}, + ast::{self, AstNode, HasAttrs, IsString}, match_ast, AstPtr, AstToken, SmolStr, SyntaxNode, TextRange, TextSize, }; use tt::Subtree; @@ -101,11 +101,7 @@ impl ops::Deref for AttrsWithOwner { impl RawAttrs { pub(crate) const EMPTY: Self = Self { entries: None }; - pub(crate) fn new( - db: &dyn DefDatabase, - owner: &dyn ast::AttrsOwner, - hygiene: &Hygiene, - ) -> Self { + pub(crate) fn new(db: &dyn DefDatabase, owner: &dyn ast::HasAttrs, hygiene: &Hygiene) -> Self { let entries = collect_attrs(owner) .flat_map(|(id, attr)| match attr { Either::Left(attr) => { @@ -122,7 +118,7 @@ impl RawAttrs { Self { entries: if entries.is_empty() { None } else { Some(entries) } } } - fn from_attrs_owner(db: &dyn DefDatabase, owner: InFile<&dyn ast::AttrsOwner>) -> Self { + fn from_attrs_owner(db: &dyn DefDatabase, owner: InFile<&dyn ast::HasAttrs>) -> Self { let hygiene = Hygiene::new(db.upcast(), owner.file_id); Self::new(db, owner.value, &hygiene) } @@ -208,7 +204,7 @@ impl Attrs { let mut res = ArenaMap::default(); for (id, var) in src.value.iter() { - let attrs = RawAttrs::from_attrs_owner(db, src.with_value(var as &dyn ast::AttrsOwner)) + let attrs = RawAttrs::from_attrs_owner(db, src.with_value(var as &dyn ast::HasAttrs)) .filter(db, krate); res.insert(id, attrs) @@ -226,7 +222,7 @@ impl Attrs { let mut res = ArenaMap::default(); for (id, fld) in src.value.iter() { - let owner: &dyn AttrsOwner = match fld { + let owner: &dyn HasAttrs = match fld { Either::Left(tuple) => tuple, Either::Right(record) => record, }; @@ -312,7 +308,7 @@ impl AttrsWithOwner { Some(it) => { let raw_attrs = RawAttrs::from_attrs_owner( db, - it.as_ref().map(|it| it as &dyn ast::AttrsOwner), + it.as_ref().map(|it| it as &dyn ast::HasAttrs), ); match mod_data.definition_source(db) { InFile { file_id, value: ModuleSource::SourceFile(file) } => raw_attrs @@ -323,9 +319,9 @@ impl AttrsWithOwner { None => RawAttrs::from_attrs_owner( db, mod_data.definition_source(db).as_ref().map(|src| match src { - ModuleSource::SourceFile(file) => file as &dyn ast::AttrsOwner, - ModuleSource::Module(module) => module as &dyn ast::AttrsOwner, - ModuleSource::BlockExpr(block) => block as &dyn ast::AttrsOwner, + ModuleSource::SourceFile(file) => file as &dyn ast::HasAttrs, + ModuleSource::Module(module) => module as &dyn ast::HasAttrs, + ModuleSource::BlockExpr(block) => block as &dyn ast::HasAttrs, }), ), } @@ -398,9 +394,9 @@ impl AttrsWithOwner { None => { let InFile { file_id, value } = mod_data.definition_source(db); let attrs_owner = match &value { - ModuleSource::SourceFile(file) => file as &dyn ast::AttrsOwner, - ModuleSource::Module(module) => module as &dyn ast::AttrsOwner, - ModuleSource::BlockExpr(block) => block as &dyn ast::AttrsOwner, + ModuleSource::SourceFile(file) => file as &dyn ast::HasAttrs, + ModuleSource::Module(module) => module as &dyn ast::HasAttrs, + ModuleSource::BlockExpr(block) => block as &dyn ast::HasAttrs, }; return AttrSourceMap::new(InFile::new(file_id, attrs_owner)); } @@ -411,51 +407,51 @@ impl AttrsWithOwner { let file_id = id.parent.file_id(db); let root = db.parse_or_expand(file_id).unwrap(); let owner = match &map[id.local_id] { - Either::Left(it) => ast::AnyAttrsOwner::new(it.to_node(&root)), - Either::Right(it) => ast::AnyAttrsOwner::new(it.to_node(&root)), + Either::Left(it) => ast::AnyHasAttrs::new(it.to_node(&root)), + Either::Right(it) => ast::AnyHasAttrs::new(it.to_node(&root)), }; InFile::new(file_id, owner) } AttrDefId::AdtId(adt) => match adt { - AdtId::StructId(id) => id.lookup(db).source(db).map(ast::AnyAttrsOwner::new), - AdtId::UnionId(id) => id.lookup(db).source(db).map(ast::AnyAttrsOwner::new), - AdtId::EnumId(id) => id.lookup(db).source(db).map(ast::AnyAttrsOwner::new), + AdtId::StructId(id) => id.lookup(db).source(db).map(ast::AnyHasAttrs::new), + AdtId::UnionId(id) => id.lookup(db).source(db).map(ast::AnyHasAttrs::new), + AdtId::EnumId(id) => id.lookup(db).source(db).map(ast::AnyHasAttrs::new), }, - AttrDefId::FunctionId(id) => id.lookup(db).source(db).map(ast::AnyAttrsOwner::new), + AttrDefId::FunctionId(id) => id.lookup(db).source(db).map(ast::AnyHasAttrs::new), AttrDefId::EnumVariantId(id) => { let map = db.variants_attrs_source_map(id.parent); let file_id = id.parent.lookup(db).id.file_id(); let root = db.parse_or_expand(file_id).unwrap(); - InFile::new(file_id, ast::AnyAttrsOwner::new(map[id.local_id].to_node(&root))) + InFile::new(file_id, ast::AnyHasAttrs::new(map[id.local_id].to_node(&root))) } - AttrDefId::StaticId(id) => id.lookup(db).source(db).map(ast::AnyAttrsOwner::new), - AttrDefId::ConstId(id) => id.lookup(db).source(db).map(ast::AnyAttrsOwner::new), - AttrDefId::TraitId(id) => id.lookup(db).source(db).map(ast::AnyAttrsOwner::new), - AttrDefId::TypeAliasId(id) => id.lookup(db).source(db).map(ast::AnyAttrsOwner::new), + AttrDefId::StaticId(id) => id.lookup(db).source(db).map(ast::AnyHasAttrs::new), + AttrDefId::ConstId(id) => id.lookup(db).source(db).map(ast::AnyHasAttrs::new), + AttrDefId::TraitId(id) => id.lookup(db).source(db).map(ast::AnyHasAttrs::new), + AttrDefId::TypeAliasId(id) => id.lookup(db).source(db).map(ast::AnyHasAttrs::new), AttrDefId::MacroDefId(id) => id.ast_id().either( - |it| it.with_value(ast::AnyAttrsOwner::new(it.to_node(db.upcast()))), - |it| it.with_value(ast::AnyAttrsOwner::new(it.to_node(db.upcast()))), + |it| it.with_value(ast::AnyHasAttrs::new(it.to_node(db.upcast()))), + |it| it.with_value(ast::AnyHasAttrs::new(it.to_node(db.upcast()))), ), - AttrDefId::ImplId(id) => id.lookup(db).source(db).map(ast::AnyAttrsOwner::new), + AttrDefId::ImplId(id) => id.lookup(db).source(db).map(ast::AnyHasAttrs::new), AttrDefId::GenericParamId(id) => match id { GenericParamId::TypeParamId(id) => { id.parent.child_source(db).map(|source| match &source[id.local_id] { - Either::Left(id) => ast::AnyAttrsOwner::new(id.clone()), - Either::Right(id) => ast::AnyAttrsOwner::new(id.clone()), + Either::Left(id) => ast::AnyHasAttrs::new(id.clone()), + Either::Right(id) => ast::AnyHasAttrs::new(id.clone()), }) } GenericParamId::LifetimeParamId(id) => id .parent .child_source(db) - .map(|source| ast::AnyAttrsOwner::new(source[id.local_id].clone())), + .map(|source| ast::AnyHasAttrs::new(source[id.local_id].clone())), GenericParamId::ConstParamId(id) => id .parent .child_source(db) - .map(|source| ast::AnyAttrsOwner::new(source[id.local_id].clone())), + .map(|source| ast::AnyHasAttrs::new(source[id.local_id].clone())), }, }; - AttrSourceMap::new(owner.as_ref().map(|node| node as &dyn AttrsOwner)) + AttrSourceMap::new(owner.as_ref().map(|node| node as &dyn HasAttrs)) } pub fn docs_with_rangemap( @@ -555,7 +551,7 @@ pub struct AttrSourceMap { } impl AttrSourceMap { - fn new(owner: InFile<&dyn ast::AttrsOwner>) -> Self { + fn new(owner: InFile<&dyn ast::HasAttrs>) -> Self { let mut attrs = Vec::new(); let mut doc_comments = Vec::new(); for (_, attr) in collect_attrs(owner.value) { @@ -812,10 +808,10 @@ impl<'a> AttrQuery<'a> { fn attrs_from_ast(src: AstId, db: &dyn DefDatabase) -> RawAttrs where - N: ast::AttrsOwner, + N: ast::HasAttrs, { let src = InFile::new(src.file_id, src.to_node(db.upcast())); - RawAttrs::from_attrs_owner(db, src.as_ref().map(|it| it as &dyn ast::AttrsOwner)) + RawAttrs::from_attrs_owner(db, src.as_ref().map(|it| it as &dyn ast::HasAttrs)) } fn attrs_from_item_tree(id: ItemTreeId, db: &dyn DefDatabase) -> RawAttrs { @@ -825,7 +821,7 @@ fn attrs_from_item_tree(id: ItemTreeId, db: &dyn DefDatabase } fn collect_attrs( - owner: &dyn ast::AttrsOwner, + owner: &dyn ast::HasAttrs, ) -> impl Iterator)> { let (inner_attrs, inner_docs) = inner_attributes(owner.syntax()) .map_or((None, None), |(attrs, docs)| (Some(attrs), Some(docs))); diff --git a/crates/hir_def/src/body.rs b/crates/hir_def/src/body.rs index 5320a96bc5..0eff093beb 100644 --- a/crates/hir_def/src/body.rs +++ b/crates/hir_def/src/body.rs @@ -70,11 +70,11 @@ impl CfgExpander { CfgExpander { cfg_options, hygiene, krate } } - pub(crate) fn parse_attrs(&self, db: &dyn DefDatabase, owner: &dyn ast::AttrsOwner) -> Attrs { + pub(crate) fn parse_attrs(&self, db: &dyn DefDatabase, owner: &dyn ast::HasAttrs) -> Attrs { RawAttrs::new(db, owner, &self.hygiene).filter(db, self.krate) } - pub(crate) fn is_cfg_enabled(&self, db: &dyn DefDatabase, owner: &dyn ast::AttrsOwner) -> bool { + pub(crate) fn is_cfg_enabled(&self, db: &dyn DefDatabase, owner: &dyn ast::HasAttrs) -> bool { let attrs = self.parse_attrs(db, owner); attrs.is_cfg_enabled(&self.cfg_options) } @@ -179,7 +179,7 @@ impl Expander { InFile { file_id: self.current_file_id, value } } - pub(crate) fn parse_attrs(&self, db: &dyn DefDatabase, owner: &dyn ast::AttrsOwner) -> Attrs { + pub(crate) fn parse_attrs(&self, db: &dyn DefDatabase, owner: &dyn ast::HasAttrs) -> Attrs { self.cfg_expander.parse_attrs(db, owner) } diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs index 6a6d992af3..804d98ce38 100644 --- a/crates/hir_def/src/body/lower.rs +++ b/crates/hir_def/src/body/lower.rs @@ -14,7 +14,7 @@ use la_arena::Arena; use profile::Count; use syntax::{ ast::{ - self, ArgListOwner, ArrayExprKind, AstChildren, LiteralKind, LoopBodyOwner, NameOwner, + self, ArrayExprKind, AstChildren, HasArgList, HasLoopBody, HasName, LiteralKind, SlicePatComponents, }, AstNode, AstPtr, SyntaxNodePtr, @@ -912,7 +912,7 @@ impl ExprCollector<'_> { /// Returns `None` (and emits diagnostics) when `owner` if `#[cfg]`d out, and `Some(())` when /// not. - fn check_cfg(&mut self, owner: &dyn ast::AttrsOwner) -> Option<()> { + fn check_cfg(&mut self, owner: &dyn ast::HasAttrs) -> Option<()> { match self.expander.parse_attrs(self.db, owner).cfg() { Some(cfg) => { if self.expander.cfg_options().check(&cfg) != Some(false) { diff --git a/crates/hir_def/src/child_by_source.rs b/crates/hir_def/src/child_by_source.rs index e4580a0ca3..6d63570428 100644 --- a/crates/hir_def/src/child_by_source.rs +++ b/crates/hir_def/src/child_by_source.rs @@ -7,7 +7,7 @@ use either::Either; use hir_expand::HirFileId; use itertools::Itertools; -use syntax::ast::AttrsOwner; +use syntax::ast::HasAttrs; use crate::{ db::DefDatabase, diff --git a/crates/hir_def/src/generics.rs b/crates/hir_def/src/generics.rs index 5425ea8bea..ef86ab8a84 100644 --- a/crates/hir_def/src/generics.rs +++ b/crates/hir_def/src/generics.rs @@ -10,7 +10,7 @@ use hir_expand::{ HirFileId, InFile, }; use la_arena::{Arena, ArenaMap}; -use syntax::ast::{self, GenericParamsOwner, NameOwner, TypeBoundsOwner}; +use syntax::ast::{self, HasGenericParams, HasName, HasTypeBounds}; use crate::{ body::LowerCtx, @@ -236,7 +236,7 @@ impl GenericParams { &mut self, lower_ctx: &LowerCtx, sm: &mut SourceMap, - node: &dyn GenericParamsOwner, + node: &dyn HasGenericParams, ) { if let Some(params) = node.generic_param_list() { self.fill_params(lower_ctx, sm, params) @@ -249,7 +249,7 @@ impl GenericParams { pub(crate) fn fill_bounds( &mut self, lower_ctx: &LowerCtx, - node: &dyn ast::TypeBoundsOwner, + node: &dyn ast::HasTypeBounds, target: Either, ) { for bound in diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs index 26621b8c7e..df46ceeaee 100644 --- a/crates/hir_def/src/item_tree.rs +++ b/crates/hir_def/src/item_tree.rs @@ -44,7 +44,7 @@ use std::{ sync::Arc, }; -use ast::{AstNode, NameOwner, StructKind}; +use ast::{AstNode, HasName, StructKind}; use base_db::CrateId; use either::Either; use hir_expand::{ diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs index 7bed19a792..0af4ae0f90 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs @@ -4,7 +4,7 @@ use std::{collections::hash_map::Entry, mem, sync::Arc}; use hir_expand::{ast_id_map::AstIdMap, hygiene::Hygiene, name::known, HirFileId}; use syntax::{ - ast::{self, ModuleItemOwner}, + ast::{self, HasModuleItem}, SyntaxNode, WalkEvent, }; @@ -40,7 +40,7 @@ impl<'a> Ctx<'a> { } } - pub(super) fn lower_module_items(mut self, item_owner: &dyn ModuleItemOwner) -> ItemTree { + pub(super) fn lower_module_items(mut self, item_owner: &dyn HasModuleItem) -> ItemTree { self.tree.top_level = item_owner.items().flat_map(|item| self.lower_mod_item(&item, false)).collect(); self.tree @@ -644,7 +644,7 @@ impl<'a> Ctx<'a> { fn lower_generic_params_and_inner_items( &mut self, owner: GenericsOwner<'_>, - node: &impl ast::GenericParamsOwner, + node: &impl ast::HasGenericParams, ) -> Interned { // Generics are part of item headers and may contain inner items we need to collect. if let Some(params) = node.generic_param_list() { @@ -660,7 +660,7 @@ impl<'a> Ctx<'a> { fn lower_generic_params( &mut self, owner: GenericsOwner<'_>, - node: &impl ast::GenericParamsOwner, + node: &impl ast::HasGenericParams, ) -> Interned { let mut sm = &mut Default::default(); let mut generics = GenericParams::default(); @@ -706,7 +706,7 @@ impl<'a> Ctx<'a> { Interned::new(generics) } - fn lower_type_bounds(&mut self, node: &impl ast::TypeBoundsOwner) -> Vec> { + fn lower_type_bounds(&mut self, node: &impl ast::HasTypeBounds) -> Vec> { match node.type_bound_list() { Some(bound_list) => bound_list .bounds() @@ -716,7 +716,7 @@ impl<'a> Ctx<'a> { } } - fn lower_visibility(&mut self, item: &impl ast::VisibilityOwner) -> RawVisibilityId { + fn lower_visibility(&mut self, item: &impl ast::HasVisibility) -> RawVisibilityId { let vis = match self.forced_visibility { Some(vis) => return vis, None => RawVisibility::from_ast_with_hygiene(self.db, item.visibility(), &self.hygiene), diff --git a/crates/hir_def/src/path/lower.rs b/crates/hir_def/src/path/lower.rs index 82bdcd5a86..99e7cdc999 100644 --- a/crates/hir_def/src/path/lower.rs +++ b/crates/hir_def/src/path/lower.rs @@ -6,7 +6,7 @@ use crate::intern::Interned; use either::Either; use hir_expand::name::{name, AsName}; -use syntax::ast::{self, AstNode, TypeBoundsOwner}; +use syntax::ast::{self, AstNode, HasTypeBounds}; use super::AssociatedTypeBinding; use crate::{ diff --git a/crates/hir_expand/src/builtin_derive.rs b/crates/hir_expand/src/builtin_derive.rs index c5738a2a0e..eeebe87acd 100644 --- a/crates/hir_expand/src/builtin_derive.rs +++ b/crates/hir_expand/src/builtin_derive.rs @@ -4,7 +4,7 @@ use tracing::debug; use mbe::ExpandResult; use syntax::{ - ast::{self, AstNode, GenericParamsOwner, ModuleItemOwner, NameOwner}, + ast::{self, AstNode, HasGenericParams, HasModuleItem, HasName}, match_ast, }; diff --git a/crates/hir_expand/src/builtin_macro.rs b/crates/hir_expand/src/builtin_macro.rs index 74f9b23d73..9293b45064 100644 --- a/crates/hir_expand/src/builtin_macro.rs +++ b/crates/hir_expand/src/builtin_macro.rs @@ -558,7 +558,7 @@ mod tests { use base_db::{fixture::WithFixture, SourceDatabase}; use expect_test::{expect, Expect}; - use syntax::ast::NameOwner; + use syntax::ast::HasName; use crate::{ name::AsName, test_db::TestDB, AstNode, EagerCallInfo, ExpandTo, MacroCallId, diff --git a/crates/hir_expand/src/db.rs b/crates/hir_expand/src/db.rs index 09ff972960..fd1d8d2e60 100644 --- a/crates/hir_expand/src/db.rs +++ b/crates/hir_expand/src/db.rs @@ -8,7 +8,7 @@ use mbe::{syntax_node_to_token_tree, ExpandError, ExpandResult}; use rustc_hash::FxHashSet; use syntax::{ algo::diff, - ast::{self, AttrsOwner, NameOwner}, + ast::{self, HasAttrs, HasName}, AstNode, GreenNode, Parse, SyntaxNode, SyntaxToken, T, }; diff --git a/crates/hir_expand/src/hygiene.rs b/crates/hir_expand/src/hygiene.rs index a1c519b804..5b3ccdeb60 100644 --- a/crates/hir_expand/src/hygiene.rs +++ b/crates/hir_expand/src/hygiene.rs @@ -9,7 +9,7 @@ use db::TokenExpander; use either::Either; use mbe::Origin; use syntax::{ - ast::{self, AttrsOwner}, + ast::{self, HasAttrs}, AstNode, SyntaxKind, SyntaxNode, TextRange, TextSize, }; diff --git a/crates/hir_expand/src/lib.rs b/crates/hir_expand/src/lib.rs index bdc3023e9c..fc1ac17213 100644 --- a/crates/hir_expand/src/lib.rs +++ b/crates/hir_expand/src/lib.rs @@ -25,7 +25,7 @@ use std::{hash::Hash, iter, sync::Arc}; use base_db::{impl_intern_key, salsa, CrateId, FileId, FileRange}; use syntax::{ algo::skip_trivia_token, - ast::{self, AstNode, AttrsOwner}, + ast::{self, AstNode, HasAttrs}, Direction, SyntaxNode, SyntaxToken, TextRange, TextSize, }; diff --git a/crates/hir_ty/src/diagnostics/decl_check.rs b/crates/hir_ty/src/diagnostics/decl_check.rs index ea9b54af63..6fbb9c93b4 100644 --- a/crates/hir_ty/src/diagnostics/decl_check.rs +++ b/crates/hir_ty/src/diagnostics/decl_check.rs @@ -22,7 +22,7 @@ use hir_def::{ use hir_expand::name::{AsName, Name}; use stdx::{always, never}; use syntax::{ - ast::{self, NameOwner}, + ast::{self, HasName}, AstNode, AstPtr, }; diff --git a/crates/hir_ty/src/tests.rs b/crates/hir_ty/src/tests.rs index af6e773217..cf6833e56a 100644 --- a/crates/hir_ty/src/tests.rs +++ b/crates/hir_ty/src/tests.rs @@ -26,7 +26,7 @@ use hir_expand::{db::AstDatabase, InFile}; use once_cell::race::OnceBool; use stdx::format_to; use syntax::{ - ast::{self, AstNode, NameOwner}, + ast::{self, AstNode, HasName}, SyntaxNode, }; use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry}; diff --git a/crates/ide/src/annotations.rs b/crates/ide/src/annotations.rs index 67f1f6dbdb..472b396ac5 100644 --- a/crates/ide/src/annotations.rs +++ b/crates/ide/src/annotations.rs @@ -5,7 +5,7 @@ use ide_db::{ helpers::visit_file_defs, RootDatabase, }; -use syntax::{ast::NameOwner, AstNode, TextRange}; +use syntax::{ast::HasName, AstNode, TextRange}; use crate::{ fn_references::find_all_methods, @@ -99,7 +99,7 @@ pub(crate) fn annotations( }); } - fn name_range(node: &InFile, file_id: FileId) -> Option { + fn name_range(node: &InFile, file_id: FileId) -> Option { if node.file_id == file_id.into() { node.value.name().map(|it| it.syntax().text_range()) } else { diff --git a/crates/ide/src/display/navigation_target.rs b/crates/ide/src/display/navigation_target.rs index 6978e4b88f..65c29f6805 100644 --- a/crates/ide/src/display/navigation_target.rs +++ b/crates/ide/src/display/navigation_target.rs @@ -14,7 +14,7 @@ use ide_db::{ }; use ide_db::{defs::Definition, RootDatabase}; use syntax::{ - ast::{self, NameOwner}, + ast::{self, HasName}, match_ast, AstNode, SmolStr, TextRange, }; @@ -133,7 +133,7 @@ impl NavigationTarget { /// Allows `NavigationTarget` to be created from a `NameOwner` pub(crate) fn from_named( db: &RootDatabase, - node: InFile<&dyn ast::NameOwner>, + node: InFile<&dyn ast::HasName>, kind: SymbolKind, ) -> NavigationTarget { let name = node.value.name().map(|it| it.text().into()).unwrap_or_else(|| "_".into()); @@ -257,13 +257,13 @@ impl ToNavFromAst for hir::Trait { impl TryToNav for D where D: HasSource + ToNavFromAst + Copy + HasAttrs + HirDisplay, - D::Ast: ast::NameOwner, + D::Ast: ast::HasName, { fn try_to_nav(&self, db: &RootDatabase) -> Option { let src = self.source(db)?; let mut res = NavigationTarget::from_named( db, - src.as_ref().map(|it| it as &dyn ast::NameOwner), + src.as_ref().map(|it| it as &dyn ast::HasName), D::KIND, ); res.docs = self.docs(db); @@ -343,7 +343,7 @@ impl TryToNav for hir::Field { impl TryToNav for hir::MacroDef { fn try_to_nav(&self, db: &RootDatabase) -> Option { let src = self.source(db)?; - let name_owner: &dyn ast::NameOwner = match &src.value { + let name_owner: &dyn ast::HasName = match &src.value { Either::Left(it) => it, Either::Right(it) => it, }; diff --git a/crates/ide/src/file_structure.rs b/crates/ide/src/file_structure.rs index 19071d6be9..409f3901f5 100644 --- a/crates/ide/src/file_structure.rs +++ b/crates/ide/src/file_structure.rs @@ -1,6 +1,6 @@ use ide_db::SymbolKind; use syntax::{ - ast::{self, AttrsOwner, GenericParamsOwner, NameOwner}, + ast::{self, HasAttrs, HasGenericParams, HasName}, match_ast, AstNode, AstToken, NodeOrToken, SourceFile, SyntaxNode, SyntaxToken, TextRange, WalkEvent, }; @@ -74,11 +74,11 @@ pub(crate) fn file_structure(file: &SourceFile) -> Vec { } fn structure_node(node: &SyntaxNode) -> Option { - fn decl(node: N, kind: StructureNodeKind) -> Option { + fn decl(node: N, kind: StructureNodeKind) -> Option { decl_with_detail(&node, None, kind) } - fn decl_with_type_ref( + fn decl_with_type_ref( node: &N, type_ref: Option, kind: StructureNodeKind, @@ -91,7 +91,7 @@ fn structure_node(node: &SyntaxNode) -> Option { decl_with_detail(node, detail, kind) } - fn decl_with_detail( + fn decl_with_detail( node: &N, detail: Option, kind: StructureNodeKind, diff --git a/crates/ide/src/fn_references.rs b/crates/ide/src/fn_references.rs index 1a99a1f371..63fb322cea 100644 --- a/crates/ide/src/fn_references.rs +++ b/crates/ide/src/fn_references.rs @@ -4,7 +4,7 @@ use hir::Semantics; use ide_assists::utils::test_related_attribute; use ide_db::RootDatabase; -use syntax::{ast, ast::NameOwner, AstNode, SyntaxNode}; +use syntax::{ast, ast::HasName, AstNode, SyntaxNode}; use crate::{FileId, FileRange}; diff --git a/crates/ide/src/folding_ranges.rs b/crates/ide/src/folding_ranges.rs index 6f69421002..66126c8d55 100755 --- a/crates/ide/src/folding_ranges.rs +++ b/crates/ide/src/folding_ranges.rs @@ -152,7 +152,7 @@ fn fold_kind(kind: SyntaxKind) -> Option { fn contiguous_range_for_item_group(first: N, visited: &mut FxHashSet) -> Option where - N: ast::VisibilityOwner + Clone + Hash + Eq, + N: ast::HasVisibility + Clone + Hash + Eq, { if !visited.insert(first.clone()) { return None; diff --git a/crates/ide/src/highlight_related.rs b/crates/ide/src/highlight_related.rs index 6aef3a9429..6b557bc92d 100644 --- a/crates/ide/src/highlight_related.rs +++ b/crates/ide/src/highlight_related.rs @@ -8,7 +8,7 @@ use ide_db::{ }; use rustc_hash::FxHashSet; use syntax::{ - ast::{self, LoopBodyOwner}, + ast::{self, HasLoopBody}, match_ast, AstNode, SyntaxKind::IDENT, SyntaxNode, SyntaxToken, TextRange, TextSize, T, diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs index 79e68aa1dd..401feffff4 100644 --- a/crates/ide/src/inlay_hints.rs +++ b/crates/ide/src/inlay_hints.rs @@ -4,7 +4,7 @@ use ide_db::RootDatabase; use ide_db::{base_db::FileRange, helpers::FamousDefs}; use stdx::to_lower_snake_case; use syntax::{ - ast::{self, ArgListOwner, AstNode, NameOwner}, + ast::{self, AstNode, HasArgList, HasName}, match_ast, Direction, NodeOrToken, SmolStr, SyntaxKind, TextRange, T, }; diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs index c39d00b6e7..3ebec4dd8f 100644 --- a/crates/ide/src/references.rs +++ b/crates/ide/src/references.rs @@ -22,7 +22,7 @@ use ide_db::{ use rustc_hash::FxHashMap; use syntax::{ algo::find_node_at_offset, - ast::{self, NameOwner}, + ast::{self, HasName}, match_ast, AstNode, SyntaxNode, TextRange, TextSize, T, }; diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index 376384670a..5d0cf7bba4 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs @@ -1,6 +1,6 @@ use std::fmt; -use ast::NameOwner; +use ast::HasName; use cfg::CfgExpr; use either::Either; use hir::{AsAssocItem, HasAttrs, HasSource, HirDisplay, InFile, Semantics}; @@ -14,7 +14,7 @@ use ide_db::{ use itertools::Itertools; use rustc_hash::{FxHashMap, FxHashSet}; use stdx::{always, format_to}; -use syntax::ast::{self, AstNode, AttrsOwner}; +use syntax::ast::{self, AstNode, HasAttrs as _}; use crate::{ display::{ToNav, TryToNav}, @@ -328,7 +328,7 @@ pub(crate) fn runnable_fn(sema: &Semantics, def: hir::Function) -> let nav = NavigationTarget::from_named( sema.db, - func.as_ref().map(|it| it as &dyn ast::NameOwner), + func.as_ref().map(|it| it as &dyn ast::HasName), SymbolKind::Function, ); let cfg = def.attrs(sema.db).cfg(); diff --git a/crates/ide_assists/src/handlers/add_lifetime_to_type.rs b/crates/ide_assists/src/handlers/add_lifetime_to_type.rs index 7030d0f978..14cdc1cf86 100644 --- a/crates/ide_assists/src/handlers/add_lifetime_to_type.rs +++ b/crates/ide_assists/src/handlers/add_lifetime_to_type.rs @@ -1,4 +1,4 @@ -use syntax::ast::{self, AstNode, GenericParamsOwner, NameOwner}; +use syntax::ast::{self, AstNode, HasGenericParams, HasName}; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide_assists/src/handlers/add_missing_match_arms.rs b/crates/ide_assists/src/handlers/add_missing_match_arms.rs index cdbd8ac183..c856ab45d7 100644 --- a/crates/ide_assists/src/handlers/add_missing_match_arms.rs +++ b/crates/ide_assists/src/handlers/add_missing_match_arms.rs @@ -5,7 +5,7 @@ use hir::{Adt, HasSource, ModuleDef, Semantics}; use ide_db::helpers::{mod_path_to_ast, FamousDefs}; use ide_db::RootDatabase; use itertools::Itertools; -use syntax::ast::{self, make, AstNode, MatchArm, NameOwner, Pat}; +use syntax::ast::{self, make, AstNode, HasName, MatchArm, Pat}; use crate::{ utils::{self, render_snippet, Cursor}, diff --git a/crates/ide_assists/src/handlers/change_visibility.rs b/crates/ide_assists/src/handlers/change_visibility.rs index ed936667f8..5f15e923ad 100644 --- a/crates/ide_assists/src/handlers/change_visibility.rs +++ b/crates/ide_assists/src/handlers/change_visibility.rs @@ -1,5 +1,5 @@ use syntax::{ - ast::{self, NameOwner, VisibilityOwner}, + ast::{self, HasName, HasVisibility}, AstNode, SyntaxKind::{ CONST, ENUM, FN, MACRO_DEF, MODULE, STATIC, STRUCT, TRAIT, TYPE_ALIAS, USE, VISIBILITY, diff --git a/crates/ide_assists/src/handlers/convert_bool_then.rs b/crates/ide_assists/src/handlers/convert_bool_then.rs index e7939269ad..2e24c22c9f 100644 --- a/crates/ide_assists/src/handlers/convert_bool_then.rs +++ b/crates/ide_assists/src/handlers/convert_bool_then.rs @@ -9,7 +9,7 @@ use ide_db::{ }; use itertools::Itertools; use syntax::{ - ast::{self, edit::AstNodeEdit, make, ArgListOwner}, + ast::{self, edit::AstNodeEdit, make, HasArgList}, ted, AstNode, SyntaxNode, }; diff --git a/crates/ide_assists/src/handlers/convert_into_to_from.rs b/crates/ide_assists/src/handlers/convert_into_to_from.rs index 2d8b936cd6..29555a5111 100644 --- a/crates/ide_assists/src/handlers/convert_into_to_from.rs +++ b/crates/ide_assists/src/handlers/convert_into_to_from.rs @@ -2,7 +2,7 @@ use ide_db::{ helpers::{mod_path_to_ast, FamousDefs}, traits::resolve_target_trait, }; -use syntax::ast::{self, AstNode, NameOwner}; +use syntax::ast::{self, AstNode, HasName}; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide_assists/src/handlers/convert_iter_for_each_to_for.rs b/crates/ide_assists/src/handlers/convert_iter_for_each_to_for.rs index aef03e3238..8744115f29 100644 --- a/crates/ide_assists/src/handlers/convert_iter_for_each_to_for.rs +++ b/crates/ide_assists/src/handlers/convert_iter_for_each_to_for.rs @@ -2,7 +2,7 @@ use hir::known; use ide_db::helpers::FamousDefs; use stdx::format_to; use syntax::{ - ast::{self, edit_in_place::Indent, make, ArgListOwner, LoopBodyOwner}, + ast::{self, edit_in_place::Indent, make, HasArgList, HasLoopBody}, AstNode, }; diff --git a/crates/ide_assists/src/handlers/convert_tuple_struct_to_named_struct.rs b/crates/ide_assists/src/handlers/convert_tuple_struct_to_named_struct.rs index bb0382e15f..9b8e548e8f 100644 --- a/crates/ide_assists/src/handlers/convert_tuple_struct_to_named_struct.rs +++ b/crates/ide_assists/src/handlers/convert_tuple_struct_to_named_struct.rs @@ -1,7 +1,7 @@ use either::Either; use ide_db::defs::{Definition, NameRefClass}; use syntax::{ - ast::{self, AstNode, GenericParamsOwner, VisibilityOwner}, + ast::{self, AstNode, HasGenericParams, HasVisibility}, match_ast, SyntaxNode, }; diff --git a/crates/ide_assists/src/handlers/convert_while_to_loop.rs b/crates/ide_assists/src/handlers/convert_while_to_loop.rs index cbddc106ff..2ecf646252 100644 --- a/crates/ide_assists/src/handlers/convert_while_to_loop.rs +++ b/crates/ide_assists/src/handlers/convert_while_to_loop.rs @@ -4,7 +4,7 @@ use syntax::{ ast::{ self, edit::{AstNodeEdit, IndentLevel}, - make, LoopBodyOwner, + make, HasLoopBody, }, AstNode, T, }; diff --git a/crates/ide_assists/src/handlers/destructure_tuple_binding.rs b/crates/ide_assists/src/handlers/destructure_tuple_binding.rs index a421f57754..a57b3c3904 100644 --- a/crates/ide_assists/src/handlers/destructure_tuple_binding.rs +++ b/crates/ide_assists/src/handlers/destructure_tuple_binding.rs @@ -5,7 +5,7 @@ use ide_db::{ }; use itertools::Itertools; use syntax::{ - ast::{self, AstNode, FieldExpr, IdentPat, MethodCallExpr, NameOwner}, + ast::{self, AstNode, FieldExpr, HasName, IdentPat, MethodCallExpr}, TextRange, }; diff --git a/crates/ide_assists/src/handlers/extract_function.rs b/crates/ide_assists/src/handlers/extract_function.rs index 733bb34788..4b11c5da19 100644 --- a/crates/ide_assists/src/handlers/extract_function.rs +++ b/crates/ide_assists/src/handlers/extract_function.rs @@ -636,7 +636,7 @@ impl FunctionBody { let mut ancestors = self.parent()?.ancestors(); let infer_expr_opt = |expr| sema.type_of_expr(&expr?).map(TypeInfo::adjusted); let mut parent_loop = None; - let mut set_parent_loop = |loop_: &dyn ast::LoopBodyOwner| { + let mut set_parent_loop = |loop_: &dyn ast::HasLoopBody| { if loop_ .loop_body() .map_or(false, |it| it.syntax().text_range().contains_range(self.text_range())) diff --git a/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs index 3bc347b1e2..d481b8c298 100644 --- a/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs @@ -15,8 +15,8 @@ use itertools::Itertools; use rustc_hash::FxHashSet; use syntax::{ ast::{ - self, edit::IndentLevel, edit_in_place::Indent, make, AstNode, AttrsOwner, - GenericParamsOwner, NameOwner, TypeBoundsOwner, VisibilityOwner, + self, edit::IndentLevel, edit_in_place::Indent, make, AstNode, HasAttrs, HasGenericParams, + HasName, HasTypeBounds, HasVisibility, }, match_ast, ted::{self, Position}, diff --git a/crates/ide_assists/src/handlers/extract_type_alias.rs b/crates/ide_assists/src/handlers/extract_type_alias.rs index a2dd23b58b..f0c4d521db 100644 --- a/crates/ide_assists/src/handlers/extract_type_alias.rs +++ b/crates/ide_assists/src/handlers/extract_type_alias.rs @@ -2,7 +2,7 @@ use either::Either; use ide_db::helpers::node_ext::walk_ty; use itertools::Itertools; use syntax::{ - ast::{self, edit::IndentLevel, AstNode, GenericParamsOwner, NameOwner}, + ast::{self, edit::IndentLevel, AstNode, HasGenericParams, HasName}, match_ast, }; diff --git a/crates/ide_assists/src/handlers/fix_visibility.rs b/crates/ide_assists/src/handlers/fix_visibility.rs index 08d665f8ee..80da4a35ad 100644 --- a/crates/ide_assists/src/handlers/fix_visibility.rs +++ b/crates/ide_assists/src/handlers/fix_visibility.rs @@ -1,7 +1,7 @@ use hir::{db::HirDatabase, HasSource, HasVisibility, PathResolution}; use ide_db::base_db::FileId; use syntax::{ - ast::{self, VisibilityOwner}, + ast::{self, HasVisibility as _}, AstNode, TextRange, TextSize, }; @@ -147,7 +147,7 @@ fn target_data_for_def( ) -> Option<(TextSize, Option, TextRange, FileId)> where S: HasSource, - Ast: AstNode + ast::VisibilityOwner, + Ast: AstNode + ast::HasVisibility, { let source = x.source(db)?; let in_file_syntax = source.syntax(); diff --git a/crates/ide_assists/src/handlers/generate_default_from_enum_variant.rs b/crates/ide_assists/src/handlers/generate_default_from_enum_variant.rs index e55c385029..e67789a662 100644 --- a/crates/ide_assists/src/handlers/generate_default_from_enum_variant.rs +++ b/crates/ide_assists/src/handlers/generate_default_from_enum_variant.rs @@ -1,5 +1,5 @@ use ide_db::{helpers::FamousDefs, RootDatabase}; -use syntax::ast::{self, AstNode, NameOwner}; +use syntax::ast::{self, AstNode, HasName}; use crate::{AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide_assists/src/handlers/generate_default_from_new.rs b/crates/ide_assists/src/handlers/generate_default_from_new.rs index b54ec59da1..680ec0d1cd 100644 --- a/crates/ide_assists/src/handlers/generate_default_from_new.rs +++ b/crates/ide_assists/src/handlers/generate_default_from_new.rs @@ -2,7 +2,7 @@ use ide_db::helpers::FamousDefs; use itertools::Itertools; use stdx::format_to; use syntax::{ - ast::{self, GenericParamsOwner, Impl, NameOwner, TypeBoundsOwner}, + ast::{self, HasGenericParams, HasName, HasTypeBounds, Impl}, AstNode, }; diff --git a/crates/ide_assists/src/handlers/generate_deref.rs b/crates/ide_assists/src/handlers/generate_deref.rs index 4e10fdb854..2208c23c15 100644 --- a/crates/ide_assists/src/handlers/generate_deref.rs +++ b/crates/ide_assists/src/handlers/generate_deref.rs @@ -2,7 +2,7 @@ use std::fmt::Display; use ide_db::{helpers::FamousDefs, RootDatabase}; use syntax::{ - ast::{self, NameOwner}, + ast::{self, HasName}, AstNode, SyntaxNode, }; diff --git a/crates/ide_assists/src/handlers/generate_derive.rs b/crates/ide_assists/src/handlers/generate_derive.rs index adae8ab7e9..28483f795e 100644 --- a/crates/ide_assists/src/handlers/generate_derive.rs +++ b/crates/ide_assists/src/handlers/generate_derive.rs @@ -1,5 +1,5 @@ use syntax::{ - ast::{self, AstNode, AttrsOwner}, + ast::{self, AstNode, HasAttrs}, SyntaxKind::{COMMENT, WHITESPACE}, TextSize, }; diff --git a/crates/ide_assists/src/handlers/generate_enum_is_method.rs b/crates/ide_assists/src/handlers/generate_enum_is_method.rs index 94216f2dff..c2a6e438b1 100644 --- a/crates/ide_assists/src/handlers/generate_enum_is_method.rs +++ b/crates/ide_assists/src/handlers/generate_enum_is_method.rs @@ -1,6 +1,6 @@ use stdx::to_lower_snake_case; -use syntax::ast::VisibilityOwner; -use syntax::ast::{self, AstNode, NameOwner}; +use syntax::ast::HasVisibility; +use syntax::ast::{self, AstNode, HasName}; use crate::{ utils::{add_method_to_adt, find_struct_impl}, diff --git a/crates/ide_assists/src/handlers/generate_enum_projection_method.rs b/crates/ide_assists/src/handlers/generate_enum_projection_method.rs index 986fb23155..a9116be67c 100644 --- a/crates/ide_assists/src/handlers/generate_enum_projection_method.rs +++ b/crates/ide_assists/src/handlers/generate_enum_projection_method.rs @@ -1,7 +1,7 @@ use itertools::Itertools; use stdx::to_lower_snake_case; -use syntax::ast::VisibilityOwner; -use syntax::ast::{self, AstNode, NameOwner}; +use syntax::ast::HasVisibility; +use syntax::ast::{self, AstNode, HasName}; use crate::{ utils::{add_method_to_adt, find_struct_impl}, diff --git a/crates/ide_assists/src/handlers/generate_from_impl_for_enum.rs b/crates/ide_assists/src/handlers/generate_from_impl_for_enum.rs index 8727be07dd..96b751f099 100644 --- a/crates/ide_assists/src/handlers/generate_from_impl_for_enum.rs +++ b/crates/ide_assists/src/handlers/generate_from_impl_for_enum.rs @@ -1,6 +1,6 @@ use ide_db::helpers::FamousDefs; use ide_db::RootDatabase; -use syntax::ast::{self, AstNode, NameOwner}; +use syntax::ast::{self, AstNode, HasName}; use crate::{utils::generate_trait_impl_text, AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide_assists/src/handlers/generate_function.rs b/crates/ide_assists/src/handlers/generate_function.rs index 0255e508b4..8a115087da 100644 --- a/crates/ide_assists/src/handlers/generate_function.rs +++ b/crates/ide_assists/src/handlers/generate_function.rs @@ -11,7 +11,7 @@ use syntax::{ ast::{ self, edit::{AstNodeEdit, IndentLevel}, - make, ArgListOwner, AstNode, CallExpr, ModuleItemOwner, + make, AstNode, CallExpr, HasArgList, HasModuleItem, }, SyntaxKind, SyntaxNode, TextRange, TextSize, }; diff --git a/crates/ide_assists/src/handlers/generate_getter.rs b/crates/ide_assists/src/handlers/generate_getter.rs index 739f3e592f..186e01fa9d 100644 --- a/crates/ide_assists/src/handlers/generate_getter.rs +++ b/crates/ide_assists/src/handlers/generate_getter.rs @@ -1,5 +1,5 @@ use stdx::{format_to, to_lower_snake_case}; -use syntax::ast::{self, AstNode, NameOwner, VisibilityOwner}; +use syntax::ast::{self, AstNode, HasName, HasVisibility}; use crate::{ utils::useless_type_special_case, diff --git a/crates/ide_assists/src/handlers/generate_impl.rs b/crates/ide_assists/src/handlers/generate_impl.rs index fd2e250bc3..58fea103f8 100644 --- a/crates/ide_assists/src/handlers/generate_impl.rs +++ b/crates/ide_assists/src/handlers/generate_impl.rs @@ -1,4 +1,4 @@ -use syntax::ast::{self, AstNode, NameOwner}; +use syntax::ast::{self, AstNode, HasName}; use crate::{utils::generate_impl_text, AssistContext, AssistId, AssistKind, Assists}; diff --git a/crates/ide_assists/src/handlers/generate_is_empty_from_len.rs b/crates/ide_assists/src/handlers/generate_is_empty_from_len.rs index 910010a044..d831289775 100644 --- a/crates/ide_assists/src/handlers/generate_is_empty_from_len.rs +++ b/crates/ide_assists/src/handlers/generate_is_empty_from_len.rs @@ -1,6 +1,6 @@ use hir::{known, HasSource, Name}; use syntax::{ - ast::{self, NameOwner}, + ast::{self, HasName}, AstNode, }; diff --git a/crates/ide_assists/src/handlers/generate_new.rs b/crates/ide_assists/src/handlers/generate_new.rs index b65e8387b0..6a1f710f6d 100644 --- a/crates/ide_assists/src/handlers/generate_new.rs +++ b/crates/ide_assists/src/handlers/generate_new.rs @@ -1,6 +1,6 @@ use itertools::Itertools; use stdx::format_to; -use syntax::ast::{self, AstNode, NameOwner, StructKind, VisibilityOwner}; +use syntax::ast::{self, AstNode, HasName, HasVisibility, StructKind}; use crate::{ utils::{find_impl_block_start, find_struct_impl, generate_impl_text}, diff --git a/crates/ide_assists/src/handlers/generate_setter.rs b/crates/ide_assists/src/handlers/generate_setter.rs index 5bdf6b3f44..5005ac9f5c 100644 --- a/crates/ide_assists/src/handlers/generate_setter.rs +++ b/crates/ide_assists/src/handlers/generate_setter.rs @@ -1,5 +1,5 @@ use stdx::{format_to, to_lower_snake_case}; -use syntax::ast::{self, AstNode, NameOwner, VisibilityOwner}; +use syntax::ast::{self, AstNode, HasName, HasVisibility}; use crate::{ utils::{find_impl_block_end, find_struct_impl, generate_impl_text}, diff --git a/crates/ide_assists/src/handlers/inline_call.rs b/crates/ide_assists/src/handlers/inline_call.rs index bd566ec820..14313fefa7 100644 --- a/crates/ide_assists/src/handlers/inline_call.rs +++ b/crates/ide_assists/src/handlers/inline_call.rs @@ -11,7 +11,7 @@ use ide_db::{ }; use itertools::{izip, Itertools}; use syntax::{ - ast::{self, edit_in_place::Indent, ArgListOwner}, + ast::{self, edit_in_place::Indent, HasArgList}, ted, AstNode, SyntaxNode, }; diff --git a/crates/ide_assists/src/handlers/inline_local_variable.rs b/crates/ide_assists/src/handlers/inline_local_variable.rs index 337cd6cb5a..f01dff0965 100644 --- a/crates/ide_assists/src/handlers/inline_local_variable.rs +++ b/crates/ide_assists/src/handlers/inline_local_variable.rs @@ -7,7 +7,7 @@ use ide_db::{ RootDatabase, }; use syntax::{ - ast::{self, AstNode, AstToken, NameOwner}, + ast::{self, AstNode, AstToken, HasName}, SyntaxElement, TextRange, }; diff --git a/crates/ide_assists/src/handlers/introduce_named_lifetime.rs b/crates/ide_assists/src/handlers/introduce_named_lifetime.rs index 8077f73d1e..ec6be2e816 100644 --- a/crates/ide_assists/src/handlers/introduce_named_lifetime.rs +++ b/crates/ide_assists/src/handlers/introduce_named_lifetime.rs @@ -1,6 +1,6 @@ use rustc_hash::FxHashSet; use syntax::{ - ast::{self, edit_in_place::GenericParamsOwnerEdit, make, GenericParamsOwner}, + ast::{self, edit_in_place::GenericParamsOwnerEdit, make, HasGenericParams}, ted::{self, Position}, AstNode, TextRange, }; diff --git a/crates/ide_assists/src/handlers/move_bounds.rs b/crates/ide_assists/src/handlers/move_bounds.rs index d89d11bdf4..01c6eea225 100644 --- a/crates/ide_assists/src/handlers/move_bounds.rs +++ b/crates/ide_assists/src/handlers/move_bounds.rs @@ -1,5 +1,5 @@ use syntax::{ - ast::{self, edit_in_place::GenericParamsOwnerEdit, make, AstNode, NameOwner, TypeBoundsOwner}, + ast::{self, edit_in_place::GenericParamsOwnerEdit, make, AstNode, HasName, HasTypeBounds}, match_ast, }; diff --git a/crates/ide_assists/src/handlers/move_module_to_file.rs b/crates/ide_assists/src/handlers/move_module_to_file.rs index cfc54be8d1..30dc7c5fa4 100644 --- a/crates/ide_assists/src/handlers/move_module_to_file.rs +++ b/crates/ide_assists/src/handlers/move_module_to_file.rs @@ -5,7 +5,7 @@ use ide_db::base_db::AnchoredPathBuf; use itertools::Itertools; use stdx::format_to; use syntax::{ - ast::{self, edit::AstNodeEdit, NameOwner}, + ast::{self, edit::AstNodeEdit, HasName}, AstNode, TextRange, }; diff --git a/crates/ide_assists/src/handlers/qualify_path.rs b/crates/ide_assists/src/handlers/qualify_path.rs index 2510eae971..8a2ec8ba80 100644 --- a/crates/ide_assists/src/handlers/qualify_path.rs +++ b/crates/ide_assists/src/handlers/qualify_path.rs @@ -8,7 +8,7 @@ use ide_db::helpers::{ use ide_db::RootDatabase; use syntax::{ ast, - ast::{make, ArgListOwner}, + ast::{make, HasArgList}, AstNode, }; diff --git a/crates/ide_assists/src/handlers/remove_unused_param.rs b/crates/ide_assists/src/handlers/remove_unused_param.rs index 75b9f827d7..545809a71d 100644 --- a/crates/ide_assists/src/handlers/remove_unused_param.rs +++ b/crates/ide_assists/src/handlers/remove_unused_param.rs @@ -1,7 +1,7 @@ use ide_db::{base_db::FileId, defs::Definition, search::FileReference}; use syntax::{ algo::find_node_at_range, - ast::{self, ArgListOwner}, + ast::{self, HasArgList}, AstNode, SourceFile, SyntaxKind, SyntaxNode, TextRange, T, }; diff --git a/crates/ide_assists/src/handlers/reorder_impl.rs b/crates/ide_assists/src/handlers/reorder_impl.rs index d398373c34..8ae12ab1f4 100644 --- a/crates/ide_assists/src/handlers/reorder_impl.rs +++ b/crates/ide_assists/src/handlers/reorder_impl.rs @@ -4,7 +4,7 @@ use rustc_hash::FxHashMap; use hir::{PathResolution, Semantics}; use ide_db::RootDatabase; use syntax::{ - ast::{self, NameOwner}, + ast::{self, HasName}, ted, AstNode, }; diff --git a/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs b/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs index d6319ea5c1..c0b7db332e 100644 --- a/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs +++ b/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs @@ -3,7 +3,7 @@ use ide_db::helpers::{import_assets::NameToImport, mod_path_to_ast}; use ide_db::items_locator; use itertools::Itertools; use syntax::{ - ast::{self, make, AstNode, NameOwner}, + ast::{self, make, AstNode, HasName}, SyntaxKind::{IDENT, WHITESPACE}, }; diff --git a/crates/ide_assists/src/handlers/replace_if_let_with_match.rs b/crates/ide_assists/src/handlers/replace_if_let_with_match.rs index 1873653306..3a89c2b996 100644 --- a/crates/ide_assists/src/handlers/replace_if_let_with_match.rs +++ b/crates/ide_assists/src/handlers/replace_if_let_with_match.rs @@ -6,7 +6,7 @@ use syntax::{ ast::{ self, edit::{AstNodeEdit, IndentLevel}, - make, NameOwner, + make, HasName, }, AstNode, TextRange, }; diff --git a/crates/ide_assists/src/handlers/sort_items.rs b/crates/ide_assists/src/handlers/sort_items.rs index f318c048b1..a9d4f4299e 100644 --- a/crates/ide_assists/src/handlers/sort_items.rs +++ b/crates/ide_assists/src/handlers/sort_items.rs @@ -3,7 +3,7 @@ use std::cmp::Ordering; use itertools::Itertools; use syntax::{ - ast::{self, NameOwner}, + ast::{self, HasName}, ted, AstNode, TextRange, }; @@ -195,7 +195,7 @@ fn add_sort_variants_assist(acc: &mut Assists, variant_list: ast::VariantList) - ) } -fn sort_by_name(initial: &[T]) -> Vec { +fn sort_by_name(initial: &[T]) -> Vec { initial .iter() .cloned() diff --git a/crates/ide_assists/src/handlers/toggle_ignore.rs b/crates/ide_assists/src/handlers/toggle_ignore.rs index 4da6089cac..feaa24c1fe 100644 --- a/crates/ide_assists/src/handlers/toggle_ignore.rs +++ b/crates/ide_assists/src/handlers/toggle_ignore.rs @@ -1,5 +1,5 @@ use syntax::{ - ast::{self, AttrsOwner}, + ast::{self, HasAttrs}, AstNode, AstToken, }; diff --git a/crates/ide_assists/src/handlers/unmerge_use.rs b/crates/ide_assists/src/handlers/unmerge_use.rs index 22853b7e36..71a816e19f 100644 --- a/crates/ide_assists/src/handlers/unmerge_use.rs +++ b/crates/ide_assists/src/handlers/unmerge_use.rs @@ -1,6 +1,6 @@ use itertools::Itertools; use syntax::{ - ast::{self, make, VisibilityOwner}, + ast::{self, make, HasVisibility}, ted::{self, Position}, AstNode, SyntaxKind, }; diff --git a/crates/ide_assists/src/utils.rs b/crates/ide_assists/src/utils.rs index aa0956d0f6..9bc70bc3fe 100644 --- a/crates/ide_assists/src/utils.rs +++ b/crates/ide_assists/src/utils.rs @@ -14,7 +14,7 @@ use syntax::{ self, edit::{self, AstNodeEdit}, edit_in_place::AttrsOwnerEdit, - make, ArgListOwner, AttrsOwner, GenericParamsOwner, NameOwner, TypeBoundsOwner, + make, HasArgList, HasAttrs, HasGenericParams, HasName, HasTypeBounds, }, ted, AstNode, Direction, SmolStr, SyntaxKind::*, diff --git a/crates/ide_assists/src/utils/gen_trait_fn_body.rs b/crates/ide_assists/src/utils/gen_trait_fn_body.rs index eb4a23a8da..6915460209 100644 --- a/crates/ide_assists/src/utils/gen_trait_fn_body.rs +++ b/crates/ide_assists/src/utils/gen_trait_fn_body.rs @@ -1,7 +1,7 @@ //! This module contains functions to generate default trait impl function bodies where possible. use syntax::{ - ast::{self, edit::AstNodeEdit, make, AstNode, BinaryOp, CmpOp, LogicOp, NameOwner}, + ast::{self, edit::AstNodeEdit, make, AstNode, BinaryOp, CmpOp, HasName, LogicOp}, ted, }; diff --git a/crates/ide_assists/src/utils/suggest_name.rs b/crates/ide_assists/src/utils/suggest_name.rs index 17db6d3c19..35e2300196 100644 --- a/crates/ide_assists/src/utils/suggest_name.rs +++ b/crates/ide_assists/src/utils/suggest_name.rs @@ -5,7 +5,7 @@ use ide_db::RootDatabase; use itertools::Itertools; use stdx::to_lower_snake_case; use syntax::{ - ast::{self, NameOwner}, + ast::{self, HasName}, match_ast, AstNode, SmolStr, }; diff --git a/crates/ide_completion/src/completions/fn_param.rs b/crates/ide_completion/src/completions/fn_param.rs index 28da6d69c8..a9f1944e28 100644 --- a/crates/ide_completion/src/completions/fn_param.rs +++ b/crates/ide_completion/src/completions/fn_param.rs @@ -2,7 +2,7 @@ use rustc_hash::FxHashMap; use syntax::{ - ast::{self, ModuleItemOwner}, + ast::{self, HasModuleItem}, match_ast, AstNode, }; diff --git a/crates/ide_completion/src/context.rs b/crates/ide_completion/src/context.rs index 7d5c36d01f..9d3e894a3d 100644 --- a/crates/ide_completion/src/context.rs +++ b/crates/ide_completion/src/context.rs @@ -9,7 +9,7 @@ use ide_db::{ }; use syntax::{ algo::find_node_at_offset, - ast::{self, NameOrNameRef, NameOwner}, + ast::{self, HasName, NameOrNameRef}, match_ast, AstNode, NodeOrToken, SyntaxKind::{self, *}, SyntaxNode, SyntaxToken, TextRange, TextSize, T, diff --git a/crates/ide_completion/src/patterns.rs b/crates/ide_completion/src/patterns.rs index 05792dd47e..381a6a83aa 100644 --- a/crates/ide_completion/src/patterns.rs +++ b/crates/ide_completion/src/patterns.rs @@ -8,7 +8,7 @@ use hir::Semantics; use ide_db::RootDatabase; use syntax::{ algo::non_trivia_sibling, - ast::{self, ArgListOwner, LoopBodyOwner}, + ast::{self, HasArgList, HasLoopBody}, match_ast, AstNode, Direction, SyntaxElement, SyntaxKind::*, SyntaxNode, SyntaxToken, TextRange, TextSize, T, diff --git a/crates/ide_completion/src/render/const_.rs b/crates/ide_completion/src/render/const_.rs index 4609f2e967..166ae3c16b 100644 --- a/crates/ide_completion/src/render/const_.rs +++ b/crates/ide_completion/src/render/const_.rs @@ -3,7 +3,7 @@ use hir::{AsAssocItem, HasSource}; use ide_db::SymbolKind; use syntax::{ - ast::{Const, NameOwner}, + ast::{Const, HasName}, display::const_label, }; diff --git a/crates/ide_completion/src/render/type_alias.rs b/crates/ide_completion/src/render/type_alias.rs index 6021448e78..c1e6182643 100644 --- a/crates/ide_completion/src/render/type_alias.rs +++ b/crates/ide_completion/src/render/type_alias.rs @@ -3,7 +3,7 @@ use hir::{AsAssocItem, HasSource}; use ide_db::SymbolKind; use syntax::{ - ast::{NameOwner, TypeAlias}, + ast::{HasName, TypeAlias}, display::type_label, }; diff --git a/crates/ide_db/src/call_info.rs b/crates/ide_db/src/call_info.rs index 3d32fddd93..e1d85f0411 100644 --- a/crates/ide_db/src/call_info.rs +++ b/crates/ide_db/src/call_info.rs @@ -5,7 +5,7 @@ use hir::{HasAttrs, HirDisplay, Semantics, Type}; use stdx::format_to; use syntax::{ algo, - ast::{self, ArgListOwner, NameOwner}, + ast::{self, HasArgList, HasName}, match_ast, AstNode, Direction, SyntaxNode, SyntaxToken, TextRange, TextSize, }; diff --git a/crates/ide_db/src/helpers.rs b/crates/ide_db/src/helpers.rs index a52c4046bf..a8087d47fe 100644 --- a/crates/ide_db/src/helpers.rs +++ b/crates/ide_db/src/helpers.rs @@ -13,7 +13,7 @@ use base_db::FileId; use either::Either; use hir::{ItemInNs, MacroDef, ModuleDef, Name, Semantics}; use syntax::{ - ast::{self, make, LoopBodyOwner}, + ast::{self, make, HasLoopBody}, AstNode, Direction, SyntaxElement, SyntaxKind, SyntaxToken, TokenAtOffset, WalkEvent, T, }; diff --git a/crates/ide_db/src/helpers/import_assets.rs b/crates/ide_db/src/helpers/import_assets.rs index a672c10917..d6bb19d129 100644 --- a/crates/ide_db/src/helpers/import_assets.rs +++ b/crates/ide_db/src/helpers/import_assets.rs @@ -6,7 +6,7 @@ use hir::{ use itertools::Itertools; use rustc_hash::FxHashSet; use syntax::{ - ast::{self, NameOwner}, + ast::{self, HasName}, utils::path_to_string_stripping_turbo_fish, AstNode, SyntaxNode, }; diff --git a/crates/ide_db/src/helpers/insert_use.rs b/crates/ide_db/src/helpers/insert_use.rs index a8ac0a9006..a5d1932775 100644 --- a/crates/ide_db/src/helpers/insert_use.rs +++ b/crates/ide_db/src/helpers/insert_use.rs @@ -7,7 +7,7 @@ use std::cmp::Ordering; use hir::Semantics; use syntax::{ algo, - ast::{self, make, AstNode, AttrsOwner, ModuleItemOwner, PathSegmentKind, VisibilityOwner}, + ast::{self, make, AstNode, HasAttrs, HasModuleItem, HasVisibility, PathSegmentKind}, match_ast, ted, AstToken, Direction, NodeOrToken, SyntaxNode, SyntaxToken, }; @@ -51,7 +51,7 @@ pub enum ImportScope { impl ImportScope { fn from(syntax: SyntaxNode) -> Option { - fn contains_cfg_attr(attrs: &dyn AttrsOwner) -> bool { + fn contains_cfg_attr(attrs: &dyn HasAttrs) -> bool { attrs .attrs() .any(|attr| attr.as_simple_call().map_or(false, |(ident, _)| ident == "cfg")) diff --git a/crates/ide_db/src/helpers/merge_imports.rs b/crates/ide_db/src/helpers/merge_imports.rs index 6f130e99b4..8189d6e53f 100644 --- a/crates/ide_db/src/helpers/merge_imports.rs +++ b/crates/ide_db/src/helpers/merge_imports.rs @@ -3,7 +3,7 @@ use std::cmp::Ordering; use itertools::{EitherOrBoth, Itertools}; use syntax::{ - ast::{self, make, AstNode, AttrsOwner, PathSegmentKind, VisibilityOwner}, + ast::{self, make, AstNode, HasAttrs, HasVisibility, PathSegmentKind}, ted, }; diff --git a/crates/ide_db/src/rename.rs b/crates/ide_db/src/rename.rs index a5dca509fe..0ca0dc8c6b 100644 --- a/crates/ide_db/src/rename.rs +++ b/crates/ide_db/src/rename.rs @@ -27,7 +27,7 @@ use either::Either; use hir::{AsAssocItem, FieldSource, HasSource, InFile, ModuleSource, Semantics}; use stdx::never; use syntax::{ - ast::{self, NameOwner}, + ast::{self, HasName}, lex_single_syntax_kind, AstNode, SyntaxKind, TextRange, T, }; use text_edit::{TextEdit, TextEditBuilder}; @@ -156,7 +156,7 @@ impl Definition { fn name_range(def: D, sema: &Semantics) -> Option where D: HasSource, - D::Ast: ast::NameOwner, + D::Ast: ast::HasName, { let src = def.source(sema.db)?; let name = src.value.name()?; diff --git a/crates/ide_db/src/symbol_index.rs b/crates/ide_db/src/symbol_index.rs index fb3568b107..54ceafa67f 100644 --- a/crates/ide_db/src/symbol_index.rs +++ b/crates/ide_db/src/symbol_index.rs @@ -37,7 +37,7 @@ use hir::db::DefDatabase; use rayon::prelude::*; use rustc_hash::{FxHashMap, FxHashSet}; use syntax::{ - ast::{self, NameOwner}, + ast::{self, HasName}, match_ast, AstNode, Parse, SmolStr, SourceFile, SyntaxKind::*, SyntaxNode, SyntaxNodePtr, TextRange, WalkEvent, @@ -427,7 +427,7 @@ fn source_file_to_file_symbols(source_file: &SourceFile, file_id: FileId) -> Vec } fn to_symbol(node: &SyntaxNode) -> Option<(SmolStr, SyntaxNodePtr, TextRange)> { - fn decl(node: N) -> Option<(SmolStr, SyntaxNodePtr, TextRange)> { + fn decl(node: N) -> Option<(SmolStr, SyntaxNodePtr, TextRange)> { let name = node.name()?; let name_range = name.syntax().text_range(); let name = name.text().into(); diff --git a/crates/ide_db/src/traits.rs b/crates/ide_db/src/traits.rs index 66ae81c73e..def7a8acaa 100644 --- a/crates/ide_db/src/traits.rs +++ b/crates/ide_db/src/traits.rs @@ -4,7 +4,7 @@ use crate::RootDatabase; use hir::Semantics; use rustc_hash::FxHashSet; use syntax::{ - ast::{self, NameOwner}, + ast::{self, HasName}, AstNode, }; diff --git a/crates/ide_diagnostics/src/handlers/replace_filter_map_next_with_find_map.rs b/crates/ide_diagnostics/src/handlers/replace_filter_map_next_with_find_map.rs index c47ceab33d..9826e1c707 100644 --- a/crates/ide_diagnostics/src/handlers/replace_filter_map_next_with_find_map.rs +++ b/crates/ide_diagnostics/src/handlers/replace_filter_map_next_with_find_map.rs @@ -1,7 +1,7 @@ use hir::{db::AstDatabase, InFile}; use ide_db::source_change::SourceChange; use syntax::{ - ast::{self, ArgListOwner}, + ast::{self, HasArgList}, AstNode, TextRange, }; use text_edit::TextEdit; diff --git a/crates/ide_diagnostics/src/handlers/unlinked_file.rs b/crates/ide_diagnostics/src/handlers/unlinked_file.rs index 9eafd42d86..cc10a63f87 100644 --- a/crates/ide_diagnostics/src/handlers/unlinked_file.rs +++ b/crates/ide_diagnostics/src/handlers/unlinked_file.rs @@ -7,7 +7,7 @@ use ide_db::{ RootDatabase, }; use syntax::{ - ast::{self, ModuleItemOwner, NameOwner}, + ast::{self, HasModuleItem, HasName}, AstNode, TextRange, TextSize, }; use text_edit::TextEdit; diff --git a/crates/ide_ssr/src/matching.rs b/crates/ide_ssr/src/matching.rs index 6812947218..88c1d80608 100644 --- a/crates/ide_ssr/src/matching.rs +++ b/crates/ide_ssr/src/matching.rs @@ -527,7 +527,7 @@ impl<'db, 'sema> Matcher<'db, 'sema> { pattern_ufcs: &UfcsCallInfo, code: &ast::MethodCallExpr, ) -> Result<(), MatchFailed> { - use ast::ArgListOwner; + use ast::HasArgList; let code_resolved_function = self .sema .resolve_method_call(code) @@ -587,7 +587,7 @@ impl<'db, 'sema> Matcher<'db, 'sema> { pattern_ufcs: &UfcsCallInfo, code: &ast::CallExpr, ) -> Result<(), MatchFailed> { - use ast::ArgListOwner; + use ast::HasArgList; // Check that the first argument is the expected type. if let (Some(pattern_type), Some(expr)) = ( &pattern_ufcs.qualifier_type, diff --git a/crates/mbe/src/benchmark.rs b/crates/mbe/src/benchmark.rs index ffa316dd24..cd5d76be3c 100644 --- a/crates/mbe/src/benchmark.rs +++ b/crates/mbe/src/benchmark.rs @@ -2,7 +2,7 @@ use rustc_hash::FxHashMap; use syntax::{ - ast::{self, NameOwner}, + ast::{self, HasName}, AstNode, SmolStr, }; use test_utils::{bench, bench_fixture, skip_slow_tests}; diff --git a/crates/mbe/src/tests.rs b/crates/mbe/src/tests.rs index e6ac9754da..26924fa8f3 100644 --- a/crates/mbe/src/tests.rs +++ b/crates/mbe/src/tests.rs @@ -238,7 +238,7 @@ fn debug_dump_ignore_spaces(node: &syntax::SyntaxNode) -> String { #[test] fn test_node_to_tt_censor() { - use syntax::ast::{AttrsOwner, ModuleItemOwner}; + use syntax::ast::{HasAttrs, HasModuleItem}; let source = r##" #[attr0] diff --git a/crates/syntax/src/ast.rs b/crates/syntax/src/ast.rs index e07b22a550..e57c3d2fe4 100644 --- a/crates/syntax/src/ast.rs +++ b/crates/syntax/src/ast.rs @@ -30,8 +30,8 @@ pub use self::{ QuoteOffsets, Radix, }, traits::{ - ArgListOwner, AttrsOwner, CommentIter, DocCommentsOwner, GenericParamsOwner, LoopBodyOwner, - ModuleItemOwner, NameOwner, TypeBoundsOwner, VisibilityOwner, + CommentIter, HasArgList, HasAttrs, HasDocComments, HasGenericParams, HasLoopBody, + HasModuleItem, HasName, HasTypeBounds, HasVisibility, }, }; @@ -118,7 +118,7 @@ mod support { #[test] fn assert_ast_is_object_safe() { - fn _f(_: &dyn AstNode, _: &dyn NameOwner) {} + fn _f(_: &dyn AstNode, _: &dyn HasName) {} } #[test] diff --git a/crates/syntax/src/ast/edit_in_place.rs b/crates/syntax/src/ast/edit_in_place.rs index d6775c89ba..4b354f7b32 100644 --- a/crates/syntax/src/ast/edit_in_place.rs +++ b/crates/syntax/src/ast/edit_in_place.rs @@ -7,16 +7,16 @@ use rowan::SyntaxElement; use crate::{ algo::neighbor, - ast::{self, edit::IndentLevel, make, GenericParamsOwner}, + ast::{self, edit::IndentLevel, make, HasGenericParams}, ted::{self, Position}, AstNode, AstToken, Direction, SyntaxKind::{ATTR, COMMENT, WHITESPACE}, SyntaxNode, }; -use super::NameOwner; +use super::HasName; -pub trait GenericParamsOwnerEdit: ast::GenericParamsOwner { +pub trait GenericParamsOwnerEdit: ast::HasGenericParams { fn get_or_create_generic_param_list(&self) -> ast::GenericParamList; fn get_or_create_where_clause(&self) -> ast::WhereClause; } @@ -194,7 +194,7 @@ fn create_generic_param_list(position: Position) -> ast::GenericParamList { gpl } -pub trait AttrsOwnerEdit: ast::AttrsOwner { +pub trait AttrsOwnerEdit: ast::HasAttrs { fn remove_attrs_and_docs(&self) { remove_attrs_and_docs(self.syntax()); @@ -218,7 +218,7 @@ pub trait AttrsOwnerEdit: ast::AttrsOwner { } } -impl AttrsOwnerEdit for T {} +impl AttrsOwnerEdit for T {} impl ast::GenericParamList { pub fn add_generic_param(&self, generic_param: ast::GenericParam) { diff --git a/crates/syntax/src/ast/expr_ext.rs b/crates/syntax/src/ast/expr_ext.rs index 4f92cc0671..7363ad905a 100644 --- a/crates/syntax/src/ast/expr_ext.rs +++ b/crates/syntax/src/ast/expr_ext.rs @@ -13,7 +13,7 @@ use crate::{ SyntaxToken, T, }; -impl ast::AttrsOwner for ast::Expr {} +impl ast::HasAttrs for ast::Expr {} impl ast::Expr { pub fn is_block_like(&self) -> bool { diff --git a/crates/syntax/src/ast/generated/nodes.rs b/crates/syntax/src/ast/generated/nodes.rs index 9fbd4aea19..5d92a0f9e5 100644 --- a/crates/syntax/src/ast/generated/nodes.rs +++ b/crates/syntax/src/ast/generated/nodes.rs @@ -104,7 +104,7 @@ impl TypeArg { pub struct AssocTypeArg { pub(crate) syntax: SyntaxNode, } -impl ast::TypeBoundsOwner for AssocTypeArg {} +impl ast::HasTypeBounds for AssocTypeArg {} impl AssocTypeArg { pub fn name_ref(&self) -> Option { support::child(&self.syntax) } pub fn generic_param_list(&self) -> Option { support::child(&self.syntax) } @@ -145,7 +145,7 @@ impl TypeBoundList { pub struct MacroCall { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for MacroCall {} +impl ast::HasAttrs for MacroCall {} impl MacroCall { pub fn path(&self) -> Option { support::child(&self.syntax) } pub fn excl_token(&self) -> Option { support::token(&self.syntax, T![!]) } @@ -179,7 +179,7 @@ impl TokenTree { pub struct MacroItems { pub(crate) syntax: SyntaxNode, } -impl ast::ModuleItemOwner for MacroItems {} +impl ast::HasModuleItem for MacroItems {} impl MacroItems {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct MacroStmts { @@ -193,8 +193,8 @@ impl MacroStmts { pub struct SourceFile { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for SourceFile {} -impl ast::ModuleItemOwner for SourceFile {} +impl ast::HasAttrs for SourceFile {} +impl ast::HasModuleItem for SourceFile {} impl SourceFile { pub fn shebang_token(&self) -> Option { support::token(&self.syntax, T![shebang]) } } @@ -202,9 +202,9 @@ impl SourceFile { pub struct Const { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for Const {} -impl ast::NameOwner for Const {} -impl ast::VisibilityOwner for Const {} +impl ast::HasAttrs for Const {} +impl ast::HasName for Const {} +impl ast::HasVisibility for Const {} impl Const { pub fn default_token(&self) -> Option { support::token(&self.syntax, T![default]) } pub fn const_token(&self) -> Option { support::token(&self.syntax, T![const]) } @@ -219,10 +219,10 @@ impl Const { pub struct Enum { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for Enum {} -impl ast::NameOwner for Enum {} -impl ast::VisibilityOwner for Enum {} -impl ast::GenericParamsOwner for Enum {} +impl ast::HasAttrs for Enum {} +impl ast::HasName for Enum {} +impl ast::HasVisibility for Enum {} +impl ast::HasGenericParams for Enum {} impl Enum { pub fn enum_token(&self) -> Option { support::token(&self.syntax, T![enum]) } pub fn variant_list(&self) -> Option { support::child(&self.syntax) } @@ -231,7 +231,7 @@ impl Enum { pub struct ExternBlock { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for ExternBlock {} +impl ast::HasAttrs for ExternBlock {} impl ExternBlock { pub fn abi(&self) -> Option { support::child(&self.syntax) } pub fn extern_item_list(&self) -> Option { support::child(&self.syntax) } @@ -240,8 +240,8 @@ impl ExternBlock { pub struct ExternCrate { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for ExternCrate {} -impl ast::VisibilityOwner for ExternCrate {} +impl ast::HasAttrs for ExternCrate {} +impl ast::HasVisibility for ExternCrate {} impl ExternCrate { pub fn extern_token(&self) -> Option { support::token(&self.syntax, T![extern]) } pub fn crate_token(&self) -> Option { support::token(&self.syntax, T![crate]) } @@ -253,10 +253,10 @@ impl ExternCrate { pub struct Fn { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for Fn {} -impl ast::NameOwner for Fn {} -impl ast::VisibilityOwner for Fn {} -impl ast::GenericParamsOwner for Fn {} +impl ast::HasAttrs for Fn {} +impl ast::HasName for Fn {} +impl ast::HasVisibility for Fn {} +impl ast::HasGenericParams for Fn {} impl Fn { pub fn default_token(&self) -> Option { support::token(&self.syntax, T![default]) } pub fn const_token(&self) -> Option { support::token(&self.syntax, T![const]) } @@ -273,9 +273,9 @@ impl Fn { pub struct Impl { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for Impl {} -impl ast::VisibilityOwner for Impl {} -impl ast::GenericParamsOwner for Impl {} +impl ast::HasAttrs for Impl {} +impl ast::HasVisibility for Impl {} +impl ast::HasGenericParams for Impl {} impl Impl { pub fn default_token(&self) -> Option { support::token(&self.syntax, T![default]) } pub fn unsafe_token(&self) -> Option { support::token(&self.syntax, T![unsafe]) } @@ -289,9 +289,9 @@ impl Impl { pub struct MacroRules { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for MacroRules {} -impl ast::NameOwner for MacroRules {} -impl ast::VisibilityOwner for MacroRules {} +impl ast::HasAttrs for MacroRules {} +impl ast::HasName for MacroRules {} +impl ast::HasVisibility for MacroRules {} impl MacroRules { pub fn macro_rules_token(&self) -> Option { support::token(&self.syntax, T![macro_rules]) @@ -303,9 +303,9 @@ impl MacroRules { pub struct MacroDef { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for MacroDef {} -impl ast::NameOwner for MacroDef {} -impl ast::VisibilityOwner for MacroDef {} +impl ast::HasAttrs for MacroDef {} +impl ast::HasName for MacroDef {} +impl ast::HasVisibility for MacroDef {} impl MacroDef { pub fn macro_token(&self) -> Option { support::token(&self.syntax, T![macro]) } pub fn args(&self) -> Option { support::child(&self.syntax) } @@ -315,9 +315,9 @@ impl MacroDef { pub struct Module { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for Module {} -impl ast::NameOwner for Module {} -impl ast::VisibilityOwner for Module {} +impl ast::HasAttrs for Module {} +impl ast::HasName for Module {} +impl ast::HasVisibility for Module {} impl Module { pub fn mod_token(&self) -> Option { support::token(&self.syntax, T![mod]) } pub fn item_list(&self) -> Option { support::child(&self.syntax) } @@ -327,9 +327,9 @@ impl Module { pub struct Static { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for Static {} -impl ast::NameOwner for Static {} -impl ast::VisibilityOwner for Static {} +impl ast::HasAttrs for Static {} +impl ast::HasName for Static {} +impl ast::HasVisibility for Static {} impl Static { pub fn static_token(&self) -> Option { support::token(&self.syntax, T![static]) } pub fn mut_token(&self) -> Option { support::token(&self.syntax, T![mut]) } @@ -343,10 +343,10 @@ impl Static { pub struct Struct { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for Struct {} -impl ast::NameOwner for Struct {} -impl ast::VisibilityOwner for Struct {} -impl ast::GenericParamsOwner for Struct {} +impl ast::HasAttrs for Struct {} +impl ast::HasName for Struct {} +impl ast::HasVisibility for Struct {} +impl ast::HasGenericParams for Struct {} impl Struct { pub fn struct_token(&self) -> Option { support::token(&self.syntax, T![struct]) } pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } @@ -356,11 +356,11 @@ impl Struct { pub struct Trait { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for Trait {} -impl ast::NameOwner for Trait {} -impl ast::VisibilityOwner for Trait {} -impl ast::GenericParamsOwner for Trait {} -impl ast::TypeBoundsOwner for Trait {} +impl ast::HasAttrs for Trait {} +impl ast::HasName for Trait {} +impl ast::HasVisibility for Trait {} +impl ast::HasGenericParams for Trait {} +impl ast::HasTypeBounds for Trait {} impl Trait { pub fn unsafe_token(&self) -> Option { support::token(&self.syntax, T![unsafe]) } pub fn auto_token(&self) -> Option { support::token(&self.syntax, T![auto]) } @@ -371,11 +371,11 @@ impl Trait { pub struct TypeAlias { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for TypeAlias {} -impl ast::NameOwner for TypeAlias {} -impl ast::VisibilityOwner for TypeAlias {} -impl ast::GenericParamsOwner for TypeAlias {} -impl ast::TypeBoundsOwner for TypeAlias {} +impl ast::HasAttrs for TypeAlias {} +impl ast::HasName for TypeAlias {} +impl ast::HasVisibility for TypeAlias {} +impl ast::HasGenericParams for TypeAlias {} +impl ast::HasTypeBounds for TypeAlias {} impl TypeAlias { pub fn default_token(&self) -> Option { support::token(&self.syntax, T![default]) } pub fn type_token(&self) -> Option { support::token(&self.syntax, T![type]) } @@ -387,10 +387,10 @@ impl TypeAlias { pub struct Union { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for Union {} -impl ast::NameOwner for Union {} -impl ast::VisibilityOwner for Union {} -impl ast::GenericParamsOwner for Union {} +impl ast::HasAttrs for Union {} +impl ast::HasName for Union {} +impl ast::HasVisibility for Union {} +impl ast::HasGenericParams for Union {} impl Union { pub fn union_token(&self) -> Option { support::token(&self.syntax, T![union]) } pub fn record_field_list(&self) -> Option { support::child(&self.syntax) } @@ -399,8 +399,8 @@ impl Union { pub struct Use { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for Use {} -impl ast::VisibilityOwner for Use {} +impl ast::HasAttrs for Use {} +impl ast::HasVisibility 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) } @@ -421,8 +421,8 @@ impl Visibility { pub struct ItemList { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for ItemList {} -impl ast::ModuleItemOwner for ItemList {} +impl ast::HasAttrs for ItemList {} +impl ast::HasModuleItem for ItemList {} impl ItemList { pub fn l_curly_token(&self) -> Option { support::token(&self.syntax, T!['{']) } pub fn r_curly_token(&self) -> Option { support::token(&self.syntax, T!['}']) } @@ -431,7 +431,7 @@ impl ItemList { pub struct Rename { pub(crate) syntax: SyntaxNode, } -impl ast::NameOwner for Rename {} +impl ast::HasName for Rename {} impl Rename { pub fn as_token(&self) -> Option { support::token(&self.syntax, T![as]) } pub fn underscore_token(&self) -> Option { support::token(&self.syntax, T![_]) } @@ -475,7 +475,7 @@ impl WhereClause { pub struct BlockExpr { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for BlockExpr {} +impl ast::HasAttrs for BlockExpr {} impl BlockExpr { pub fn label(&self) -> Option