From fc5f73de45478058aa6d61e328733224cfa16efa Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 19 Mar 2021 19:42:06 +0100 Subject: Move `AttrsOwnerNode` to syntax and make it public --- crates/syntax/src/ast.rs | 4 ++-- crates/syntax/src/ast/node_ext.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) (limited to 'crates/syntax') diff --git a/crates/syntax/src/ast.rs b/crates/syntax/src/ast.rs index 38e0b04ef..7f472d4db 100644 --- a/crates/syntax/src/ast.rs +++ b/crates/syntax/src/ast.rs @@ -20,8 +20,8 @@ pub use self::{ expr_ext::{ArrayExprKind, BinOp, Effect, ElseBranch, LiteralKind, PrefixOp, RangeOp}, generated::{nodes::*, tokens::*}, node_ext::{ - AttrKind, FieldKind, Macro, NameLike, NameOrNameRef, PathSegmentKind, SelfParamKind, - SlicePatComponents, StructKind, TypeBoundKind, VisibilityKind, + AttrKind, AttrsOwnerNode, FieldKind, Macro, NameLike, NameOrNameRef, PathSegmentKind, + SelfParamKind, SlicePatComponents, StructKind, TypeBoundKind, VisibilityKind, }, token_ext::*, traits::*, diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs index 5a9834cbb..01f580a40 100644 --- a/crates/syntax/src/ast/node_ext.rs +++ b/crates/syntax/src/ast/node_ext.rs @@ -90,6 +90,36 @@ impl NameOwner for Macro { impl AttrsOwner for Macro {} +/// Basically an owned `dyn AttrsOwner` without extra boxing. +pub struct AttrsOwnerNode { + node: SyntaxNode, +} + +impl AttrsOwnerNode { + pub fn new(node: N) -> Self { + AttrsOwnerNode { node: node.syntax().clone() } + } +} + +impl AttrsOwner for AttrsOwnerNode {} +impl AstNode for AttrsOwnerNode { + fn can_cast(_: SyntaxKind) -> bool + where + Self: Sized, + { + false + } + fn cast(_: SyntaxNode) -> Option + where + Self: Sized, + { + None + } + fn syntax(&self) -> &SyntaxNode { + &self.node + } +} + #[derive(Debug, Clone, PartialEq, Eq)] pub enum AttrKind { Inner, -- cgit v1.2.3