Rename *Owner traits to Has*

This commit is contained in:
Lukas Wirth 2021-09-27 12:54:24 +02:00
parent a28c5d7311
commit b6ed91a6de
101 changed files with 393 additions and 397 deletions

View file

@ -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,

View file

@ -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};

View file

@ -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<LifetimeParam> {
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))
})?;

View file

@ -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,
};

View file

@ -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::{

View file

@ -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<N>(src: AstId<N>, 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<N: ItemTreeNode>(id: ItemTreeId<N>, db: &dyn DefDatabase) -> RawAttrs {
@ -825,7 +821,7 @@ fn attrs_from_item_tree<N: ItemTreeNode>(id: ItemTreeId<N>, db: &dyn DefDatabase
}
fn collect_attrs(
owner: &dyn ast::AttrsOwner,
owner: &dyn ast::HasAttrs,
) -> impl Iterator<Item = (AttrId, Either<ast::Attr, ast::Comment>)> {
let (inner_attrs, inner_docs) = inner_attributes(owner.syntax())
.map_or((None, None), |(attrs, docs)| (Some(attrs), Some(docs)));

View file

@ -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)
}

View file

@ -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) {

View file

@ -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,

View file

@ -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<TypeRef, LifetimeRef>,
) {
for bound in

View file

@ -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::{

View file

@ -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<GenericParams> {
// 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<GenericParams> {
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<Interned<TypeBound>> {
fn lower_type_bounds(&mut self, node: &impl ast::HasTypeBounds) -> Vec<Interned<TypeBound>> {
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),

View file

@ -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::{

View file

@ -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,
};

View file

@ -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,

View file

@ -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,
};

View file

@ -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,
};

View file

@ -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,
};

View file

@ -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,
};

View file

@ -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};

View file

@ -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<T: NameOwner>(node: &InFile<T>, file_id: FileId) -> Option<TextRange> {
fn name_range<T: HasName>(node: &InFile<T>, file_id: FileId) -> Option<TextRange> {
if node.file_id == file_id.into() {
node.value.name().map(|it| it.syntax().text_range())
} else {

View file

@ -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<D> 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<NavigationTarget> {
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<NavigationTarget> {
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,
};

View file

@ -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<StructureNode> {
}
fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
fn decl<N: NameOwner + AttrsOwner>(node: N, kind: StructureNodeKind) -> Option<StructureNode> {
fn decl<N: HasName + HasAttrs>(node: N, kind: StructureNodeKind) -> Option<StructureNode> {
decl_with_detail(&node, None, kind)
}
fn decl_with_type_ref<N: NameOwner + AttrsOwner>(
fn decl_with_type_ref<N: HasName + HasAttrs>(
node: &N,
type_ref: Option<ast::Type>,
kind: StructureNodeKind,
@ -91,7 +91,7 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> {
decl_with_detail(node, detail, kind)
}
fn decl_with_detail<N: NameOwner + AttrsOwner>(
fn decl_with_detail<N: HasName + HasAttrs>(
node: &N,
detail: Option<String>,
kind: StructureNodeKind,

View file

@ -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};

View file

@ -152,7 +152,7 @@ fn fold_kind(kind: SyntaxKind) -> Option<FoldKind> {
fn contiguous_range_for_item_group<N>(first: N, visited: &mut FxHashSet<N>) -> Option<TextRange>
where
N: ast::VisibilityOwner + Clone + Hash + Eq,
N: ast::HasVisibility + Clone + Hash + Eq,
{
if !visited.insert(first.clone()) {
return None;

View file

@ -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,

View file

@ -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,
};

View file

@ -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,
};

View file

@ -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<RootDatabase>, 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();

View file

@ -1,4 +1,4 @@
use syntax::ast::{self, AstNode, GenericParamsOwner, NameOwner};
use syntax::ast::{self, AstNode, HasGenericParams, HasName};
use crate::{AssistContext, AssistId, AssistKind, Assists};

View file

@ -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},

View file

@ -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,

View file

@ -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,
};

View file

@ -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};

View file

@ -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,
};

View file

@ -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,
};

View file

@ -4,7 +4,7 @@ use syntax::{
ast::{
self,
edit::{AstNodeEdit, IndentLevel},
make, LoopBodyOwner,
make, HasLoopBody,
},
AstNode, T,
};

View file

@ -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,
};

View file

@ -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()))

View file

@ -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},

View file

@ -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,
};

View file

@ -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<ast::Visibility>, TextRange, FileId)>
where
S: HasSource<Ast = Ast>,
Ast: AstNode + ast::VisibilityOwner,
Ast: AstNode + ast::HasVisibility,
{
let source = x.source(db)?;
let in_file_syntax = source.syntax();

View file

@ -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};

View file

@ -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,
};

View file

@ -2,7 +2,7 @@ use std::fmt::Display;
use ide_db::{helpers::FamousDefs, RootDatabase};
use syntax::{
ast::{self, NameOwner},
ast::{self, HasName},
AstNode, SyntaxNode,
};

View file

@ -1,5 +1,5 @@
use syntax::{
ast::{self, AstNode, AttrsOwner},
ast::{self, AstNode, HasAttrs},
SyntaxKind::{COMMENT, WHITESPACE},
TextSize,
};

View file

@ -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},

View file

@ -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},

View file

@ -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};

View file

@ -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,
};

View file

@ -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,

View file

@ -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};

View file

@ -1,6 +1,6 @@
use hir::{known, HasSource, Name};
use syntax::{
ast::{self, NameOwner},
ast::{self, HasName},
AstNode,
};

View file

@ -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},

View file

@ -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},

View file

@ -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,
};

View file

