diff options
Diffstat (limited to 'crates/ra_syntax/src')
27 files changed, 3493 insertions, 2155 deletions
diff --git a/crates/ra_syntax/src/algo/mod.rs b/crates/ra_syntax/src/algo/mod.rs index faf5a6211..4b3548ea9 100644 --- a/crates/ra_syntax/src/algo/mod.rs +++ b/crates/ra_syntax/src/algo/mod.rs | |||
@@ -1,116 +1,19 @@ | |||
1 | pub mod visit; | 1 | pub mod visit; |
2 | // pub mod walk; | ||
3 | 2 | ||
4 | use crate::{text_utils::contains_offset_nonstrict, SyntaxNodeRef, TextRange, TextUnit}; | 3 | use crate::{SyntaxNode, SyntaxNodeRef, TextRange, TextUnit}; |
5 | 4 | ||
6 | pub fn find_leaf_at_offset(node: SyntaxNodeRef, offset: TextUnit) -> LeafAtOffset { | 5 | pub use rowan::LeafAtOffset; |
7 | let range = node.range(); | ||
8 | assert!( | ||
9 | contains_offset_nonstrict(range, offset), | ||
10 | "Bad offset: range {:?} offset {:?}", | ||
11 | range, | ||
12 | offset | ||
13 | ); | ||
14 | if range.is_empty() { | ||
15 | return LeafAtOffset::None; | ||
16 | } | ||
17 | |||
18 | if node.is_leaf() { | ||
19 | return LeafAtOffset::Single(node); | ||
20 | } | ||
21 | |||
22 | let mut children = node.children().filter(|child| { | ||
23 | let child_range = child.range(); | ||
24 | !child_range.is_empty() && contains_offset_nonstrict(child_range, offset) | ||
25 | }); | ||
26 | |||
27 | let left = children.next().unwrap(); | ||
28 | let right = children.next(); | ||
29 | assert!(children.next().is_none()); | ||
30 | |||
31 | if let Some(right) = right { | ||
32 | match ( | ||
33 | find_leaf_at_offset(left, offset), | ||
34 | find_leaf_at_offset(right, offset), | ||
35 | ) { | ||
36 | (LeafAtOffset::Single(left), LeafAtOffset::Single(right)) => { | ||
37 | LeafAtOffset::Between(left, right) | ||
38 | } | ||
39 | _ => unreachable!(), | ||
40 | } | ||
41 | } else { | ||
42 | find_leaf_at_offset(left, offset) | ||
43 | } | ||
44 | } | ||
45 | |||
46 | #[derive(Clone, Debug)] | ||
47 | pub enum LeafAtOffset<'a> { | ||
48 | None, | ||
49 | Single(SyntaxNodeRef<'a>), | ||
50 | Between(SyntaxNodeRef<'a>, SyntaxNodeRef<'a>), | ||
51 | } | ||
52 | 6 | ||
53 | impl<'a> LeafAtOffset<'a> { | 7 | pub fn find_leaf_at_offset(node: SyntaxNodeRef, offset: TextUnit) -> LeafAtOffset<SyntaxNodeRef> { |
54 | pub fn right_biased(self) -> Option<SyntaxNodeRef<'a>> { | 8 | match node.0.leaf_at_offset(offset) { |
55 | match self { | 9 | LeafAtOffset::None => LeafAtOffset::None, |
56 | LeafAtOffset::None => None, | 10 | LeafAtOffset::Single(n) => LeafAtOffset::Single(SyntaxNode(n)), |
57 | LeafAtOffset::Single(node) => Some(node), | 11 | LeafAtOffset::Between(l, r) => LeafAtOffset::Between(SyntaxNode(l), SyntaxNode(r)), |
58 | LeafAtOffset::Between(_, right) => Some(right), | ||
59 | } | ||
60 | } | ||
61 | |||
62 | pub fn left_biased(self) -> Option<SyntaxNodeRef<'a>> { | ||
63 | match self { | ||
64 | LeafAtOffset::None => None, | ||
65 | LeafAtOffset::Single(node) => Some(node), | ||
66 | LeafAtOffset::Between(left, _) => Some(left), | ||
67 | } | ||
68 | } | ||
69 | } | ||
70 | |||
71 | impl<'f> Iterator for LeafAtOffset<'f> { | ||
72 | type Item = SyntaxNodeRef<'f>; | ||
73 | |||
74 | fn next(&mut self) -> Option<SyntaxNodeRef<'f>> { | ||
75 | match *self { | ||
76 | LeafAtOffset::None => None, | ||
77 | LeafAtOffset::Single(node) => { | ||
78 | *self = LeafAtOffset::None; | ||
79 | Some(node) | ||
80 | } | ||
81 | LeafAtOffset::Between(left, right) => { | ||
82 | *self = LeafAtOffset::Single(right); | ||
83 | Some(left) | ||
84 | } | ||
85 | } | ||
86 | } | 12 | } |
87 | } | 13 | } |
88 | 14 | ||
89 | pub fn find_covering_node(root: SyntaxNodeRef, range: TextRange) -> SyntaxNodeRef { | 15 | pub fn find_covering_node(root: SyntaxNodeRef, range: TextRange) -> SyntaxNodeRef { |
90 | assert!( | 16 | SyntaxNode(root.0.covering_node(range)) |
91 | range.is_subrange(&root.range()), | ||
92 | "node range: {:?}, target range: {:?}", | ||
93 | root.range(), | ||
94 | range, | ||
95 | ); | ||
96 | let (left, right) = match ( | ||
97 | find_leaf_at_offset(root, range.start()).right_biased(), | ||
98 | find_leaf_at_offset(root, range.end()).left_biased(), | ||
99 | ) { | ||
100 | (Some(l), Some(r)) => (l, r), | ||
101 | _ => return root, | ||
102 | }; | ||
103 | |||
104 | common_ancestor(left, right) | ||
105 | } | ||
106 | |||
107 | fn common_ancestor<'a>(n1: SyntaxNodeRef<'a>, n2: SyntaxNodeRef<'a>) -> SyntaxNodeRef<'a> { | ||
108 | for p in n1.ancestors() { | ||
109 | if n2.ancestors().any(|a| a == p) { | ||
110 | return p; | ||
111 | } | ||
112 | } | ||
113 | panic!("Can't find common ancestor of {:?} and {:?}", n1, n2) | ||
114 | } | 17 | } |
115 | 18 | ||
116 | pub fn generate<T>(seed: Option<T>, step: impl Fn(&T) -> Option<T>) -> impl Iterator<Item = T> { | 19 | pub fn generate<T>(seed: Option<T>, step: impl Fn(&T) -> Option<T>) -> impl Iterator<Item = T> { |
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 75769a4e9..bf056131e 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -1,34 +1,36 @@ | |||
1 | // This file is automatically generated based on the file `./generated.rs.tera` when `cargo gen-syntax` is run | 1 | // This file is automatically generated based on the file `./generated.rs.tera` when `cargo gen-syntax` is run |
2 | // Do not edit manually | 2 | // Do not edit manually |
3 | 3 | ||
4 | //! This module contains auto-generated Rust AST. Like `SyntaxNode`s, AST nodes | ||
5 | //! are generic over ownership: `X<'a>` things are `Copy` references, `XNode` | ||
6 | //! are Arc-based. You can switch between the two variants using `.owned` and | ||
7 | //! `.borrowed` functions. Most of the code works with borowed mode, and only | ||
8 | //! this mode has all AST accessors. | ||
9 | |||
4 | #![cfg_attr(rustfmt, rustfmt_skip)] | 10 | #![cfg_attr(rustfmt, rustfmt_skip)] |
5 | 11 | ||
12 | use std::hash::{Hash, Hasher}; | ||
13 | |||
6 | use crate::{ | 14 | use crate::{ |
7 | ast, | 15 | ast, |
8 | SyntaxNode, SyntaxNodeRef, AstNode, | 16 | SyntaxNode, SyntaxNodeRef, AstNode, |
17 | yellow::{TreeRoot, RaTypes, OwnedRoot, RefRoot}, | ||
9 | SyntaxKind::*, | 18 | SyntaxKind::*, |
10 | }; | 19 | }; |
11 | 20 | ||
12 | // ArgList | 21 | // ArgList |
13 | 22 | #[derive(Debug, Clone, Copy,)] | |
14 | #[derive(Debug, Clone)] | 23 | pub struct ArgListNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
15 | pub struct ArgListNode(SyntaxNode); | 24 | pub(crate) syntax: SyntaxNode<R>, |
16 | |||
17 | impl ArgListNode { | ||
18 | pub fn ast(&self) -> ArgList { | ||
19 | ArgList::cast(self.0.borrowed()).unwrap() | ||
20 | } | ||
21 | } | 25 | } |
26 | pub type ArgList<'a> = ArgListNode<RefRoot<'a>>; | ||
22 | 27 | ||
23 | impl<'a> From<ArgList<'a>> for ArgListNode { | 28 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ArgListNode<R1>> for ArgListNode<R2> { |
24 | fn from(ast: ArgList<'a>) -> ArgListNode { | 29 | fn eq(&self, other: &ArgListNode<R1>) -> bool { self.syntax == other.syntax } |
25 | let syntax = ast.syntax().owned(); | ||
26 | ArgListNode(syntax) | ||
27 | } | ||
28 | } | 30 | } |
29 | #[derive(Debug, Clone, Copy)] | 31 | impl<R: TreeRoot<RaTypes>> Eq for ArgListNode<R> {} |
30 | pub struct ArgList<'a> { | 32 | impl<R: TreeRoot<RaTypes>> Hash for ArgListNode<R> { |
31 | syntax: SyntaxNodeRef<'a>, | 33 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
32 | } | 34 | } |
33 | 35 | ||
34 | impl<'a> AstNode<'a> for ArgList<'a> { | 36 | impl<'a> AstNode<'a> for ArgList<'a> { |
@@ -41,6 +43,16 @@ impl<'a> AstNode<'a> for ArgList<'a> { | |||
41 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 43 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
42 | } | 44 | } |
43 | 45 | ||
46 | impl<R: TreeRoot<RaTypes>> ArgListNode<R> { | ||
47 | pub fn borrowed(&self) -> ArgList { | ||
48 | ArgListNode { syntax: self.syntax.borrowed() } | ||
49 | } | ||
50 | pub fn owned(&self) -> ArgListNode { | ||
51 | ArgListNode { syntax: self.syntax.owned() } | ||
52 | } | ||
53 | } | ||
54 | |||
55 | |||
44 | impl<'a> ArgList<'a> { | 56 | impl<'a> ArgList<'a> { |
45 | pub fn args(self) -> impl Iterator<Item = Expr<'a>> + 'a { | 57 | pub fn args(self) -> impl Iterator<Item = Expr<'a>> + 'a { |
46 | super::children(self) | 58 | super::children(self) |
@@ -48,25 +60,18 @@ impl<'a> ArgList<'a> { | |||
48 | } | 60 | } |
49 | 61 | ||
50 | // ArrayExpr | 62 | // ArrayExpr |
51 | 63 | #[derive(Debug, Clone, Copy,)] | |
52 | #[derive(Debug, Clone)] | 64 | pub struct ArrayExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
53 | pub struct ArrayExprNode(SyntaxNode); | 65 | pub(crate) syntax: SyntaxNode<R>, |
54 | |||
55 | impl ArrayExprNode { | ||
56 | pub fn ast(&self) -> ArrayExpr { | ||
57 | ArrayExpr::cast(self.0.borrowed()).unwrap() | ||
58 | } | ||
59 | } | 66 | } |
67 | pub type ArrayExpr<'a> = ArrayExprNode<RefRoot<'a>>; | ||
60 | 68 | ||
61 | impl<'a> From<ArrayExpr<'a>> for ArrayExprNode { | 69 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ArrayExprNode<R1>> for ArrayExprNode<R2> { |
62 | fn from(ast: ArrayExpr<'a>) -> ArrayExprNode { | 70 | fn eq(&self, other: &ArrayExprNode<R1>) -> bool { self.syntax == other.syntax } |
63 | let syntax = ast.syntax().owned(); | ||
64 | ArrayExprNode(syntax) | ||
65 | } | ||
66 | } | 71 | } |
67 | #[derive(Debug, Clone, Copy)] | 72 | impl<R: TreeRoot<RaTypes>> Eq for ArrayExprNode<R> {} |
68 | pub struct ArrayExpr<'a> { | 73 | impl<R: TreeRoot<RaTypes>> Hash for ArrayExprNode<R> { |
69 | syntax: SyntaxNodeRef<'a>, | 74 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
70 | } | 75 | } |
71 | 76 | ||
72 | impl<'a> AstNode<'a> for ArrayExpr<'a> { | 77 | impl<'a> AstNode<'a> for ArrayExpr<'a> { |
@@ -79,28 +84,31 @@ impl<'a> AstNode<'a> for ArrayExpr<'a> { | |||
79 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 84 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
80 | } | 85 | } |
81 | 86 | ||
82 | impl<'a> ArrayExpr<'a> {} | 87 | impl<R: TreeRoot<RaTypes>> ArrayExprNode<R> { |
88 | pub fn borrowed(&self) -> ArrayExpr { | ||
89 | ArrayExprNode { syntax: self.syntax.borrowed() } | ||
90 | } | ||
91 | pub fn owned(&self) -> ArrayExprNode { | ||
92 | ArrayExprNode { syntax: self.syntax.owned() } | ||
93 | } | ||
94 | } | ||
83 | 95 | ||
84 | // ArrayType | ||
85 | 96 | ||
86 | #[derive(Debug, Clone)] | 97 | impl<'a> ArrayExpr<'a> {} |
87 | pub struct ArrayTypeNode(SyntaxNode); | ||
88 | 98 | ||
89 | impl ArrayTypeNode { | 99 | // ArrayType |
90 | pub fn ast(&self) -> ArrayType { | 100 | #[derive(Debug, Clone, Copy,)] |
91 | ArrayType::cast(self.0.borrowed()).unwrap() | 101 | pub struct ArrayTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
92 | } | 102 | pub(crate) syntax: SyntaxNode<R>, |
93 | } | 103 | } |
104 | pub type ArrayType<'a> = ArrayTypeNode<RefRoot<'a>>; | ||
94 | 105 | ||
95 | impl<'a> From<ArrayType<'a>> for ArrayTypeNode { | 106 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ArrayTypeNode<R1>> for ArrayTypeNode<R2> { |
96 | fn from(ast: ArrayType<'a>) -> ArrayTypeNode { | 107 | fn eq(&self, other: &ArrayTypeNode<R1>) -> bool { self.syntax == other.syntax } |
97 | let syntax = ast.syntax().owned(); | ||
98 | ArrayTypeNode(syntax) | ||
99 | } | ||
100 | } | 108 | } |
101 | #[derive(Debug, Clone, Copy)] | 109 | impl<R: TreeRoot<RaTypes>> Eq for ArrayTypeNode<R> {} |
102 | pub struct ArrayType<'a> { | 110 | impl<R: TreeRoot<RaTypes>> Hash for ArrayTypeNode<R> { |
103 | syntax: SyntaxNodeRef<'a>, | 111 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
104 | } | 112 | } |
105 | 113 | ||
106 | impl<'a> AstNode<'a> for ArrayType<'a> { | 114 | impl<'a> AstNode<'a> for ArrayType<'a> { |
@@ -113,28 +121,31 @@ impl<'a> AstNode<'a> for ArrayType<'a> { | |||
113 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 121 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
114 | } | 122 | } |
115 | 123 | ||
116 | impl<'a> ArrayType<'a> {} | 124 | impl<R: TreeRoot<RaTypes>> ArrayTypeNode<R> { |
125 | pub fn borrowed(&self) -> ArrayType { | ||
126 | ArrayTypeNode { syntax: self.syntax.borrowed() } | ||
127 | } | ||
128 | pub fn owned(&self) -> ArrayTypeNode { | ||
129 | ArrayTypeNode { syntax: self.syntax.owned() } | ||
130 | } | ||
131 | } | ||
117 | 132 | ||
118 | // Attr | ||
119 | 133 | ||
120 | #[derive(Debug, Clone)] | 134 | impl<'a> ArrayType<'a> {} |
121 | pub struct AttrNode(SyntaxNode); | ||
122 | 135 | ||
123 | impl AttrNode { | 136 | // Attr |
124 | pub fn ast(&self) -> Attr { | 137 | #[derive(Debug, Clone, Copy,)] |
125 | Attr::cast(self.0.borrowed()).unwrap() | 138 | pub struct AttrNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
126 | } | 139 | pub(crate) syntax: SyntaxNode<R>, |
127 | } | 140 | } |
141 | pub type Attr<'a> = AttrNode<RefRoot<'a>>; | ||
128 | 142 | ||
129 | impl<'a> From<Attr<'a>> for AttrNode { | 143 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<AttrNode<R1>> for AttrNode<R2> { |
130 | fn from(ast: Attr<'a>) -> AttrNode { | 144 | fn eq(&self, other: &AttrNode<R1>) -> bool { self.syntax == other.syntax } |
131 | let syntax = ast.syntax().owned(); | ||
132 | AttrNode(syntax) | ||
133 | } | ||
134 | } | 145 | } |
135 | #[derive(Debug, Clone, Copy)] | 146 | impl<R: TreeRoot<RaTypes>> Eq for AttrNode<R> {} |
136 | pub struct Attr<'a> { | 147 | impl<R: TreeRoot<RaTypes>> Hash for AttrNode<R> { |
137 | syntax: SyntaxNodeRef<'a>, | 148 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
138 | } | 149 | } |
139 | 150 | ||
140 | impl<'a> AstNode<'a> for Attr<'a> { | 151 | impl<'a> AstNode<'a> for Attr<'a> { |
@@ -147,6 +158,16 @@ impl<'a> AstNode<'a> for Attr<'a> { | |||
147 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 158 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
148 | } | 159 | } |
149 | 160 | ||
161 | impl<R: TreeRoot<RaTypes>> AttrNode<R> { | ||
162 | pub fn borrowed(&self) -> Attr { | ||
163 | AttrNode { syntax: self.syntax.borrowed() } | ||
164 | } | ||
165 | pub fn owned(&self) -> AttrNode { | ||
166 | AttrNode { syntax: self.syntax.owned() } | ||
167 | } | ||
168 | } | ||
169 | |||
170 | |||
150 | impl<'a> Attr<'a> { | 171 | impl<'a> Attr<'a> { |
151 | pub fn value(self) -> Option<TokenTree<'a>> { | 172 | pub fn value(self) -> Option<TokenTree<'a>> { |
152 | super::child_opt(self) | 173 | super::child_opt(self) |
@@ -154,25 +175,18 @@ impl<'a> Attr<'a> { | |||
154 | } | 175 | } |
155 | 176 | ||
156 | // BinExpr | 177 | // BinExpr |
157 | 178 | #[derive(Debug, Clone, Copy,)] | |
158 | #[derive(Debug, Clone)] | 179 | pub struct BinExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
159 | pub struct BinExprNode(SyntaxNode); | 180 | pub(crate) syntax: SyntaxNode<R>, |
160 | |||
161 | impl BinExprNode { | ||
162 | pub fn ast(&self) -> BinExpr { | ||
163 | BinExpr::cast(self.0.borrowed()).unwrap() | ||
164 | } | ||
165 | } | 181 | } |
182 | pub type BinExpr<'a> = BinExprNode<RefRoot<'a>>; | ||
166 | 183 | ||
167 | impl<'a> From<BinExpr<'a>> for BinExprNode { | 184 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<BinExprNode<R1>> for BinExprNode<R2> { |
168 | fn from(ast: BinExpr<'a>) -> BinExprNode { | 185 | fn eq(&self, other: &BinExprNode<R1>) -> bool { self.syntax == other.syntax } |
169 | let syntax = ast.syntax().owned(); | ||
170 | BinExprNode(syntax) | ||
171 | } | ||
172 | } | 186 | } |
173 | #[derive(Debug, Clone, Copy)] | 187 | impl<R: TreeRoot<RaTypes>> Eq for BinExprNode<R> {} |
174 | pub struct BinExpr<'a> { | 188 | impl<R: TreeRoot<RaTypes>> Hash for BinExprNode<R> { |
175 | syntax: SyntaxNodeRef<'a>, | 189 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
176 | } | 190 | } |
177 | 191 | ||
178 | impl<'a> AstNode<'a> for BinExpr<'a> { | 192 | impl<'a> AstNode<'a> for BinExpr<'a> { |
@@ -185,28 +199,31 @@ impl<'a> AstNode<'a> for BinExpr<'a> { | |||
185 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 199 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
186 | } | 200 | } |
187 | 201 | ||
188 | impl<'a> BinExpr<'a> {} | 202 | impl<R: TreeRoot<RaTypes>> BinExprNode<R> { |
203 | pub fn borrowed(&self) -> BinExpr { | ||
204 | BinExprNode { syntax: self.syntax.borrowed() } | ||
205 | } | ||
206 | pub fn owned(&self) -> BinExprNode { | ||
207 | BinExprNode { syntax: self.syntax.owned() } | ||
208 | } | ||
209 | } | ||
189 | 210 | ||
190 | // BindPat | ||
191 | 211 | ||
192 | #[derive(Debug, Clone)] | 212 | impl<'a> BinExpr<'a> {} |
193 | pub struct BindPatNode(SyntaxNode); | ||
194 | 213 | ||
195 | impl BindPatNode { | 214 | // BindPat |
196 | pub fn ast(&self) -> BindPat { | 215 | #[derive(Debug, Clone, Copy,)] |
197 | BindPat::cast(self.0.borrowed()).unwrap() | 216 | pub struct BindPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
198 | } | 217 | pub(crate) syntax: SyntaxNode<R>, |
199 | } | 218 | } |
219 | pub type BindPat<'a> = BindPatNode<RefRoot<'a>>; | ||
200 | 220 | ||
201 | impl<'a> From<BindPat<'a>> for BindPatNode { | 221 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<BindPatNode<R1>> for BindPatNode<R2> { |
202 | fn from(ast: BindPat<'a>) -> BindPatNode { | 222 | fn eq(&self, other: &BindPatNode<R1>) -> bool { self.syntax == other.syntax } |
203 | let syntax = ast.syntax().owned(); | ||
204 | BindPatNode(syntax) | ||
205 | } | ||
206 | } | 223 | } |
207 | #[derive(Debug, Clone, Copy)] | 224 | impl<R: TreeRoot<RaTypes>> Eq for BindPatNode<R> {} |
208 | pub struct BindPat<'a> { | 225 | impl<R: TreeRoot<RaTypes>> Hash for BindPatNode<R> { |
209 | syntax: SyntaxNodeRef<'a>, | 226 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
210 | } | 227 | } |
211 | 228 | ||
212 | impl<'a> AstNode<'a> for BindPat<'a> { | 229 | impl<'a> AstNode<'a> for BindPat<'a> { |
@@ -219,29 +236,32 @@ impl<'a> AstNode<'a> for BindPat<'a> { | |||
219 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 236 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
220 | } | 237 | } |
221 | 238 | ||
239 | impl<R: TreeRoot<RaTypes>> BindPatNode<R> { | ||
240 | pub fn borrowed(&self) -> BindPat { | ||
241 | BindPatNode { syntax: self.syntax.borrowed() } | ||
242 | } | ||
243 | pub fn owned(&self) -> BindPatNode { | ||
244 | BindPatNode { syntax: self.syntax.owned() } | ||
245 | } | ||
246 | } | ||
247 | |||
248 | |||
222 | impl<'a> ast::NameOwner<'a> for BindPat<'a> {} | 249 | impl<'a> ast::NameOwner<'a> for BindPat<'a> {} |
223 | impl<'a> BindPat<'a> {} | 250 | impl<'a> BindPat<'a> {} |
224 | 251 | ||
225 | // Block | 252 | // Block |
226 | 253 | #[derive(Debug, Clone, Copy,)] | |
227 | #[derive(Debug, Clone)] | 254 | pub struct BlockNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
228 | pub struct BlockNode(SyntaxNode); | 255 | pub(crate) syntax: SyntaxNode<R>, |
229 | |||
230 | impl BlockNode { | ||
231 | pub fn ast(&self) -> Block { | ||
232 | Block::cast(self.0.borrowed()).unwrap() | ||
233 | } | ||
234 | } | 256 | } |
257 | pub type Block<'a> = BlockNode<RefRoot<'a>>; | ||
235 | 258 | ||
236 | impl<'a> From<Block<'a>> for BlockNode { | 259 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<BlockNode<R1>> for BlockNode<R2> { |
237 | fn from(ast: Block<'a>) -> BlockNode { | 260 | fn eq(&self, other: &BlockNode<R1>) -> bool { self.syntax == other.syntax } |
238 | let syntax = ast.syntax().owned(); | ||
239 | BlockNode(syntax) | ||
240 | } | ||
241 | } | 261 | } |
242 | #[derive(Debug, Clone, Copy)] | 262 | impl<R: TreeRoot<RaTypes>> Eq for BlockNode<R> {} |
243 | pub struct Block<'a> { | 263 | impl<R: TreeRoot<RaTypes>> Hash for BlockNode<R> { |
244 | syntax: SyntaxNodeRef<'a>, | 264 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
245 | } | 265 | } |
246 | 266 | ||
247 | impl<'a> AstNode<'a> for Block<'a> { | 267 | impl<'a> AstNode<'a> for Block<'a> { |
@@ -254,6 +274,16 @@ impl<'a> AstNode<'a> for Block<'a> { | |||
254 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 274 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
255 | } | 275 | } |
256 | 276 | ||
277 | impl<R: TreeRoot<RaTypes>> BlockNode<R> { | ||
278 | pub fn borrowed(&self) -> Block { | ||
279 | BlockNode { syntax: self.syntax.borrowed() } | ||
280 | } | ||
281 | pub fn owned(&self) -> BlockNode { | ||
282 | BlockNode { syntax: self.syntax.owned() } | ||
283 | } | ||
284 | } | ||
285 | |||
286 | |||
257 | impl<'a> Block<'a> { | 287 | impl<'a> Block<'a> { |
258 | pub fn statements(self) -> impl Iterator<Item = Stmt<'a>> + 'a { | 288 | pub fn statements(self) -> impl Iterator<Item = Stmt<'a>> + 'a { |
259 | super::children(self) | 289 | super::children(self) |
@@ -265,25 +295,18 @@ impl<'a> Block<'a> { | |||
265 | } | 295 | } |
266 | 296 | ||
267 | // BlockExpr | 297 | // BlockExpr |
268 | 298 | #[derive(Debug, Clone, Copy,)] | |
269 | #[derive(Debug, Clone)] | 299 | pub struct BlockExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
270 | pub struct BlockExprNode(SyntaxNode); | 300 | pub(crate) syntax: SyntaxNode<R>, |
271 | |||
272 | impl BlockExprNode { | ||
273 | pub fn ast(&self) -> BlockExpr { | ||
274 | BlockExpr::cast(self.0.borrowed()).unwrap() | ||
275 | } | ||
276 | } | 301 | } |
302 | pub type BlockExpr<'a> = BlockExprNode<RefRoot<'a>>; | ||
277 | 303 | ||
278 | impl<'a> From<BlockExpr<'a>> for BlockExprNode { | 304 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<BlockExprNode<R1>> for BlockExprNode<R2> { |
279 | fn from(ast: BlockExpr<'a>) -> BlockExprNode { | 305 | fn eq(&self, other: &BlockExprNode<R1>) -> bool { self.syntax == other.syntax } |
280 | let syntax = ast.syntax().owned(); | ||
281 | BlockExprNode(syntax) | ||
282 | } | ||
283 | } | 306 | } |
284 | #[derive(Debug, Clone, Copy)] | 307 | impl<R: TreeRoot<RaTypes>> Eq for BlockExprNode<R> {} |
285 | pub struct BlockExpr<'a> { | 308 | impl<R: TreeRoot<RaTypes>> Hash for BlockExprNode<R> { |
286 | syntax: SyntaxNodeRef<'a>, | 309 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
287 | } | 310 | } |
288 | 311 | ||
289 | impl<'a> AstNode<'a> for BlockExpr<'a> { | 312 | impl<'a> AstNode<'a> for BlockExpr<'a> { |
@@ -296,6 +319,16 @@ impl<'a> AstNode<'a> for BlockExpr<'a> { | |||
296 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 319 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
297 | } | 320 | } |
298 | 321 | ||
322 | impl<R: TreeRoot<RaTypes>> BlockExprNode<R> { | ||
323 | pub fn borrowed(&self) -> BlockExpr { | ||
324 | BlockExprNode { syntax: self.syntax.borrowed() } | ||
325 | } | ||
326 | pub fn owned(&self) -> BlockExprNode { | ||
327 | BlockExprNode { syntax: self.syntax.owned() } | ||
328 | } | ||
329 | } | ||
330 | |||
331 | |||
299 | impl<'a> BlockExpr<'a> { | 332 | impl<'a> BlockExpr<'a> { |
300 | pub fn block(self) -> Option<Block<'a>> { | 333 | pub fn block(self) -> Option<Block<'a>> { |
301 | super::child_opt(self) | 334 | super::child_opt(self) |
@@ -303,59 +336,129 @@ impl<'a> BlockExpr<'a> { | |||
303 | } | 336 | } |
304 | 337 | ||
305 | // BreakExpr | 338 | // BreakExpr |
339 | #[derive(Debug, Clone, Copy,)] | ||
340 | pub struct BreakExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | ||
341 | pub(crate) syntax: SyntaxNode<R>, | ||
342 | } | ||
343 | pub type BreakExpr<'a> = BreakExprNode<RefRoot<'a>>; | ||
306 | 344 | ||
307 | #[derive(Debug, Clone)] | 345 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<BreakExprNode<R1>> for BreakExprNode<R2> { |
308 | pub struct BreakExprNode(SyntaxNode); | 346 | fn eq(&self, other: &BreakExprNode<R1>) -> bool { self.syntax == other.syntax } |
347 | } | ||
348 | impl<R: TreeRoot<RaTypes>> Eq for BreakExprNode<R> {} | ||
349 | impl<R: TreeRoot<RaTypes>> Hash for BreakExprNode<R> { | ||
350 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
351 | } | ||
309 | 352 | ||
310 | impl BreakExprNode { | 353 | impl<'a> AstNode<'a> for BreakExpr<'a> { |
311 | pub fn ast(&self) -> BreakExpr { | 354 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
312 | BreakExpr::cast(self.0.borrowed()).unwrap() | 355 | match syntax.kind() { |
356 | BREAK_EXPR => Some(BreakExpr { syntax }), | ||
357 | _ => None, | ||
358 | } | ||
313 | } | 359 | } |
360 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | ||
314 | } | 361 | } |
315 | 362 | ||
316 | impl<'a> From<BreakExpr<'a>> for BreakExprNode { | 363 | impl<R: TreeRoot<RaTypes>> BreakExprNode<R> { |
317 | fn from(ast: BreakExpr<'a>) -> BreakExprNode { | 364 | pub fn borrowed(&self) -> BreakExpr { |
318 | let syntax = ast.syntax().owned(); | 365 | BreakExprNode { syntax: self.syntax.borrowed() } |
319 | BreakExprNode(syntax) | 366 | } |
367 | pub fn owned(&self) -> BreakExprNode { | ||
368 | BreakExprNode { syntax: self.syntax.owned() } | ||
320 | } | 369 | } |
321 | } | 370 | } |
322 | #[derive(Debug, Clone, Copy)] | 371 | |
323 | pub struct BreakExpr<'a> { | 372 | |
324 | syntax: SyntaxNodeRef<'a>, | 373 | impl<'a> BreakExpr<'a> {} |
374 | |||
375 | // Byte | ||
376 | #[derive(Debug, Clone, Copy,)] | ||
377 | pub struct ByteNode<R: TreeRoot<RaTypes> = OwnedRoot> { | ||
378 | pub(crate) syntax: SyntaxNode<R>, | ||
325 | } | 379 | } |
380 | pub type Byte<'a> = ByteNode<RefRoot<'a>>; | ||
326 | 381 | ||
327 | impl<'a> AstNode<'a> for BreakExpr<'a> { | 382 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ByteNode<R1>> for ByteNode<R2> { |
383 | fn eq(&self, other: &ByteNode<R1>) -> bool { self.syntax == other.syntax } | ||
384 | } | ||
385 | impl<R: TreeRoot<RaTypes>> Eq for ByteNode<R> {} | ||
386 | impl<R: TreeRoot<RaTypes>> Hash for ByteNode<R> { | ||
387 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
388 | } | ||
389 | |||
390 | impl<'a> AstNode<'a> for Byte<'a> { | ||
328 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 391 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
329 | match syntax.kind() { | 392 | match syntax.kind() { |
330 | BREAK_EXPR => Some(BreakExpr { syntax }), | 393 | BYTE => Some(Byte { syntax }), |
331 | _ => None, | 394 | _ => None, |
332 | } | 395 | } |
333 | } | 396 | } |
334 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 397 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
335 | } | 398 | } |
336 | 399 | ||
337 | impl<'a> BreakExpr<'a> {} | 400 | impl<R: TreeRoot<RaTypes>> ByteNode<R> { |
401 | pub fn borrowed(&self) -> Byte { | ||
402 | ByteNode { syntax: self.syntax.borrowed() } | ||
403 | } | ||
404 | pub fn owned(&self) -> ByteNode { | ||
405 | ByteNode { syntax: self.syntax.owned() } | ||
406 | } | ||
407 | } | ||
338 | 408 | ||
339 | // CallExpr | ||
340 | 409 | ||
341 | #[derive(Debug, Clone)] | 410 | impl<'a> Byte<'a> {} |
342 | pub struct CallExprNode(SyntaxNode); | 411 | |
412 | // ByteString | ||
413 | #[derive(Debug, Clone, Copy,)] | ||
414 | pub struct ByteStringNode<R: TreeRoot<RaTypes> = OwnedRoot> { | ||
415 | pub(crate) syntax: SyntaxNode<R>, | ||
416 | } | ||
417 | pub type ByteString<'a> = ByteStringNode<RefRoot<'a>>; | ||
343 | 418 | ||
344 | impl CallExprNode { | 419 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ByteStringNode<R1>> for ByteStringNode<R2> { |
345 | pub fn ast(&self) -> CallExpr { | 420 | fn eq(&self, other: &ByteStringNode<R1>) -> bool { self.syntax == other.syntax } |
346 | CallExpr::cast(self.0.borrowed()).unwrap() | 421 | } |
422 | impl<R: TreeRoot<RaTypes>> Eq for ByteStringNode<R> {} | ||
423 | impl<R: TreeRoot<RaTypes>> Hash for ByteStringNode<R> { | ||
424 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
425 | } | ||
426 | |||
427 | impl<'a> AstNode<'a> for ByteString<'a> { | ||
428 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | ||
429 | match syntax.kind() { | ||
430 | BYTE_STRING => Some(ByteString { syntax }), | ||
431 | _ => None, | ||
432 | } | ||
347 | } | 433 | } |
434 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | ||
348 | } | 435 | } |
349 | 436 | ||
350 | impl<'a> From<CallExpr<'a>> for CallExprNode { | 437 | impl<R: TreeRoot<RaTypes>> ByteStringNode<R> { |
351 | fn from(ast: CallExpr<'a>) -> CallExprNode { | 438 | pub fn borrowed(&self) -> ByteString { |
352 | let syntax = ast.syntax().owned(); | 439 | ByteStringNode { syntax: self.syntax.borrowed() } |
353 | CallExprNode(syntax) | ||
354 | } | 440 | } |
441 | pub fn owned(&self) -> ByteStringNode { | ||
442 | ByteStringNode { syntax: self.syntax.owned() } | ||
443 | } | ||
444 | } | ||
445 | |||
446 | |||
447 | impl<'a> ByteString<'a> {} | ||
448 | |||
449 | // CallExpr | ||
450 | #[derive(Debug, Clone, Copy,)] | ||
451 | pub struct CallExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | ||
452 | pub(crate) syntax: SyntaxNode<R>, | ||
355 | } | 453 | } |
356 | #[derive(Debug, Clone, Copy)] | 454 | pub type CallExpr<'a> = CallExprNode<RefRoot<'a>>; |
357 | pub struct CallExpr<'a> { | 455 | |
358 | syntax: SyntaxNodeRef<'a>, | 456 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<CallExprNode<R1>> for CallExprNode<R2> { |
457 | fn eq(&self, other: &CallExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
458 | } | ||
459 | impl<R: TreeRoot<RaTypes>> Eq for CallExprNode<R> {} | ||
460 | impl<R: TreeRoot<RaTypes>> Hash for CallExprNode<R> { | ||
461 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
359 | } | 462 | } |
360 | 463 | ||
361 | impl<'a> AstNode<'a> for CallExpr<'a> { | 464 | impl<'a> AstNode<'a> for CallExpr<'a> { |
@@ -368,6 +471,16 @@ impl<'a> AstNode<'a> for CallExpr<'a> { | |||
368 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 471 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
369 | } | 472 | } |
370 | 473 | ||
474 | impl<R: TreeRoot<RaTypes>> CallExprNode<R> { | ||
475 | pub fn borrowed(&self) -> CallExpr { | ||
476 | CallExprNode { syntax: self.syntax.borrowed() } | ||
477 | } | ||
478 | pub fn owned(&self) -> CallExprNode { | ||
479 | CallExprNode { syntax: self.syntax.owned() } | ||
480 | } | ||
481 | } | ||
482 | |||
483 | |||
371 | impl<'a> ast::ArgListOwner<'a> for CallExpr<'a> {} | 484 | impl<'a> ast::ArgListOwner<'a> for CallExpr<'a> {} |
372 | impl<'a> CallExpr<'a> { | 485 | impl<'a> CallExpr<'a> { |
373 | pub fn expr(self) -> Option<Expr<'a>> { | 486 | pub fn expr(self) -> Option<Expr<'a>> { |
@@ -376,25 +489,18 @@ impl<'a> CallExpr<'a> { | |||
376 | } | 489 | } |
377 | 490 | ||
378 | // CastExpr | 491 | // CastExpr |
379 | 492 | #[derive(Debug, Clone, Copy,)] | |
380 | #[derive(Debug, Clone)] | 493 | pub struct CastExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
381 | pub struct CastExprNode(SyntaxNode); | 494 | pub(crate) syntax: SyntaxNode<R>, |
382 | |||
383 | impl CastExprNode { | ||
384 | pub fn ast(&self) -> CastExpr { | ||
385 | CastExpr::cast(self.0.borrowed()).unwrap() | ||
386 | } | ||
387 | } | 495 | } |
496 | pub type CastExpr<'a> = CastExprNode<RefRoot<'a>>; | ||
388 | 497 | ||
389 | impl<'a> From<CastExpr<'a>> for CastExprNode { | 498 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<CastExprNode<R1>> for CastExprNode<R2> { |
390 | fn from(ast: CastExpr<'a>) -> CastExprNode { | 499 | fn eq(&self, other: &CastExprNode<R1>) -> bool { self.syntax == other.syntax } |
391 | let syntax = ast.syntax().owned(); | ||
392 | CastExprNode(syntax) | ||
393 | } | ||
394 | } | 500 | } |
395 | #[derive(Debug, Clone, Copy)] | 501 | impl<R: TreeRoot<RaTypes>> Eq for CastExprNode<R> {} |
396 | pub struct CastExpr<'a> { | 502 | impl<R: TreeRoot<RaTypes>> Hash for CastExprNode<R> { |
397 | syntax: SyntaxNodeRef<'a>, | 503 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
398 | } | 504 | } |
399 | 505 | ||
400 | impl<'a> AstNode<'a> for CastExpr<'a> { | 506 | impl<'a> AstNode<'a> for CastExpr<'a> { |
@@ -407,28 +513,31 @@ impl<'a> AstNode<'a> for CastExpr<'a> { | |||
407 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 513 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
408 | } | 514 | } |
409 | 515 | ||
410 | impl<'a> CastExpr<'a> {} | 516 | impl<R: TreeRoot<RaTypes>> CastExprNode<R> { |
517 | pub fn borrowed(&self) -> CastExpr { | ||
518 | CastExprNode { syntax: self.syntax.borrowed() } | ||
519 | } | ||
520 | pub fn owned(&self) -> CastExprNode { | ||
521 | CastExprNode { syntax: self.syntax.owned() } | ||
522 | } | ||
523 | } | ||
411 | 524 | ||
412 | // Char | ||
413 | 525 | ||
414 | #[derive(Debug, Clone)] | 526 | impl<'a> CastExpr<'a> {} |
415 | pub struct CharNode(SyntaxNode); | ||
416 | 527 | ||
417 | impl CharNode { | 528 | // Char |
418 | pub fn ast(&self) -> Char { | 529 | #[derive(Debug, Clone, Copy,)] |
419 | Char::cast(self.0.borrowed()).unwrap() | 530 | pub struct CharNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
420 | } | 531 | pub(crate) syntax: SyntaxNode<R>, |
421 | } | 532 | } |
533 | pub type Char<'a> = CharNode<RefRoot<'a>>; | ||
422 | 534 | ||
423 | impl<'a> From<Char<'a>> for CharNode { | 535 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<CharNode<R1>> for CharNode<R2> { |
424 | fn from(ast: Char<'a>) -> CharNode { | 536 | fn eq(&self, other: &CharNode<R1>) -> bool { self.syntax == other.syntax } |
425 | let syntax = ast.syntax().owned(); | ||
426 | CharNode(syntax) | ||
427 | } | ||
428 | } | 537 | } |
429 | #[derive(Debug, Clone, Copy)] | 538 | impl<R: TreeRoot<RaTypes>> Eq for CharNode<R> {} |
430 | pub struct Char<'a> { | 539 | impl<R: TreeRoot<RaTypes>> Hash for CharNode<R> { |
431 | syntax: SyntaxNodeRef<'a>, | 540 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
432 | } | 541 | } |
433 | 542 | ||
434 | impl<'a> AstNode<'a> for Char<'a> { | 543 | impl<'a> AstNode<'a> for Char<'a> { |
@@ -441,28 +550,31 @@ impl<'a> AstNode<'a> for Char<'a> { | |||
441 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 550 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
442 | } | 551 | } |
443 | 552 | ||
444 | impl<'a> Char<'a> {} | 553 | impl<R: TreeRoot<RaTypes>> CharNode<R> { |
554 | pub fn borrowed(&self) -> Char { | ||
555 | CharNode { syntax: self.syntax.borrowed() } | ||
556 | } | ||
557 | pub fn owned(&self) -> CharNode { | ||
558 | CharNode { syntax: self.syntax.owned() } | ||
559 | } | ||
560 | } | ||
445 | 561 | ||
446 | // Comment | ||
447 | 562 | ||
448 | #[derive(Debug, Clone)] | 563 | impl<'a> Char<'a> {} |
449 | pub struct CommentNode(SyntaxNode); | ||
450 | 564 | ||
451 | impl CommentNode { | 565 | // Comment |
452 | pub fn ast(&self) -> Comment { | 566 | #[derive(Debug, Clone, Copy,)] |
453 | Comment::cast(self.0.borrowed()).unwrap() | 567 | pub struct CommentNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
454 | } | 568 | pub(crate) syntax: SyntaxNode<R>, |
455 | } | 569 | } |
570 | pub type Comment<'a> = CommentNode<RefRoot<'a>>; | ||
456 | 571 | ||
457 | impl<'a> From<Comment<'a>> for CommentNode { | 572 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<CommentNode<R1>> for CommentNode<R2> { |
458 | fn from(ast: Comment<'a>) -> CommentNode { | 573 | fn eq(&self, other: &CommentNode<R1>) -> bool { self.syntax == other.syntax } |
459 | let syntax = ast.syntax().owned(); | ||
460 | CommentNode(syntax) | ||
461 | } | ||
462 | } | 574 | } |
463 | #[derive(Debug, Clone, Copy)] | 575 | impl<R: TreeRoot<RaTypes>> Eq for CommentNode<R> {} |
464 | pub struct Comment<'a> { | 576 | impl<R: TreeRoot<RaTypes>> Hash for CommentNode<R> { |
465 | syntax: SyntaxNodeRef<'a>, | 577 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
466 | } | 578 | } |
467 | 579 | ||
468 | impl<'a> AstNode<'a> for Comment<'a> { | 580 | impl<'a> AstNode<'a> for Comment<'a> { |
@@ -475,28 +587,31 @@ impl<'a> AstNode<'a> for Comment<'a> { | |||
475 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 587 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
476 | } | 588 | } |
477 | 589 | ||
478 | impl<'a> Comment<'a> {} | 590 | impl<R: TreeRoot<RaTypes>> CommentNode<R> { |
591 | pub fn borrowed(&self) -> Comment { | ||
592 | CommentNode { syntax: self.syntax.borrowed() } | ||
593 | } | ||
594 | pub fn owned(&self) -> CommentNode { | ||
595 | CommentNode { syntax: self.syntax.owned() } | ||
596 | } | ||
597 | } | ||
479 | 598 | ||
480 | // Condition | ||
481 | 599 | ||
482 | #[derive(Debug, Clone)] | 600 | impl<'a> Comment<'a> {} |
483 | pub struct ConditionNode(SyntaxNode); | ||
484 | 601 | ||
485 | impl ConditionNode { | 602 | // Condition |
486 | pub fn ast(&self) -> Condition { | 603 | #[derive(Debug, Clone, Copy,)] |
487 | Condition::cast(self.0.borrowed()).unwrap() | 604 | pub struct ConditionNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
488 | } | 605 | pub(crate) syntax: SyntaxNode<R>, |
489 | } | 606 | } |
607 | pub type Condition<'a> = ConditionNode<RefRoot<'a>>; | ||
490 | 608 | ||
491 | impl<'a> From<Condition<'a>> for ConditionNode { | 609 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ConditionNode<R1>> for ConditionNode<R2> { |
492 | fn from(ast: Condition<'a>) -> ConditionNode { | 610 | fn eq(&self, other: &ConditionNode<R1>) -> bool { self.syntax == other.syntax } |
493 | let syntax = ast.syntax().owned(); | ||
494 | ConditionNode(syntax) | ||
495 | } | ||
496 | } | 611 | } |
497 | #[derive(Debug, Clone, Copy)] | 612 | impl<R: TreeRoot<RaTypes>> Eq for ConditionNode<R> {} |
498 | pub struct Condition<'a> { | 613 | impl<R: TreeRoot<RaTypes>> Hash for ConditionNode<R> { |
499 | syntax: SyntaxNodeRef<'a>, | 614 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
500 | } | 615 | } |
501 | 616 | ||
502 | impl<'a> AstNode<'a> for Condition<'a> { | 617 | impl<'a> AstNode<'a> for Condition<'a> { |
@@ -509,6 +624,16 @@ impl<'a> AstNode<'a> for Condition<'a> { | |||
509 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 624 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
510 | } | 625 | } |
511 | 626 | ||
627 | impl<R: TreeRoot<RaTypes>> ConditionNode<R> { | ||
628 | pub fn borrowed(&self) -> Condition { | ||
629 | ConditionNode { syntax: self.syntax.borrowed() } | ||
630 | } | ||
631 | pub fn owned(&self) -> ConditionNode { | ||
632 | ConditionNode { syntax: self.syntax.owned() } | ||
633 | } | ||
634 | } | ||
635 | |||
636 | |||
512 | impl<'a> Condition<'a> { | 637 | impl<'a> Condition<'a> { |
513 | pub fn pat(self) -> Option<Pat<'a>> { | 638 | pub fn pat(self) -> Option<Pat<'a>> { |
514 | super::child_opt(self) | 639 | super::child_opt(self) |
@@ -520,25 +645,18 @@ impl<'a> Condition<'a> { | |||
520 | } | 645 | } |
521 | 646 | ||
522 | // ConstDef | 647 | // ConstDef |
523 | 648 | #[derive(Debug, Clone, Copy,)] | |
524 | #[derive(Debug, Clone)] | 649 | pub struct ConstDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
525 | pub struct ConstDefNode(SyntaxNode); | 650 | pub(crate) syntax: SyntaxNode<R>, |
526 | |||
527 | impl ConstDefNode { | ||
528 | pub fn ast(&self) -> ConstDef { | ||
529 | ConstDef::cast(self.0.borrowed()).unwrap() | ||
530 | } | ||
531 | } | 651 | } |
652 | pub type ConstDef<'a> = ConstDefNode<RefRoot<'a>>; | ||
532 | 653 | ||
533 | impl<'a> From<ConstDef<'a>> for ConstDefNode { | 654 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ConstDefNode<R1>> for ConstDefNode<R2> { |
534 | fn from(ast: ConstDef<'a>) -> ConstDefNode { | 655 | fn eq(&self, other: &ConstDefNode<R1>) -> bool { self.syntax == other.syntax } |
535 | let syntax = ast.syntax().owned(); | ||
536 | ConstDefNode(syntax) | ||
537 | } | ||
538 | } | 656 | } |
539 | #[derive(Debug, Clone, Copy)] | 657 | impl<R: TreeRoot<RaTypes>> Eq for ConstDefNode<R> {} |
540 | pub struct ConstDef<'a> { | 658 | impl<R: TreeRoot<RaTypes>> Hash for ConstDefNode<R> { |
541 | syntax: SyntaxNodeRef<'a>, | 659 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
542 | } | 660 | } |
543 | 661 | ||
544 | impl<'a> AstNode<'a> for ConstDef<'a> { | 662 | impl<'a> AstNode<'a> for ConstDef<'a> { |
@@ -551,31 +669,35 @@ impl<'a> AstNode<'a> for ConstDef<'a> { | |||
551 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 669 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
552 | } | 670 | } |
553 | 671 | ||
672 | impl<R: TreeRoot<RaTypes>> ConstDefNode<R> { | ||
673 | pub fn borrowed(&self) -> ConstDef { | ||
674 | ConstDefNode { syntax: self.syntax.borrowed() } | ||
675 | } | ||
676 | pub fn owned(&self) -> ConstDefNode { | ||
677 | ConstDefNode { syntax: self.syntax.owned() } | ||
678 | } | ||
679 | } | ||
680 | |||
681 | |||
554 | impl<'a> ast::NameOwner<'a> for ConstDef<'a> {} | 682 | impl<'a> ast::NameOwner<'a> for ConstDef<'a> {} |
555 | impl<'a> ast::TypeParamsOwner<'a> for ConstDef<'a> {} | 683 | impl<'a> ast::TypeParamsOwner<'a> for ConstDef<'a> {} |
556 | impl<'a> ast::AttrsOwner<'a> for ConstDef<'a> {} | 684 | impl<'a> ast::AttrsOwner<'a> for ConstDef<'a> {} |
685 | impl<'a> ast::DocCommentsOwner<'a> for ConstDef<'a> {} | ||
557 | impl<'a> ConstDef<'a> {} | 686 | impl<'a> ConstDef<'a> {} |
558 | 687 | ||
559 | // ContinueExpr | 688 | // ContinueExpr |
560 | 689 | #[derive(Debug, Clone, Copy,)] | |
561 | #[derive(Debug, Clone)] | 690 | pub struct ContinueExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
562 | pub struct ContinueExprNode(SyntaxNode); | 691 | pub(crate) syntax: SyntaxNode<R>, |
563 | |||
564 | impl ContinueExprNode { | ||
565 | pub fn ast(&self) -> ContinueExpr { | ||
566 | ContinueExpr::cast(self.0.borrowed()).unwrap() | ||
567 | } | ||
568 | } | 692 | } |
693 | pub type ContinueExpr<'a> = ContinueExprNode<RefRoot<'a>>; | ||
569 | 694 | ||
570 | impl<'a> From<ContinueExpr<'a>> for ContinueExprNode { | 695 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ContinueExprNode<R1>> for ContinueExprNode<R2> { |
571 | fn from(ast: ContinueExpr<'a>) -> ContinueExprNode { | 696 | fn eq(&self, other: &ContinueExprNode<R1>) -> bool { self.syntax == other.syntax } |
572 | let syntax = ast.syntax().owned(); | ||
573 | ContinueExprNode(syntax) | ||
574 | } | ||
575 | } | 697 | } |
576 | #[derive(Debug, Clone, Copy)] | 698 | impl<R: TreeRoot<RaTypes>> Eq for ContinueExprNode<R> {} |
577 | pub struct ContinueExpr<'a> { | 699 | impl<R: TreeRoot<RaTypes>> Hash for ContinueExprNode<R> { |
578 | syntax: SyntaxNodeRef<'a>, | 700 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
579 | } | 701 | } |
580 | 702 | ||
581 | impl<'a> AstNode<'a> for ContinueExpr<'a> { | 703 | impl<'a> AstNode<'a> for ContinueExpr<'a> { |
@@ -588,28 +710,31 @@ impl<'a> AstNode<'a> for ContinueExpr<'a> { | |||
588 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 710 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
589 | } | 711 | } |
590 | 712 | ||
591 | impl<'a> ContinueExpr<'a> {} | 713 | impl<R: TreeRoot<RaTypes>> ContinueExprNode<R> { |
714 | pub fn borrowed(&self) -> ContinueExpr { | ||
715 | ContinueExprNode { syntax: self.syntax.borrowed() } | ||
716 | } | ||
717 | pub fn owned(&self) -> ContinueExprNode { | ||
718 | ContinueExprNode { syntax: self.syntax.owned() } | ||
719 | } | ||
720 | } | ||
592 | 721 | ||
593 | // DynTraitType | ||
594 | 722 | ||
595 | #[derive(Debug, Clone)] | 723 | impl<'a> ContinueExpr<'a> {} |
596 | pub struct DynTraitTypeNode(SyntaxNode); | ||
597 | 724 | ||
598 | impl DynTraitTypeNode { | 725 | // DynTraitType |
599 | pub fn ast(&self) -> DynTraitType { | 726 | #[derive(Debug, Clone, Copy,)] |
600 | DynTraitType::cast(self.0.borrowed()).unwrap() | 727 | pub struct DynTraitTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
601 | } | 728 | pub(crate) syntax: SyntaxNode<R>, |
602 | } | 729 | } |
730 | pub type DynTraitType<'a> = DynTraitTypeNode<RefRoot<'a>>; | ||
603 | 731 | ||
604 | impl<'a> From<DynTraitType<'a>> for DynTraitTypeNode { | 732 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<DynTraitTypeNode<R1>> for DynTraitTypeNode<R2> { |
605 | fn from(ast: DynTraitType<'a>) -> DynTraitTypeNode { | 733 | fn eq(&self, other: &DynTraitTypeNode<R1>) -> bool { self.syntax == other.syntax } |
606 | let syntax = ast.syntax().owned(); | ||
607 | DynTraitTypeNode(syntax) | ||
608 | } | ||
609 | } | 734 | } |
610 | #[derive(Debug, Clone, Copy)] | 735 | impl<R: TreeRoot<RaTypes>> Eq for DynTraitTypeNode<R> {} |
611 | pub struct DynTraitType<'a> { | 736 | impl<R: TreeRoot<RaTypes>> Hash for DynTraitTypeNode<R> { |
612 | syntax: SyntaxNodeRef<'a>, | 737 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
613 | } | 738 | } |
614 | 739 | ||
615 | impl<'a> AstNode<'a> for DynTraitType<'a> { | 740 | impl<'a> AstNode<'a> for DynTraitType<'a> { |
@@ -622,28 +747,31 @@ impl<'a> AstNode<'a> for DynTraitType<'a> { | |||
622 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 747 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
623 | } | 748 | } |
624 | 749 | ||
625 | impl<'a> DynTraitType<'a> {} | 750 | impl<R: TreeRoot<RaTypes>> DynTraitTypeNode<R> { |
751 | pub fn borrowed(&self) -> DynTraitType { | ||
752 | DynTraitTypeNode { syntax: self.syntax.borrowed() } | ||
753 | } | ||
754 | pub fn owned(&self) -> DynTraitTypeNode { | ||
755 | DynTraitTypeNode { syntax: self.syntax.owned() } | ||
756 | } | ||
757 | } | ||
626 | 758 | ||
627 | // EnumDef | ||
628 | 759 | ||
629 | #[derive(Debug, Clone)] | 760 | impl<'a> DynTraitType<'a> {} |
630 | pub struct EnumDefNode(SyntaxNode); | ||
631 | 761 | ||
632 | impl EnumDefNode { | 762 | // EnumDef |
633 | pub fn ast(&self) -> EnumDef { | 763 | #[derive(Debug, Clone, Copy,)] |
634 | EnumDef::cast(self.0.borrowed()).unwrap() | 764 | pub struct EnumDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
635 | } | 765 | pub(crate) syntax: SyntaxNode<R>, |
636 | } | 766 | } |
767 | pub type EnumDef<'a> = EnumDefNode<RefRoot<'a>>; | ||
637 | 768 | ||
638 | impl<'a> From<EnumDef<'a>> for EnumDefNode { | 769 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<EnumDefNode<R1>> for EnumDefNode<R2> { |
639 | fn from(ast: EnumDef<'a>) -> EnumDefNode { | 770 | fn eq(&self, other: &EnumDefNode<R1>) -> bool { self.syntax == other.syntax } |
640 | let syntax = ast.syntax().owned(); | ||
641 | EnumDefNode(syntax) | ||
642 | } | ||
643 | } | 771 | } |
644 | #[derive(Debug, Clone, Copy)] | 772 | impl<R: TreeRoot<RaTypes>> Eq for EnumDefNode<R> {} |
645 | pub struct EnumDef<'a> { | 773 | impl<R: TreeRoot<RaTypes>> Hash for EnumDefNode<R> { |
646 | syntax: SyntaxNodeRef<'a>, | 774 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
647 | } | 775 | } |
648 | 776 | ||
649 | impl<'a> AstNode<'a> for EnumDef<'a> { | 777 | impl<'a> AstNode<'a> for EnumDef<'a> { |
@@ -656,29 +784,24 @@ impl<'a> AstNode<'a> for EnumDef<'a> { | |||
656 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 784 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
657 | } | 785 | } |
658 | 786 | ||
787 | impl<R: TreeRoot<RaTypes>> EnumDefNode<R> { | ||
788 | pub fn borrowed(&self) -> EnumDef { | ||
789 | EnumDefNode { syntax: self.syntax.borrowed() } | ||
790 | } | ||
791 | pub fn owned(&self) -> EnumDefNode { | ||
792 | EnumDefNode { syntax: self.syntax.owned() } | ||
793 | } | ||
794 | } | ||
795 | |||
796 | |||
659 | impl<'a> ast::NameOwner<'a> for EnumDef<'a> {} | 797 | impl<'a> ast::NameOwner<'a> for EnumDef<'a> {} |
660 | impl<'a> ast::TypeParamsOwner<'a> for EnumDef<'a> {} | 798 | impl<'a> ast::TypeParamsOwner<'a> for EnumDef<'a> {} |
661 | impl<'a> ast::AttrsOwner<'a> for EnumDef<'a> {} | 799 | impl<'a> ast::AttrsOwner<'a> for EnumDef<'a> {} |
800 | impl<'a> ast::DocCommentsOwner<'a> for EnumDef<'a> {} | ||
662 | impl<'a> EnumDef<'a> {} | 801 | impl<'a> EnumDef<'a> {} |
663 | 802 | ||
664 | // Expr | 803 | // Expr |
665 | 804 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | |
666 | #[derive(Debug, Clone)] | ||
667 | pub struct ExprNode(SyntaxNode); | ||
668 | |||
669 | impl ExprNode { | ||
670 | pub fn ast(&self) -> Expr { | ||
671 | Expr::cast(self.0.borrowed()).unwrap() | ||
672 | } | ||
673 | } | ||
674 | |||
675 | impl<'a> From<Expr<'a>> for ExprNode { | ||
676 | fn from(ast: Expr<'a>) -> ExprNode { | ||
677 | let syntax = ast.syntax().owned(); | ||
678 | ExprNode(syntax) | ||
679 | } | ||
680 | } | ||
681 | #[derive(Debug, Clone, Copy)] | ||
682 | pub enum Expr<'a> { | 805 | pub enum Expr<'a> { |
683 | TupleExpr(TupleExpr<'a>), | 806 | TupleExpr(TupleExpr<'a>), |
684 | ArrayExpr(ArrayExpr<'a>), | 807 | ArrayExpr(ArrayExpr<'a>), |
@@ -793,25 +916,18 @@ impl<'a> AstNode<'a> for Expr<'a> { | |||
793 | impl<'a> Expr<'a> {} | 916 | impl<'a> Expr<'a> {} |
794 | 917 | ||
795 | // ExprStmt | 918 | // ExprStmt |
796 | 919 | #[derive(Debug, Clone, Copy,)] | |
797 | #[derive(Debug, Clone)] | 920 | pub struct ExprStmtNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
798 | pub struct ExprStmtNode(SyntaxNode); | 921 | pub(crate) syntax: SyntaxNode<R>, |
799 | |||
800 | impl ExprStmtNode { | ||
801 | pub fn ast(&self) -> ExprStmt { | ||
802 | ExprStmt::cast(self.0.borrowed()).unwrap() | ||
803 | } | ||
804 | } | 922 | } |
923 | pub type ExprStmt<'a> = ExprStmtNode<RefRoot<'a>>; | ||
805 | 924 | ||
806 | impl<'a> From<ExprStmt<'a>> for ExprStmtNode { | 925 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ExprStmtNode<R1>> for ExprStmtNode<R2> { |
807 | fn from(ast: ExprStmt<'a>) -> ExprStmtNode { | 926 | fn eq(&self, other: &ExprStmtNode<R1>) -> bool { self.syntax == other.syntax } |
808 | let syntax = ast.syntax().owned(); | ||
809 | ExprStmtNode(syntax) | ||
810 | } | ||
811 | } | 927 | } |
812 | #[derive(Debug, Clone, Copy)] | 928 | impl<R: TreeRoot<RaTypes>> Eq for ExprStmtNode<R> {} |
813 | pub struct ExprStmt<'a> { | 929 | impl<R: TreeRoot<RaTypes>> Hash for ExprStmtNode<R> { |
814 | syntax: SyntaxNodeRef<'a>, | 930 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
815 | } | 931 | } |
816 | 932 | ||
817 | impl<'a> AstNode<'a> for ExprStmt<'a> { | 933 | impl<'a> AstNode<'a> for ExprStmt<'a> { |
@@ -824,6 +940,16 @@ impl<'a> AstNode<'a> for ExprStmt<'a> { | |||
824 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 940 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
825 | } | 941 | } |
826 | 942 | ||
943 | impl<R: TreeRoot<RaTypes>> ExprStmtNode<R> { | ||
944 | pub fn borrowed(&self) -> ExprStmt { | ||
945 | ExprStmtNode { syntax: self.syntax.borrowed() } | ||
946 | } | ||
947 | pub fn owned(&self) -> ExprStmtNode { | ||
948 | ExprStmtNode { syntax: self.syntax.owned() } | ||
949 | } | ||
950 | } | ||
951 | |||
952 | |||
827 | impl<'a> ExprStmt<'a> { | 953 | impl<'a> ExprStmt<'a> { |
828 | pub fn expr(self) -> Option<Expr<'a>> { | 954 | pub fn expr(self) -> Option<Expr<'a>> { |
829 | super::child_opt(self) | 955 | super::child_opt(self) |
@@ -831,25 +957,18 @@ impl<'a> ExprStmt<'a> { | |||
831 | } | 957 | } |
832 | 958 | ||
833 | // ExternCrateItem | 959 | // ExternCrateItem |
834 | 960 | #[derive(Debug, Clone, Copy,)] | |
835 | #[derive(Debug, Clone)] | 961 | pub struct ExternCrateItemNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
836 | pub struct ExternCrateItemNode(SyntaxNode); | 962 | pub(crate) syntax: SyntaxNode<R>, |
837 | |||
838 | impl ExternCrateItemNode { | ||
839 | pub fn ast(&self) -> ExternCrateItem { | ||
840 | ExternCrateItem::cast(self.0.borrowed()).unwrap() | ||
841 | } | ||
842 | } | 963 | } |
964 | pub type ExternCrateItem<'a> = ExternCrateItemNode<RefRoot<'a>>; | ||
843 | 965 | ||
844 | impl<'a> From<ExternCrateItem<'a>> for ExternCrateItemNode { | 966 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ExternCrateItemNode<R1>> for ExternCrateItemNode<R2> { |
845 | fn from(ast: ExternCrateItem<'a>) -> ExternCrateItemNode { | 967 | fn eq(&self, other: &ExternCrateItemNode<R1>) -> bool { self.syntax == other.syntax } |
846 | let syntax = ast.syntax().owned(); | ||
847 | ExternCrateItemNode(syntax) | ||
848 | } | ||
849 | } | 968 | } |
850 | #[derive(Debug, Clone, Copy)] | 969 | impl<R: TreeRoot<RaTypes>> Eq for ExternCrateItemNode<R> {} |
851 | pub struct ExternCrateItem<'a> { | 970 | impl<R: TreeRoot<RaTypes>> Hash for ExternCrateItemNode<R> { |
852 | syntax: SyntaxNodeRef<'a>, | 971 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
853 | } | 972 | } |
854 | 973 | ||
855 | impl<'a> AstNode<'a> for ExternCrateItem<'a> { | 974 | impl<'a> AstNode<'a> for ExternCrateItem<'a> { |
@@ -862,28 +981,31 @@ impl<'a> AstNode<'a> for ExternCrateItem<'a> { | |||
862 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 981 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
863 | } | 982 | } |
864 | 983 | ||
865 | impl<'a> ExternCrateItem<'a> {} | 984 | impl<R: TreeRoot<RaTypes>> ExternCrateItemNode<R> { |
985 | pub fn borrowed(&self) -> ExternCrateItem { | ||
986 | ExternCrateItemNode { syntax: self.syntax.borrowed() } | ||
987 | } | ||
988 | pub fn owned(&self) -> ExternCrateItemNode { | ||
989 | ExternCrateItemNode { syntax: self.syntax.owned() } | ||
990 | } | ||
991 | } | ||
866 | 992 | ||
867 | // FieldExpr | ||
868 | 993 | ||
869 | #[derive(Debug, Clone)] | 994 | impl<'a> ExternCrateItem<'a> {} |
870 | pub struct FieldExprNode(SyntaxNode); | ||
871 | 995 | ||
872 | impl FieldExprNode { | 996 | // FieldExpr |
873 | pub fn ast(&self) -> FieldExpr { | 997 | #[derive(Debug, Clone, Copy,)] |
874 | FieldExpr::cast(self.0.borrowed()).unwrap() | 998 | pub struct FieldExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
875 | } | 999 | pub(crate) syntax: SyntaxNode<R>, |
876 | } | 1000 | } |
1001 | pub type FieldExpr<'a> = FieldExprNode<RefRoot<'a>>; | ||
877 | 1002 | ||
878 | impl<'a> From<FieldExpr<'a>> for FieldExprNode { | 1003 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<FieldExprNode<R1>> for FieldExprNode<R2> { |
879 | fn from(ast: FieldExpr<'a>) -> FieldExprNode { | 1004 | fn eq(&self, other: &FieldExprNode<R1>) -> bool { self.syntax == other.syntax } |
880 | let syntax = ast.syntax().owned(); | ||
881 | FieldExprNode(syntax) | ||
882 | } | ||
883 | } | 1005 | } |
884 | #[derive(Debug, Clone, Copy)] | 1006 | impl<R: TreeRoot<RaTypes>> Eq for FieldExprNode<R> {} |
885 | pub struct FieldExpr<'a> { | 1007 | impl<R: TreeRoot<RaTypes>> Hash for FieldExprNode<R> { |
886 | syntax: SyntaxNodeRef<'a>, | 1008 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
887 | } | 1009 | } |
888 | 1010 | ||
889 | impl<'a> AstNode<'a> for FieldExpr<'a> { | 1011 | impl<'a> AstNode<'a> for FieldExpr<'a> { |
@@ -896,28 +1018,31 @@ impl<'a> AstNode<'a> for FieldExpr<'a> { | |||
896 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1018 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
897 | } | 1019 | } |
898 | 1020 | ||
899 | impl<'a> FieldExpr<'a> {} | 1021 | impl<R: TreeRoot<RaTypes>> FieldExprNode<R> { |
1022 | pub fn borrowed(&self) -> FieldExpr { | ||
1023 | FieldExprNode { syntax: self.syntax.borrowed() } | ||
1024 | } | ||
1025 | pub fn owned(&self) -> FieldExprNode { | ||
1026 | FieldExprNode { syntax: self.syntax.owned() } | ||
1027 | } | ||
1028 | } | ||
900 | 1029 | ||
901 | // FieldPatList | ||
902 | 1030 | ||
903 | #[derive(Debug, Clone)] | 1031 | impl<'a> FieldExpr<'a> {} |
904 | pub struct FieldPatListNode(SyntaxNode); | ||
905 | 1032 | ||
906 | impl FieldPatListNode { | 1033 | // FieldPatList |
907 | pub fn ast(&self) -> FieldPatList { | 1034 | #[derive(Debug, Clone, Copy,)] |
908 | FieldPatList::cast(self.0.borrowed()).unwrap() | 1035 | pub struct FieldPatListNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
909 | } | 1036 | pub(crate) syntax: SyntaxNode<R>, |
910 | } | 1037 | } |
1038 | pub type FieldPatList<'a> = FieldPatListNode<RefRoot<'a>>; | ||
911 | 1039 | ||
912 | impl<'a> From<FieldPatList<'a>> for FieldPatListNode { | 1040 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<FieldPatListNode<R1>> for FieldPatListNode<R2> { |
913 | fn from(ast: FieldPatList<'a>) -> FieldPatListNode { | 1041 | fn eq(&self, other: &FieldPatListNode<R1>) -> bool { self.syntax == other.syntax } |
914 | let syntax = ast.syntax().owned(); | ||
915 | FieldPatListNode(syntax) | ||
916 | } | ||
917 | } | 1042 | } |
918 | #[derive(Debug, Clone, Copy)] | 1043 | impl<R: TreeRoot<RaTypes>> Eq for FieldPatListNode<R> {} |
919 | pub struct FieldPatList<'a> { | 1044 | impl<R: TreeRoot<RaTypes>> Hash for FieldPatListNode<R> { |
920 | syntax: SyntaxNodeRef<'a>, | 1045 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
921 | } | 1046 | } |
922 | 1047 | ||
923 | impl<'a> AstNode<'a> for FieldPatList<'a> { | 1048 | impl<'a> AstNode<'a> for FieldPatList<'a> { |
@@ -930,28 +1055,31 @@ impl<'a> AstNode<'a> for FieldPatList<'a> { | |||
930 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1055 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
931 | } | 1056 | } |
932 | 1057 | ||
933 | impl<'a> FieldPatList<'a> {} | 1058 | impl<R: TreeRoot<RaTypes>> FieldPatListNode<R> { |
1059 | pub fn borrowed(&self) -> FieldPatList { | ||
1060 | FieldPatListNode { syntax: self.syntax.borrowed() } | ||
1061 | } | ||
1062 | pub fn owned(&self) -> FieldPatListNode { | ||
1063 | FieldPatListNode { syntax: self.syntax.owned() } | ||
1064 | } | ||
1065 | } | ||
934 | 1066 | ||
935 | // FnDef | ||
936 | 1067 | ||
937 | #[derive(Debug, Clone)] | 1068 | impl<'a> FieldPatList<'a> {} |
938 | pub struct FnDefNode(SyntaxNode); | ||
939 | 1069 | ||
940 | impl FnDefNode { | 1070 | // FnDef |
941 | pub fn ast(&self) -> FnDef { | 1071 | #[derive(Debug, Clone, Copy,)] |
942 | FnDef::cast(self.0.borrowed()).unwrap() | 1072 | pub struct FnDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
943 | } | 1073 | pub(crate) syntax: SyntaxNode<R>, |
944 | } | 1074 | } |
1075 | pub type FnDef<'a> = FnDefNode<RefRoot<'a>>; | ||
945 | 1076 | ||
946 | impl<'a> From<FnDef<'a>> for FnDefNode { | 1077 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<FnDefNode<R1>> for FnDefNode<R2> { |
947 | fn from(ast: FnDef<'a>) -> FnDefNode { | 1078 | fn eq(&self, other: &FnDefNode<R1>) -> bool { self.syntax == other.syntax } |
948 | let syntax = ast.syntax().owned(); | ||
949 | FnDefNode(syntax) | ||
950 | } | ||
951 | } | 1079 | } |
952 | #[derive(Debug, Clone, Copy)] | 1080 | impl<R: TreeRoot<RaTypes>> Eq for FnDefNode<R> {} |
953 | pub struct FnDef<'a> { | 1081 | impl<R: TreeRoot<RaTypes>> Hash for FnDefNode<R> { |
954 | syntax: SyntaxNodeRef<'a>, | 1082 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
955 | } | 1083 | } |
956 | 1084 | ||
957 | impl<'a> AstNode<'a> for FnDef<'a> { | 1085 | impl<'a> AstNode<'a> for FnDef<'a> { |
@@ -964,6 +1092,16 @@ impl<'a> AstNode<'a> for FnDef<'a> { | |||
964 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1092 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
965 | } | 1093 | } |
966 | 1094 | ||
1095 | impl<R: TreeRoot<RaTypes>> FnDefNode<R> { | ||
1096 | pub fn borrowed(&self) -> FnDef { | ||
1097 | FnDefNode { syntax: self.syntax.borrowed() } | ||
1098 | } | ||
1099 | pub fn owned(&self) -> FnDefNode { | ||
1100 | FnDefNode { syntax: self.syntax.owned() } | ||
1101 | } | ||
1102 | } | ||
1103 | |||
1104 | |||
967 | impl<'a> ast::NameOwner<'a> for FnDef<'a> {} | 1105 | impl<'a> ast::NameOwner<'a> for FnDef<'a> {} |
968 | impl<'a> ast::TypeParamsOwner<'a> for FnDef<'a> {} | 1106 | impl<'a> ast::TypeParamsOwner<'a> for FnDef<'a> {} |
969 | impl<'a> ast::AttrsOwner<'a> for FnDef<'a> {} | 1107 | impl<'a> ast::AttrsOwner<'a> for FnDef<'a> {} |
@@ -983,25 +1121,18 @@ impl<'a> FnDef<'a> { | |||
983 | } | 1121 | } |
984 | 1122 | ||
985 | // FnPointerType | 1123 | // FnPointerType |
986 | 1124 | #[derive(Debug, Clone, Copy,)] | |
987 | #[derive(Debug, Clone)] | 1125 | pub struct FnPointerTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
988 | pub struct FnPointerTypeNode(SyntaxNode); | 1126 | pub(crate) syntax: SyntaxNode<R>, |
989 | |||
990 | impl FnPointerTypeNode { | ||
991 | pub fn ast(&self) -> FnPointerType { | ||
992 | FnPointerType::cast(self.0.borrowed()).unwrap() | ||
993 | } | ||
994 | } | 1127 | } |
1128 | pub type FnPointerType<'a> = FnPointerTypeNode<RefRoot<'a>>; | ||
995 | 1129 | ||
996 | impl<'a> From<FnPointerType<'a>> for FnPointerTypeNode { | 1130 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<FnPointerTypeNode<R1>> for FnPointerTypeNode<R2> { |
997 | fn from(ast: FnPointerType<'a>) -> FnPointerTypeNode { | 1131 | fn eq(&self, other: &FnPointerTypeNode<R1>) -> bool { self.syntax == other.syntax } |
998 | let syntax = ast.syntax().owned(); | ||
999 | FnPointerTypeNode(syntax) | ||
1000 | } | ||
1001 | } | 1132 | } |
1002 | #[derive(Debug, Clone, Copy)] | 1133 | impl<R: TreeRoot<RaTypes>> Eq for FnPointerTypeNode<R> {} |
1003 | pub struct FnPointerType<'a> { | 1134 | impl<R: TreeRoot<RaTypes>> Hash for FnPointerTypeNode<R> { |
1004 | syntax: SyntaxNodeRef<'a>, | 1135 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
1005 | } | 1136 | } |
1006 | 1137 | ||
1007 | impl<'a> AstNode<'a> for FnPointerType<'a> { | 1138 | impl<'a> AstNode<'a> for FnPointerType<'a> { |
@@ -1014,28 +1145,31 @@ impl<'a> AstNode<'a> for FnPointerType<'a> { | |||
1014 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1145 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
1015 | } | 1146 | } |
1016 | 1147 | ||
1017 | impl<'a> FnPointerType<'a> {} | 1148 | impl<R: TreeRoot<RaTypes>> FnPointerTypeNode<R> { |
1149 | pub fn borrowed(&self) -> FnPointerType { | ||
1150 | FnPointerTypeNode { syntax: self.syntax.borrowed() } | ||
1151 | } | ||
1152 | pub fn owned(&self) -> FnPointerTypeNode { | ||
1153 | FnPointerTypeNode { syntax: self.syntax.owned() } | ||
1154 | } | ||
1155 | } | ||
1018 | 1156 | ||
1019 | // ForExpr | ||
1020 | 1157 | ||
1021 | #[derive(Debug, Clone)] | 1158 | impl<'a> FnPointerType<'a> {} |
1022 | pub struct ForExprNode(SyntaxNode); | ||
1023 | 1159 | ||
1024 | impl ForExprNode { | 1160 | // ForExpr |
1025 | pub fn ast(&self) -> ForExpr { | 1161 | #[derive(Debug, Clone, Copy,)] |
1026 | ForExpr::cast(self.0.borrowed()).unwrap() | 1162 | pub struct ForExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1027 | } | 1163 | pub(crate) syntax: SyntaxNode<R>, |
1028 | } | 1164 | } |
1165 | pub type ForExpr<'a> = ForExprNode<RefRoot<'a>>; | ||
1029 | 1166 | ||
1030 | impl<'a> From<ForExpr<'a>> for ForExprNode { | 1167 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ForExprNode<R1>> for ForExprNode<R2> { |
1031 | fn from(ast: ForExpr<'a>) -> ForExprNode { | 1168 | fn eq(&self, other: &ForExprNode<R1>) -> bool { self.syntax == other.syntax } |
1032 | let syntax = ast.syntax().owned(); | ||
1033 | ForExprNode(syntax) | ||
1034 | } | ||
1035 | } | 1169 | } |
1036 | #[derive(Debug, Clone, Copy)] | 1170 | impl<R: TreeRoot<RaTypes>> Eq for ForExprNode<R> {} |
1037 | pub struct ForExpr<'a> { | 1171 | impl<R: TreeRoot<RaTypes>> Hash for ForExprNode<R> { |
1038 | syntax: SyntaxNodeRef<'a>, | 1172 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
1039 | } | 1173 | } |
1040 | 1174 | ||
1041 | impl<'a> AstNode<'a> for ForExpr<'a> { | 1175 | impl<'a> AstNode<'a> for ForExpr<'a> { |
@@ -1048,6 +1182,16 @@ impl<'a> AstNode<'a> for ForExpr<'a> { | |||
1048 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1182 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
1049 | } | 1183 | } |
1050 | 1184 | ||
1185 | impl<R: TreeRoot<RaTypes>> ForExprNode<R> { | ||
1186 | pub fn borrowed(&self) -> ForExpr { | ||
1187 | ForExprNode { syntax: self.syntax.borrowed() } | ||
1188 | } | ||
1189 | pub fn owned(&self) -> ForExprNode { | ||
1190 | ForExprNode { syntax: self.syntax.owned() } | ||
1191 | } | ||
1192 | } | ||
1193 | |||
1194 | |||
1051 | impl<'a> ast::LoopBodyOwner<'a> for ForExpr<'a> {} | 1195 | impl<'a> ast::LoopBodyOwner<'a> for ForExpr<'a> {} |
1052 | impl<'a> ForExpr<'a> { | 1196 | impl<'a> ForExpr<'a> { |
1053 | pub fn pat(self) -> Option<Pat<'a>> { | 1197 | pub fn pat(self) -> Option<Pat<'a>> { |
@@ -1060,25 +1204,18 @@ impl<'a> ForExpr<'a> { | |||
1060 | } | 1204 | } |
1061 | 1205 | ||
1062 | // ForType | 1206 | // ForType |
1063 | 1207 | #[derive(Debug, Clone, Copy,)] | |
1064 | #[derive(Debug, Clone)] | 1208 | pub struct ForTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1065 | pub struct ForTypeNode(SyntaxNode); | 1209 | pub(crate) syntax: SyntaxNode<R>, |
1066 | |||
1067 | impl ForTypeNode { | ||
1068 | pub fn ast(&self) -> ForType { | ||
1069 | ForType::cast(self.0.borrowed()).unwrap() | ||
1070 | } | ||
1071 | } | 1210 | } |
1211 | pub type ForType<'a> = ForTypeNode<RefRoot<'a>>; | ||
1072 | 1212 | ||
1073 | impl<'a> From<ForType<'a>> for ForTypeNode { | 1213 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ForTypeNode<R1>> for ForTypeNode<R2> { |
1074 | fn from(ast: ForType<'a>) -> ForTypeNode { | 1214 | fn eq(&self, other: &ForTypeNode<R1>) -> bool { self.syntax == other.syntax } |
1075 | let syntax = ast.syntax().owned(); | ||
1076 | ForTypeNode(syntax) | ||
1077 | } | ||
1078 | } | 1215 | } |
1079 | #[derive(Debug, Clone, Copy)] | 1216 | impl<R: TreeRoot<RaTypes>> Eq for ForTypeNode<R> {} |
1080 | pub struct ForType<'a> { | 1217 | impl<R: TreeRoot<RaTypes>> Hash for ForTypeNode<R> { |
1081 | syntax: SyntaxNodeRef<'a>, | 1218 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
1082 | } | 1219 | } |
1083 | 1220 | ||
1084 | impl<'a> AstNode<'a> for ForType<'a> { | 1221 | impl<'a> AstNode<'a> for ForType<'a> { |
@@ -1091,28 +1228,31 @@ impl<'a> AstNode<'a> for ForType<'a> { | |||
1091 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1228 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
1092 | } | 1229 | } |
1093 | 1230 | ||
1094 | impl<'a> ForType<'a> {} | 1231 | impl<R: TreeRoot<RaTypes>> ForTypeNode<R> { |
1232 | pub fn borrowed(&self) -> ForType { | ||
1233 | ForTypeNode { syntax: self.syntax.borrowed() } | ||
1234 | } | ||
1235 | pub fn owned(&self) -> ForTypeNode { | ||
1236 | ForTypeNode { syntax: self.syntax.owned() } | ||
1237 | } | ||
1238 | } | ||
1095 | 1239 | ||
1096 | // IfExpr | ||
1097 | 1240 | ||
1098 | #[derive(Debug, Clone)] | 1241 | impl<'a> ForType<'a> {} |
1099 | pub struct IfExprNode(SyntaxNode); | ||
1100 | 1242 | ||
1101 | impl IfExprNode { | 1243 | // IfExpr |
1102 | pub fn ast(&self) -> IfExpr { | 1244 | #[derive(Debug, Clone, Copy,)] |
1103 | IfExpr::cast(self.0.borrowed()).unwrap() | 1245 | pub struct IfExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1104 | } | 1246 | pub(crate) syntax: SyntaxNode<R>, |
1105 | } | 1247 | } |
1248 | pub type IfExpr<'a> = IfExprNode<RefRoot<'a>>; | ||
1106 | 1249 | ||
1107 | impl<'a> From<IfExpr<'a>> for IfExprNode { | 1250 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<IfExprNode<R1>> for IfExprNode<R2> { |
1108 | fn from(ast: IfExpr<'a>) -> IfExprNode { | 1251 | fn eq(&self, other: &IfExprNode<R1>) -> bool { self.syntax == other.syntax } |
1109 | let syntax = ast.syntax().owned(); | ||
1110 | IfExprNode(syntax) | ||
1111 | } | ||
1112 | } | 1252 | } |
1113 | #[derive(Debug, Clone, Copy)] | 1253 | impl<R: TreeRoot<RaTypes>> Eq for IfExprNode<R> {} |
1114 | pub struct IfExpr<'a> { | 1254 | impl<R: TreeRoot<RaTypes>> Hash for IfExprNode<R> { |
1115 | syntax: SyntaxNodeRef<'a>, | 1255 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
1116 | } | 1256 | } |
1117 | 1257 | ||
1118 | impl<'a> AstNode<'a> for IfExpr<'a> { | 1258 | impl<'a> AstNode<'a> for IfExpr<'a> { |
@@ -1125,6 +1265,16 @@ impl<'a> AstNode<'a> for IfExpr<'a> { | |||
1125 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1265 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
1126 | } | 1266 | } |
1127 | 1267 | ||
1268 | impl<R: TreeRoot<RaTypes>> IfExprNode<R> { | ||
1269 | pub fn borrowed(&self) -> IfExpr { | ||
1270 | IfExprNode { syntax: self.syntax.borrowed() } | ||
1271 | } | ||
1272 | pub fn owned(&self) -> IfExprNode { | ||
1273 | IfExprNode { syntax: self.syntax.owned() } | ||
1274 | } | ||
1275 | } | ||
1276 | |||
1277 | |||
1128 | impl<'a> IfExpr<'a> { | 1278 | impl<'a> IfExpr<'a> { |
1129 | pub fn condition(self) -> Option<Condition<'a>> { | 1279 | pub fn condition(self) -> Option<Condition<'a>> { |
1130 | super::child_opt(self) | 1280 | super::child_opt(self) |
@@ -1132,25 +1282,18 @@ impl<'a> IfExpr<'a> { | |||
1132 | } | 1282 | } |
1133 | 1283 | ||
1134 | // ImplItem | 1284 | // ImplItem |
1135 | 1285 | #[derive(Debug, Clone, Copy,)] | |
1136 | #[derive(Debug, Clone)] | 1286 | pub struct ImplItemNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1137 | pub struct ImplItemNode(SyntaxNode); | 1287 | pub(crate) syntax: SyntaxNode<R>, |
1138 | |||
1139 | impl ImplItemNode { | ||
1140 | pub fn ast(&self) -> ImplItem { | ||
1141 | ImplItem::cast(self.0.borrowed()).unwrap() | ||
1142 | } | ||
1143 | } | 1288 | } |
1289 | pub type ImplItem<'a> = ImplItemNode<RefRoot<'a>>; | ||
1144 | 1290 | ||
1145 | impl<'a> From<ImplItem<'a>> for ImplItemNode { | 1291 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ImplItemNode<R1>> for ImplItemNode<R2> { |
1146 | fn from(ast: ImplItem<'a>) -> ImplItemNode { | 1292 | fn eq(&self, other: &ImplItemNode<R1>) -> bool { self.syntax == other.syntax } |
1147 | let syntax = ast.syntax().owned(); | ||
1148 | ImplItemNode(syntax) | ||
1149 | } | ||
1150 | } | 1293 | } |
1151 | #[derive(Debug, Clone, Copy)] | 1294 | impl<R: TreeRoot<RaTypes>> Eq for ImplItemNode<R> {} |
1152 | pub struct ImplItem<'a> { | 1295 | impl<R: TreeRoot<RaTypes>> Hash for ImplItemNode<R> { |
1153 | syntax: SyntaxNodeRef<'a>, | 1296 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
1154 | } | 1297 | } |
1155 | 1298 | ||
1156 | impl<'a> AstNode<'a> for ImplItem<'a> { | 1299 | impl<'a> AstNode<'a> for ImplItem<'a> { |
@@ -1163,28 +1306,31 @@ impl<'a> AstNode<'a> for ImplItem<'a> { | |||
1163 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1306 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
1164 | } | 1307 | } |
1165 | 1308 | ||
1166 | impl<'a> ImplItem<'a> {} | 1309 | impl<R: TreeRoot<RaTypes>> ImplItemNode<R> { |
1310 | pub fn borrowed(&self) -> ImplItem { | ||
1311 | ImplItemNode { syntax: self.syntax.borrowed() } | ||
1312 | } | ||
1313 | pub fn owned(&self) -> ImplItemNode { | ||
1314 | ImplItemNode { syntax: self.syntax.owned() } | ||
1315 | } | ||
1316 | } | ||
1167 | 1317 | ||
1168 | // ImplTraitType | ||
1169 | 1318 | ||
1170 | #[derive(Debug, Clone)] | 1319 | impl<'a> ImplItem<'a> {} |
1171 | pub struct ImplTraitTypeNode(SyntaxNode); | ||
1172 | 1320 | ||
1173 | impl ImplTraitTypeNode { | 1321 | // ImplTraitType |
1174 | pub fn ast(&self) -> ImplTraitType { | 1322 | #[derive(Debug, Clone, Copy,)] |
1175 | ImplTraitType::cast(self.0.borrowed()).unwrap() | 1323 | pub struct ImplTraitTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1176 | } | 1324 | pub(crate) syntax: SyntaxNode<R>, |
1177 | } | 1325 | } |
1326 | pub type ImplTraitType<'a> = ImplTraitTypeNode<RefRoot<'a>>; | ||
1178 | 1327 | ||
1179 | impl<'a> From<ImplTraitType<'a>> for ImplTraitTypeNode { | 1328 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ImplTraitTypeNode<R1>> for ImplTraitTypeNode<R2> { |
1180 | fn from(ast: ImplTraitType<'a>) -> ImplTraitTypeNode { | 1329 | fn eq(&self, other: &ImplTraitTypeNode<R1>) -> bool { self.syntax == other.syntax } |
1181 | let syntax = ast.syntax().owned(); | ||
1182 | ImplTraitTypeNode(syntax) | ||
1183 | } | ||
1184 | } | 1330 | } |
1185 | #[derive(Debug, Clone, Copy)] | 1331 | impl<R: TreeRoot<RaTypes>> Eq for ImplTraitTypeNode<R> {} |
1186 | pub struct ImplTraitType<'a> { | 1332 | impl<R: TreeRoot<RaTypes>> Hash for ImplTraitTypeNode<R> { |
1187 | syntax: SyntaxNodeRef<'a>, | 1333 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
1188 | } | 1334 | } |
1189 | 1335 | ||
1190 | impl<'a> AstNode<'a> for ImplTraitType<'a> { | 1336 | impl<'a> AstNode<'a> for ImplTraitType<'a> { |
@@ -1197,28 +1343,31 @@ impl<'a> AstNode<'a> for ImplTraitType<'a> { | |||
1197 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1343 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
1198 | } | 1344 | } |
1199 | 1345 | ||
1200 | impl<'a> ImplTraitType<'a> {} | 1346 | impl<R: TreeRoot<RaTypes>> ImplTraitTypeNode<R> { |
1347 | pub fn borrowed(&self) -> ImplTraitType { | ||
1348 | ImplTraitTypeNode { syntax: self.syntax.borrowed() } | ||
1349 | } | ||
1350 | pub fn owned(&self) -> ImplTraitTypeNode { | ||
1351 | ImplTraitTypeNode { syntax: self.syntax.owned() } | ||
1352 | } | ||
1353 | } | ||
1201 | 1354 | ||
1202 | // IndexExpr | ||
1203 | 1355 | ||
1204 | #[derive(Debug, Clone)] | 1356 | impl<'a> ImplTraitType<'a> {} |
1205 | pub struct IndexExprNode(SyntaxNode); | ||
1206 | 1357 | ||
1207 | impl IndexExprNode { | 1358 | // IndexExpr |
1208 | pub fn ast(&self) -> IndexExpr { | 1359 | #[derive(Debug, Clone, Copy,)] |
1209 | IndexExpr::cast(self.0.borrowed()).unwrap() | 1360 | pub struct IndexExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1210 | } | 1361 | pub(crate) syntax: SyntaxNode<R>, |
1211 | } | 1362 | } |
1363 | pub type IndexExpr<'a> = IndexExprNode<RefRoot<'a>>; | ||
1212 | 1364 | ||
1213 | impl<'a> From<IndexExpr<'a>> for IndexExprNode { | 1365 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<IndexExprNode<R1>> for IndexExprNode<R2> { |
1214 | fn from(ast: IndexExpr<'a>) -> IndexExprNode { | 1366 | fn eq(&self, other: &IndexExprNode<R1>) -> bool { self.syntax == other.syntax } |
1215 | let syntax = ast.syntax().owned(); | ||
1216 | IndexExprNode(syntax) | ||
1217 | } | ||
1218 | } | 1367 | } |
1219 | #[derive(Debug, Clone, Copy)] | 1368 | impl<R: TreeRoot<RaTypes>> Eq for IndexExprNode<R> {} |
1220 | pub struct IndexExpr<'a> { | 1369 | impl<R: TreeRoot<RaTypes>> Hash for IndexExprNode<R> { |
1221 | syntax: SyntaxNodeRef<'a>, | 1370 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
1222 | } | 1371 | } |
1223 | 1372 | ||
1224 | impl<'a> AstNode<'a> for IndexExpr<'a> { | 1373 | impl<'a> AstNode<'a> for IndexExpr<'a> { |
@@ -1231,28 +1380,31 @@ impl<'a> AstNode<'a> for IndexExpr<'a> { | |||
1231 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1380 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
1232 | } | 1381 | } |
1233 | 1382 | ||
1234 | impl<'a> IndexExpr<'a> {} | 1383 | impl<R: TreeRoot<RaTypes>> IndexExprNode<R> { |
1384 | pub fn borrowed(&self) -> IndexExpr { | ||
1385 | IndexExprNode { syntax: self.syntax.borrowed() } | ||
1386 | } | ||
1387 | pub fn owned(&self) -> IndexExprNode { | ||
1388 | IndexExprNode { syntax: self.syntax.owned() } | ||
1389 | } | ||
1390 | } | ||
1235 | 1391 | ||
1236 | // ItemList | ||
1237 | 1392 | ||
1238 | #[derive(Debug, Clone)] | 1393 | impl<'a> IndexExpr<'a> {} |
1239 | pub struct ItemListNode(SyntaxNode); | ||
1240 | 1394 | ||
1241 | impl ItemListNode { | 1395 | // ItemList |
1242 | pub fn ast(&self) -> ItemList { | 1396 | #[derive(Debug, Clone, Copy,)] |
1243 | ItemList::cast(self.0.borrowed()).unwrap() | 1397 | pub struct ItemListNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1244 | } | 1398 | pub(crate) syntax: SyntaxNode<R>, |
1245 | } | 1399 | } |
1400 | pub type ItemList<'a> = ItemListNode<RefRoot<'a>>; | ||
1246 | 1401 | ||
1247 | impl<'a> From<ItemList<'a>> for ItemListNode { | 1402 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ItemListNode<R1>> for ItemListNode<R2> { |
1248 | fn from(ast: ItemList<'a>) -> ItemListNode { | 1403 | fn eq(&self, other: &ItemListNode<R1>) -> bool { self.syntax == other.syntax } |
1249 | let syntax = ast.syntax().owned(); | ||
1250 | ItemListNode(syntax) | ||
1251 | } | ||
1252 | } | 1404 | } |
1253 | #[derive(Debug, Clone, Copy)] | 1405 | impl<R: TreeRoot<RaTypes>> Eq for ItemListNode<R> {} |
1254 | pub struct ItemList<'a> { | 1406 | impl<R: TreeRoot<RaTypes>> Hash for ItemListNode<R> { |
1255 | syntax: SyntaxNodeRef<'a>, | 1407 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
1256 | } | 1408 | } |
1257 | 1409 | ||
1258 | impl<'a> AstNode<'a> for ItemList<'a> { | 1410 | impl<'a> AstNode<'a> for ItemList<'a> { |
@@ -1265,30 +1417,33 @@ impl<'a> AstNode<'a> for ItemList<'a> { | |||
1265 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1417 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
1266 | } | 1418 | } |
1267 | 1419 | ||
1420 | impl<R: TreeRoot<RaTypes>> ItemListNode<R> { | ||
1421 | pub fn borrowed(&self) -> ItemList { | ||
1422 | ItemListNode { syntax: self.syntax.borrowed() } | ||
1423 | } | ||
1424 | pub fn owned(&self) -> ItemListNode { | ||
1425 | ItemListNode { syntax: self.syntax.owned() } | ||
1426 | } | ||
1427 | } | ||
1428 | |||
1429 | |||
1268 | impl<'a> ast::FnDefOwner<'a> for ItemList<'a> {} | 1430 | impl<'a> ast::FnDefOwner<'a> for ItemList<'a> {} |
1269 | impl<'a> ast::ModuleItemOwner<'a> for ItemList<'a> {} | 1431 | impl<'a> ast::ModuleItemOwner<'a> for ItemList<'a> {} |
1270 | impl<'a> ItemList<'a> {} | 1432 | impl<'a> ItemList<'a> {} |
1271 | 1433 | ||
1272 | // Label | 1434 | // Label |
1273 | 1435 | #[derive(Debug, Clone, Copy,)] | |
1274 | #[derive(Debug, Clone)] | 1436 | pub struct LabelNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1275 | pub struct LabelNode(SyntaxNode); | 1437 | pub(crate) syntax: SyntaxNode<R>, |
1276 | |||
1277 | impl LabelNode { | ||
1278 | pub fn ast(&self) -> Label { | ||
1279 | Label::cast(self.0.borrowed()).unwrap() | ||
1280 | } | ||
1281 | } | 1438 | } |
1439 | pub type Label<'a> = LabelNode<RefRoot<'a>>; | ||
1282 | 1440 | ||
1283 | impl<'a> From<Label<'a>> for LabelNode { | 1441 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LabelNode<R1>> for LabelNode<R2> { |
1284 | fn from(ast: Label<'a>) -> LabelNode { | 1442 | fn eq(&self, other: &LabelNode<R1>) -> bool { self.syntax == other.syntax } |
1285 | let syntax = ast.syntax().owned(); | ||
1286 | LabelNode(syntax) | ||
1287 | } | ||
1288 | } | 1443 | } |
1289 | #[derive(Debug, Clone, Copy)] | 1444 | impl<R: TreeRoot<RaTypes>> Eq for LabelNode<R> {} |
1290 | pub struct Label<'a> { | 1445 | impl<R: TreeRoot<RaTypes>> Hash for LabelNode<R> { |
1291 | syntax: SyntaxNodeRef<'a>, | 1446 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
1292 | } | 1447 | } |
1293 | 1448 | ||
1294 | impl<'a> AstNode<'a> for Label<'a> { | 1449 | impl<'a> AstNode<'a> for Label<'a> { |
@@ -1301,28 +1456,31 @@ impl<'a> AstNode<'a> for Label<'a> { | |||
1301 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1456 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
1302 | } | 1457 | } |
1303 | 1458 | ||
1304 | impl<'a> Label<'a> {} | 1459 | impl<R: TreeRoot<RaTypes>> LabelNode<R> { |
1460 | pub fn borrowed(&self) -> Label { | ||
1461 | LabelNode { syntax: self.syntax.borrowed() } | ||
1462 | } | ||
1463 | pub fn owned(&self) -> LabelNode { | ||
1464 | LabelNode { syntax: self.syntax.owned() } | ||
1465 | } | ||
1466 | } | ||
1305 | 1467 | ||
1306 | // LambdaExpr | ||
1307 | 1468 | ||
1308 | #[derive(Debug, Clone)] | 1469 | impl<'a> Label<'a> {} |
1309 | pub struct LambdaExprNode(SyntaxNode); | ||
1310 | 1470 | ||
1311 | impl LambdaExprNode { | 1471 | // LambdaExpr |
1312 | pub fn ast(&self) -> LambdaExpr { | 1472 | #[derive(Debug, Clone, Copy,)] |
1313 | LambdaExpr::cast(self.0.borrowed()).unwrap() | 1473 | pub struct LambdaExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1314 | } | 1474 | pub(crate) syntax: SyntaxNode<R>, |
1315 | } | 1475 | } |
1476 | pub type LambdaExpr<'a> = LambdaExprNode<RefRoot<'a>>; | ||
1316 | 1477 | ||
1317 | impl<'a> From<LambdaExpr<'a>> for LambdaExprNode { | 1478 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LambdaExprNode<R1>> for LambdaExprNode<R2> { |
1318 | fn from(ast: LambdaExpr<'a>) -> LambdaExprNode { | 1479 | fn eq(&self, other: &LambdaExprNode<R1>) -> bool { self.syntax == other.syntax } |
1319 | let syntax = ast.syntax().owned(); | ||
1320 | LambdaExprNode(syntax) | ||
1321 | } | ||
1322 | } | 1480 | } |
1323 | #[derive(Debug, Clone, Copy)] | 1481 | impl<R: TreeRoot<RaTypes>> Eq for LambdaExprNode<R> {} |
1324 | pub struct LambdaExpr<'a> { | 1482 | impl<R: TreeRoot<RaTypes>> Hash for LambdaExprNode<R> { |
1325 | syntax: SyntaxNodeRef<'a>, | 1483 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
1326 | } | 1484 | } |
1327 | 1485 | ||
1328 | impl<'a> AstNode<'a> for LambdaExpr<'a> { | 1486 | impl<'a> AstNode<'a> for LambdaExpr<'a> { |
@@ -1335,6 +1493,16 @@ impl<'a> AstNode<'a> for LambdaExpr<'a> { | |||
1335 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1493 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
1336 | } | 1494 | } |
1337 | 1495 | ||
1496 | impl<R: TreeRoot<RaTypes>> LambdaExprNode<R> { | ||
1497 | pub fn borrowed(&self) -> LambdaExpr { | ||
1498 | LambdaExprNode { syntax: self.syntax.borrowed() } | ||
1499 | } | ||
1500 | pub fn owned(&self) -> LambdaExprNode { | ||
1501 | LambdaExprNode { syntax: self.syntax.owned() } | ||
1502 | } | ||
1503 | } | ||
1504 | |||
1505 | |||
1338 | impl<'a> LambdaExpr<'a> { | 1506 | impl<'a> LambdaExpr<'a> { |
1339 | pub fn param_list(self) -> Option<ParamList<'a>> { | 1507 | pub fn param_list(self) -> Option<ParamList<'a>> { |
1340 | super::child_opt(self) | 1508 | super::child_opt(self) |
@@ -1346,25 +1514,18 @@ impl<'a> LambdaExpr<'a> { | |||
1346 | } | 1514 | } |
1347 | 1515 | ||
1348 | // LetStmt | 1516 | // LetStmt |
1349 | 1517 | #[derive(Debug, Clone, Copy,)] | |
1350 | #[derive(Debug, Clone)] | 1518 | pub struct LetStmtNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1351 | pub struct LetStmtNode(SyntaxNode); | 1519 | pub(crate) syntax: SyntaxNode<R>, |
1352 | |||
1353 | impl LetStmtNode { | ||
1354 | pub fn ast(&self) -> LetStmt { | ||
1355 | LetStmt::cast(self.0.borrowed()).unwrap() | ||
1356 | } | ||
1357 | } | 1520 | } |
1521 | pub type LetStmt<'a> = LetStmtNode<RefRoot<'a>>; | ||
1358 | 1522 | ||
1359 | impl<'a> From<LetStmt<'a>> for LetStmtNode { | 1523 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LetStmtNode<R1>> for LetStmtNode<R2> { |
1360 | fn from(ast: LetStmt<'a>) -> LetStmtNode { | 1524 | fn eq(&self, other: &LetStmtNode<R1>) -> bool { self.syntax == other.syntax } |
1361 | let syntax = ast.syntax().owned(); | ||
1362 | LetStmtNode(syntax) | ||
1363 | } | ||
1364 | } | 1525 | } |
1365 | #[derive(Debug, Clone, Copy)] | 1526 | impl<R: TreeRoot<RaTypes>> Eq for LetStmtNode<R> {} |
1366 | pub struct LetStmt<'a> { | 1527 | impl<R: TreeRoot<RaTypes>> Hash for LetStmtNode<R> { |
1367 | syntax: SyntaxNodeRef<'a>, | 1528 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
1368 | } | 1529 | } |
1369 | 1530 | ||
1370 | impl<'a> AstNode<'a> for LetStmt<'a> { | 1531 | impl<'a> AstNode<'a> for LetStmt<'a> { |
@@ -1377,6 +1538,16 @@ impl<'a> AstNode<'a> for LetStmt<'a> { | |||
1377 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1538 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
1378 | } | 1539 | } |
1379 | 1540 | ||
1541 | impl<R: TreeRoot<RaTypes>> LetStmtNode<R> { | ||
1542 | pub fn borrowed(&self) -> LetStmt { | ||
1543 | LetStmtNode { syntax: self.syntax.borrowed() } | ||
1544 | } | ||
1545 | pub fn owned(&self) -> LetStmtNode { | ||
1546 | LetStmtNode { syntax: self.syntax.owned() } | ||
1547 | } | ||
1548 | } | ||
1549 | |||
1550 | |||
1380 | impl<'a> LetStmt<'a> { | 1551 | impl<'a> LetStmt<'a> { |
1381 | pub fn pat(self) -> Option<Pat<'a>> { | 1552 | pub fn pat(self) -> Option<Pat<'a>> { |
1382 | super::child_opt(self) | 1553 | super::child_opt(self) |
@@ -1388,25 +1559,18 @@ impl<'a> LetStmt<'a> { | |||
1388 | } | 1559 | } |
1389 | 1560 | ||
1390 | // Lifetime | 1561 | // Lifetime |
1391 | 1562 | #[derive(Debug, Clone, Copy,)] | |
1392 | #[derive(Debug, Clone)] | 1563 | pub struct LifetimeNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1393 | pub struct LifetimeNode(SyntaxNode); | 1564 | pub(crate) syntax: SyntaxNode<R>, |
1394 | |||
1395 | impl LifetimeNode { | ||
1396 | pub fn ast(&self) -> Lifetime { | ||
1397 | Lifetime::cast(self.0.borrowed()).unwrap() | ||
1398 | } | ||
1399 | } | 1565 | } |
1566 | pub type Lifetime<'a> = LifetimeNode<RefRoot<'a>>; | ||
1400 | 1567 | ||
1401 | impl<'a> From<Lifetime<'a>> for LifetimeNode { | 1568 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LifetimeNode<R1>> for LifetimeNode<R2> { |
1402 | fn from(ast: Lifetime<'a>) -> LifetimeNode { | 1569 | fn eq(&self, other: &LifetimeNode<R1>) -> bool { self.syntax == other.syntax } |
1403 | let syntax = ast.syntax().owned(); | ||
1404 | LifetimeNode(syntax) | ||
1405 | } | ||
1406 | } | 1570 | } |
1407 | #[derive(Debug, Clone, Copy)] | 1571 | impl<R: TreeRoot<RaTypes>> Eq for LifetimeNode<R> {} |
1408 | pub struct Lifetime<'a> { | 1572 | impl<R: TreeRoot<RaTypes>> Hash for LifetimeNode<R> { |
1409 | syntax: SyntaxNodeRef<'a>, | 1573 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
1410 | } | 1574 | } |
1411 | 1575 | ||
1412 | impl<'a> AstNode<'a> for Lifetime<'a> { | 1576 | impl<'a> AstNode<'a> for Lifetime<'a> { |
@@ -1419,28 +1583,31 @@ impl<'a> AstNode<'a> for Lifetime<'a> { | |||
1419 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1583 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
1420 | } | 1584 | } |
1421 | 1585 | ||
1422 | impl<'a> Lifetime<'a> {} | 1586 | impl<R: TreeRoot<RaTypes>> LifetimeNode<R> { |
1587 | pub fn borrowed(&self) -> Lifetime { | ||
1588 | LifetimeNode { syntax: self.syntax.borrowed() } | ||
1589 | } | ||
1590 | pub fn owned(&self) -> LifetimeNode { | ||
1591 | LifetimeNode { syntax: self.syntax.owned() } | ||
1592 | } | ||
1593 | } | ||
1423 | 1594 | ||
1424 | // LifetimeParam | ||
1425 | 1595 | ||
1426 | #[derive(Debug, Clone)] | 1596 | impl<'a> Lifetime<'a> {} |
1427 | pub struct LifetimeParamNode(SyntaxNode); | ||
1428 | 1597 | ||
1429 | impl LifetimeParamNode { | 1598 | // LifetimeParam |
1430 | pub fn ast(&self) -> LifetimeParam { | 1599 | #[derive(Debug, Clone, Copy,)] |
1431 | LifetimeParam::cast(self.0.borrowed()).unwrap() | 1600 | pub struct LifetimeParamNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1432 | } | 1601 | pub(crate) syntax: SyntaxNode<R>, |
1433 | } | 1602 | } |
1603 | pub type LifetimeParam<'a> = LifetimeParamNode<RefRoot<'a>>; | ||
1434 | 1604 | ||
1435 | impl<'a> From<LifetimeParam<'a>> for LifetimeParamNode { | 1605 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LifetimeParamNode<R1>> for LifetimeParamNode<R2> { |
1436 | fn from(ast: LifetimeParam<'a>) -> LifetimeParamNode { | 1606 | fn eq(&self, other: &LifetimeParamNode<R1>) -> bool { self.syntax == other.syntax } |
1437 | let syntax = ast.syntax().owned(); | ||
1438 | LifetimeParamNode(syntax) | ||
1439 | } | ||
1440 | } | 1607 | } |
1441 | #[derive(Debug, Clone, Copy)] | 1608 | impl<R: TreeRoot<RaTypes>> Eq for LifetimeParamNode<R> {} |
1442 | pub struct LifetimeParam<'a> { | 1609 | impl<R: TreeRoot<RaTypes>> Hash for LifetimeParamNode<R> { |
1443 | syntax: SyntaxNodeRef<'a>, | 1610 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
1444 | } | 1611 | } |
1445 | 1612 | ||
1446 | impl<'a> AstNode<'a> for LifetimeParam<'a> { | 1613 | impl<'a> AstNode<'a> for LifetimeParam<'a> { |
@@ -1453,6 +1620,16 @@ impl<'a> AstNode<'a> for LifetimeParam<'a> { | |||
1453 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1620 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
1454 | } | 1621 | } |
1455 | 1622 | ||
1623 | impl<R: TreeRoot<RaTypes>> LifetimeParamNode<R> { | ||
1624 | pub fn borrowed(&self) -> LifetimeParam { | ||
1625 | LifetimeParamNode { syntax: self.syntax.borrowed() } | ||
1626 | } | ||
1627 | pub fn owned(&self) -> LifetimeParamNode { | ||
1628 | LifetimeParamNode { syntax: self.syntax.owned() } | ||
1629 | } | ||
1630 | } | ||
1631 | |||
1632 | |||
1456 | impl<'a> LifetimeParam<'a> { | 1633 | impl<'a> LifetimeParam<'a> { |
1457 | pub fn lifetime(self) -> Option<Lifetime<'a>> { | 1634 | pub fn lifetime(self) -> Option<Lifetime<'a>> { |
1458 | super::child_opt(self) | 1635 | super::child_opt(self) |
@@ -1460,25 +1637,18 @@ impl<'a> LifetimeParam<'a> { | |||
1460 | } | 1637 | } |
1461 | 1638 | ||
1462 | // Literal | 1639 | // Literal |
1463 | 1640 | #[derive(Debug, Clone, Copy,)] | |
1464 | #[derive(Debug, Clone)] | 1641 | pub struct LiteralNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1465 | pub struct LiteralNode(SyntaxNode); | 1642 | pub(crate) syntax: SyntaxNode<R>, |
1466 | |||
1467 | impl LiteralNode { | ||
1468 | pub fn ast(&self) -> Literal { | ||
1469 | Literal::cast(self.0.borrowed()).unwrap() | ||
1470 | } | ||
1471 | } | 1643 | } |
1644 | pub type Literal<'a> = LiteralNode<RefRoot<'a>>; | ||
1472 | 1645 | ||
1473 | impl<'a> From<Literal<'a>> for LiteralNode { | 1646 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LiteralNode<R1>> for LiteralNode<R2> { |
1474 | fn from(ast: Literal<'a>) -> LiteralNode { | 1647 | fn eq(&self, other: &LiteralNode<R1>) -> bool { self.syntax == other.syntax } |
1475 | let syntax = ast.syntax().owned(); | ||
1476 | LiteralNode(syntax) | ||
1477 | } | ||
1478 | } | 1648 | } |
1479 | #[derive(Debug, Clone, Copy)] | 1649 | impl<R: TreeRoot<RaTypes>> Eq for LiteralNode<R> {} |
1480 | pub struct Literal<'a> { | 1650 | impl<R: TreeRoot<RaTypes>> Hash for LiteralNode<R> { |
1481 | syntax: SyntaxNodeRef<'a>, | 1651 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
1482 | } | 1652 | } |
1483 | 1653 | ||
1484 | impl<'a> AstNode<'a> for Literal<'a> { | 1654 | impl<'a> AstNode<'a> for Literal<'a> { |
@@ -1491,28 +1661,31 @@ impl<'a> AstNode<'a> for Literal<'a> { | |||
1491 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1661 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
1492 | } | 1662 | } |
1493 | 1663 | ||
1494 | impl<'a> Literal<'a> {} | 1664 | impl<R: TreeRoot<RaTypes>> LiteralNode<R> { |
1665 | pub fn borrowed(&self) -> Literal { | ||
1666 | LiteralNode { syntax: self.syntax.borrowed() } | ||
1667 | } | ||
1668 | pub fn owned(&self) -> LiteralNode { | ||
1669 | LiteralNode { syntax: self.syntax.owned() } | ||
1670 | } | ||
1671 | } | ||
1495 | 1672 | ||
1496 | // LoopExpr | ||
1497 | 1673 | ||
1498 | #[derive(Debug, Clone)] | 1674 | impl<'a> Literal<'a> {} |
1499 | pub struct LoopExprNode(SyntaxNode); | ||
1500 | 1675 | ||
1501 | impl LoopExprNode { | 1676 | // LoopExpr |
1502 | pub fn ast(&self) -> LoopExpr { | 1677 | #[derive(Debug, Clone, Copy,)] |
1503 | LoopExpr::cast(self.0.borrowed()).unwrap() | 1678 | pub struct LoopExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1504 | } | 1679 | pub(crate) syntax: SyntaxNode<R>, |
1505 | } | 1680 | } |
1681 | pub type LoopExpr<'a> = LoopExprNode<RefRoot<'a>>; | ||
1506 | 1682 | ||
1507 | impl<'a> From<LoopExpr<'a>> for LoopExprNode { | 1683 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LoopExprNode<R1>> for LoopExprNode<R2> { |
1508 | fn from(ast: LoopExpr<'a>) -> LoopExprNode { | 1684 | fn eq(&self, other: &LoopExprNode<R1>) -> bool { self.syntax == other.syntax } |
1509 | let syntax = ast.syntax().owned(); | ||
1510 | LoopExprNode(syntax) | ||
1511 | } | ||
1512 | } | 1685 | } |
1513 | #[derive(Debug, Clone, Copy)] | 1686 | impl<R: TreeRoot<RaTypes>> Eq for LoopExprNode<R> {} |
1514 | pub struct LoopExpr<'a> { | 1687 | impl<R: TreeRoot<RaTypes>> Hash for LoopExprNode<R> { |
1515 | syntax: SyntaxNodeRef<'a>, | 1688 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
1516 | } | 1689 | } |
1517 | 1690 | ||
1518 | impl<'a> AstNode<'a> for LoopExpr<'a> { | 1691 | impl<'a> AstNode<'a> for LoopExpr<'a> { |
@@ -1525,29 +1698,32 @@ impl<'a> AstNode<'a> for LoopExpr<'a> { | |||
1525 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1698 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
1526 | } | 1699 | } |
1527 | 1700 | ||
1701 | impl<R: TreeRoot<RaTypes>> LoopExprNode<R> { | ||
1702 | pub fn borrowed(&self) -> LoopExpr { | ||
1703 | LoopExprNode { syntax: self.syntax.borrowed() } | ||
1704 | } | ||
1705 | pub fn owned(&self) -> LoopExprNode { | ||
1706 | LoopExprNode { syntax: self.syntax.owned() } | ||
1707 | } | ||
1708 | } | ||
1709 | |||
1710 | |||
1528 | impl<'a> ast::LoopBodyOwner<'a> for LoopExpr<'a> {} | 1711 | impl<'a> ast::LoopBodyOwner<'a> for LoopExpr<'a> {} |
1529 | impl<'a> LoopExpr<'a> {} | 1712 | impl<'a> LoopExpr<'a> {} |
1530 | 1713 | ||
1531 | // MatchArm | 1714 | // MatchArm |
1532 | 1715 | #[derive(Debug, Clone, Copy,)] | |
1533 | #[derive(Debug, Clone)] | 1716 | pub struct MatchArmNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1534 | pub struct MatchArmNode(SyntaxNode); | 1717 | pub(crate) syntax: SyntaxNode<R>, |
1535 | |||
1536 | impl MatchArmNode { | ||
1537 | pub fn ast(&self) -> MatchArm { | ||
1538 | MatchArm::cast(self.0.borrowed()).unwrap() | ||
1539 | } | ||
1540 | } | 1718 | } |
1719 | pub type MatchArm<'a> = MatchArmNode<RefRoot<'a>>; | ||
1541 | 1720 | ||
1542 | impl<'a> From<MatchArm<'a>> for MatchArmNode { | 1721 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<MatchArmNode<R1>> for MatchArmNode<R2> { |
1543 | fn from(ast: MatchArm<'a>) -> MatchArmNode { | 1722 | fn eq(&self, other: &MatchArmNode<R1>) -> bool { self.syntax == other.syntax } |
1544 | let syntax = ast.syntax().owned(); | ||
1545 | MatchArmNode(syntax) | ||
1546 | } | ||
1547 | } | 1723 | } |
1548 | #[derive(Debug, Clone, Copy)] | 1724 | impl<R: TreeRoot<RaTypes>> Eq for MatchArmNode<R> {} |
1549 | pub struct MatchArm<'a> { | 1725 | impl<R: TreeRoot<RaTypes>> Hash for MatchArmNode<R> { |
1550 | syntax: SyntaxNodeRef<'a>, | 1726 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
1551 | } | 1727 | } |
1552 | 1728 | ||
1553 | impl<'a> AstNode<'a> for MatchArm<'a> { | 1729 | impl<'a> AstNode<'a> for MatchArm<'a> { |
@@ -1560,6 +1736,16 @@ impl<'a> AstNode<'a> for MatchArm<'a> { | |||
1560 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1736 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
1561 | } | 1737 | } |
1562 | 1738 | ||
1739 | impl<R: TreeRoot<RaTypes>> MatchArmNode<R> { | ||
1740 | pub fn borrowed(&self) -> MatchArm { | ||
1741 | MatchArmNode { syntax: self.syntax.borrowed() } | ||
1742 | } | ||
1743 | pub fn owned(&self) -> MatchArmNode { | ||
1744 | MatchArmNode { syntax: self.syntax.owned() } | ||
1745 | } | ||
1746 | } | ||
1747 | |||
1748 | |||
1563 | impl<'a> MatchArm<'a> { | 1749 | impl<'a> MatchArm<'a> { |
1564 | pub fn pats(self) -> impl Iterator<Item = Pat<'a>> + 'a { | 1750 | pub fn pats(self) -> impl Iterator<Item = Pat<'a>> + 'a { |
1565 | super::children(self) | 1751 | super::children(self) |
@@ -1575,25 +1761,18 @@ impl<'a> MatchArm<'a> { | |||
1575 | } | 1761 | } |
1576 | 1762 | ||
1577 | // MatchArmList | 1763 | // MatchArmList |
1578 | 1764 | #[derive(Debug, Clone, Copy,)] | |
1579 | #[derive(Debug, Clone)] | 1765 | pub struct MatchArmListNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1580 | pub struct MatchArmListNode(SyntaxNode); | 1766 | pub(crate) syntax: SyntaxNode<R>, |
1581 | |||
1582 | impl MatchArmListNode { | ||
1583 | pub fn ast(&self) -> MatchArmList { | ||
1584 | MatchArmList::cast(self.0.borrowed()).unwrap() | ||
1585 | } | ||
1586 | } | 1767 | } |
1768 | pub type MatchArmList<'a> = MatchArmListNode<RefRoot<'a>>; | ||
1587 | 1769 | ||
1588 | impl<'a> From<MatchArmList<'a>> for MatchArmListNode { | 1770 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<MatchArmListNode<R1>> for MatchArmListNode<R2> { |
1589 | fn from(ast: MatchArmList<'a>) -> MatchArmListNode { | 1771 | fn eq(&self, other: &MatchArmListNode<R1>) -> bool { self.syntax == other.syntax } |
1590 | let syntax = ast.syntax().owned(); | ||
1591 | MatchArmListNode(syntax) | ||
1592 | } | ||
1593 | } | 1772 | } |
1594 | #[derive(Debug, Clone, Copy)] | 1773 | impl<R: TreeRoot<RaTypes>> Eq for MatchArmListNode<R> {} |
1595 | pub struct MatchArmList<'a> { | 1774 | impl<R: TreeRoot<RaTypes>> Hash for MatchArmListNode<R> { |
1596 | syntax: SyntaxNodeRef<'a>, | 1775 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
1597 | } | 1776 | } |
1598 | 1777 | ||
1599 | impl<'a> AstNode<'a> for MatchArmList<'a> { | 1778 | impl<'a> AstNode<'a> for MatchArmList<'a> { |
@@ -1606,6 +1785,16 @@ impl<'a> AstNode<'a> for MatchArmList<'a> { | |||
1606 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1785 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
1607 | } | 1786 | } |
1608 | 1787 | ||
1788 | impl<R: TreeRoot<RaTypes>> MatchArmListNode<R> { | ||
1789 | pub fn borrowed(&self) -> MatchArmList { | ||
1790 | MatchArmListNode { syntax: self.syntax.borrowed() } | ||
1791 | } | ||
1792 | pub fn owned(&self) -> MatchArmListNode { | ||
1793 | MatchArmListNode { syntax: self.syntax.owned() } | ||
1794 | } | ||
1795 | } | ||
1796 | |||
1797 | |||
1609 | impl<'a> MatchArmList<'a> { | 1798 | impl<'a> MatchArmList<'a> { |
1610 | pub fn arms(self) -> impl Iterator<Item = MatchArm<'a>> + 'a { | 1799 | pub fn arms(self) -> impl Iterator<Item = MatchArm<'a>> + 'a { |
1611 | super::children(self) | 1800 | super::children(self) |
@@ -1613,25 +1802,18 @@ impl<'a> MatchArmList<'a> { | |||
1613 | } | 1802 | } |
1614 | 1803 | ||
1615 | // MatchExpr | 1804 | // MatchExpr |
1616 | 1805 | #[derive(Debug, Clone, Copy,)] | |
1617 | #[derive(Debug, Clone)] | 1806 | pub struct MatchExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1618 | pub struct MatchExprNode(SyntaxNode); | 1807 | pub(crate) syntax: SyntaxNode<R>, |
1619 | |||
1620 | impl MatchExprNode { | ||
1621 | pub fn ast(&self) -> MatchExpr { | ||
1622 | MatchExpr::cast(self.0.borrowed()).unwrap() | ||
1623 | } | ||
1624 | } | 1808 | } |
1809 | pub type MatchExpr<'a> = MatchExprNode<RefRoot<'a>>; | ||
1625 | 1810 | ||
1626 | impl<'a> From<MatchExpr<'a>> for MatchExprNode { | 1811 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<MatchExprNode<R1>> for MatchExprNode<R2> { |
1627 | fn from(ast: MatchExpr<'a>) -> MatchExprNode { | 1812 | fn eq(&self, other: &MatchExprNode<R1>) -> bool { self.syntax == other.syntax } |
1628 | let syntax = ast.syntax().owned(); | ||
1629 | MatchExprNode(syntax) | ||
1630 | } | ||
1631 | } | 1813 | } |
1632 | #[derive(Debug, Clone, Copy)] | 1814 | impl<R: TreeRoot<RaTypes>> Eq for MatchExprNode<R> {} |
1633 | pub struct MatchExpr<'a> { | 1815 | impl<R: TreeRoot<RaTypes>> Hash for MatchExprNode<R> { |
1634 | syntax: SyntaxNodeRef<'a>, | 1816 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
1635 | } | 1817 | } |
1636 | 1818 | ||
1637 | impl<'a> AstNode<'a> for MatchExpr<'a> { | 1819 | impl<'a> AstNode<'a> for MatchExpr<'a> { |
@@ -1644,6 +1826,16 @@ impl<'a> AstNode<'a> for MatchExpr<'a> { | |||
1644 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1826 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
1645 | } | 1827 | } |
1646 | 1828 | ||
1829 | impl<R: TreeRoot<RaTypes>> MatchExprNode<R> { | ||
1830 | pub fn borrowed(&self) -> MatchExpr { | ||
1831 | MatchExprNode { syntax: self.syntax.borrowed() } | ||
1832 | } | ||
1833 | pub fn owned(&self) -> MatchExprNode { | ||
1834 | MatchExprNode { syntax: self.syntax.owned() } | ||
1835 | } | ||
1836 | } | ||
1837 | |||
1838 | |||
1647 | impl<'a> MatchExpr<'a> { | 1839 | impl<'a> MatchExpr<'a> { |
1648 | pub fn expr(self) -> Option<Expr<'a>> { | 1840 | pub fn expr(self) -> Option<Expr<'a>> { |
1649 | super::child_opt(self) | 1841 | super::child_opt(self) |
@@ -1655,25 +1847,18 @@ impl<'a> MatchExpr<'a> { | |||
1655 | } | 1847 | } |
1656 | 1848 | ||
1657 | // MatchGuard | 1849 | // MatchGuard |
1658 | 1850 | #[derive(Debug, Clone, Copy,)] | |
1659 | #[derive(Debug, Clone)] | 1851 | pub struct MatchGuardNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1660 | pub struct MatchGuardNode(SyntaxNode); | 1852 | pub(crate) syntax: SyntaxNode<R>, |
1661 | |||
1662 | impl MatchGuardNode { | ||
1663 | pub fn ast(&self) -> MatchGuard { | ||
1664 | MatchGuard::cast(self.0.borrowed()).unwrap() | ||
1665 | } | ||
1666 | } | 1853 | } |
1854 | pub type MatchGuard<'a> = MatchGuardNode<RefRoot<'a>>; | ||
1667 | 1855 | ||
1668 | impl<'a> From<MatchGuard<'a>> for MatchGuardNode { | 1856 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<MatchGuardNode<R1>> for MatchGuardNode<R2> { |
1669 | fn from(ast: MatchGuard<'a>) -> MatchGuardNode { | 1857 | fn eq(&self, other: &MatchGuardNode<R1>) -> bool { self.syntax == other.syntax } |
1670 | let syntax = ast.syntax().owned(); | ||
1671 | MatchGuardNode(syntax) | ||
1672 | } | ||
1673 | } | 1858 | } |
1674 | #[derive(Debug, Clone, Copy)] | 1859 | impl<R: TreeRoot<RaTypes>> Eq for MatchGuardNode<R> {} |
1675 | pub struct MatchGuard<'a> { | 1860 | impl<R: TreeRoot<RaTypes>> Hash for MatchGuardNode<R> { |
1676 | syntax: SyntaxNodeRef<'a>, | 1861 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
1677 | } | 1862 | } |
1678 | 1863 | ||
1679 | impl<'a> AstNode<'a> for MatchGuard<'a> { | 1864 | impl<'a> AstNode<'a> for MatchGuard<'a> { |
@@ -1686,28 +1871,31 @@ impl<'a> AstNode<'a> for MatchGuard<'a> { | |||
1686 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1871 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
1687 | } | 1872 | } |
1688 | 1873 | ||
1689 | impl<'a> MatchGuard<'a> {} | 1874 | impl<R: TreeRoot<RaTypes>> MatchGuardNode<R> { |
1875 | pub fn borrowed(&self) -> MatchGuard { | ||
1876 | MatchGuardNode { syntax: self.syntax.borrowed() } | ||
1877 | } | ||
1878 | pub fn owned(&self) -> MatchGuardNode { | ||
1879 | MatchGuardNode { syntax: self.syntax.owned() } | ||
1880 | } | ||
1881 | } | ||
1690 | 1882 | ||
1691 | // MethodCallExpr | ||
1692 | 1883 | ||
1693 | #[derive(Debug, Clone)] | 1884 | impl<'a> MatchGuard<'a> {} |
1694 | pub struct MethodCallExprNode(SyntaxNode); | ||
1695 | 1885 | ||
1696 | impl MethodCallExprNode { | 1886 | // MethodCallExpr |
1697 | pub fn ast(&self) -> MethodCallExpr { | 1887 | #[derive(Debug, Clone, Copy,)] |
1698 | MethodCallExpr::cast(self.0.borrowed()).unwrap() | 1888 | pub struct MethodCallExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1699 | } | 1889 | pub(crate) syntax: SyntaxNode<R>, |
1700 | } | 1890 | } |
1891 | pub type MethodCallExpr<'a> = MethodCallExprNode<RefRoot<'a>>; | ||
1701 | 1892 | ||
1702 | impl<'a> From<MethodCallExpr<'a>> for MethodCallExprNode { | 1893 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<MethodCallExprNode<R1>> for MethodCallExprNode<R2> { |
1703 | fn from(ast: MethodCallExpr<'a>) -> MethodCallExprNode { | 1894 | fn eq(&self, other: &MethodCallExprNode<R1>) -> bool { self.syntax == other.syntax } |
1704 | let syntax = ast.syntax().owned(); | ||
1705 | MethodCallExprNode(syntax) | ||
1706 | } | ||
1707 | } | 1895 | } |
1708 | #[derive(Debug, Clone, Copy)] | 1896 | impl<R: TreeRoot<RaTypes>> Eq for MethodCallExprNode<R> {} |
1709 | pub struct MethodCallExpr<'a> { | 1897 | impl<R: TreeRoot<RaTypes>> Hash for MethodCallExprNode<R> { |
1710 | syntax: SyntaxNodeRef<'a>, | 1898 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
1711 | } | 1899 | } |
1712 | 1900 | ||
1713 | impl<'a> AstNode<'a> for MethodCallExpr<'a> { | 1901 | impl<'a> AstNode<'a> for MethodCallExpr<'a> { |
@@ -1720,6 +1908,16 @@ impl<'a> AstNode<'a> for MethodCallExpr<'a> { | |||
1720 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1908 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
1721 | } | 1909 | } |
1722 | 1910 | ||
1911 | impl<R: TreeRoot<RaTypes>> MethodCallExprNode<R> { | ||
1912 | pub fn borrowed(&self) -> MethodCallExpr { | ||
1913 | MethodCallExprNode { syntax: self.syntax.borrowed() } | ||
1914 | } | ||
1915 | pub fn owned(&self) -> MethodCallExprNode { | ||
1916 | MethodCallExprNode { syntax: self.syntax.owned() } | ||
1917 | } | ||
1918 | } | ||
1919 | |||
1920 | |||
1723 | impl<'a> ast::ArgListOwner<'a> for MethodCallExpr<'a> {} | 1921 | impl<'a> ast::ArgListOwner<'a> for MethodCallExpr<'a> {} |
1724 | impl<'a> MethodCallExpr<'a> { | 1922 | impl<'a> MethodCallExpr<'a> { |
1725 | pub fn expr(self) -> Option<Expr<'a>> { | 1923 | pub fn expr(self) -> Option<Expr<'a>> { |
@@ -1728,25 +1926,18 @@ impl<'a> MethodCallExpr<'a> { | |||
1728 | } | 1926 | } |
1729 | 1927 | ||
1730 | // Module | 1928 | // Module |
1731 | 1929 | #[derive(Debug, Clone, Copy,)] | |
1732 | #[derive(Debug, Clone)] | 1930 | pub struct ModuleNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1733 | pub struct ModuleNode(SyntaxNode); | 1931 | pub(crate) syntax: SyntaxNode<R>, |
1734 | |||
1735 | impl ModuleNode { | ||
1736 | pub fn ast(&self) -> Module { | ||
1737 | Module::cast(self.0.borrowed()).unwrap() | ||
1738 | } | ||
1739 | } | 1932 | } |
1933 | pub type Module<'a> = ModuleNode<RefRoot<'a>>; | ||
1740 | 1934 | ||
1741 | impl<'a> From<Module<'a>> for ModuleNode { | 1935 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ModuleNode<R1>> for ModuleNode<R2> { |
1742 | fn from(ast: Module<'a>) -> ModuleNode { | 1936 | fn eq(&self, other: &ModuleNode<R1>) -> bool { self.syntax == other.syntax } |
1743 | let syntax = ast.syntax().owned(); | ||
1744 | ModuleNode(syntax) | ||
1745 | } | ||
1746 | } | 1937 | } |
1747 | #[derive(Debug, Clone, Copy)] | 1938 | impl<R: TreeRoot<RaTypes>> Eq for ModuleNode<R> {} |
1748 | pub struct Module<'a> { | 1939 | impl<R: TreeRoot<RaTypes>> Hash for ModuleNode<R> { |
1749 | syntax: SyntaxNodeRef<'a>, | 1940 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
1750 | } | 1941 | } |
1751 | 1942 | ||
1752 | impl<'a> AstNode<'a> for Module<'a> { | 1943 | impl<'a> AstNode<'a> for Module<'a> { |
@@ -1759,8 +1950,19 @@ impl<'a> AstNode<'a> for Module<'a> { | |||
1759 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1950 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
1760 | } | 1951 | } |
1761 | 1952 | ||
1953 | impl<R: TreeRoot<RaTypes>> ModuleNode<R> { | ||
1954 | pub fn borrowed(&self) -> Module { | ||
1955 | ModuleNode { syntax: self.syntax.borrowed() } | ||
1956 | } | ||
1957 | pub fn owned(&self) -> ModuleNode { | ||
1958 | ModuleNode { syntax: self.syntax.owned() } | ||
1959 | } | ||
1960 | } | ||
1961 | |||
1962 | |||
1762 | impl<'a> ast::NameOwner<'a> for Module<'a> {} | 1963 | impl<'a> ast::NameOwner<'a> for Module<'a> {} |
1763 | impl<'a> ast::AttrsOwner<'a> for Module<'a> {} | 1964 | impl<'a> ast::AttrsOwner<'a> for Module<'a> {} |
1965 | impl<'a> ast::DocCommentsOwner<'a> for Module<'a> {} | ||
1764 | impl<'a> Module<'a> { | 1966 | impl<'a> Module<'a> { |
1765 | pub fn item_list(self) -> Option<ItemList<'a>> { | 1967 | pub fn item_list(self) -> Option<ItemList<'a>> { |
1766 | super::child_opt(self) | 1968 | super::child_opt(self) |
@@ -1768,23 +1970,7 @@ impl<'a> Module<'a> { | |||
1768 | } | 1970 | } |
1769 | 1971 | ||
1770 | // ModuleItem | 1972 | // ModuleItem |
1771 | 1973 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | |
1772 | #[derive(Debug, Clone)] | ||
1773 | pub struct ModuleItemNode(SyntaxNode); | ||
1774 | |||
1775 | impl ModuleItemNode { | ||
1776 | pub fn ast(&self) -> ModuleItem { | ||
1777 | ModuleItem::cast(self.0.borrowed()).unwrap() | ||
1778 | } | ||
1779 | } | ||
1780 | |||
1781 | impl<'a> From<ModuleItem<'a>> for ModuleItemNode { | ||
1782 | fn from(ast: ModuleItem<'a>) -> ModuleItemNode { | ||
1783 | let syntax = ast.syntax().owned(); | ||
1784 | ModuleItemNode(syntax) | ||
1785 | } | ||
1786 | } | ||
1787 | #[derive(Debug, Clone, Copy)] | ||
1788 | pub enum ModuleItem<'a> { | 1974 | pub enum ModuleItem<'a> { |
1789 | StructDef(StructDef<'a>), | 1975 | StructDef(StructDef<'a>), |
1790 | EnumDef(EnumDef<'a>), | 1976 | EnumDef(EnumDef<'a>), |
@@ -1836,25 +2022,18 @@ impl<'a> AstNode<'a> for ModuleItem<'a> { | |||
1836 | impl<'a> ModuleItem<'a> {} | 2022 | impl<'a> ModuleItem<'a> {} |
1837 | 2023 | ||
1838 | // Name | 2024 | // Name |
1839 | 2025 | #[derive(Debug, Clone, Copy,)] | |
1840 | #[derive(Debug, Clone)] | 2026 | pub struct NameNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1841 | pub struct NameNode(SyntaxNode); | 2027 | pub(crate) syntax: SyntaxNode<R>, |
1842 | |||
1843 | impl NameNode { | ||
1844 | pub fn ast(&self) -> Name { | ||
1845 | Name::cast(self.0.borrowed()).unwrap() | ||
1846 | } | ||
1847 | } | 2028 | } |
2029 | pub type Name<'a> = NameNode<RefRoot<'a>>; | ||
1848 | 2030 | ||
1849 | impl<'a> From<Name<'a>> for NameNode { | 2031 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NameNode<R1>> for NameNode<R2> { |
1850 | fn from(ast: Name<'a>) -> NameNode { | 2032 | fn eq(&self, other: &NameNode<R1>) -> bool { self.syntax == other.syntax } |
1851 | let syntax = ast.syntax().owned(); | ||
1852 | NameNode(syntax) | ||
1853 | } | ||
1854 | } | 2033 | } |
1855 | #[derive(Debug, Clone, Copy)] | 2034 | impl<R: TreeRoot<RaTypes>> Eq for NameNode<R> {} |
1856 | pub struct Name<'a> { | 2035 | impl<R: TreeRoot<RaTypes>> Hash for NameNode<R> { |
1857 | syntax: SyntaxNodeRef<'a>, | 2036 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
1858 | } | 2037 | } |
1859 | 2038 | ||
1860 | impl<'a> AstNode<'a> for Name<'a> { | 2039 | impl<'a> AstNode<'a> for Name<'a> { |
@@ -1867,28 +2046,31 @@ impl<'a> AstNode<'a> for Name<'a> { | |||
1867 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2046 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
1868 | } | 2047 | } |
1869 | 2048 | ||
1870 | impl<'a> Name<'a> {} | 2049 | impl<R: TreeRoot<RaTypes>> NameNode<R> { |
2050 | pub fn borrowed(&self) -> Name { | ||
2051 | NameNode { syntax: self.syntax.borrowed() } | ||
2052 | } | ||
2053 | pub fn owned(&self) -> NameNode { | ||
2054 | NameNode { syntax: self.syntax.owned() } | ||
2055 | } | ||
2056 | } | ||
1871 | 2057 | ||
1872 | // NameRef | ||
1873 | 2058 | ||
1874 | #[derive(Debug, Clone)] | 2059 | impl<'a> Name<'a> {} |
1875 | pub struct NameRefNode(SyntaxNode); | ||
1876 | 2060 | ||
1877 | impl NameRefNode { | 2061 | // NameRef |
1878 | pub fn ast(&self) -> NameRef { | 2062 | #[derive(Debug, Clone, Copy,)] |
1879 | NameRef::cast(self.0.borrowed()).unwrap() | 2063 | pub struct NameRefNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1880 | } | 2064 | pub(crate) syntax: SyntaxNode<R>, |
1881 | } | 2065 | } |
2066 | pub type NameRef<'a> = NameRefNode<RefRoot<'a>>; | ||
1882 | 2067 | ||
1883 | impl<'a> From<NameRef<'a>> for NameRefNode { | 2068 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NameRefNode<R1>> for NameRefNode<R2> { |
1884 | fn from(ast: NameRef<'a>) -> NameRefNode { | 2069 | fn eq(&self, other: &NameRefNode<R1>) -> bool { self.syntax == other.syntax } |
1885 | let syntax = ast.syntax().owned(); | ||
1886 | NameRefNode(syntax) | ||
1887 | } | ||
1888 | } | 2070 | } |
1889 | #[derive(Debug, Clone, Copy)] | 2071 | impl<R: TreeRoot<RaTypes>> Eq for NameRefNode<R> {} |
1890 | pub struct NameRef<'a> { | 2072 | impl<R: TreeRoot<RaTypes>> Hash for NameRefNode<R> { |
1891 | syntax: SyntaxNodeRef<'a>, | 2073 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
1892 | } | 2074 | } |
1893 | 2075 | ||
1894 | impl<'a> AstNode<'a> for NameRef<'a> { | 2076 | impl<'a> AstNode<'a> for NameRef<'a> { |
@@ -1901,28 +2083,31 @@ impl<'a> AstNode<'a> for NameRef<'a> { | |||
1901 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2083 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
1902 | } | 2084 | } |
1903 | 2085 | ||
1904 | impl<'a> NameRef<'a> {} | 2086 | impl<R: TreeRoot<RaTypes>> NameRefNode<R> { |
2087 | pub fn borrowed(&self) -> NameRef { | ||
2088 | NameRefNode { syntax: self.syntax.borrowed() } | ||
2089 | } | ||
2090 | pub fn owned(&self) -> NameRefNode { | ||
2091 | NameRefNode { syntax: self.syntax.owned() } | ||
2092 | } | ||
2093 | } | ||
1905 | 2094 | ||
1906 | // NamedField | ||
1907 | 2095 | ||
1908 | #[derive(Debug, Clone)] | 2096 | impl<'a> NameRef<'a> {} |
1909 | pub struct NamedFieldNode(SyntaxNode); | ||
1910 | 2097 | ||
1911 | impl NamedFieldNode { | 2098 | // NamedField |
1912 | pub fn ast(&self) -> NamedField { | 2099 | #[derive(Debug, Clone, Copy,)] |
1913 | NamedField::cast(self.0.borrowed()).unwrap() | 2100 | pub struct NamedFieldNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1914 | } | 2101 | pub(crate) syntax: SyntaxNode<R>, |
1915 | } | 2102 | } |
2103 | pub type NamedField<'a> = NamedFieldNode<RefRoot<'a>>; | ||
1916 | 2104 | ||
1917 | impl<'a> From<NamedField<'a>> for NamedFieldNode { | 2105 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NamedFieldNode<R1>> for NamedFieldNode<R2> { |
1918 | fn from(ast: NamedField<'a>) -> NamedFieldNode { | 2106 | fn eq(&self, other: &NamedFieldNode<R1>) -> bool { self.syntax == other.syntax } |
1919 | let syntax = ast.syntax().owned(); | ||
1920 | NamedFieldNode(syntax) | ||
1921 | } | ||
1922 | } | 2107 | } |
1923 | #[derive(Debug, Clone, Copy)] | 2108 | impl<R: TreeRoot<RaTypes>> Eq for NamedFieldNode<R> {} |
1924 | pub struct NamedField<'a> { | 2109 | impl<R: TreeRoot<RaTypes>> Hash for NamedFieldNode<R> { |
1925 | syntax: SyntaxNodeRef<'a>, | 2110 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
1926 | } | 2111 | } |
1927 | 2112 | ||
1928 | impl<'a> AstNode<'a> for NamedField<'a> { | 2113 | impl<'a> AstNode<'a> for NamedField<'a> { |
@@ -1935,28 +2120,31 @@ impl<'a> AstNode<'a> for NamedField<'a> { | |||
1935 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2120 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
1936 | } | 2121 | } |
1937 | 2122 | ||
1938 | impl<'a> NamedField<'a> {} | 2123 | impl<R: TreeRoot<RaTypes>> NamedFieldNode<R> { |
2124 | pub fn borrowed(&self) -> NamedField { | ||
2125 | NamedFieldNode { syntax: self.syntax.borrowed() } | ||
2126 | } | ||
2127 | pub fn owned(&self) -> NamedFieldNode { | ||
2128 | NamedFieldNode { syntax: self.syntax.owned() } | ||
2129 | } | ||
2130 | } | ||
1939 | 2131 | ||
1940 | // NamedFieldDef | ||
1941 | 2132 | ||
1942 | #[derive(Debug, Clone)] | 2133 | impl<'a> NamedField<'a> {} |
1943 | pub struct NamedFieldDefNode(SyntaxNode); | ||
1944 | 2134 | ||
1945 | impl NamedFieldDefNode { | 2135 | // NamedFieldDef |
1946 | pub fn ast(&self) -> NamedFieldDef { | 2136 | #[derive(Debug, Clone, Copy,)] |
1947 | NamedFieldDef::cast(self.0.borrowed()).unwrap() | 2137 | pub struct NamedFieldDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1948 | } | 2138 | pub(crate) syntax: SyntaxNode<R>, |
1949 | } | 2139 | } |
2140 | pub type NamedFieldDef<'a> = NamedFieldDefNode<RefRoot<'a>>; | ||
1950 | 2141 | ||
1951 | impl<'a> From<NamedFieldDef<'a>> for NamedFieldDefNode { | 2142 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NamedFieldDefNode<R1>> for NamedFieldDefNode<R2> { |
1952 | fn from(ast: NamedFieldDef<'a>) -> NamedFieldDefNode { | 2143 | fn eq(&self, other: &NamedFieldDefNode<R1>) -> bool { self.syntax == other.syntax } |
1953 | let syntax = ast.syntax().owned(); | ||
1954 | NamedFieldDefNode(syntax) | ||
1955 | } | ||
1956 | } | 2144 | } |
1957 | #[derive(Debug, Clone, Copy)] | 2145 | impl<R: TreeRoot<RaTypes>> Eq for NamedFieldDefNode<R> {} |
1958 | pub struct NamedFieldDef<'a> { | 2146 | impl<R: TreeRoot<RaTypes>> Hash for NamedFieldDefNode<R> { |
1959 | syntax: SyntaxNodeRef<'a>, | 2147 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
1960 | } | 2148 | } |
1961 | 2149 | ||
1962 | impl<'a> AstNode<'a> for NamedFieldDef<'a> { | 2150 | impl<'a> AstNode<'a> for NamedFieldDef<'a> { |
@@ -1969,30 +2157,33 @@ impl<'a> AstNode<'a> for NamedFieldDef<'a> { | |||
1969 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2157 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
1970 | } | 2158 | } |
1971 | 2159 | ||
2160 | impl<R: TreeRoot<RaTypes>> NamedFieldDefNode<R> { | ||
2161 | pub fn borrowed(&self) -> NamedFieldDef { | ||
2162 | NamedFieldDefNode { syntax: self.syntax.borrowed() } | ||
2163 | } | ||
2164 | pub fn owned(&self) -> NamedFieldDefNode { | ||
2165 | NamedFieldDefNode { syntax: self.syntax.owned() } | ||
2166 | } | ||
2167 | } | ||
2168 | |||
2169 | |||
1972 | impl<'a> ast::NameOwner<'a> for NamedFieldDef<'a> {} | 2170 | impl<'a> ast::NameOwner<'a> for NamedFieldDef<'a> {} |
1973 | impl<'a> ast::AttrsOwner<'a> for NamedFieldDef<'a> {} | 2171 | impl<'a> ast::AttrsOwner<'a> for NamedFieldDef<'a> {} |
1974 | impl<'a> NamedFieldDef<'a> {} | 2172 | impl<'a> NamedFieldDef<'a> {} |
1975 | 2173 | ||
1976 | // NamedFieldList | 2174 | // NamedFieldList |
1977 | 2175 | #[derive(Debug, Clone, Copy,)] | |
1978 | #[derive(Debug, Clone)] | 2176 | pub struct NamedFieldListNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1979 | pub struct NamedFieldListNode(SyntaxNode); | 2177 | pub(crate) syntax: SyntaxNode<R>, |
1980 | |||
1981 | impl NamedFieldListNode { | ||
1982 | pub fn ast(&self) -> NamedFieldList { | ||
1983 | NamedFieldList::cast(self.0.borrowed()).unwrap() | ||
1984 | } | ||
1985 | } | 2178 | } |
2179 | pub type NamedFieldList<'a> = NamedFieldListNode<RefRoot<'a>>; | ||
1986 | 2180 | ||
1987 | impl<'a> From<NamedFieldList<'a>> for NamedFieldListNode { | 2181 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NamedFieldListNode<R1>> for NamedFieldListNode<R2> { |
1988 | fn from(ast: NamedFieldList<'a>) -> NamedFieldListNode { | 2182 | fn eq(&self, other: &NamedFieldListNode<R1>) -> bool { self.syntax == other.syntax } |
1989 | let syntax = ast.syntax().owned(); | ||
1990 | NamedFieldListNode(syntax) | ||
1991 | } | ||
1992 | } | 2183 | } |
1993 | #[derive(Debug, Clone, Copy)] | 2184 | impl<R: TreeRoot<RaTypes>> Eq for NamedFieldListNode<R> {} |
1994 | pub struct NamedFieldList<'a> { | 2185 | impl<R: TreeRoot<RaTypes>> Hash for NamedFieldListNode<R> { |
1995 | syntax: SyntaxNodeRef<'a>, | 2186 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
1996 | } | 2187 | } |
1997 | 2188 | ||
1998 | impl<'a> AstNode<'a> for NamedFieldList<'a> { | 2189 | impl<'a> AstNode<'a> for NamedFieldList<'a> { |
@@ -2005,28 +2196,31 @@ impl<'a> AstNode<'a> for NamedFieldList<'a> { | |||
2005 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2196 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
2006 | } | 2197 | } |
2007 | 2198 | ||
2008 | impl<'a> NamedFieldList<'a> {} | 2199 | impl<R: TreeRoot<RaTypes>> NamedFieldListNode<R> { |
2200 | pub fn borrowed(&self) -> NamedFieldList { | ||
2201 | NamedFieldListNode { syntax: self.syntax.borrowed() } | ||
2202 | } | ||
2203 | pub fn owned(&self) -> NamedFieldListNode { | ||
2204 | NamedFieldListNode { syntax: self.syntax.owned() } | ||
2205 | } | ||
2206 | } | ||
2009 | 2207 | ||
2010 | // NeverType | ||
2011 | 2208 | ||
2012 | #[derive(Debug, Clone)] | 2209 | impl<'a> NamedFieldList<'a> {} |
2013 | pub struct NeverTypeNode(SyntaxNode); | ||
2014 | 2210 | ||
2015 | impl NeverTypeNode { | 2211 | // NeverType |
2016 | pub fn ast(&self) -> NeverType { | 2212 | #[derive(Debug, Clone, Copy,)] |
2017 | NeverType::cast(self.0.borrowed()).unwrap() | 2213 | pub struct NeverTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2018 | } | 2214 | pub(crate) syntax: SyntaxNode<R>, |
2019 | } | 2215 | } |
2216 | pub type NeverType<'a> = NeverTypeNode<RefRoot<'a>>; | ||
2020 | 2217 | ||
2021 | impl<'a> From<NeverType<'a>> for NeverTypeNode { | 2218 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NeverTypeNode<R1>> for NeverTypeNode<R2> { |
2022 | fn from(ast: NeverType<'a>) -> NeverTypeNode { | 2219 | fn eq(&self, other: &NeverTypeNode<R1>) -> bool { self.syntax == other.syntax } |
2023 | let syntax = ast.syntax().owned(); | ||
2024 | NeverTypeNode(syntax) | ||
2025 | } | ||
2026 | } | 2220 | } |
2027 | #[derive(Debug, Clone, Copy)] | 2221 | impl<R: TreeRoot<RaTypes>> Eq for NeverTypeNode<R> {} |
2028 | pub struct NeverType<'a> { | 2222 | impl<R: TreeRoot<RaTypes>> Hash for NeverTypeNode<R> { |
2029 | syntax: SyntaxNodeRef<'a>, | 2223 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
2030 | } | 2224 | } |
2031 | 2225 | ||
2032 | impl<'a> AstNode<'a> for NeverType<'a> { | 2226 | impl<'a> AstNode<'a> for NeverType<'a> { |
@@ -2039,26 +2233,20 @@ impl<'a> AstNode<'a> for NeverType<'a> { | |||
2039 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2233 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
2040 | } | 2234 | } |
2041 | 2235 | ||
2042 | impl<'a> NeverType<'a> {} | 2236 | impl<R: TreeRoot<RaTypes>> NeverTypeNode<R> { |
2043 | 2237 | pub fn borrowed(&self) -> NeverType { | |
2044 | // NominalDef | 2238 | NeverTypeNode { syntax: self.syntax.borrowed() } |
2045 | |||
2046 | #[derive(Debug, Clone)] | ||
2047 | pub struct NominalDefNode(SyntaxNode); | ||
2048 | |||
2049 | impl NominalDefNode { | ||
2050 | pub fn ast(&self) -> NominalDef { | ||
2051 | NominalDef::cast(self.0.borrowed()).unwrap() | ||
2052 | } | 2239 | } |
2053 | } | 2240 | pub fn owned(&self) -> NeverTypeNode { |
2054 | 2241 | NeverTypeNode { syntax: self.syntax.owned() } | |
2055 | impl<'a> From<NominalDef<'a>> for NominalDefNode { | ||
2056 | fn from(ast: NominalDef<'a>) -> NominalDefNode { | ||
2057 | let syntax = ast.syntax().owned(); | ||
2058 | NominalDefNode(syntax) | ||
2059 | } | 2242 | } |
2060 | } | 2243 | } |
2061 | #[derive(Debug, Clone, Copy)] | 2244 | |
2245 | |||
2246 | impl<'a> NeverType<'a> {} | ||
2247 | |||
2248 | // NominalDef | ||
2249 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
2062 | pub enum NominalDef<'a> { | 2250 | pub enum NominalDef<'a> { |
2063 | StructDef(StructDef<'a>), | 2251 | StructDef(StructDef<'a>), |
2064 | EnumDef(EnumDef<'a>), | 2252 | EnumDef(EnumDef<'a>), |
@@ -2086,25 +2274,18 @@ impl<'a> ast::AttrsOwner<'a> for NominalDef<'a> {} | |||
2086 | impl<'a> NominalDef<'a> {} | 2274 | impl<'a> NominalDef<'a> {} |
2087 | 2275 | ||
2088 | // Param | 2276 | // Param |
2089 | 2277 | #[derive(Debug, Clone, Copy,)] | |
2090 | #[derive(Debug, Clone)] | 2278 | pub struct ParamNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2091 | pub struct ParamNode(SyntaxNode); | 2279 | pub(crate) syntax: SyntaxNode<R>, |
2092 | |||
2093 | impl ParamNode { | ||
2094 | pub fn ast(&self) -> Param { | ||
2095 | Param::cast(self.0.borrowed()).unwrap() | ||
2096 | } | ||
2097 | } | 2280 | } |
2281 | pub type Param<'a> = ParamNode<RefRoot<'a>>; | ||
2098 | 2282 | ||
2099 | impl<'a> From<Param<'a>> for ParamNode { | 2283 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ParamNode<R1>> for ParamNode<R2> { |
2100 | fn from(ast: Param<'a>) -> ParamNode { | 2284 | fn eq(&self, other: &ParamNode<R1>) -> bool { self.syntax == other.syntax } |
2101 | let syntax = ast.syntax().owned(); | ||
2102 | ParamNode(syntax) | ||
2103 | } | ||
2104 | } | 2285 | } |
2105 | #[derive(Debug, Clone, Copy)] | 2286 | impl<R: TreeRoot<RaTypes>> Eq for ParamNode<R> {} |
2106 | pub struct Param<'a> { | 2287 | impl<R: TreeRoot<RaTypes>> Hash for ParamNode<R> { |
2107 | syntax: SyntaxNodeRef<'a>, | 2288 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
2108 | } | 2289 | } |
2109 | 2290 | ||
2110 | impl<'a> AstNode<'a> for Param<'a> { | 2291 | impl<'a> AstNode<'a> for Param<'a> { |
@@ -2117,6 +2298,16 @@ impl<'a> AstNode<'a> for Param<'a> { | |||
2117 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2298 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
2118 | } | 2299 | } |
2119 | 2300 | ||
2301 | impl<R: TreeRoot<RaTypes>> ParamNode<R> { | ||
2302 | pub fn borrowed(&self) -> Param { | ||
2303 | ParamNode { syntax: self.syntax.borrowed() } | ||
2304 | } | ||
2305 | pub fn owned(&self) -> ParamNode { | ||
2306 | ParamNode { syntax: self.syntax.owned() } | ||
2307 | } | ||
2308 | } | ||
2309 | |||
2310 | |||
2120 | impl<'a> Param<'a> { | 2311 | impl<'a> Param<'a> { |
2121 | pub fn pat(self) -> Option<Pat<'a>> { | 2312 | pub fn pat(self) -> Option<Pat<'a>> { |
2122 | super::child_opt(self) | 2313 | super::child_opt(self) |
@@ -2124,25 +2315,18 @@ impl<'a> Param<'a> { | |||
2124 | } | 2315 | } |
2125 | 2316 | ||
2126 | // ParamList | 2317 | // ParamList |
2127 | 2318 | #[derive(Debug, Clone, Copy,)] | |
2128 | #[derive(Debug, Clone)] | 2319 | pub struct ParamListNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2129 | pub struct ParamListNode(SyntaxNode); | 2320 | pub(crate) syntax: SyntaxNode<R>, |
2130 | |||
2131 | impl ParamListNode { | ||
2132 | pub fn ast(&self) -> ParamList { | ||
2133 | ParamList::cast(self.0.borrowed()).unwrap() | ||
2134 | } | ||
2135 | } | 2321 | } |
2322 | pub type ParamList<'a> = ParamListNode<RefRoot<'a>>; | ||
2136 | 2323 | ||
2137 | impl<'a> From<ParamList<'a>> for ParamListNode { | 2324 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ParamListNode<R1>> for ParamListNode<R2> { |
2138 | fn from(ast: ParamList<'a>) -> ParamListNode { | 2325 | fn eq(&self, other: &ParamListNode<R1>) -> bool { self.syntax == other.syntax } |
2139 | let syntax = ast.syntax().owned(); | ||
2140 | ParamListNode(syntax) | ||
2141 | } | ||
2142 | } | 2326 | } |
2143 | #[derive(Debug, Clone, Copy)] | 2327 | impl<R: TreeRoot<RaTypes>> Eq for ParamListNode<R> {} |
2144 | pub struct ParamList<'a> { | 2328 | impl<R: TreeRoot<RaTypes>> Hash for ParamListNode<R> { |
2145 | syntax: SyntaxNodeRef<'a>, | 2329 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
2146 | } | 2330 | } |
2147 | 2331 | ||
2148 | impl<'a> AstNode<'a> for ParamList<'a> { | 2332 | impl<'a> AstNode<'a> for ParamList<'a> { |
@@ -2155,6 +2339,16 @@ impl<'a> AstNode<'a> for ParamList<'a> { | |||
2155 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2339 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
2156 | } | 2340 | } |
2157 | 2341 | ||
2342 | impl<R: TreeRoot<RaTypes>> ParamListNode<R> { | ||
2343 | pub fn borrowed(&self) -> ParamList { | ||
2344 | ParamListNode { syntax: self.syntax.borrowed() } | ||
2345 | } | ||
2346 | pub fn owned(&self) -> ParamListNode { | ||
2347 | ParamListNode { syntax: self.syntax.owned() } | ||
2348 | } | ||
2349 | } | ||
2350 | |||
2351 | |||
2158 | impl<'a> ParamList<'a> { | 2352 | impl<'a> ParamList<'a> { |
2159 | pub fn params(self) -> impl Iterator<Item = Param<'a>> + 'a { | 2353 | pub fn params(self) -> impl Iterator<Item = Param<'a>> + 'a { |
2160 | super::children(self) | 2354 | super::children(self) |
@@ -2166,25 +2360,18 @@ impl<'a> ParamList<'a> { | |||
2166 | } | 2360 | } |
2167 | 2361 | ||
2168 | // ParenExpr | 2362 | // ParenExpr |
2169 | 2363 | #[derive(Debug, Clone, Copy,)] | |
2170 | #[derive(Debug, Clone)] | 2364 | pub struct ParenExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2171 | pub struct ParenExprNode(SyntaxNode); | 2365 | pub(crate) syntax: SyntaxNode<R>, |
2172 | |||
2173 | impl ParenExprNode { | ||
2174 | pub fn ast(&self) -> ParenExpr { | ||
2175 | ParenExpr::cast(self.0.borrowed()).unwrap() | ||
2176 | } | ||
2177 | } | 2366 | } |
2367 | pub type ParenExpr<'a> = ParenExprNode<RefRoot<'a>>; | ||
2178 | 2368 | ||
2179 | impl<'a> From<ParenExpr<'a>> for ParenExprNode { | 2369 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ParenExprNode<R1>> for ParenExprNode<R2> { |
2180 | fn from(ast: ParenExpr<'a>) -> ParenExprNode { | 2370 | fn eq(&self, other: &ParenExprNode<R1>) -> bool { self.syntax == other.syntax } |
2181 | let syntax = ast.syntax().owned(); | ||
2182 | ParenExprNode(syntax) | ||
2183 | } | ||
2184 | } | 2371 | } |
2185 | #[derive(Debug, Clone, Copy)] | 2372 | impl<R: TreeRoot<RaTypes>> Eq for ParenExprNode<R> {} |
2186 | pub struct ParenExpr<'a> { | 2373 | impl<R: TreeRoot<RaTypes>> Hash for ParenExprNode<R> { |
2187 | syntax: SyntaxNodeRef<'a>, | 2374 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
2188 | } | 2375 | } |
2189 | 2376 | ||
2190 | impl<'a> AstNode<'a> for ParenExpr<'a> { | 2377 | impl<'a> AstNode<'a> for ParenExpr<'a> { |
@@ -2197,28 +2384,31 @@ impl<'a> AstNode<'a> for ParenExpr<'a> { | |||
2197 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2384 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
2198 | } | 2385 | } |
2199 | 2386 | ||
2200 | impl<'a> ParenExpr<'a> {} | 2387 | impl<R: TreeRoot<RaTypes>> ParenExprNode<R> { |
2388 | pub fn borrowed(&self) -> ParenExpr { | ||
2389 | ParenExprNode { syntax: self.syntax.borrowed() } | ||
2390 | } | ||
2391 | pub fn owned(&self) -> ParenExprNode { | ||
2392 | ParenExprNode { syntax: self.syntax.owned() } | ||
2393 | } | ||
2394 | } | ||
2201 | 2395 | ||
2202 | // ParenType | ||
2203 | 2396 | ||
2204 | #[derive(Debug, Clone)] | 2397 | impl<'a> ParenExpr<'a> {} |
2205 | pub struct ParenTypeNode(SyntaxNode); | ||
2206 | 2398 | ||
2207 | impl ParenTypeNode { | 2399 | // ParenType |
2208 | pub fn ast(&self) -> ParenType { | 2400 | #[derive(Debug, Clone, Copy,)] |
2209 | ParenType::cast(self.0.borrowed()).unwrap() | 2401 | pub struct ParenTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2210 | } | 2402 | pub(crate) syntax: SyntaxNode<R>, |
2211 | } | 2403 | } |
2404 | pub type ParenType<'a> = ParenTypeNode<RefRoot<'a>>; | ||
2212 | 2405 | ||
2213 | impl<'a> From<ParenType<'a>> for ParenTypeNode { | 2406 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ParenTypeNode<R1>> for ParenTypeNode<R2> { |
2214 | fn from(ast: ParenType<'a>) -> ParenTypeNode { | 2407 | fn eq(&self, other: &ParenTypeNode<R1>) -> bool { self.syntax == other.syntax } |
2215 | let syntax = ast.syntax().owned(); | ||
2216 | ParenTypeNode(syntax) | ||
2217 | } | ||
2218 | } | 2408 | } |
2219 | #[derive(Debug, Clone, Copy)] | 2409 | impl<R: TreeRoot<RaTypes>> Eq for ParenTypeNode<R> {} |
2220 | pub struct ParenType<'a> { | 2410 | impl<R: TreeRoot<RaTypes>> Hash for ParenTypeNode<R> { |
2221 | syntax: SyntaxNodeRef<'a>, | 2411 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
2222 | } | 2412 | } |
2223 | 2413 | ||
2224 | impl<'a> AstNode<'a> for ParenType<'a> { | 2414 | impl<'a> AstNode<'a> for ParenType<'a> { |
@@ -2231,26 +2421,20 @@ impl<'a> AstNode<'a> for ParenType<'a> { | |||
2231 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2421 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
2232 | } | 2422 | } |
2233 | 2423 | ||
2234 | impl<'a> ParenType<'a> {} | 2424 | impl<R: TreeRoot<RaTypes>> ParenTypeNode<R> { |
2235 | 2425 | pub fn borrowed(&self) -> ParenType { | |
2236 | // Pat | 2426 | ParenTypeNode { syntax: self.syntax.borrowed() } |
2237 | |||
2238 | #[derive(Debug, Clone)] | ||
2239 | pub struct PatNode(SyntaxNode); | ||
2240 | |||
2241 | impl PatNode { | ||
2242 | pub fn ast(&self) -> Pat { | ||
2243 | Pat::cast(self.0.borrowed()).unwrap() | ||
2244 | } | 2427 | } |
2245 | } | 2428 | pub fn owned(&self) -> ParenTypeNode { |
2246 | 2429 | ParenTypeNode { syntax: self.syntax.owned() } | |
2247 | impl<'a> From<Pat<'a>> for PatNode { | ||
2248 | fn from(ast: Pat<'a>) -> PatNode { | ||
2249 | let syntax = ast.syntax().owned(); | ||
2250 | PatNode(syntax) | ||
2251 | } | 2430 | } |
2252 | } | 2431 | } |
2253 | #[derive(Debug, Clone, Copy)] | 2432 | |
2433 | |||
2434 | impl<'a> ParenType<'a> {} | ||
2435 | |||
2436 | // Pat | ||
2437 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
2254 | pub enum Pat<'a> { | 2438 | pub enum Pat<'a> { |
2255 | RefPat(RefPat<'a>), | 2439 | RefPat(RefPat<'a>), |
2256 | BindPat(BindPat<'a>), | 2440 | BindPat(BindPat<'a>), |
@@ -2299,25 +2483,18 @@ impl<'a> AstNode<'a> for Pat<'a> { | |||
2299 | impl<'a> Pat<'a> {} | 2483 | impl<'a> Pat<'a> {} |
2300 | 2484 | ||
2301 | // Path | 2485 | // Path |
2302 | 2486 | #[derive(Debug, Clone, Copy,)] | |
2303 | #[derive(Debug, Clone)] | 2487 | pub struct PathNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2304 | pub struct PathNode(SyntaxNode); | 2488 | pub(crate) syntax: SyntaxNode<R>, |
2305 | |||
2306 | impl PathNode { | ||
2307 | pub fn ast(&self) -> Path { | ||
2308 | Path::cast(self.0.borrowed()).unwrap() | ||
2309 | } | ||
2310 | } | 2489 | } |
2490 | pub type Path<'a> = PathNode<RefRoot<'a>>; | ||
2311 | 2491 | ||
2312 | impl<'a> From<Path<'a>> for PathNode { | 2492 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PathNode<R1>> for PathNode<R2> { |
2313 | fn from(ast: Path<'a>) -> PathNode { | 2493 | fn eq(&self, other: &PathNode<R1>) -> bool { self.syntax == other.syntax } |
2314 | let syntax = ast.syntax().owned(); | ||
2315 | PathNode(syntax) | ||
2316 | } | ||
2317 | } | 2494 | } |
2318 | #[derive(Debug, Clone, Copy)] | 2495 | impl<R: TreeRoot<RaTypes>> Eq for PathNode<R> {} |
2319 | pub struct Path<'a> { | 2496 | impl<R: TreeRoot<RaTypes>> Hash for PathNode<R> { |
2320 | syntax: SyntaxNodeRef<'a>, | 2497 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
2321 | } | 2498 | } |
2322 | 2499 | ||
2323 | impl<'a> AstNode<'a> for Path<'a> { | 2500 | impl<'a> AstNode<'a> for Path<'a> { |
@@ -2330,6 +2507,16 @@ impl<'a> AstNode<'a> for Path<'a> { | |||
2330 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2507 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
2331 | } | 2508 | } |
2332 | 2509 | ||
2510 | impl<R: TreeRoot<RaTypes>> PathNode<R> { | ||
2511 | pub fn borrowed(&self) -> Path { | ||
2512 | PathNode { syntax: self.syntax.borrowed() } | ||
2513 | } | ||
2514 | pub fn owned(&self) -> PathNode { | ||
2515 | PathNode { syntax: self.syntax.owned() } | ||
2516 | } | ||
2517 | } | ||
2518 | |||
2519 | |||
2333 | impl<'a> Path<'a> { | 2520 | impl<'a> Path<'a> { |
2334 | pub fn segment(self) -> Option<PathSegment<'a>> { | 2521 | pub fn segment(self) -> Option<PathSegment<'a>> { |
2335 | super::child_opt(self) | 2522 | super::child_opt(self) |
@@ -2341,25 +2528,18 @@ impl<'a> Path<'a> { | |||
2341 | } | 2528 | } |
2342 | 2529 | ||
2343 | // PathExpr | 2530 | // PathExpr |
2344 | 2531 | #[derive(Debug, Clone, Copy,)] | |
2345 | #[derive(Debug, Clone)] | 2532 | pub struct PathExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2346 | pub struct PathExprNode(SyntaxNode); | 2533 | pub(crate) syntax: SyntaxNode<R>, |
2347 | |||
2348 | impl PathExprNode { | ||
2349 | pub fn ast(&self) -> PathExpr { | ||
2350 | PathExpr::cast(self.0.borrowed()).unwrap() | ||
2351 | } | ||
2352 | } | 2534 | } |
2535 | pub type PathExpr<'a> = PathExprNode<RefRoot<'a>>; | ||
2353 | 2536 | ||
2354 | impl<'a> From<PathExpr<'a>> for PathExprNode { | 2537 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PathExprNode<R1>> for PathExprNode<R2> { |
2355 | fn from(ast: PathExpr<'a>) -> PathExprNode { | 2538 | fn eq(&self, other: &PathExprNode<R1>) -> bool { self.syntax == other.syntax } |
2356 | let syntax = ast.syntax().owned(); | ||
2357 | PathExprNode(syntax) | ||
2358 | } | ||
2359 | } | 2539 | } |
2360 | #[derive(Debug, Clone, Copy)] | 2540 | impl<R: TreeRoot<RaTypes>> Eq for PathExprNode<R> {} |
2361 | pub struct PathExpr<'a> { | 2541 | impl<R: TreeRoot<RaTypes>> Hash for PathExprNode<R> { |
2362 | syntax: SyntaxNodeRef<'a>, | 2542 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } |
2363 | } | 2543 | } |
2364 | 2544 | ||
2365 | impl<'a> AstNode<'a> for PathExpr<'a> { | 2545 | impl<'a> AstNode<'a> for PathExpr<'a> { |
@@ -2372,6 +2552,16 @@ impl<'a> AstNode<'a> for PathExpr<'a> { | |||
2372 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 2552 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
2373 | } | 2553 | } |
2374 | 2554 | ||
2555 | impl<R: TreeRoot<RaTypes>> PathExprNode<R> { | ||
2556 | pub fn borrowed(&self) -> PathExpr { | ||
2557 | PathExprNode { syntax: self.syntax.borrowed() } | ||
2558 | } | ||
2559 | pub fn owned(&self) -> PathExprNode { | ||
2560 | PathExprNode { syntax: self.syntax.owned() } | ||
2561 | } | ||
2562 | } | ||
2563 | |||
2564 | |||
2375 | impl<'a> PathExpr<'a> { | 2565 | impl<'a> PathExpr<'a> { |
2376 | pub fn path(self) -> Option<Path<'a>> { | 2566 | pub fn path(self) -> Option<Path<'a>> { |
2377 | super::child_opt(self) | 2567 | super::child_opt(self) |
@@ -2379,25 +2569,18 @@ impl<'a> PathExpr<'a> { | |||
2379 | } | 2569 | } |
2380 | 2570 | ||
2381 | // PathPat | 2571 | // PathPat |
2382 | 2572 | #[derive(Debug, Clone, Copy,)] | |
2383 | #[derive(Debug, Clone)] | 2573 | pub struct PathPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2384 | pub struct PathPatNode(SyntaxNode); | 2574 | pub(crate) syntax: SyntaxNode<R>, |
2385 | |||
2386 | impl PathPatNode { | ||
2387 | pub fn ast(&self) -> PathPat { | ||
2388 | PathPat::cast(self.0.borrowed()).unwrap() | ||
2389 | } | ||
2390 | } | 2575 | } |
2576 | pub type PathPat<'a> = PathPatNode<RefRoot<'a>>; | ||
2391 | 2577 | ||
2392 | impl<'a> From<PathPat<'a>> for PathPatNode { | 2578 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PathPatNode<R1>> for PathPatNode<R2> { |
2393 | fn from(ast: PathPat<'a>) -> PathPatNode { | 2579 | fn eq(&self, other: &PathPatNode<R1>) -> bool { self.syntax == other.syntax } |
2394 | let syntax = ast.syntax().owned(); | ||
2395 | PathPatNode(syntax) | ||
2396 | } | ||
2397 | } | 2580 | } |
2398 | #[derive(Debug, Clone, Copy)] | 2581 | impl<R: TreeRoot<RaTypes>> Eq for PathPatNode<R> {} |
2399 | pub struct PathPat<'a> { |