diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index 5cda6cc1e9..9de2c32111 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -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::DynGenericParamsOwner::cast(syn)?.generic_param_list()?; + let gpl = ast::AnyGenericParamsOwner::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_def/src/attr.rs b/crates/hir_def/src/attr.rs index 04011d9129..95516e2e83 100644 --- a/crates/hir_def/src/attr.rs +++ b/crates/hir_def/src/attr.rs @@ -411,47 +411,47 @@ 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::DynAttrsOwner::new(it.to_node(&root)), - Either::Right(it) => ast::DynAttrsOwner::new(it.to_node(&root)), + Either::Left(it) => ast::AnyAttrsOwner::new(it.to_node(&root)), + Either::Right(it) => ast::AnyAttrsOwner::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::DynAttrsOwner::new), - AdtId::UnionId(id) => id.lookup(db).source(db).map(ast::DynAttrsOwner::new), - AdtId::EnumId(id) => id.lookup(db).source(db).map(ast::DynAttrsOwner::new), + 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), }, - AttrDefId::FunctionId(id) => id.lookup(db).source(db).map(ast::DynAttrsOwner::new), + AttrDefId::FunctionId(id) => id.lookup(db).source(db).map(ast::AnyAttrsOwner::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::DynAttrsOwner::new(map[id.local_id].to_node(&root))) + InFile::new(file_id, ast::AnyAttrsOwner::new(map[id.local_id].to_node(&root))) } - AttrDefId::StaticId(id) => id.lookup(db).source(db).map(ast::DynAttrsOwner::new), - AttrDefId::ConstId(id) => id.lookup(db).source(db).map(ast::DynAttrsOwner::new), - AttrDefId::TraitId(id) => id.lookup(db).source(db).map(ast::DynAttrsOwner::new), - AttrDefId::TypeAliasId(id) => id.lookup(db).source(db).map(ast::DynAttrsOwner::new), + 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::MacroDefId(id) => id.ast_id().either( - |it| it.with_value(ast::DynAttrsOwner::new(it.to_node(db.upcast()))), - |it| it.with_value(ast::DynAttrsOwner::new(it.to_node(db.upcast()))), + |it| it.with_value(ast::AnyAttrsOwner::new(it.to_node(db.upcast()))), + |it| it.with_value(ast::AnyAttrsOwner::new(it.to_node(db.upcast()))), ), - AttrDefId::ImplId(id) => id.lookup(db).source(db).map(ast::DynAttrsOwner::new), + AttrDefId::ImplId(id) => id.lookup(db).source(db).map(ast::AnyAttrsOwner::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::DynAttrsOwner::new(id.clone()), - Either::Right(id) => ast::DynAttrsOwner::new(id.clone()), + Either::Left(id) => ast::AnyAttrsOwner::new(id.clone()), + Either::Right(id) => ast::AnyAttrsOwner::new(id.clone()), }) } GenericParamId::LifetimeParamId(id) => id .parent .child_source(db) - .map(|source| ast::DynAttrsOwner::new(source[id.local_id].clone())), + .map(|source| ast::AnyAttrsOwner::new(source[id.local_id].clone())), GenericParamId::ConstParamId(id) => id .parent .child_source(db) - .map(|source| ast::DynAttrsOwner::new(source[id.local_id].clone())), + .map(|source| ast::AnyAttrsOwner::new(source[id.local_id].clone())), }, }; diff --git a/crates/syntax/src/ast/generated/nodes.rs b/crates/syntax/src/ast/generated/nodes.rs index 066ad91d38..9fbd4aea19 100644 --- a/crates/syntax/src/ast/generated/nodes.rs +++ b/crates/syntax/src/ast/generated/nodes.rs @@ -1444,45 +1444,45 @@ pub enum GenericParam { } impl ast::AttrsOwner for GenericParam {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct DynArgListOwner { +pub struct AnyArgListOwner { pub(crate) syntax: SyntaxNode, } -impl ast::ArgListOwner for DynArgListOwner {} +impl ast::ArgListOwner for AnyArgListOwner {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct DynAttrsOwner { +pub struct AnyAttrsOwner { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for DynAttrsOwner {} +impl ast::AttrsOwner for AnyAttrsOwner {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct DynGenericParamsOwner { +pub struct AnyGenericParamsOwner { pub(crate) syntax: SyntaxNode, } -impl ast::GenericParamsOwner for DynGenericParamsOwner {} +impl ast::GenericParamsOwner for AnyGenericParamsOwner {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct DynLoopBodyOwner { +pub struct AnyLoopBodyOwner { pub(crate) syntax: SyntaxNode, } -impl ast::LoopBodyOwner for DynLoopBodyOwner {} +impl ast::LoopBodyOwner for AnyLoopBodyOwner {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct DynModuleItemOwner { +pub struct AnyModuleItemOwner { pub(crate) syntax: SyntaxNode, } -impl ast::ModuleItemOwner for DynModuleItemOwner {} +impl ast::ModuleItemOwner for AnyModuleItemOwner {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct DynNameOwner { +pub struct AnyNameOwner { pub(crate) syntax: SyntaxNode, } -impl ast::NameOwner for DynNameOwner {} +impl ast::NameOwner for AnyNameOwner {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct DynTypeBoundsOwner { +pub struct AnyTypeBoundsOwner { pub(crate) syntax: SyntaxNode, } -impl ast::TypeBoundsOwner for DynTypeBoundsOwner {} +impl ast::TypeBoundsOwner for AnyTypeBoundsOwner {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct DynVisibilityOwner { +pub struct AnyVisibilityOwner { pub(crate) syntax: SyntaxNode, } -impl ast::VisibilityOwner for DynVisibilityOwner {} +impl ast::VisibilityOwner for AnyVisibilityOwner {} impl AstNode for Name { fn can_cast(kind: SyntaxKind) -> bool { kind == NAME } fn cast(syntax: SyntaxNode) -> Option { @@ -3597,13 +3597,13 @@ impl AstNode for GenericParam { } } } -impl DynArgListOwner { +impl AnyArgListOwner { #[inline] - pub fn new(node: T) -> DynArgListOwner { - DynArgListOwner { syntax: node.syntax().clone() } + pub fn new(node: T) -> AnyArgListOwner { + AnyArgListOwner { syntax: node.syntax().clone() } } } -impl AstNode for DynArgListOwner { +impl AstNode for AnyArgListOwner { fn can_cast(kind: SyntaxKind) -> bool { match kind { CALL_EXPR | METHOD_CALL_EXPR => true, @@ -3611,17 +3611,17 @@ impl AstNode for DynArgListOwner { } } fn cast(syntax: SyntaxNode) -> Option { - Self::can_cast(syntax.kind()).then(|| DynArgListOwner { syntax }) + Self::can_cast(syntax.kind()).then(|| AnyArgListOwner { syntax }) } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl DynAttrsOwner { +impl AnyAttrsOwner { #[inline] - pub fn new(node: T) -> DynAttrsOwner { - DynAttrsOwner { syntax: node.syntax().clone() } + pub fn new(node: T) -> AnyAttrsOwner { + AnyAttrsOwner { syntax: node.syntax().clone() } } } -impl AstNode for DynAttrsOwner { +impl AstNode for AnyAttrsOwner { fn can_cast(kind: SyntaxKind) -> bool { match kind { MACRO_CALL @@ -3692,17 +3692,17 @@ impl AstNode for DynAttrsOwner { } } fn cast(syntax: SyntaxNode) -> Option { - Self::can_cast(syntax.kind()).then(|| DynAttrsOwner { syntax }) + Self::can_cast(syntax.kind()).then(|| AnyAttrsOwner { syntax }) } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl DynGenericParamsOwner { +impl AnyGenericParamsOwner { #[inline] - pub fn new(node: T) -> DynGenericParamsOwner { - DynGenericParamsOwner { syntax: node.syntax().clone() } + pub fn new(node: T) -> AnyGenericParamsOwner { + AnyGenericParamsOwner { syntax: node.syntax().clone() } } } -impl AstNode for DynGenericParamsOwner { +impl AstNode for AnyGenericParamsOwner { fn can_cast(kind: SyntaxKind) -> bool { match kind { ENUM | FN | IMPL | STRUCT | TRAIT | TYPE_ALIAS | UNION => true, @@ -3710,17 +3710,17 @@ impl AstNode for DynGenericParamsOwner { } } fn cast(syntax: SyntaxNode) -> Option { - Self::can_cast(syntax.kind()).then(|| DynGenericParamsOwner { syntax }) + Self::can_cast(syntax.kind()).then(|| AnyGenericParamsOwner { syntax }) } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl DynLoopBodyOwner { +impl AnyLoopBodyOwner { #[inline] - pub fn new(node: T) -> DynLoopBodyOwner { - DynLoopBodyOwner { syntax: node.syntax().clone() } + pub fn new(node: T) -> AnyLoopBodyOwner { + AnyLoopBodyOwner { syntax: node.syntax().clone() } } } -impl AstNode for DynLoopBodyOwner { +impl AstNode for AnyLoopBodyOwner { fn can_cast(kind: SyntaxKind) -> bool { match kind { FOR_EXPR | LOOP_EXPR | WHILE_EXPR => true, @@ -3728,17 +3728,17 @@ impl AstNode for DynLoopBodyOwner { } } fn cast(syntax: SyntaxNode) -> Option { - Self::can_cast(syntax.kind()).then(|| DynLoopBodyOwner { syntax }) + Self::can_cast(syntax.kind()).then(|| AnyLoopBodyOwner { syntax }) } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl DynModuleItemOwner { +impl AnyModuleItemOwner { #[inline] - pub fn new(node: T) -> DynModuleItemOwner { - DynModuleItemOwner { syntax: node.syntax().clone() } + pub fn new(node: T) -> AnyModuleItemOwner { + AnyModuleItemOwner { syntax: node.syntax().clone() } } } -impl AstNode for DynModuleItemOwner { +impl AstNode for AnyModuleItemOwner { fn can_cast(kind: SyntaxKind) -> bool { match kind { MACRO_ITEMS | SOURCE_FILE | ITEM_LIST => true, @@ -3746,17 +3746,17 @@ impl AstNode for DynModuleItemOwner { } } fn cast(syntax: SyntaxNode) -> Option { - Self::can_cast(syntax.kind()).then(|| DynModuleItemOwner { syntax }) + Self::can_cast(syntax.kind()).then(|| AnyModuleItemOwner { syntax }) } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl DynNameOwner { +impl AnyNameOwner { #[inline] - pub fn new(node: T) -> DynNameOwner { - DynNameOwner { syntax: node.syntax().clone() } + pub fn new(node: T) -> AnyNameOwner { + AnyNameOwner { syntax: node.syntax().clone() } } } -impl AstNode for DynNameOwner { +impl AstNode for AnyNameOwner { 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 DynNameOwner { } } fn cast(syntax: SyntaxNode) -> Option { - Self::can_cast(syntax.kind()).then(|| DynNameOwner { syntax }) + Self::can_cast(syntax.kind()).then(|| AnyNameOwner { syntax }) } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl DynTypeBoundsOwner { +impl AnyTypeBoundsOwner { #[inline] - pub fn new(node: T) -> DynTypeBoundsOwner { - DynTypeBoundsOwner { syntax: node.syntax().clone() } + pub fn new(node: T) -> AnyTypeBoundsOwner { + AnyTypeBoundsOwner { syntax: node.syntax().clone() } } } -impl AstNode for DynTypeBoundsOwner { +impl AstNode for AnyTypeBoundsOwner { 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 DynTypeBoundsOwner { } } fn cast(syntax: SyntaxNode) -> Option { - Self::can_cast(syntax.kind()).then(|| DynTypeBoundsOwner { syntax }) + Self::can_cast(syntax.kind()).then(|| AnyTypeBoundsOwner { syntax }) } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl DynVisibilityOwner { +impl AnyVisibilityOwner { #[inline] - pub fn new(node: T) -> DynVisibilityOwner { - DynVisibilityOwner { syntax: node.syntax().clone() } + pub fn new(node: T) -> AnyVisibilityOwner { + AnyVisibilityOwner { syntax: node.syntax().clone() } } } -impl AstNode for DynVisibilityOwner { +impl AstNode for AnyVisibilityOwner { 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 DynVisibilityOwner { } } fn cast(syntax: SyntaxNode) -> Option { - Self::can_cast(syntax.kind()).then(|| DynVisibilityOwner { syntax }) + Self::can_cast(syntax.kind()).then(|| AnyVisibilityOwner { syntax }) } fn syntax(&self) -> &SyntaxNode { &self.syntax } } diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs index cb3bdaac1b..18a324e3ea 100644 --- a/crates/syntax/src/ast/node_ext.rs +++ b/crates/syntax/src/ast/node_ext.rs @@ -531,7 +531,7 @@ impl ast::Variant { impl ast::Item { pub fn generic_param_list(&self) -> Option { - ast::DynGenericParamsOwner::cast(self.syntax().clone())?.generic_param_list() + ast::AnyGenericParamsOwner::cast(self.syntax().clone())?.generic_param_list() } } diff --git a/crates/syntax/src/tests/sourcegen_ast.rs b/crates/syntax/src/tests/sourcegen_ast.rs index 07213b08be..8897c29722 100644 --- a/crates/syntax/src/tests/sourcegen_ast.rs +++ b/crates/syntax/src/tests/sourcegen_ast.rs @@ -209,7 +209,7 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: &AstSrc) -> String { }) .unzip(); - let (dyn_node_defs, dyn_node_boilerplate_impls): (Vec<_>, Vec<_>) = grammar + let (any_node_defs, any_node_boilerplate_impls): (Vec<_>, Vec<_>) = grammar .nodes .iter() .flat_map(|node| node.traits.iter().map(move |t| (t, node))) @@ -217,7 +217,7 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: &AstSrc) -> String { .into_iter() .sorted_by_key(|(k, _)| k.clone()) .map(|(trait_name, nodes)| { - let name = format_ident!("Dyn{}", trait_name); + let name = format_ident!("Any{}", trait_name); let trait_name = format_ident!("{}", trait_name); let kinds: Vec<_> = nodes .iter() @@ -297,10 +297,10 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: &AstSrc) -> String { #(#node_defs)* #(#enum_defs)* - #(#dyn_node_defs)* + #(#any_node_defs)* #(#node_boilerplate_impls)* #(#enum_boilerplate_impls)* - #(#dyn_node_boilerplate_impls)* + #(#any_node_boilerplate_impls)* #(#display_impls)* };