@ -7,7 +7,7 @@ use ide_db::{
RootDatabase,
};
use syntax::{
ast::{self, AstNode, AstToken, NameOwner},
ast::{self, AstNode, AstToken, HasName},
SyntaxElement, TextRange,
};

View file

@ -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,
};

View file

@ -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,
};

View file

@ -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,
};

View file

@ -8,7 +8,7 @@ use ide_db::helpers::{
use ide_db::RootDatabase;
use syntax::{
ast,
ast::{make, ArgListOwner},
ast::{make, HasArgList},
AstNode,
};

View file

@ -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,
};

View file

@ -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,
};

View file

@ -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},
};

View file

@ -6,7 +6,7 @@ use syntax::{
ast::{
self,
edit::{AstNodeEdit, IndentLevel},
make, NameOwner,
make, HasName,
},
AstNode, TextRange,
};

View file

@ -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<T: NameOwner + Clone>(initial: &[T]) -> Vec<T> {
fn sort_by_name<T: HasName + Clone>(initial: &[T]) -> Vec<T> {
initial
.iter()
.cloned()

View file

@ -1,5 +1,5 @@
use syntax::{
ast::{self, AttrsOwner},
ast::{self, HasAttrs},
AstNode, AstToken,
};

View file

@ -1,6 +1,6 @@
use itertools::Itertools;
use syntax::{
ast::{self, make, VisibilityOwner},
ast::{self, make, HasVisibility},
ted::{self, Position},
AstNode, SyntaxKind,
};

View file

@ -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::*,

View file

@ -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,
};

View file

@ -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,
};

View file

@ -2,7 +2,7 @@
use rustc_hash::FxHashMap;
use syntax::{
ast::{self, ModuleItemOwner},
ast::{self, HasModuleItem},
match_ast, AstNode,
};

View file

@ -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,

View file

@ -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,

View file

@ -3,7 +3,7 @@
use hir::{AsAssocItem, HasSource};
use ide_db::SymbolKind;
use syntax::{
ast::{Const, NameOwner},
ast::{Const, HasName},
display::const_label,
};

View file

@ -3,7 +3,7 @@
use hir::{AsAssocItem, HasSource};
use ide_db::SymbolKind;
use syntax::{
ast::{NameOwner, TypeAlias},
ast::{HasName, TypeAlias},
display::type_label,
};

View file

@ -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,
};

View file

@ -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,
};

View file

@ -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,
};

View file

@ -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<Self> {
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"))

View file

@ -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,
};

View file

@ -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<D>(def: D, sema: &Semantics<RootDatabase>) -> Option<FileRange>
where
D: HasSource,
D::Ast: ast::NameOwner,
D::Ast: ast::HasName,
{
let src = def.source(sema.db)?;
let name = src.value.name()?;

View file

@ -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<N: NameOwner>(node: N) -> Option<(SmolStr, SyntaxNodePtr, TextRange)> {
fn decl<N: HasName>(node: N) -> Option<(SmolStr, SyntaxNodePtr, TextRange)> {
let name = node.name()?;
let name_range = name.syntax().text_range();
let name = name.text().into();

View file

@ -4,7 +4,7 @@ use crate::RootDatabase;
use hir::Semantics;
use rustc_hash::FxHashSet;
use syntax::{
ast::{self, NameOwner},
ast::{self, HasName},
AstNode,
};

View file

@ -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;

View file

@ -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;

View file

@ -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,

View file

@ -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};

View file

@ -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]

View file

@ -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]

View file

