diff options
Diffstat (limited to 'crates/syntax')
-rw-r--r-- | crates/syntax/src/ast.rs | 4 | ||||
-rw-r--r-- | crates/syntax/src/ast/node_ext.rs | 30 |
2 files changed, 32 insertions, 2 deletions
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::{ | |||
20 | expr_ext::{ArrayExprKind, BinOp, Effect, ElseBranch, LiteralKind, PrefixOp, RangeOp}, | 20 | expr_ext::{ArrayExprKind, BinOp, Effect, ElseBranch, LiteralKind, PrefixOp, RangeOp}, |
21 | generated::{nodes::*, tokens::*}, | 21 | generated::{nodes::*, tokens::*}, |
22 | node_ext::{ | 22 | node_ext::{ |
23 | AttrKind, FieldKind, Macro, NameLike, NameOrNameRef, PathSegmentKind, SelfParamKind, | 23 | AttrKind, AttrsOwnerNode, FieldKind, Macro, NameLike, NameOrNameRef, PathSegmentKind, |
24 | SlicePatComponents, StructKind, TypeBoundKind, VisibilityKind, | 24 | SelfParamKind, SlicePatComponents, StructKind, TypeBoundKind, VisibilityKind, |
25 | }, | 25 | }, |
26 | token_ext::*, | 26 | token_ext::*, |
27 | traits::*, | 27 | 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 { | |||
90 | 90 | ||
91 | impl AttrsOwner for Macro {} | 91 | impl AttrsOwner for Macro {} |
92 | 92 | ||
93 | /// Basically an owned `dyn AttrsOwner` without extra boxing. | ||
94 | pub struct AttrsOwnerNode { | ||
95 | node: SyntaxNode, | ||
96 | } | ||
97 | |||
98 | impl AttrsOwnerNode { | ||
99 | pub fn new<N: AttrsOwner>(node: N) -> Self { | ||
100 | AttrsOwnerNode { node: node.syntax().clone() } | ||
101 | } | ||
102 | } | ||
103 | |||
104 | impl AttrsOwner for AttrsOwnerNode {} | ||
105 | impl AstNode for AttrsOwnerNode { | ||
106 | fn can_cast(_: SyntaxKind) -> bool | ||
107 | where | ||
108 | Self: Sized, | ||
109 | { | ||
110 | false | ||
111 | } | ||
112 | fn cast(_: SyntaxNode) -> Option<Self> | ||
113 | where | ||
114 | Self: Sized, | ||
115 | { | ||
116 | None | ||
117 | } | ||
118 | fn syntax(&self) -> &SyntaxNode { | ||
119 | &self.node | ||
120 | } | ||
121 | } | ||
122 | |||
93 | #[derive(Debug, Clone, PartialEq, Eq)] | 123 | #[derive(Debug, Clone, PartialEq, Eq)] |
94 | pub enum AttrKind { | 124 | pub enum AttrKind { |
95 | Inner, | 125 | Inner, |