@ -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<T: ast::AttrsOwner> AttrsOwnerEdit for T {}
impl<T: ast::HasAttrs> AttrsOwnerEdit for T {}
impl ast::GenericParamList {
pub fn add_generic_param(&self, generic_param: ast::GenericParam) {

View file

@ -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 {

View file

@ -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<NameRef> { support::child(&self.syntax) }
pub fn generic_param_list(&self) -> Option<GenericParamList> { 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<Path> { support::child(&self.syntax) }
pub fn excl_token(&self) -> Option<SyntaxToken> { 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<SyntaxToken> { 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<SyntaxToken> { support::token(&self.syntax, T![default]) }
pub fn const_token(&self) -> Option<SyntaxToken> { 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<SyntaxToken> { support::token(&self.syntax, T![enum]) }
pub fn variant_list(&self) -> Option<VariantList> { 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<Abi> { support::child(&self.syntax) }
pub fn extern_item_list(&self) -> Option<ExternItemList> { 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<SyntaxToken> { support::token(&self.syntax, T![extern]) }
pub fn crate_token(&self) -> Option<SyntaxToken> { 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<SyntaxToken> { support::token(&self.syntax, T![default]) }
pub fn const_token(&self) -> Option<SyntaxToken> { 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<SyntaxToken> { support::token(&self.syntax, T![default]) }
pub fn unsafe_token(&self) -> Option<SyntaxToken> { 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<SyntaxToken> {
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<SyntaxToken> { support::token(&self.syntax, T![macro]) }
pub fn args(&self) -> Option<TokenTree> { 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<SyntaxToken> { support::token(&self.syntax, T![mod]) }
pub fn item_list(&self) -> Option<ItemList> { 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<SyntaxToken> { support::token(&self.syntax, T![static]) }
pub fn mut_token(&self) -> Option<SyntaxToken> { 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<SyntaxToken> { support::token(&self.syntax, T![struct]) }
pub fn semicolon_token(&self) -> Option<SyntaxToken> { 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<SyntaxToken> { support::token(&self.syntax, T![unsafe]) }
pub fn auto_token(&self) -> Option<SyntaxToken> { 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<SyntaxToken> { support::token(&self.syntax, T![default]) }
pub fn type_token(&self) -> Option<SyntaxToken> { 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<SyntaxToken> { support::token(&self.syntax, T![union]) }
pub fn record_field_list(&self) -> Option<RecordFieldList> { 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<SyntaxToken> { support::token(&self.syntax, T![use]) }
pub fn use_tree(&self) -> Option<UseTree> { 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<SyntaxToken> { support::token(&self.syntax, T!['{']) }
pub fn r_curly_token(&self) -> Option<SyntaxToken> { 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<SyntaxToken> { support::token(&self.syntax, T![as]) }
pub fn underscore_token(&self) -> Option<SyntaxToken> { 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<Label> { support::child(&self.syntax) }
pub fn try_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![try]) }
@ -488,8 +488,8 @@ impl BlockExpr {
pub struct SelfParam {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for SelfParam {}
impl ast::NameOwner for SelfParam {}
impl ast::HasAttrs for SelfParam {}
impl ast::HasName for SelfParam {}
impl SelfParam {
pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) }
pub fn lifetime(&self) -> Option<Lifetime> { support::child(&self.syntax) }
@ -501,7 +501,7 @@ impl SelfParam {
pub struct Param {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for Param {}
impl ast::HasAttrs for Param {}
impl Param {
pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
@ -530,9 +530,9 @@ impl TupleFieldList {
pub struct RecordField {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for RecordField {}
impl ast::NameOwner for RecordField {}
impl ast::VisibilityOwner for RecordField {}
impl ast::HasAttrs for RecordField {}
impl ast::HasName for RecordField {}
impl ast::HasVisibility for RecordField {}
impl RecordField {
pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
@ -541,8 +541,8 @@ impl RecordField {
pub struct TupleField {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for TupleField {}
impl ast::VisibilityOwner for TupleField {}
impl ast::HasAttrs for TupleField {}
impl ast::HasVisibility for TupleField {}
impl TupleField {
pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
}
@ -559,9 +559,9 @@ impl VariantList {
pub struct Variant {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for Variant {}
impl ast::NameOwner for Variant {}
impl ast::VisibilityOwner for Variant {}
impl ast::HasAttrs for Variant {}
impl ast::HasName for Variant {}
impl ast::HasVisibility for Variant {}
impl Variant {
pub fn field_list(&self) -> Option<FieldList> { support::child(&self.syntax) }
pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
@ -571,7 +571,7 @@ impl Variant {
pub struct AssocItemList {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for AssocItemList {}
impl ast::HasAttrs for AssocItemList {}
impl AssocItemList {
pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
pub fn assoc_items(&self) -> AstChildren<AssocItem> { support::children(&self.syntax) }
@ -581,7 +581,7 @@ impl AssocItemList {
pub struct ExternItemList {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for ExternItemList {}
impl ast::HasAttrs for ExternItemList {}
impl ExternItemList {
pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
pub fn extern_items(&self) -> AstChildren<ExternItem> { support::children(&self.syntax) }
@ -591,8 +591,8 @@ impl ExternItemList {
pub struct ConstParam {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for ConstParam {}
impl ast::NameOwner for ConstParam {}
impl ast::HasAttrs for ConstParam {}
impl ast::HasName for ConstParam {}
impl ConstParam {
pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
@ -604,8 +604,8 @@ impl ConstParam {
pub struct LifetimeParam {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for LifetimeParam {}
impl ast::TypeBoundsOwner for LifetimeParam {}
impl ast::HasAttrs for LifetimeParam {}
impl ast::HasTypeBounds for LifetimeParam {}
impl LifetimeParam {
pub fn lifetime(&self) -> Option<Lifetime> { support::child(&self.syntax) }
}
@ -613,9 +613,9 @@ impl LifetimeParam {
pub struct TypeParam {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for TypeParam {}
impl ast::NameOwner for TypeParam {}
impl ast::TypeBoundsOwner for TypeParam {}
impl ast::HasAttrs for TypeParam {}
impl ast::HasName for TypeParam {}
impl ast::HasTypeBounds for TypeParam {}
impl TypeParam {
pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
pub fn default_type(&self) -> Option<Type> { support::child(&self.syntax) }
@ -624,7 +624,7 @@ impl TypeParam {
pub struct WherePred {
pub(crate) syntax: SyntaxNode,
}
impl ast::TypeBoundsOwner for WherePred {}
impl ast::HasTypeBounds for WherePred {}
impl WherePred {
pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) }
pub fn generic_param_list(&self) -> Option<GenericParamList> { support::child(&self.syntax) }
@ -653,7 +653,7 @@ impl ExprStmt {
pub struct LetStmt {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for LetStmt {}
impl ast::HasAttrs for LetStmt {}
impl LetStmt {
pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) }
pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
@ -667,7 +667,7 @@ impl LetStmt {
pub struct ArrayExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for ArrayExpr {}
impl ast::HasAttrs for ArrayExpr {}
impl ArrayExpr {
pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
pub fn exprs(&self) -> AstChildren<Expr> { support::children(&self.syntax) }
@ -679,7 +679,7 @@ impl ArrayExpr {
pub struct AwaitExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for AwaitExpr {}
impl ast::HasAttrs for AwaitExpr {}
impl AwaitExpr {
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) }
@ -689,13 +689,13 @@ impl AwaitExpr {
pub struct BinExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for BinExpr {}
impl ast::HasAttrs for BinExpr {}
impl BinExpr {}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct BoxExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for BoxExpr {}
impl ast::HasAttrs for BoxExpr {}
impl BoxExpr {
pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) }
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
@ -704,7 +704,7 @@ impl BoxExpr {
pub struct BreakExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for BreakExpr {}
impl ast::HasAttrs for BreakExpr {}
impl BreakExpr {
pub fn break_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![break]) }
pub fn lifetime(&self) -> Option<Lifetime> { support::child(&self.syntax) }
@ -714,8 +714,8 @@ impl BreakExpr {
pub struct CallExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for CallExpr {}
impl ast::ArgListOwner for CallExpr {}
impl ast::HasAttrs for CallExpr {}
impl ast::HasArgList for CallExpr {}
impl CallExpr {
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
}
@ -723,7 +723,7 @@ impl CallExpr {
pub struct CastExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for CastExpr {}
impl ast::HasAttrs for CastExpr {}
impl CastExpr {
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) }
@ -733,7 +733,7 @@ impl CastExpr {
pub struct ClosureExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for ClosureExpr {}
impl ast::HasAttrs for ClosureExpr {}
impl ClosureExpr {
pub fn static_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![static]) }
pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) }
@ -746,7 +746,7 @@ impl ClosureExpr {
pub struct ContinueExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for ContinueExpr {}
impl ast::HasAttrs for ContinueExpr {}
impl ContinueExpr {
pub fn continue_token(&self) -> Option<SyntaxToken> {
support::token(&self.syntax, T![continue])
@ -757,7 +757,7 @@ impl ContinueExpr {
pub struct FieldExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for FieldExpr {}
impl ast::HasAttrs for FieldExpr {}
impl FieldExpr {
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) }
@ -767,8 +767,8 @@ impl FieldExpr {
pub struct ForExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for ForExpr {}
impl ast::LoopBodyOwner for ForExpr {}
impl ast::HasAttrs for ForExpr {}
impl ast::HasLoopBody for ForExpr {}
impl ForExpr {
pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) }
pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
@ -779,7 +779,7 @@ impl ForExpr {
pub struct IfExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for IfExpr {}
impl ast::HasAttrs for IfExpr {}
impl IfExpr {
pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) }
pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) }
@ -789,7 +789,7 @@ impl IfExpr {
pub struct IndexExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for IndexExpr {}
impl ast::HasAttrs for IndexExpr {}
impl IndexExpr {
pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
@ -798,14 +798,14 @@ impl IndexExpr {
pub struct Literal {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for Literal {}
impl ast::HasAttrs for Literal {}
impl Literal {}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct LoopExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for LoopExpr {}
impl ast::LoopBodyOwner for LoopExpr {}
impl ast::HasAttrs for LoopExpr {}
impl ast::HasLoopBody for LoopExpr {}
impl LoopExpr {
pub fn loop_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![loop]) }
}
@ -813,7 +813,7 @@ impl LoopExpr {
pub struct MatchExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for MatchExpr {}
impl ast::HasAttrs for MatchExpr {}
impl MatchExpr {
pub fn match_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![match]) }
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
@ -823,8 +823,8 @@ impl MatchExpr {
pub struct MethodCallExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for MethodCallExpr {}
impl ast::ArgListOwner for MethodCallExpr {}
impl ast::HasAttrs for MethodCallExpr {}
impl ast::HasArgList for MethodCallExpr {}
impl MethodCallExpr {
pub fn receiver(&self) -> Option<Expr> { support::child(&self.syntax) }
pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) }
@ -835,7 +835,7 @@ impl MethodCallExpr {
pub struct ParenExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for ParenExpr {}
impl ast::HasAttrs for ParenExpr {}
impl ParenExpr {
pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
@ -845,7 +845,7 @@ impl ParenExpr {
pub struct PathExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for PathExpr {}
impl ast::HasAttrs for PathExpr {}
impl PathExpr {
pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
}
@ -853,7 +853,7 @@ impl PathExpr {
pub struct PrefixExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for PrefixExpr {}
impl ast::HasAttrs for PrefixExpr {}
impl PrefixExpr {
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
}
@ -861,7 +861,7 @@ impl PrefixExpr {
pub struct RangeExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for RangeExpr {}
impl ast::HasAttrs for RangeExpr {}
impl RangeExpr {}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct RecordExpr {
@ -877,7 +877,7 @@ impl RecordExpr {
pub struct RefExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for RefExpr {}
impl ast::HasAttrs for RefExpr {}
impl RefExpr {
pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) }
pub fn raw_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![raw]) }
@ -889,7 +889,7 @@ impl RefExpr {
pub struct ReturnExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for ReturnExpr {}
impl ast::HasAttrs for ReturnExpr {}
impl ReturnExpr {
pub fn return_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![return]) }
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
@ -898,7 +898,7 @@ impl ReturnExpr {
pub struct TryExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for TryExpr {}
impl ast::HasAttrs for TryExpr {}
impl TryExpr {
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
pub fn question_mark_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![?]) }
@ -907,7 +907,7 @@ impl TryExpr {
pub struct TupleExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for TupleExpr {}
impl ast::HasAttrs for TupleExpr {}
impl TupleExpr {
pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
pub fn fields(&self) -> AstChildren<Expr> { support::children(&self.syntax) }
@ -917,8 +917,8 @@ impl TupleExpr {
pub struct WhileExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for WhileExpr {}
impl ast::LoopBodyOwner for WhileExpr {}
impl ast::HasAttrs for WhileExpr {}
impl ast::HasLoopBody for WhileExpr {}
impl WhileExpr {
pub fn while_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![while]) }
pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) }
@ -927,7 +927,7 @@ impl WhileExpr {
pub struct YieldExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for YieldExpr {}
impl ast::HasAttrs for YieldExpr {}
impl YieldExpr {
pub fn yield_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![yield]) }
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
@ -936,7 +936,7 @@ impl YieldExpr {
pub struct StmtList {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for StmtList {}
impl ast::HasAttrs for StmtList {}
impl StmtList {
pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) }
@ -955,7 +955,7 @@ impl Label {
pub struct RecordExprFieldList {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for RecordExprFieldList {}
impl ast::HasAttrs for RecordExprFieldList {}
impl RecordExprFieldList {
pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
pub fn fields(&self) -> AstChildren<RecordExprField> { support::children(&self.syntax) }
@ -967,7 +967,7 @@ impl RecordExprFieldList {
pub struct RecordExprField {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for RecordExprField {}
impl ast::HasAttrs for RecordExprField {}
impl RecordExprField {
pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
@ -996,7 +996,7 @@ impl Condition {
pub struct MatchArmList {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for MatchArmList {}
impl ast::HasAttrs for MatchArmList {}
impl MatchArmList {
pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
pub fn arms(&self) -> AstChildren<MatchArm> { support::children(&self.syntax) }
@ -1006,7 +1006,7 @@ impl MatchArmList {
pub struct MatchArm {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for MatchArm {}
impl ast::HasAttrs for MatchArm {}
impl MatchArm {
pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
pub fn guard(&self) -> Option<MatchGuard> { support::child(&self.syntax) }
@ -1155,8 +1155,8 @@ impl TypeBound {
pub struct IdentPat {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for IdentPat {}
impl ast::NameOwner for IdentPat {}
impl ast::HasAttrs for IdentPat {}
impl ast::HasName for IdentPat {}
impl IdentPat {
pub fn ref_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ref]) }
pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
@ -1296,7 +1296,7 @@ impl RecordPatFieldList {
pub struct RecordPatField {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for RecordPatField {}
impl ast::HasAttrs for RecordPatField {}
impl RecordPatField {
pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
@ -1379,7 +1379,7 @@ pub enum Item {
Union(Union),
Use(Use),
}
impl ast::AttrsOwner for Item {}
impl ast::HasAttrs for Item {}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Stmt {
ExprStmt(ExprStmt),
@ -1416,10 +1416,10 @@ pub enum Adt {
Struct(Struct),
Union(Union),
}
impl ast::AttrsOwner for Adt {}
impl ast::GenericParamsOwner for Adt {}
impl ast::NameOwner for Adt {}
impl ast::VisibilityOwner for Adt {}
impl ast::HasAttrs for Adt {}
impl ast::HasGenericParams for Adt {}
impl ast::HasName for Adt {}
impl ast::HasVisibility for Adt {}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum AssocItem {
Const(Const),
@ -1427,7 +1427,7 @@ pub enum AssocItem {
MacroCall(MacroCall),
TypeAlias(TypeAlias),
}
impl ast::AttrsOwner for AssocItem {}
impl ast::HasAttrs for AssocItem {}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ExternItem {
Fn(Fn),
@ -1435,54 +1435,54 @@ pub enum ExternItem {
Static(Static),
TypeAlias(TypeAlias),
}
impl ast::AttrsOwner for ExternItem {}
impl ast::HasAttrs for ExternItem {}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum GenericParam {
ConstParam(ConstParam),
LifetimeParam(LifetimeParam),
TypeParam(TypeParam),
}
impl ast::AttrsOwner for GenericParam {}
impl ast::HasAttrs for GenericParam {}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct AnyArgListOwner {
pub struct AnyHasArgList {
pub(crate) syntax: SyntaxNode,
}
impl ast::ArgListOwner for AnyArgListOwner {}
impl ast::HasArgList for AnyHasArgList {}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct AnyAttrsOwner {
pub struct AnyHasAttrs {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for AnyAttrsOwner {}
impl ast::HasAttrs for AnyHasAttrs {}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct AnyGenericParamsOwner {
pub struct AnyHasGenericParams {
pub(crate) syntax: SyntaxNode,
}
impl ast::GenericParamsOwner for AnyGenericParamsOwner {}
impl ast::HasGenericParams for AnyHasGenericParams {}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct AnyLoopBodyOwner {
pub struct AnyHasLoopBody {
pub(crate) syntax: SyntaxNode,
}
impl ast::LoopBodyOwner for AnyLoopBodyOwner {}
impl ast::HasLoopBody for AnyHasLoopBody {}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct AnyModuleItemOwner {
pub struct AnyHasModuleItem {
pub(crate) syntax: SyntaxNode,
}
impl ast::ModuleItemOwner for AnyModuleItemOwner {}
impl ast::HasModuleItem for AnyHasModuleItem {}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct AnyNameOwner {
pub struct AnyHasName {
pub(crate) syntax: SyntaxNode,
}
impl ast::NameOwner for AnyNameOwner {}
impl ast::HasName for AnyHasName {}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct AnyTypeBoundsOwner {
pub struct AnyHasTypeBounds {
pub(crate) syntax: SyntaxNode,
}
impl ast::TypeBoundsOwner for AnyTypeBoundsOwner {}
impl ast::HasTypeBounds for AnyHasTypeBounds {}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct AnyVisibilityOwner {
pub struct AnyHasVisibility {
pub(crate) syntax: SyntaxNode,
}
impl ast::VisibilityOwner for AnyVisibilityOwner {}
impl ast::HasVisibility for AnyHasVisibility {}
impl AstNode for Name {
fn can_cast(kind: SyntaxKind) -> bool { kind == NAME }
fn cast(syntax: SyntaxNode) -> Option<Self> {
@ -3597,13 +3597,13 @@ impl AstNode for GenericParam {
}
}
}
impl AnyArgListOwner {
impl AnyHasArgList {
#[inline]
pub fn new<T: ast::ArgListOwner>(node: T) -> AnyArgListOwner {
AnyArgListOwner { syntax: node.syntax().clone() }
pub fn new<T: ast::HasArgList>(node: T) -> AnyHasArgList {
AnyHasArgList { syntax: node.syntax().clone() }
}
}
impl AstNode for AnyArgListOwner {
impl AstNode for AnyHasArgList {
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
CALL_EXPR | METHOD_CALL_EXPR => true,
@ -3611,17 +3611,17 @@ impl AstNode for AnyArgListOwner {
}
}
fn cast(syntax: SyntaxNode) -> Option<Self> {
Self::can_cast(syntax.kind()).then(|| AnyArgListOwner { syntax })
Self::can_cast(syntax.kind()).then(|| AnyHasArgList { syntax })
}
fn syntax(&self) -> &SyntaxNode { &self.syntax }
}
impl AnyAttrsOwner {
impl AnyHasAttrs {
#[inline]
pub fn new<T: ast::AttrsOwner>(node: T) -> AnyAttrsOwner {
AnyAttrsOwner { syntax: node.syntax().clone() }
pub fn new<T: ast::HasAttrs>(node: T) -> AnyHasAttrs {
AnyHasAttrs { syntax: node.syntax().clone() }
}
}
impl AstNode for AnyAttrsOwner {
impl AstNode for AnyHasAttrs {
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
MACRO_CALL
@ -3692,17 +3692,17 @@ impl AstNode for AnyAttrsOwner {
}
}
fn cast(syntax: SyntaxNode) -> Option<Self> {
Self::can_cast(syntax.kind()).then(|| AnyAttrsOwner { syntax })
Self::can_cast(syntax.kind()).then(|| AnyHasAttrs { syntax })
}
fn syntax(&self) -> &SyntaxNode { &self.syntax }
}
impl AnyGenericParamsOwner {
impl AnyHasGenericParams {
#[inline]
pub fn new<T: ast::GenericParamsOwner>(node: T) -> AnyGenericParamsOwner {
AnyGenericParamsOwner { syntax: node.syntax().clone() }
pub fn new<T: ast::HasGenericParams>(node: T) -> AnyHasGenericParams {
AnyHasGenericParams { syntax: node.syntax().clone() }
}
}
impl AstNode for AnyGenericParamsOwner {
impl AstNode for AnyHasGenericParams {
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
ENUM | FN | IMPL | STRUCT | TRAIT | TYPE_ALIAS | UNION => true,
@ -3710,17 +3710,17 @@ impl AstNode for AnyGenericParamsOwner {
}
}
fn cast(syntax: SyntaxNode) -> Option<Self> {
Self::can_cast(syntax.kind()).then(|| AnyGenericParamsOwner { syntax })
Self::can_cast(syntax.kind()).then(|| AnyHasGenericParams { syntax })
}
fn syntax(&self) -> &SyntaxNode { &self.syntax }
}
impl AnyLoopBodyOwner {
impl AnyHasLoopBody {
#[inline]
pub fn new<T: ast::LoopBodyOwner>(node: T) -> AnyLoopBodyOwner {
AnyLoopBodyOwner { syntax: node.syntax().clone() }
pub fn new<T: ast::HasLoopBody>(node: T) -> AnyHasLoopBody {
AnyHasLoopBody { syntax: node.syntax().clone() }
}
}
impl AstNode for AnyLoopBodyOwner {
impl AstNode for AnyHasLoopBody {
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
FOR_EXPR | LOOP_EXPR | WHILE_EXPR => true,
@ -3728,17 +3728,17 @@ impl AstNode for AnyLoopBodyOwner {
}
}
fn cast(syntax: SyntaxNode) -> Option<Self> {
Self::can_cast(syntax.kind()).then(|| AnyLoopBodyOwner { syntax })
Self::can_cast(syntax.kind()).then(|| AnyHasLoopBody { syntax })
}
fn syntax(&self) -> &SyntaxNode { &self.syntax }
}
impl AnyModuleItemOwner {
impl AnyHasModuleItem {
#[inline]
pub fn new<T: ast::ModuleItemOwner>(node: T) -> AnyModuleItemOwner {
AnyModuleItemOwner { syntax: node.syntax().clone() }
pub fn new<T: ast::HasModuleItem>(node: T) -> AnyHasModuleItem {
AnyHasModuleItem { syntax: node.syntax().clone() }
}
}
impl AstNode for AnyModuleItemOwner {
impl AstNode for AnyHasModuleItem {
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
MACRO_ITEMS | SOURCE_FILE | ITEM_LIST => true,
@ -3746,17 +3746,17 @@ impl AstNode for AnyModuleItemOwner {
}
}
fn cast(syntax: SyntaxNode) -> Option<Self> {
Self::can_cast(syntax.kind()).then(|| AnyModuleItemOwner { syntax })
Self::can_cast(syntax.kind()).then(|| AnyHasModuleItem { syntax })
}
fn syntax(&self) -> &SyntaxNode { &self.syntax }
}
impl AnyNameOwner {
impl AnyHasName {
#[inline]
pub fn new<T: ast::NameOwner>(node: T) -> AnyNameOwner {
AnyNameOwner { syntax: node.syntax().clone() }
pub fn new<T: ast::HasName>(node: T) -> AnyHasName {
AnyHasName { syntax: node.syntax().clone() }
}
}
impl AstNode for AnyNameOwner {
impl AstNode for AnyHasName {
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
CONST | ENUM | FN | MACRO_RULES | MACRO_DEF | MODULE | STATIC | STRUCT | TRAIT
@ -3766,17 +3766,17 @@ impl AstNode for AnyNameOwner {
}
}
fn cast(syntax: SyntaxNode) -> Option<Self> {
Self::can_cast(syntax.kind()).then(|| AnyNameOwner { syntax })
Self::can_cast(syntax.kind()).then(|| AnyHasName { syntax })
}
fn syntax(&self) -> &SyntaxNode { &self.syntax }
}
impl AnyTypeBoundsOwner {
impl AnyHasTypeBounds {
#[inline]
pub fn new<T: ast::TypeBoundsOwner>(node: T) -> AnyTypeBoundsOwner {
AnyTypeBoundsOwner { syntax: node.syntax().clone() }
pub fn new<T: ast::HasTypeBounds>(node: T) -> AnyHasTypeBounds {
AnyHasTypeBounds { syntax: node.syntax().clone() }
}
}
impl AstNode for AnyTypeBoundsOwner {
impl AstNode for AnyHasTypeBounds {
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
ASSOC_TYPE_ARG | TRAIT | TYPE_ALIAS | LIFETIME_PARAM | TYPE_PARAM | WHERE_PRED => true,
@ -3784,17 +3784,17 @@ impl AstNode for AnyTypeBoundsOwner {
}
}
fn cast(syntax: SyntaxNode) -> Option<Self> {
Self::can_cast(syntax.kind()).then(|| AnyTypeBoundsOwner { syntax })
Self::can_cast(syntax.kind()).then(|| AnyHasTypeBounds { syntax })
}
fn syntax(&self) -> &SyntaxNode { &self.syntax }
}
impl AnyVisibilityOwner {
impl AnyHasVisibility {
#[inline]
pub fn new<T: ast::VisibilityOwner>(node: T) -> AnyVisibilityOwner {
AnyVisibilityOwner { syntax: node.syntax().clone() }
pub fn new<T: ast::HasVisibility>(node: T) -> AnyHasVisibility {
AnyHasVisibility { syntax: node.syntax().clone() }
}
}
impl AstNode for AnyVisibilityOwner {
impl AstNode for AnyHasVisibility {
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
CONST | ENUM | EXTERN_CRATE | FN | IMPL | MACRO_RULES | MACRO_DEF | MODULE | STATIC
@ -3805,7 +3805,7 @@ impl AstNode for AnyVisibilityOwner {
}
}
fn cast(syntax: SyntaxNode) -> Option<Self> {
Self::can_cast(syntax.kind()).then(|| AnyVisibilityOwner { syntax })
Self::can_cast(syntax.kind()).then(|| AnyHasVisibility { syntax })
}
fn syntax(&self) -> &SyntaxNode { &self.syntax }
}

View file

@ -11,8 +11,8 @@ use rowan::{GreenNodeData, GreenTokenData};
use crate::{
ast::{
self, support, AstNode, AstToken, AttrsOwner, GenericParamsOwner, ModuleItemOwner,
NameOwner, SyntaxNode,
self, support, AstNode, AstToken, HasAttrs, HasGenericParams, HasModuleItem, HasName,
SyntaxNode,
},
NodeOrToken, SmolStr, SyntaxElement, SyntaxToken, TokenText, T,
};
@ -50,7 +50,7 @@ fn text_of_first_token(node: &SyntaxNode) -> TokenText<'_> {
}
}
impl ast::ModuleItemOwner for ast::StmtList {}
impl ast::HasModuleItem for ast::StmtList {}
impl ast::BlockExpr {
// FIXME: remove all these methods, they belong to ast::StmtList
@ -107,7 +107,7 @@ impl AstNode for Macro {
}
}
impl NameOwner for Macro {
impl HasName for Macro {
fn name(&self) -> Option<ast::Name> {
match self {
Macro::MacroRules(mac) => mac.name(),
@ -116,7 +116,7 @@ impl NameOwner for Macro {
}
}
impl AttrsOwner for Macro {}
impl HasAttrs for Macro {}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum AttrKind {
@ -531,7 +531,7 @@ impl ast::Variant {
impl ast::Item {
pub fn generic_param_list(&self) -> Option<ast::GenericParamList> {
ast::AnyGenericParamsOwner::cast(self.syntax().clone())?.generic_param_list()
ast::AnyHasGenericParams::cast(self.syntax().clone())?.generic_param_list()
}
}
@ -765,21 +765,21 @@ impl ast::GenericParamList {
}
}
impl ast::DocCommentsOwner for ast::SourceFile {}
impl ast::DocCommentsOwner for ast::Fn {}
impl ast::DocCommentsOwner for ast::Struct {}
impl ast::DocCommentsOwner for ast::Union {}
impl ast::DocCommentsOwner for ast::RecordField {}
impl ast::DocCommentsOwner for ast::TupleField {}
impl ast::DocCommentsOwner for ast::Enum {}
impl ast::DocCommentsOwner for ast::Variant {}
impl ast::DocCommentsOwner for ast::Trait {}
impl ast::DocCommentsOwner for ast::Module {}
impl ast::DocCommentsOwner for ast::Static {}
impl ast::DocCommentsOwner for ast::Const {}
impl ast::DocCommentsOwner for ast::TypeAlias {}
impl ast::DocCommentsOwner for ast::Impl {}
impl ast::DocCommentsOwner for ast::MacroRules {}
impl ast::DocCommentsOwner for ast::MacroDef {}
impl ast::DocCommentsOwner for ast::Macro {}
impl ast::DocCommentsOwner for ast::Use {}
impl ast::HasDocComments for ast::SourceFile {}
impl ast::HasDocComments for ast::Fn {}
impl ast::HasDocComments for ast::Struct {}
impl ast::HasDocComments for ast::Union {}
impl ast::HasDocComments for ast::RecordField {}
impl ast::HasDocComments for ast::TupleField {}
impl ast::HasDocComments for ast::Enum {}
impl ast::HasDocComments for ast::Variant {}
impl ast::HasDocComments for ast::Trait {}
impl ast::HasDocComments for ast::Module {}
impl ast::HasDocComments for ast::Static {}
impl ast::HasDocComments for ast::Const {}
impl ast::HasDocComments for ast::TypeAlias {}
impl ast::HasDocComments for ast::Impl {}
impl ast::HasDocComments for ast::MacroRules {}
impl ast::HasDocComments for ast::MacroDef {}
impl ast::HasDocComments for ast::Macro {}
impl ast::HasDocComments for ast::Use {}

View file

@ -7,19 +7,19 @@ use crate::{
SyntaxToken, T,
};
pub trait NameOwner: AstNode {
pub trait HasName: AstNode {
fn name(&self) -> Option<ast::Name> {
support::child(self.syntax())
}
}
pub trait VisibilityOwner: AstNode {
pub trait HasVisibility: AstNode {
fn visibility(&self) -> Option<ast::Visibility> {
support::child(self.syntax())
}
}
pub trait LoopBodyOwner: AstNode {
pub trait HasLoopBody: AstNode {
fn loop_body(&self) -> Option<ast::BlockExpr> {
support::child(self.syntax())
}
@ -29,19 +29,19 @@ pub trait LoopBodyOwner: AstNode {
}
}
pub trait ArgListOwner: AstNode {
pub trait HasArgList: AstNode {
fn arg_list(&self) -> Option<ast::ArgList> {
support::child(self.syntax())
}
}
pub trait ModuleItemOwner: AstNode {
pub trait HasModuleItem: AstNode {
fn items(&self) -> AstChildren<ast::Item> {
support::children(self.syntax())
}
}
pub trait GenericParamsOwner: AstNode {
pub trait HasGenericParams: AstNode {
fn generic_param_list(&self) -> Option<ast::GenericParamList> {
support::child(self.syntax())
}
@ -51,7 +51,7 @@ pub trait GenericParamsOwner: AstNode {
}
}
pub trait TypeBoundsOwner: AstNode {
pub trait HasTypeBounds: AstNode {
fn type_bound_list(&self) -> Option<ast::TypeBoundList> {
support::child(self.syntax())
}
@ -61,7 +61,7 @@ pub trait TypeBoundsOwner: AstNode {
}
}
pub trait AttrsOwner: AstNode {
pub trait HasAttrs: AstNode {
fn attrs(&self) -> AstChildren<ast::Attr> {
support::children(self.syntax())
}
@ -70,7 +70,7 @@ pub trait AttrsOwner: AstNode {
}
}
pub trait DocCommentsOwner: AttrsOwner {
pub trait HasDocComments: HasAttrs {
fn doc_comments(&self) -> CommentIter {
CommentIter { iter: self.syntax().children_with_tokens() }
}

View file

@ -2,11 +2,11 @@
//! into types that may be used to render in a UI.
use crate::{
ast::{self, AstNode, AttrsOwner, GenericParamsOwner, NameOwner},
ast::{self, AstNode, HasAttrs, HasGenericParams, HasName},
SyntaxKind::{ATTR, COMMENT},
};
use ast::VisibilityOwner;
use ast::HasVisibility;
use stdx::format_to;
pub fn function_declaration(node: &ast::Fn) -> String {

View file

@ -255,7 +255,7 @@ macro_rules! match_ast {
/// API.
#[test]
fn api_walkthrough() {
use ast::{ModuleItemOwner, NameOwner};
use ast::{HasModuleItem, HasName};
let source_code = "
fn foo() {

View file

@ -8,7 +8,7 @@ use std::{
path::{Path, PathBuf},
};
use ast::NameOwner;
use ast::HasName;
use expect_test::expect_file;
use rayon::prelude::*;
use test_utils::{bench, bench_fixture, project_root};

View file

@ -740,14 +740,14 @@ fn extract_enums(ast: &mut AstSrc) {
fn extract_struct_traits(ast: &mut AstSrc) {
let traits: &[(&str, &[&str])] = &[
("AttrsOwner", &["attrs"]),
("NameOwner", &["name"]),
("VisibilityOwner", &["visibility"]),
("GenericParamsOwner", &["generic_param_list", "where_clause"]),
("TypeBoundsOwner", &["type_bound_list", "colon_token"]),
("ModuleItemOwner", &["items"]),
("LoopBodyOwner", &["label", "loop_body"]),
("ArgListOwner", &["arg_list"]),
("HasAttrs", &["attrs"]),
("HasName", &["name"]),
("HasVisibility", &["visibility"]),
("HasGenericParams", &["generic_param_list", "where_clause"]),
("HasTypeBounds", &["type_bound_list", "colon_token"]),
("HasModuleItem", &["items"]),
("HasLoopBody", &["label", "loop_body"]),
("HasArgList", &["arg_list"]),
];
for node in &mut ast.nodes {

View file

@ -13,7 +13,7 @@ use rustc_lexer::unescape::{
use crate::{
algo,
ast::{self, VisibilityOwner},
ast::{self, HasVisibility},
match_ast, AstNode, SyntaxError,
SyntaxKind::{CONST, FN, INT_NUMBER, TYPE_ALIAS},
SyntaxNode, SyntaxToken, TextSize, T,

Some files were not shown because too many files have changed in this diff Show more