diff options
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs | 2596 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs.tera | 101 | ||||
-rw-r--r-- | crates/ra_tools/src/codegen.rs | 3 |
3 files changed, 1410 insertions, 1290 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index f322e1d84..016668380 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -1,25 +1,14 @@ | |||
1 | // This file is automatically generated based on the file `./generated.rs.tera` when `cargo gen-syntax` is run | 1 | // Generated file, do not edit by hand, see `crate/ra_tools/src/codegen` |
2 | // Do not edit manually | ||
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 | |||
10 | #![cfg_attr(rustfmt, rustfmt_skip)] | ||
11 | 2 | ||
12 | use crate::{ | 3 | use crate::{ |
13 | SyntaxNode, SyntaxKind::{self, *}, | 4 | ast::{self, AstChildren, AstNode}, |
14 | ast::{self, AstNode}, | 5 | SyntaxKind::{self, *}, |
6 | SyntaxNode, | ||
15 | }; | 7 | }; |
16 | |||
17 | // Alias | ||
18 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 8 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
19 | pub struct Alias { | 9 | pub struct Alias { |
20 | pub(crate) syntax: SyntaxNode, | 10 | pub(crate) syntax: SyntaxNode, |
21 | } | 11 | } |
22 | |||
23 | impl AstNode for Alias { | 12 | impl AstNode for Alias { |
24 | fn can_cast(kind: SyntaxKind) -> bool { | 13 | fn can_cast(kind: SyntaxKind) -> bool { |
25 | match kind { | 14 | match kind { |
@@ -28,21 +17,22 @@ impl AstNode for Alias { | |||
28 | } | 17 | } |
29 | } | 18 | } |
30 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 19 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
31 | if Self::can_cast(syntax.kind()) { Some(Alias { syntax }) } else { None } | 20 | if Self::can_cast(syntax.kind()) { |
21 | Some(Self { syntax }) | ||
22 | } else { | ||
23 | None | ||
24 | } | ||
25 | } | ||
26 | fn syntax(&self) -> &SyntaxNode { | ||
27 | &self.syntax | ||
32 | } | 28 | } |
33 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
34 | } | 29 | } |
35 | |||
36 | |||
37 | impl ast::NameOwner for Alias {} | 30 | impl ast::NameOwner for Alias {} |
38 | impl Alias {} | 31 | impl Alias {} |
39 | |||
40 | // ArgList | ||
41 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 32 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
42 | pub struct ArgList { | 33 | pub struct ArgList { |
43 | pub(crate) syntax: SyntaxNode, | 34 | pub(crate) syntax: SyntaxNode, |
44 | } | 35 | } |
45 | |||
46 | impl AstNode for ArgList { | 36 | impl AstNode for ArgList { |
47 | fn can_cast(kind: SyntaxKind) -> bool { | 37 | fn can_cast(kind: SyntaxKind) -> bool { |
48 | match kind { | 38 | match kind { |
@@ -51,24 +41,25 @@ impl AstNode for ArgList { | |||
51 | } | 41 | } |
52 | } | 42 | } |
53 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 43 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
54 | if Self::can_cast(syntax.kind()) { Some(ArgList { syntax }) } else { None } | 44 | if Self::can_cast(syntax.kind()) { |
45 | Some(Self { syntax }) | ||
46 | } else { | ||
47 | None | ||
48 | } | ||
49 | } | ||
50 | fn syntax(&self) -> &SyntaxNode { | ||
51 | &self.syntax | ||
55 | } | 52 | } |
56 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
57 | } | 53 | } |
58 | |||
59 | |||
60 | impl ArgList { | 54 | impl ArgList { |
61 | pub fn args(&self) -> impl Iterator<Item = Expr> { | 55 | pub fn args(&self) -> AstChildren<Expr> { |
62 | super::children(self) | 56 | AstChildren::new(&self.syntax) |
63 | } | 57 | } |
64 | } | 58 | } |
65 | |||
66 | // ArrayExpr | ||
67 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 59 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
68 | pub struct ArrayExpr { | 60 | pub struct ArrayExpr { |
69 | pub(crate) syntax: SyntaxNode, | 61 | pub(crate) syntax: SyntaxNode, |
70 | } | 62 | } |
71 | |||
72 | impl AstNode for ArrayExpr { | 63 | impl AstNode for ArrayExpr { |
73 | fn can_cast(kind: SyntaxKind) -> bool { | 64 | fn can_cast(kind: SyntaxKind) -> bool { |
74 | match kind { | 65 | match kind { |
@@ -77,24 +68,25 @@ impl AstNode for ArrayExpr { | |||
77 | } | 68 | } |
78 | } | 69 | } |
79 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 70 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
80 | if Self::can_cast(syntax.kind()) { Some(ArrayExpr { syntax }) } else { None } | 71 | if Self::can_cast(syntax.kind()) { |
72 | Some(Self { syntax }) | ||
73 | } else { | ||
74 | None | ||
75 | } | ||
76 | } | ||
77 | fn syntax(&self) -> &SyntaxNode { | ||
78 | &self.syntax | ||
81 | } | 79 | } |
82 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
83 | } | 80 | } |
84 | |||
85 | |||
86 | impl ArrayExpr { | 81 | impl ArrayExpr { |
87 | pub fn exprs(&self) -> impl Iterator<Item = Expr> { | 82 | pub fn exprs(&self) -> AstChildren<Expr> { |
88 | super::children(self) | 83 | AstChildren::new(&self.syntax) |
89 | } | 84 | } |
90 | } | 85 | } |
91 | |||
92 | // ArrayType | ||
93 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 86 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
94 | pub struct ArrayType { | 87 | pub struct ArrayType { |
95 | pub(crate) syntax: SyntaxNode, | 88 | pub(crate) syntax: SyntaxNode, |
96 | } | 89 | } |
97 | |||
98 | impl AstNode for ArrayType { | 90 | impl AstNode for ArrayType { |
99 | fn can_cast(kind: SyntaxKind) -> bool { | 91 | fn can_cast(kind: SyntaxKind) -> bool { |
100 | match kind { | 92 | match kind { |
@@ -103,28 +95,28 @@ impl AstNode for ArrayType { | |||
103 | } | 95 | } |
104 | } | 96 | } |
105 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 97 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
106 | if Self::can_cast(syntax.kind()) { Some(ArrayType { syntax }) } else { None } | 98 | if Self::can_cast(syntax.kind()) { |
99 | Some(Self { syntax }) | ||
100 | } else { | ||
101 | None | ||
102 | } | ||
103 | } | ||
104 | fn syntax(&self) -> &SyntaxNode { | ||
105 | &self.syntax | ||
107 | } | 106 | } |
108 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
109 | } | 107 | } |
110 | |||
111 | |||
112 | impl ArrayType { | 108 | impl ArrayType { |
113 | pub fn type_ref(&self) -> Option<TypeRef> { | 109 | pub fn type_ref(&self) -> Option<TypeRef> { |
114 | super::child_opt(self) | 110 | AstChildren::new(&self.syntax).next() |
115 | } | 111 | } |
116 | |||
117 | pub fn expr(&self) -> Option<Expr> { | 112 | pub fn expr(&self) -> Option<Expr> { |
118 | super::child_opt(self) | 113 | AstChildren::new(&self.syntax).next() |
119 | } | 114 | } |
120 | } | 115 | } |
121 | |||
122 | // AssocTypeArg | ||
123 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 116 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
124 | pub struct AssocTypeArg { | 117 | pub struct AssocTypeArg { |
125 | pub(crate) syntax: SyntaxNode, | 118 | pub(crate) syntax: SyntaxNode, |
126 | } | 119 | } |
127 | |||
128 | impl AstNode for AssocTypeArg { | 120 | impl AstNode for AssocTypeArg { |
129 | fn can_cast(kind: SyntaxKind) -> bool { | 121 | fn can_cast(kind: SyntaxKind) -> bool { |
130 | match kind { | 122 | match kind { |
@@ -133,28 +125,28 @@ impl AstNode for AssocTypeArg { | |||
133 | } | 125 | } |
134 | } | 126 | } |
135 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 127 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
136 | if Self::can_cast(syntax.kind()) { Some(AssocTypeArg { syntax }) } else { None } | 128 | if Self::can_cast(syntax.kind()) { |
129 | Some(Self { syntax }) | ||
130 | } else { | ||
131 | None | ||
132 | } | ||
133 | } | ||
134 | fn syntax(&self) -> &SyntaxNode { | ||
135 | &self.syntax | ||
137 | } | 136 | } |
138 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
139 | } | 137 | } |
140 | |||
141 | |||
142 | impl AssocTypeArg { | 138 | impl AssocTypeArg { |
143 | pub fn name_ref(&self) -> Option<NameRef> { | 139 | pub fn name_ref(&self) -> Option<NameRef> { |
144 | super::child_opt(self) | 140 | AstChildren::new(&self.syntax).next() |
145 | } | 141 | } |
146 | |||
147 | pub fn type_ref(&self) -> Option<TypeRef> { | 142 | pub fn type_ref(&self) -> Option<TypeRef> { |
148 | super::child_opt(self) | 143 | AstChildren::new(&self.syntax).next() |
149 | } | 144 | } |
150 | } | 145 | } |
151 | |||
152 | // Attr | ||
153 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 146 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
154 | pub struct Attr { | 147 | pub struct Attr { |
155 | pub(crate) syntax: SyntaxNode, | 148 | pub(crate) syntax: SyntaxNode, |
156 | } | 149 | } |
157 | |||
158 | impl AstNode for Attr { | 150 | impl AstNode for Attr { |
159 | fn can_cast(kind: SyntaxKind) -> bool { | 151 | fn can_cast(kind: SyntaxKind) -> bool { |
160 | match kind { | 152 | match kind { |
@@ -163,24 +155,25 @@ impl AstNode for Attr { | |||
163 | } | 155 | } |
164 | } | 156 | } |
165 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 157 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
166 | if Self::can_cast(syntax.kind()) { Some(Attr { syntax }) } else { None } | 158 | if Self::can_cast(syntax.kind()) { |
159 | Some(Self { syntax }) | ||
160 | } else { | ||
161 | None | ||
162 | } | ||
163 | } | ||
164 | fn syntax(&self) -> &SyntaxNode { | ||
165 | &self.syntax | ||
167 | } | 166 | } |
168 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
169 | } | 167 | } |
170 | |||
171 | |||
172 | impl Attr { | 168 | impl Attr { |
173 | pub fn value(&self) -> Option<TokenTree> { | 169 | pub fn value(&self) -> Option<TokenTree> { |
174 | super::child_opt(self) | 170 | AstChildren::new(&self.syntax).next() |
175 | } | 171 | } |
176 | } | 172 | } |
177 | |||
178 | // AwaitExpr | ||
179 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 173 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
180 | pub struct AwaitExpr { | 174 | pub struct AwaitExpr { |
181 | pub(crate) syntax: SyntaxNode, | 175 | pub(crate) syntax: SyntaxNode, |
182 | } | 176 | } |
183 | |||
184 | impl AstNode for AwaitExpr { | 177 | impl AstNode for AwaitExpr { |
185 | fn can_cast(kind: SyntaxKind) -> bool { | 178 | fn can_cast(kind: SyntaxKind) -> bool { |
186 | match kind { | 179 | match kind { |
@@ -189,24 +182,25 @@ impl AstNode for AwaitExpr { | |||
189 | } | 182 | } |
190 | } | 183 | } |
191 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 184 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
192 | if Self::can_cast(syntax.kind()) { Some(AwaitExpr { syntax }) } else { None } | 185 | if Self::can_cast(syntax.kind()) { |
186 | Some(Self { syntax }) | ||
187 | } else { | ||
188 | None | ||
189 | } | ||
190 | } | ||
191 | fn syntax(&self) -> &SyntaxNode { | ||
192 | &self.syntax | ||
193 | } | 193 | } |
194 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
195 | } | 194 | } |
196 | |||
197 | |||
198 | impl AwaitExpr { | 195 | impl AwaitExpr { |
199 | pub fn expr(&self) -> Option<Expr> { | 196 | pub fn expr(&self) -> Option<Expr> { |
200 | super::child_opt(self) | 197 | AstChildren::new(&self.syntax).next() |
201 | } | 198 | } |
202 | } | 199 | } |
203 | |||
204 | // BinExpr | ||
205 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 200 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
206 | pub struct BinExpr { | 201 | pub struct BinExpr { |
207 | pub(crate) syntax: SyntaxNode, | 202 | pub(crate) syntax: SyntaxNode, |
208 | } | 203 | } |
209 | |||
210 | impl AstNode for BinExpr { | 204 | impl AstNode for BinExpr { |
211 | fn can_cast(kind: SyntaxKind) -> bool { | 205 | fn can_cast(kind: SyntaxKind) -> bool { |
212 | match kind { | 206 | match kind { |
@@ -215,20 +209,21 @@ impl AstNode for BinExpr { | |||
215 | } | 209 | } |
216 | } | 210 | } |
217 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 211 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
218 | if Self::can_cast(syntax.kind()) { Some(BinExpr { syntax }) } else { None } | 212 | if Self::can_cast(syntax.kind()) { |
213 | Some(Self { syntax }) | ||
214 | } else { | ||
215 | None | ||
216 | } | ||
217 | } | ||
218 | fn syntax(&self) -> &SyntaxNode { | ||
219 | &self.syntax | ||
219 | } | 220 | } |
220 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
221 | } | 221 | } |
222 | |||
223 | |||
224 | impl BinExpr {} | 222 | impl BinExpr {} |
225 | |||
226 | // BindPat | ||
227 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 223 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
228 | pub struct BindPat { | 224 | pub struct BindPat { |
229 | pub(crate) syntax: SyntaxNode, | 225 | pub(crate) syntax: SyntaxNode, |
230 | } | 226 | } |
231 | |||
232 | impl AstNode for BindPat { | 227 | impl AstNode for BindPat { |
233 | fn can_cast(kind: SyntaxKind) -> bool { | 228 | fn can_cast(kind: SyntaxKind) -> bool { |
234 | match kind { | 229 | match kind { |
@@ -237,25 +232,26 @@ impl AstNode for BindPat { | |||
237 | } | 232 | } |
238 | } | 233 | } |
239 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 234 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
240 | if Self::can_cast(syntax.kind()) { Some(BindPat { syntax }) } else { None } | 235 | if Self::can_cast(syntax.kind()) { |
236 | Some(Self { syntax }) | ||
237 | } else { | ||
238 | None | ||
239 | } | ||
240 | } | ||
241 | fn syntax(&self) -> &SyntaxNode { | ||
242 | &self.syntax | ||
241 | } | 243 | } |
242 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
243 | } | 244 | } |
244 | |||
245 | |||
246 | impl ast::NameOwner for BindPat {} | 245 | impl ast::NameOwner for BindPat {} |
247 | impl BindPat { | 246 | impl BindPat { |
248 | pub fn pat(&self) -> Option<Pat> { | 247 | pub fn pat(&self) -> Option<Pat> { |
249 | super::child_opt(self) | 248 | AstChildren::new(&self.syntax).next() |
250 | } | 249 | } |
251 | } | 250 | } |
252 | |||
253 | // Block | ||
254 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 251 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
255 | pub struct Block { | 252 | pub struct Block { |
256 | pub(crate) syntax: SyntaxNode, | 253 | pub(crate) syntax: SyntaxNode, |
257 | } | 254 | } |
258 | |||
259 | impl AstNode for Block { | 255 | impl AstNode for Block { |
260 | fn can_cast(kind: SyntaxKind) -> bool { | 256 | fn can_cast(kind: SyntaxKind) -> bool { |
261 | match kind { | 257 | match kind { |
@@ -264,29 +260,29 @@ impl AstNode for Block { | |||
264 | } | 260 | } |
265 | } | 261 | } |
266 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 262 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
267 | if Self::can_cast(syntax.kind()) { Some(Block { syntax }) } else { None } | 263 | if Self::can_cast(syntax.kind()) { |
264 | Some(Self { syntax }) | ||
265 | } else { | ||
266 | None | ||
267 | } | ||
268 | } | ||
269 | fn syntax(&self) -> &SyntaxNode { | ||
270 | &self.syntax | ||
268 | } | 271 | } |
269 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
270 | } | 272 | } |
271 | |||
272 | |||
273 | impl ast::AttrsOwner for Block {} | 273 | impl ast::AttrsOwner for Block {} |
274 | impl Block { | 274 | impl Block { |
275 | pub fn statements(&self) -> impl Iterator<Item = Stmt> { | 275 | pub fn statements(&self) -> AstChildren<Stmt> { |
276 | super::children(self) | 276 | AstChildren::new(&self.syntax) |
277 | } | 277 | } |
278 | |||
279 | pub fn expr(&self) -> Option<Expr> { | 278 | pub fn expr(&self) -> Option<Expr> { |
280 | super::child_opt(self) | 279 | AstChildren::new(&self.syntax).next() |
281 | } | 280 | } |
282 | } | 281 | } |
283 | |||
284 | // BlockExpr | ||
285 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 282 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
286 | pub struct BlockExpr { | 283 | pub struct BlockExpr { |
287 | pub(crate) syntax: SyntaxNode, | 284 | pub(crate) syntax: SyntaxNode, |
288 | } | 285 | } |
289 | |||
290 | impl AstNode for BlockExpr { | 286 | impl AstNode for BlockExpr { |
291 | fn can_cast(kind: SyntaxKind) -> bool { | 287 | fn can_cast(kind: SyntaxKind) -> bool { |
292 | match kind { | 288 | match kind { |
@@ -295,24 +291,25 @@ impl AstNode for BlockExpr { | |||
295 | } | 291 | } |
296 | } | 292 | } |
297 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 293 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
298 | if Self::can_cast(syntax.kind()) { Some(BlockExpr { syntax }) } else { None } | 294 | if Self::can_cast(syntax.kind()) { |
295 | Some(Self { syntax }) | ||
296 | } else { | ||
297 | None | ||
298 | } | ||
299 | } | ||
300 | fn syntax(&self) -> &SyntaxNode { | ||
301 | &self.syntax | ||
299 | } | 302 | } |
300 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
301 | } | 303 | } |
302 | |||
303 | |||
304 | impl BlockExpr { | 304 | impl BlockExpr { |
305 | pub fn block(&self) -> Option<Block> { | 305 | pub fn block(&self) -> Option<Block> { |
306 | super::child_opt(self) | 306 | AstChildren::new(&self.syntax).next() |
307 | } | 307 | } |
308 | } | 308 | } |
309 | |||
310 | // BreakExpr | ||
311 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 309 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
312 | pub struct BreakExpr { | 310 | pub struct BreakExpr { |
313 | pub(crate) syntax: SyntaxNode, | 311 | pub(crate) syntax: SyntaxNode, |
314 | } | 312 | } |
315 | |||
316 | impl AstNode for BreakExpr { | 313 | impl AstNode for BreakExpr { |
317 | fn can_cast(kind: SyntaxKind) -> bool { | 314 | fn can_cast(kind: SyntaxKind) -> bool { |
318 | match kind { | 315 | match kind { |
@@ -321,24 +318,25 @@ impl AstNode for BreakExpr { | |||
321 | } | 318 | } |
322 | } | 319 | } |
323 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 320 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
324 | if Self::can_cast(syntax.kind()) { Some(BreakExpr { syntax }) } else { None } | 321 | if Self::can_cast(syntax.kind()) { |
322 | Some(Self { syntax }) | ||
323 | } else { | ||
324 | None | ||
325 | } | ||
326 | } | ||
327 | fn syntax(&self) -> &SyntaxNode { | ||
328 | &self.syntax | ||
325 | } | 329 | } |
326 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
327 | } | 330 | } |
328 | |||
329 | |||
330 | impl BreakExpr { | 331 | impl BreakExpr { |
331 | pub fn expr(&self) -> Option<Expr> { | 332 | pub fn expr(&self) -> Option<Expr> { |
332 | super::child_opt(self) | 333 | AstChildren::new(&self.syntax).next() |
333 | } | 334 | } |
334 | } | 335 | } |
335 | |||
336 | // CallExpr | ||
337 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 336 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
338 | pub struct CallExpr { | 337 | pub struct CallExpr { |
339 | pub(crate) syntax: SyntaxNode, | 338 | pub(crate) syntax: SyntaxNode, |
340 | } | 339 | } |
341 | |||
342 | impl AstNode for CallExpr { | 340 | impl AstNode for CallExpr { |
343 | fn can_cast(kind: SyntaxKind) -> bool { | 341 | fn can_cast(kind: SyntaxKind) -> bool { |
344 | match kind { | 342 | match kind { |
@@ -347,25 +345,26 @@ impl AstNode for CallExpr { | |||
347 | } | 345 | } |
348 | } | 346 | } |
349 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 347 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
350 | if Self::can_cast(syntax.kind()) { Some(CallExpr { syntax }) } else { None } | 348 | if Self::can_cast(syntax.kind()) { |
349 | Some(Self { syntax }) | ||
350 | } else { | ||
351 | None | ||
352 | } | ||
353 | } | ||
354 | fn syntax(&self) -> &SyntaxNode { | ||
355 | &self.syntax | ||
351 | } | 356 | } |
352 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
353 | } | 357 | } |
354 | |||
355 | |||
356 | impl ast::ArgListOwner for CallExpr {} | 358 | impl ast::ArgListOwner for CallExpr {} |
357 | impl CallExpr { | 359 | impl CallExpr { |
358 | pub fn expr(&self) -> Option<Expr> { | 360 | pub fn expr(&self) -> Option<Expr> { |
359 | super::child_opt(self) | 361 | AstChildren::new(&self.syntax).next() |
360 | } | 362 | } |
361 | } | 363 | } |
362 | |||
363 | // CastExpr | ||
364 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 364 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
365 | pub struct CastExpr { | 365 | pub struct CastExpr { |
366 | pub(crate) syntax: SyntaxNode, | 366 | pub(crate) syntax: SyntaxNode, |
367 | } | 367 | } |
368 | |||
369 | impl AstNode for CastExpr { | 368 | impl AstNode for CastExpr { |
370 | fn can_cast(kind: SyntaxKind) -> bool { | 369 | fn can_cast(kind: SyntaxKind) -> bool { |
371 | match kind { | 370 | match kind { |
@@ -374,28 +373,28 @@ impl AstNode for CastExpr { | |||
374 | } | 373 | } |
375 | } | 374 | } |
376 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 375 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
377 | if Self::can_cast(syntax.kind()) { Some(CastExpr { syntax }) } else { None } | 376 | if Self::can_cast(syntax.kind()) { |
377 | Some(Self { syntax }) | ||
378 | } else { | ||
379 | None | ||
380 | } | ||
381 | } | ||
382 | fn syntax(&self) -> &SyntaxNode { | ||
383 | &self.syntax | ||
378 | } | 384 | } |
379 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
380 | } | 385 | } |
381 | |||
382 | |||
383 | impl CastExpr { | 386 | impl CastExpr { |
384 | pub fn expr(&self) -> Option<Expr> { | 387 | pub fn expr(&self) -> Option<Expr> { |
385 | super::child_opt(self) | 388 | AstChildren::new(&self.syntax).next() |
386 | } | 389 | } |
387 | |||
388 | pub fn type_ref(&self) -> Option<TypeRef> { | 390 | pub fn type_ref(&self) -> Option<TypeRef> { |
389 | super::child_opt(self) | 391 | AstChildren::new(&self.syntax).next() |
390 | } | 392 | } |
391 | } | 393 | } |
392 | |||
393 | // Condition | ||
394 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 394 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
395 | pub struct Condition { | 395 | pub struct Condition { |
396 | pub(crate) syntax: SyntaxNode, | 396 | pub(crate) syntax: SyntaxNode, |
397 | } | 397 | } |
398 | |||
399 | impl AstNode for Condition { | 398 | impl AstNode for Condition { |
400 | fn can_cast(kind: SyntaxKind) -> bool { | 399 | fn can_cast(kind: SyntaxKind) -> bool { |
401 | match kind { | 400 | match kind { |
@@ -404,28 +403,28 @@ impl AstNode for Condition { | |||
404 | } | 403 | } |
405 | } | 404 | } |
406 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 405 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
407 | if Self::can_cast(syntax.kind()) { Some(Condition { syntax }) } else { None } | 406 | if Self::can_cast(syntax.kind()) { |
407 | Some(Self { syntax }) | ||
408 | } else { | ||
409 | None | ||
410 | } | ||
411 | } | ||
412 | fn syntax(&self) -> &SyntaxNode { | ||
413 | &self.syntax | ||
408 | } | 414 | } |
409 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
410 | } | 415 | } |
411 | |||
412 | |||
413 | impl Condition { | 416 | impl Condition { |
414 | pub fn pat(&self) -> Option<Pat> { | 417 | pub fn pat(&self) -> Option<Pat> { |
415 | super::child_opt(self) | 418 | AstChildren::new(&self.syntax).next() |
416 | } | 419 | } |
417 | |||
418 | pub fn expr(&self) -> Option<Expr> { | 420 | pub fn expr(&self) -> Option<Expr> { |
419 | super::child_opt(self) | 421 | AstChildren::new(&self.syntax).next() |
420 | } | 422 | } |
421 | } | 423 | } |
422 | |||
423 | // ConstDef | ||
424 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 424 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
425 | pub struct ConstDef { | 425 | pub struct ConstDef { |
426 | pub(crate) syntax: SyntaxNode, | 426 | pub(crate) syntax: SyntaxNode, |
427 | } | 427 | } |
428 | |||
429 | impl AstNode for ConstDef { | 428 | impl AstNode for ConstDef { |
430 | fn can_cast(kind: SyntaxKind) -> bool { | 429 | fn can_cast(kind: SyntaxKind) -> bool { |
431 | match kind { | 430 | match kind { |
@@ -434,12 +433,16 @@ impl AstNode for ConstDef { | |||
434 | } | 433 | } |
435 | } | 434 | } |
436 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 435 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
437 | if Self::can_cast(syntax.kind()) { Some(ConstDef { syntax }) } else { None } | 436 | if Self::can_cast(syntax.kind()) { |
437 | Some(Self { syntax }) | ||
438 | } else { | ||
439 | None | ||
440 | } | ||
441 | } | ||
442 | fn syntax(&self) -> &SyntaxNode { | ||
443 | &self.syntax | ||
438 | } | 444 | } |
439 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
440 | } | 445 | } |
441 | |||
442 | |||
443 | impl ast::VisibilityOwner for ConstDef {} | 446 | impl ast::VisibilityOwner for ConstDef {} |
444 | impl ast::NameOwner for ConstDef {} | 447 | impl ast::NameOwner for ConstDef {} |
445 | impl ast::TypeParamsOwner for ConstDef {} | 448 | impl ast::TypeParamsOwner for ConstDef {} |
@@ -448,16 +451,13 @@ impl ast::DocCommentsOwner for ConstDef {} | |||
448 | impl ast::TypeAscriptionOwner for ConstDef {} | 451 | impl ast::TypeAscriptionOwner for ConstDef {} |
449 | impl ConstDef { | 452 | impl ConstDef { |
450 | pub fn body(&self) -> Option<Expr> { | 453 | pub fn body(&self) -> Option<Expr> { |
451 | super::child_opt(self) | 454 | AstChildren::new(&self.syntax).next() |
452 | } | 455 | } |
453 | } | 456 | } |
454 | |||
455 | // ContinueExpr | ||
456 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 457 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
457 | pub struct ContinueExpr { | 458 | pub struct ContinueExpr { |
458 | pub(crate) syntax: SyntaxNode, | 459 | pub(crate) syntax: SyntaxNode, |
459 | } | 460 | } |
460 | |||
461 | impl AstNode for ContinueExpr { | 461 | impl AstNode for ContinueExpr { |
462 | fn can_cast(kind: SyntaxKind) -> bool { | 462 | fn can_cast(kind: SyntaxKind) -> bool { |
463 | match kind { | 463 | match kind { |
@@ -466,20 +466,21 @@ impl AstNode for ContinueExpr { | |||
466 | } | 466 | } |
467 | } | 467 | } |
468 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 468 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
469 | if Self::can_cast(syntax.kind()) { Some(ContinueExpr { syntax }) } else { None } | 469 | if Self::can_cast(syntax.kind()) { |
470 | Some(Self { syntax }) | ||
471 | } else { | ||
472 | None | ||
473 | } | ||
474 | } | ||
475 | fn syntax(&self) -> &SyntaxNode { | ||
476 | &self.syntax | ||
470 | } | 477 | } |
471 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
472 | } | 478 | } |
473 | |||
474 | |||
475 | impl ContinueExpr {} | 479 | impl ContinueExpr {} |
476 | |||
477 | // DynTraitType | ||
478 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 480 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
479 | pub struct DynTraitType { | 481 | pub struct DynTraitType { |
480 | pub(crate) syntax: SyntaxNode, | 482 | pub(crate) syntax: SyntaxNode, |
481 | } | 483 | } |
482 | |||
483 | impl AstNode for DynTraitType { | 484 | impl AstNode for DynTraitType { |
484 | fn can_cast(kind: SyntaxKind) -> bool { | 485 | fn can_cast(kind: SyntaxKind) -> bool { |
485 | match kind { | 486 | match kind { |
@@ -488,21 +489,22 @@ impl AstNode for DynTraitType { | |||
488 | } | 489 | } |
489 | } | 490 | } |
490 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 491 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
491 | if Self::can_cast(syntax.kind()) { Some(DynTraitType { syntax }) } else { None } | 492 | if Self::can_cast(syntax.kind()) { |
493 | Some(Self { syntax }) | ||
494 | } else { | ||
495 | None | ||
496 | } | ||
497 | } | ||
498 | fn syntax(&self) -> &SyntaxNode { | ||
499 | &self.syntax | ||
492 | } | 500 | } |
493 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
494 | } | 501 | } |
495 | |||
496 | |||
497 | impl ast::TypeBoundsOwner for DynTraitType {} | 502 | impl ast::TypeBoundsOwner for DynTraitType {} |
498 | impl DynTraitType {} | 503 | impl DynTraitType {} |
499 | |||
500 | // EnumDef | ||
501 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 504 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
502 | pub struct EnumDef { | 505 | pub struct EnumDef { |
503 | pub(crate) syntax: SyntaxNode, | 506 | pub(crate) syntax: SyntaxNode, |
504 | } | 507 | } |
505 | |||
506 | impl AstNode for EnumDef { | 508 | impl AstNode for EnumDef { |
507 | fn can_cast(kind: SyntaxKind) -> bool { | 509 | fn can_cast(kind: SyntaxKind) -> bool { |
508 | match kind { | 510 | match kind { |
@@ -511,12 +513,16 @@ impl AstNode for EnumDef { | |||
511 | } | 513 | } |
512 | } | 514 | } |
513 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 515 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
514 | if Self::can_cast(syntax.kind()) { Some(EnumDef { syntax }) } else { None } | 516 | if Self::can_cast(syntax.kind()) { |
517 | Some(Self { syntax }) | ||
518 | } else { | ||
519 | None | ||
520 | } | ||
521 | } | ||
522 | fn syntax(&self) -> &SyntaxNode { | ||
523 | &self.syntax | ||
515 | } | 524 | } |
516 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
517 | } | 525 | } |
518 | |||
519 | |||
520 | impl ast::VisibilityOwner for EnumDef {} | 526 | impl ast::VisibilityOwner for EnumDef {} |
521 | impl ast::NameOwner for EnumDef {} | 527 | impl ast::NameOwner for EnumDef {} |
522 | impl ast::TypeParamsOwner for EnumDef {} | 528 | impl ast::TypeParamsOwner for EnumDef {} |
@@ -524,16 +530,13 @@ impl ast::AttrsOwner for EnumDef {} | |||
524 | impl ast::DocCommentsOwner for EnumDef {} | 530 | impl ast::DocCommentsOwner for EnumDef {} |
525 | impl EnumDef { | 531 | impl EnumDef { |
526 | pub fn variant_list(&self) -> Option<EnumVariantList> { | 532 | pub fn variant_list(&self) -> Option<EnumVariantList> { |
527 | super::child_opt(self) | 533 | AstChildren::new(&self.syntax).next() |
528 | } | 534 | } |
529 | } | 535 | } |
530 | |||
531 | // EnumVariant | ||
532 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 536 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
533 | pub struct EnumVariant { | 537 | pub struct EnumVariant { |
534 | pub(crate) syntax: SyntaxNode, | 538 | pub(crate) syntax: SyntaxNode, |
535 | } | 539 | } |
536 | |||
537 | impl AstNode for EnumVariant { | 540 | impl AstNode for EnumVariant { |
538 | fn can_cast(kind: SyntaxKind) -> bool { | 541 | fn can_cast(kind: SyntaxKind) -> bool { |
539 | match kind { | 542 | match kind { |
@@ -542,27 +545,28 @@ impl AstNode for EnumVariant { | |||
542 | } | 545 | } |
543 | } | 546 | } |
544 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 547 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
545 | if Self::can_cast(syntax.kind()) { Some(EnumVariant { syntax }) } else { None } | 548 | if Self::can_cast(syntax.kind()) { |
549 | Some(Self { syntax }) | ||
550 | } else { | ||
551 | None | ||
552 | } | ||
553 | } | ||
554 | fn syntax(&self) -> &SyntaxNode { | ||
555 | &self.syntax | ||
546 | } | 556 | } |
547 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
548 | } | 557 | } |
549 | |||
550 | |||
551 | impl ast::NameOwner for EnumVariant {} | 558 | impl ast::NameOwner for EnumVariant {} |
552 | impl ast::DocCommentsOwner for EnumVariant {} | 559 | impl ast::DocCommentsOwner for EnumVariant {} |
553 | impl ast::AttrsOwner for EnumVariant {} | 560 | impl ast::AttrsOwner for EnumVariant {} |
554 | impl EnumVariant { | 561 | impl EnumVariant { |
555 | pub fn expr(&self) -> Option<Expr> { | 562 | pub fn expr(&self) -> Option<Expr> { |
556 | super::child_opt(self) | 563 | AstChildren::new(&self.syntax).next() |
557 | } | 564 | } |
558 | } | 565 | } |
559 | |||
560 | // EnumVariantList | ||
561 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 566 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
562 | pub struct EnumVariantList { | 567 | pub struct EnumVariantList { |
563 | pub(crate) syntax: SyntaxNode, | 568 | pub(crate) syntax: SyntaxNode, |
564 | } | 569 | } |
565 | |||
566 | impl AstNode for EnumVariantList { | 570 | impl AstNode for EnumVariantList { |
567 | fn can_cast(kind: SyntaxKind) -> bool { | 571 | fn can_cast(kind: SyntaxKind) -> bool { |
568 | match kind { | 572 | match kind { |
@@ -571,39 +575,49 @@ impl AstNode for EnumVariantList { | |||
571 | } | 575 | } |
572 | } | 576 | } |
573 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 577 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
574 | if Self::can_cast(syntax.kind()) { Some(EnumVariantList { syntax }) } else { None } | 578 | if Self::can_cast(syntax.kind()) { |
579 | Some(Self { syntax }) | ||
580 | } else { | ||
581 | None | ||
582 | } | ||
583 | } | ||
584 | fn syntax(&self) -> &SyntaxNode { | ||
585 | &self.syntax | ||
575 | } | 586 | } |
576 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
577 | } | 587 | } |
578 | |||
579 | |||
580 | impl EnumVariantList { | 588 | impl EnumVariantList { |
581 | pub fn variants(&self) -> impl Iterator<Item = EnumVariant> { | 589 | pub fn variants(&self) -> AstChildren<EnumVariant> { |
582 | super::children(self) | 590 | AstChildren::new(&self.syntax) |
583 | } | 591 | } |
584 | } | 592 | } |
585 | |||
586 | // Expr | ||
587 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 593 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
588 | pub struct Expr { | 594 | pub struct Expr { |
589 | pub(crate) syntax: SyntaxNode, | 595 | pub(crate) syntax: SyntaxNode, |
590 | } | 596 | } |
591 | |||
592 | impl AstNode for Expr { | 597 | impl AstNode for Expr { |
593 | fn can_cast(kind: SyntaxKind) -> bool { | 598 | fn can_cast(kind: SyntaxKind) -> bool { |
594 | match kind { | 599 | match kind { |
595 | | TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | STRUCT_LIT | CALL_EXPR | INDEX_EXPR | METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | TRY_BLOCK_EXPR | CAST_EXPR | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL => true, | 600 | TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR |
601 | | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL | ||
602 | | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | STRUCT_LIT | CALL_EXPR | INDEX_EXPR | ||
603 | | METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | TRY_BLOCK_EXPR | ||
604 | | CAST_EXPR | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL => { | ||
605 | true | ||
606 | } | ||
596 | _ => false, | 607 | _ => false, |
597 | } | 608 | } |
598 | } | 609 | } |
599 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 610 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
600 | if Self::can_cast(syntax.kind()) { Some(Expr { syntax }) } else { None } | 611 | if Self::can_cast(syntax.kind()) { |
612 | Some(Self { syntax }) | ||
613 | } else { | ||
614 | None | ||
615 | } | ||
616 | } | ||
617 | fn syntax(&self) -> &SyntaxNode { | ||
618 | &self.syntax | ||
601 | } | 619 | } |
602 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
603 | } | 620 | } |
604 | |||
605 | |||
606 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
607 | pub enum ExprKind { | 621 | pub enum ExprKind { |
608 | TupleExpr(TupleExpr), | 622 | TupleExpr(TupleExpr), |
609 | ArrayExpr(ArrayExpr), | 623 | ArrayExpr(ArrayExpr), |
@@ -637,141 +651,198 @@ pub enum ExprKind { | |||
637 | MacroCall(MacroCall), | 651 | MacroCall(MacroCall), |
638 | } | 652 | } |
639 | impl From<TupleExpr> for Expr { | 653 | impl From<TupleExpr> for Expr { |
640 | fn from(n: TupleExpr) -> Expr { Expr { syntax: n.syntax } } | 654 | fn from(node: TupleExpr) -> Expr { |
655 | Expr { syntax: node.syntax } | ||
656 | } | ||
641 | } | 657 | } |
642 | impl From<ArrayExpr> for Expr { | 658 | impl From<ArrayExpr> for Expr { |
643 | fn from(n: ArrayExpr) -> Expr { Expr { syntax: n.syntax } } | 659 | fn from(node: ArrayExpr) -> Expr { |
660 | Expr { syntax: node.syntax } | ||
661 | } | ||
644 | } | 662 | } |
645 | impl From<ParenExpr> for Expr { | 663 | impl From<ParenExpr> for Expr { |
646 | fn from(n: ParenExpr) -> Expr { Expr { syntax: n.syntax } } | 664 | fn from(node: ParenExpr) -> Expr { |
665 | Expr { syntax: node.syntax } | ||
666 | } | ||
647 | } | 667 | } |
648 | impl From<PathExpr> for Expr { | 668 | impl From<PathExpr> for Expr { |
649 | fn from(n: PathExpr) -> Expr { Expr { syntax: n.syntax } } | 669 | fn from(node: PathExpr) -> Expr { |
670 | Expr { syntax: node.syntax } | ||
671 | } | ||
650 | } | 672 | } |
651 | impl From<LambdaExpr> for Expr { | 673 | impl From<LambdaExpr> for Expr { |
652 | fn from(n: LambdaExpr) -> Expr { Expr { syntax: n.syntax } } | 674 | fn from(node: LambdaExpr) -> Expr { |
675 | Expr { syntax: node.syntax } | ||
676 | } | ||
653 | } | 677 | } |
654 | impl From<IfExpr> for Expr { | 678 | impl From<IfExpr> for Expr { |
655 | fn from(n: IfExpr) -> Expr { Expr { syntax: n.syntax } } | 679 | fn from(node: IfExpr) -> Expr { |
680 | Expr { syntax: node.syntax } | ||
681 | } | ||
656 | } | 682 | } |
657 | impl From<LoopExpr> for Expr { | 683 | impl From<LoopExpr> for Expr { |
658 | fn from(n: LoopExpr) -> Expr { Expr { syntax: n.syntax } } | 684 | fn from(node: LoopExpr) -> Expr { |
685 | Expr { syntax: node.syntax } | ||
686 | } | ||
659 | } | 687 | } |
660 | impl From<ForExpr> for Expr { | 688 | impl From<ForExpr> for Expr { |
661 | fn from(n: ForExpr) -> Expr { Expr { syntax: n.syntax } } | 689 | fn from(node: ForExpr) -> Expr { |
690 | Expr { syntax: node.syntax } | ||
691 | } | ||
662 | } | 692 | } |
663 | impl From<WhileExpr> for Expr { | 693 | impl From<WhileExpr> for Expr { |
664 | fn from(n: WhileExpr) -> Expr { Expr { syntax: n.syntax } } | 694 | fn from(node: WhileExpr) -> Expr { |
695 | Expr { syntax: node.syntax } | ||
696 | } | ||
665 | } | 697 | } |
666 | impl From<ContinueExpr> for Expr { | 698 | impl From<ContinueExpr> for Expr { |
667 | fn from(n: ContinueExpr) -> Expr { Expr { syntax: n.syntax } } | 699 | fn from(node: ContinueExpr) -> Expr { |
700 | Expr { syntax: node.syntax } | ||
701 | } | ||
668 | } | 702 | } |
669 | impl From<BreakExpr> for Expr { | 703 | impl From<BreakExpr> for Expr { |
670 | fn from(n: BreakExpr) -> Expr { Expr { syntax: n.syntax } } | 704 | fn from(node: BreakExpr) -> Expr { |
705 | Expr { syntax: node.syntax } | ||
706 | } | ||
671 | } | 707 | } |
672 | impl From<Label> for Expr { | 708 | impl From<Label> for Expr { |
673 | fn from(n: Label) -> Expr { Expr { syntax: n.syntax } } | 709 | fn from(node: Label) -> Expr { |
710 | Expr { syntax: node.syntax } | ||
711 | } | ||
674 | } | 712 | } |
675 | impl From<BlockExpr> for Expr { | 713 | impl From<BlockExpr> for Expr { |
676 | fn from(n: BlockExpr) -> Expr { Expr { syntax: n.syntax } } | 714 | fn from(node: BlockExpr) -> Expr { |
715 | Expr { syntax: node.syntax } | ||
716 | } | ||
677 | } | 717 | } |
678 | impl From<ReturnExpr> for Expr { | 718 | impl From<ReturnExpr> for Expr { |
679 | fn from(n: ReturnExpr) -> Expr { Expr { syntax: n.syntax } } | 719 | fn from(node: ReturnExpr) -> Expr { |
720 | Expr { syntax: node.syntax } | ||
721 | } | ||
680 | } | 722 | } |
681 | impl From<MatchExpr> for Expr { | 723 | impl From<MatchExpr> for Expr { |
682 | fn from(n: MatchExpr) -> Expr { Expr { syntax: n.syntax } } | 724 | fn from(node: MatchExpr) -> Expr { |
725 | Expr { syntax: node.syntax } | ||
726 | } | ||
683 | } | 727 | } |
684 | impl From<StructLit> for Expr { | 728 | impl From<StructLit> for Expr { |
685 | fn from(n: StructLit) -> Expr { Expr { syntax: n.syntax } } | 729 | fn from(node: StructLit) -> Expr { |
730 | Expr { syntax: node.syntax } | ||
731 | } | ||
686 | } | 732 | } |
687 | impl From<CallExpr> for Expr { | 733 | impl From<CallExpr> for Expr { |
688 | fn from(n: CallExpr) -> Expr { Expr { syntax: n.syntax } } | 734 | fn from(node: CallExpr) -> Expr { |
735 | Expr { syntax: node.syntax } | ||
736 | } | ||
689 | } | 737 | } |
690 | impl From<IndexExpr> for Expr { | 738 | impl From<IndexExpr> for Expr { |
691 | fn from(n: IndexExpr) -> Expr { Expr { syntax: n.syntax } } | 739 | fn from(node: IndexExpr) -> Expr { |
740 | Expr { syntax: node.syntax } | ||
741 | } | ||
692 | } | 742 | } |
693 | impl From<MethodCallExpr> for Expr { | 743 | impl From<MethodCallExpr> for Expr { |
694 | fn from(n: MethodCallExpr) -> Expr { Expr { syntax: n.syntax } } | 744 | fn from(node: MethodCallExpr) -> Expr { |
745 | Expr { syntax: node.syntax } | ||
746 | } | ||
695 | } | 747 | } |
696 | impl From<FieldExpr> for Expr { | 748 | impl From<FieldExpr> for Expr { |
697 | fn from(n: FieldExpr) -> Expr { Expr { syntax: n.syntax } } | 749 | fn from(node: FieldExpr) -> Expr { |
750 | Expr { syntax: node.syntax } | ||
751 | } | ||
698 | } | 752 | } |
699 | impl From<AwaitExpr> for Expr { | 753 | impl From<AwaitExpr> for Expr { |
700 | fn from(n: AwaitExpr) -> Expr { Expr { syntax: n.syntax } } | 754 | fn from(node: AwaitExpr) -> Expr { |
755 | Expr { syntax: node.syntax } | ||
756 | } | ||
701 | } | 757 | } |
702 | impl From<TryExpr> for Expr { | 758 | impl From<TryExpr> for Expr { |
703 | fn from(n: TryExpr) -> Expr { Expr { syntax: n.syntax } } | 759 | fn from(node: TryExpr) -> Expr { |
760 | Expr { syntax: node.syntax } | ||
761 | } | ||
704 | } | 762 | } |
705 | impl From<TryBlockExpr> for Expr { | 763 | impl From<TryBlockExpr> for Expr { |
706 | fn from(n: TryBlockExpr) -> Expr { Expr { syntax: n.syntax } } | 764 | fn from(node: TryBlockExpr) -> Expr { |
765 | Expr { syntax: node.syntax } | ||
766 | } | ||
707 | } | 767 | } |
708 | impl From<CastExpr> for Expr { | 768 | impl From<CastExpr> for Expr { |
709 | fn from(n: CastExpr) -> Expr { Expr { syntax: n.syntax } } | 769 | fn from(node: CastExpr) -> Expr { |
770 | Expr { syntax: node.syntax } | ||
771 | } | ||
710 | } | 772 | } |
711 | impl From<RefExpr> for Expr { | 773 | impl From<RefExpr> for Expr { |
712 | fn from(n: RefExpr) -> Expr { Expr { syntax: n.syntax } } | 774 | fn from(node: RefExpr) -> Expr { |
775 | Expr { syntax: node.syntax } | ||
776 | } | ||
713 | } | 777 | } |
714 | impl From<PrefixExpr> for Expr { | 778 | impl From<PrefixExpr> for Expr { |
715 | fn from(n: PrefixExpr) -> Expr { Expr { syntax: n.syntax } } | 779 | fn from(node: PrefixExpr) -> Expr { |
780 | Expr { syntax: node.syntax } | ||
781 | } | ||
716 | } | 782 | } |
717 | impl From<RangeExpr> for Expr { | 783 | impl From<RangeExpr> for Expr { |
718 | fn from(n: RangeExpr) -> Expr { Expr { syntax: n.syntax } } | 784 | fn from(node: RangeExpr) -> Expr { |
785 | Expr { syntax: node.syntax } | ||
786 | } | ||
719 | } | 787 | } |
720 | impl From<BinExpr> for Expr { | 788 | impl From<BinExpr> for Expr { |
721 | fn from(n: BinExpr) -> Expr { Expr { syntax: n.syntax } } | 789 | fn from(node: BinExpr) -> Expr { |
790 | Expr { syntax: node.syntax } | ||
791 | } | ||
722 | } | 792 | } |
723 | impl From<Literal> for Expr { | 793 | impl From<Literal> for Expr { |
724 | fn from(n: Literal) -> Expr { Expr { syntax: n.syntax } } | 794 | fn from(node: Literal) -> Expr { |
795 | Expr { syntax: node.syntax } | ||
796 | } | ||
725 | } | 797 | } |
726 | impl From<MacroCall> for Expr { | 798 | impl From<MacroCall> for Expr { |
727 | fn from(n: MacroCall) -> Expr { Expr { syntax: n.syntax } } | 799 | fn from(node: MacroCall) -> Expr { |
800 | Expr { syntax: node.syntax } | ||
801 | } | ||
728 | } | 802 | } |
729 | impl Expr { | 803 | impl Expr { |
730 | pub fn kind(&self) -> ExprKind { | 804 | pub fn kind(&self) -> ExprKind { |
731 | match self.syntax.kind() { | 805 | let syntax = self.syntax.clone(); |
732 | TUPLE_EXPR => ExprKind::TupleExpr(TupleExpr::cast(self.syntax.clone()).unwrap()), | 806 | match syntax.kind() { |
733 | ARRAY_EXPR => ExprKind::ArrayExpr(ArrayExpr::cast(self.syntax.clone()).unwrap()), | 807 | TUPLE_EXPR => ExprKind::TupleExpr(TupleExpr { syntax }), |
734 | PAREN_EXPR => ExprKind::ParenExpr(ParenExpr::cast(self.syntax.clone()).unwrap()), | 808 | ARRAY_EXPR => ExprKind::ArrayExpr(ArrayExpr { syntax }), |
735 | PATH_EXPR => ExprKind::PathExpr(PathExpr::cast(self.syntax.clone()).unwrap()), | 809 | PAREN_EXPR => ExprKind::ParenExpr(ParenExpr { syntax }), |
736 | LAMBDA_EXPR => ExprKind::LambdaExpr(LambdaExpr::cast(self.syntax.clone()).unwrap()), | 810 | PATH_EXPR => ExprKind::PathExpr(PathExpr { syntax }), |
737 | IF_EXPR => ExprKind::IfExpr(IfExpr::cast(self.syntax.clone()).unwrap()), | 811 | LAMBDA_EXPR => ExprKind::LambdaExpr(LambdaExpr { syntax }), |
738 | LOOP_EXPR => ExprKind::LoopExpr(LoopExpr::cast(self.syntax.clone()).unwrap()), | 812 | IF_EXPR => ExprKind::IfExpr(IfExpr { syntax }), |
739 | FOR_EXPR => ExprKind::ForExpr(ForExpr::cast(self.syntax.clone()).unwrap()), | 813 | LOOP_EXPR => ExprKind::LoopExpr(LoopExpr { syntax }), |
740 | WHILE_EXPR => ExprKind::WhileExpr(WhileExpr::cast(self.syntax.clone()).unwrap()), | 814 | FOR_EXPR => ExprKind::ForExpr(ForExpr { syntax }), |
741 | CONTINUE_EXPR => ExprKind::ContinueExpr(ContinueExpr::cast(self.syntax.clone()).unwrap()), | 815 | WHILE_EXPR => ExprKind::WhileExpr(WhileExpr { syntax }), |
742 | BREAK_EXPR => ExprKind::BreakExpr(BreakExpr::cast(self.syntax.clone()).unwrap()), | 816 | CONTINUE_EXPR => ExprKind::ContinueExpr(ContinueExpr { syntax }), |
743 | LABEL => ExprKind::Label(Label::cast(self.syntax.clone()).unwrap()), | 817 | BREAK_EXPR => ExprKind::BreakExpr(BreakExpr { syntax }), |
744 | BLOCK_EXPR => ExprKind::BlockExpr(BlockExpr::cast(self.syntax.clone()).unwrap()), | 818 | LABEL => ExprKind::Label(Label { syntax }), |
745 | RETURN_EXPR => ExprKind::ReturnExpr(ReturnExpr::cast(self.syntax.clone()).unwrap()), | 819 | BLOCK_EXPR => ExprKind::BlockExpr(BlockExpr { syntax }), |
746 | MATCH_EXPR => ExprKind::MatchExpr(MatchExpr::cast(self.syntax.clone()).unwrap()), | 820 | RETURN_EXPR => ExprKind::ReturnExpr(ReturnExpr { syntax }), |
747 | STRUCT_LIT => ExprKind::StructLit(StructLit::cast(self.syntax.clone()).unwrap()), | 821 | MATCH_EXPR => ExprKind::MatchExpr(MatchExpr { syntax }), |
748 | CALL_EXPR => ExprKind::CallExpr(CallExpr::cast(self.syntax.clone()).unwrap()), | 822 | STRUCT_LIT => ExprKind::StructLit(StructLit { syntax }), |
749 | INDEX_EXPR => ExprKind::IndexExpr(IndexExpr::cast(self.syntax.clone()).unwrap()), | 823 | CALL_EXPR => ExprKind::CallExpr(CallExpr { syntax }), |
750 | METHOD_CALL_EXPR => ExprKind::MethodCallExpr(MethodCallExpr::cast(self.syntax.clone()).unwrap()), | 824 | INDEX_EXPR => ExprKind::IndexExpr(IndexExpr { syntax }), |
751 | FIELD_EXPR => ExprKind::FieldExpr(FieldExpr::cast(self.syntax.clone()).unwrap()), | 825 | METHOD_CALL_EXPR => ExprKind::MethodCallExpr(MethodCallExpr { syntax }), |
752 | AWAIT_EXPR => ExprKind::AwaitExpr(AwaitExpr::cast(self.syntax.clone()).unwrap()), | 826 | FIELD_EXPR => ExprKind::FieldExpr(FieldExpr { syntax }), |
753 | TRY_EXPR => ExprKind::TryExpr(TryExpr::cast(self.syntax.clone()).unwrap()), | 827 | AWAIT_EXPR => ExprKind::AwaitExpr(AwaitExpr { syntax }), |
754 | TRY_BLOCK_EXPR => ExprKind::TryBlockExpr(TryBlockExpr::cast(self.syntax.clone()).unwrap()), | 828 | TRY_EXPR => ExprKind::TryExpr(TryExpr { syntax }), |
755 | CAST_EXPR => ExprKind::CastExpr(CastExpr::cast(self.syntax.clone()).unwrap()), | 829 | TRY_BLOCK_EXPR => ExprKind::TryBlockExpr(TryBlockExpr { syntax }), |
756 | REF_EXPR => ExprKind::RefExpr(RefExpr::cast(self.syntax.clone()).unwrap()), | 830 | CAST_EXPR => ExprKind::CastExpr(CastExpr { syntax }), |
757 | PREFIX_EXPR => ExprKind::PrefixExpr(PrefixExpr::cast(self.syntax.clone()).unwrap()), | 831 | REF_EXPR => ExprKind::RefExpr(RefExpr { syntax }), |
758 | RANGE_EXPR => ExprKind::RangeExpr(RangeExpr::cast(self.syntax.clone()).unwrap()), | 832 | PREFIX_EXPR => ExprKind::PrefixExpr(PrefixExpr { syntax }), |
759 | BIN_EXPR => ExprKind::BinExpr(BinExpr::cast(self.syntax.clone()).unwrap()), | 833 | RANGE_EXPR => ExprKind::RangeExpr(RangeExpr { syntax }), |
760 | LITERAL => ExprKind::Literal(Literal::cast(self.syntax.clone()).unwrap()), | 834 | BIN_EXPR => ExprKind::BinExpr(BinExpr { syntax }), |
761 | MACRO_CALL => ExprKind::MacroCall(MacroCall::cast(self.syntax.clone()).unwrap()), | 835 | LITERAL => ExprKind::Literal(Literal { syntax }), |
836 | MACRO_CALL => ExprKind::MacroCall(MacroCall { syntax }), | ||
762 | _ => unreachable!(), | 837 | _ => unreachable!(), |
763 | } | 838 | } |
764 | } | 839 | } |
765 | } | 840 | } |
766 | |||
767 | impl Expr {} | 841 | impl Expr {} |
768 | |||
769 | // ExprStmt | ||
770 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 842 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
771 | pub struct ExprStmt { | 843 | pub struct ExprStmt { |
772 | pub(crate) syntax: SyntaxNode, | 844 | pub(crate) syntax: SyntaxNode, |
773 | } | 845 | } |
774 | |||
775 | impl AstNode for ExprStmt { | 846 | impl AstNode for ExprStmt { |
776 | fn can_cast(kind: SyntaxKind) -> bool { | 847 | fn can_cast(kind: SyntaxKind) -> bool { |
777 | match kind { | 848 | match kind { |
@@ -780,24 +851,25 @@ impl AstNode for ExprStmt { | |||
780 | } | 851 | } |
781 | } | 852 | } |
782 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 853 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
783 | if Self::can_cast(syntax.kind()) { Some(ExprStmt { syntax }) } else { None } | 854 | if Self::can_cast(syntax.kind()) { |
855 | Some(Self { syntax }) | ||
856 | } else { | ||
857 | None | ||
858 | } | ||
859 | } | ||
860 | fn syntax(&self) -> &SyntaxNode { | ||
861 | &self.syntax | ||
784 | } | 862 | } |
785 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
786 | } | 863 | } |
787 | |||
788 | |||
789 | impl ExprStmt { | 864 | impl ExprStmt { |
790 | pub fn expr(&self) -> Option<Expr> { | 865 | pub fn expr(&self) -> Option<Expr> { |
791 | super::child_opt(self) | 866 | AstChildren::new(&self.syntax).next() |
792 | } | 867 | } |
793 | } | 868 | } |
794 | |||
795 | // ExternCrateItem | ||
796 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 869 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
797 | pub struct ExternCrateItem { | 870 | pub struct ExternCrateItem { |
798 | pub(crate) syntax: SyntaxNode, | 871 | pub(crate) syntax: SyntaxNode, |
799 | } | 872 | } |
800 | |||
801 | impl AstNode for ExternCrateItem { | 873 | impl AstNode for ExternCrateItem { |
802 | fn can_cast(kind: SyntaxKind) -> bool { | 874 | fn can_cast(kind: SyntaxKind) -> bool { |
803 | match kind { | 875 | match kind { |
@@ -806,28 +878,28 @@ impl AstNode for ExternCrateItem { | |||
806 | } | 878 | } |
807 | } | 879 | } |
808 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 880 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
809 | if Self::can_cast(syntax.kind()) { Some(ExternCrateItem { syntax }) } else { None } | 881 | if Self::can_cast(syntax.kind()) { |
882 | Some(Self { syntax }) | ||
883 | } else { | ||
884 | None | ||
885 | } | ||
886 | } | ||
887 | fn syntax(&self) -> &SyntaxNode { | ||
888 | &self.syntax | ||
810 | } | 889 | } |
811 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
812 | } | 890 | } |
813 | |||
814 | |||
815 | impl ExternCrateItem { | 891 | impl ExternCrateItem { |
816 | pub fn name_ref(&self) -> Option<NameRef> { | 892 | pub fn name_ref(&self) -> Option<NameRef> { |
817 | super::child_opt(self) | 893 | AstChildren::new(&self.syntax).next() |
818 | } | 894 | } |
819 | |||
820 | pub fn alias(&self) -> Option<Alias> { | 895 | pub fn alias(&self) -> Option<Alias> { |
821 | super::child_opt(self) | 896 | AstChildren::new(&self.syntax).next() |
822 | } | 897 | } |
823 | } | 898 | } |
824 | |||
825 | // FieldExpr | ||
826 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 899 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
827 | pub struct FieldExpr { | 900 | pub struct FieldExpr { |
828 | pub(crate) syntax: SyntaxNode, | 901 | pub(crate) syntax: SyntaxNode, |
829 | } | 902 | } |
830 | |||
831 | impl AstNode for FieldExpr { | 903 | impl AstNode for FieldExpr { |
832 | fn can_cast(kind: SyntaxKind) -> bool { | 904 | fn can_cast(kind: SyntaxKind) -> bool { |
833 | match kind { | 905 | match kind { |
@@ -836,28 +908,28 @@ impl AstNode for FieldExpr { | |||
836 | } | 908 | } |
837 | } | 909 | } |
838 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 910 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
839 | if Self::can_cast(syntax.kind()) { Some(FieldExpr { syntax }) } else { None } | 911 | if Self::can_cast(syntax.kind()) { |
912 | Some(Self { syntax }) | ||
913 | } else { | ||
914 | None | ||
915 | } | ||
916 | } | ||
917 | fn syntax(&self) -> &SyntaxNode { | ||
918 | &self.syntax | ||
840 | } | 919 | } |
841 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
842 | } | 920 | } |
843 | |||
844 | |||
845 | impl FieldExpr { | 921 | impl FieldExpr { |
846 | pub fn expr(&self) -> Option<Expr> { | 922 | pub fn expr(&self) -> Option<Expr> { |
847 | super::child_opt(self) | 923 | AstChildren::new(&self.syntax).next() |
848 | } | 924 | } |
849 | |||
850 | pub fn name_ref(&self) -> Option<NameRef> { | 925 | pub fn name_ref(&self) -> Option<NameRef> { |
851 | super::child_opt(self) | 926 | AstChildren::new(&self.syntax).next() |
852 | } | 927 | } |
853 | } | 928 | } |
854 | |||
855 | // FieldPat | ||
856 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 929 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
857 | pub struct FieldPat { | 930 | pub struct FieldPat { |
858 | pub(crate) syntax: SyntaxNode, | 931 | pub(crate) syntax: SyntaxNode, |
859 | } | 932 | } |
860 | |||
861 | impl AstNode for FieldPat { | 933 | impl AstNode for FieldPat { |
862 | fn can_cast(kind: SyntaxKind) -> bool { | 934 | fn can_cast(kind: SyntaxKind) -> bool { |
863 | match kind { | 935 | match kind { |
@@ -866,25 +938,26 @@ impl AstNode for FieldPat { | |||
866 | } | 938 | } |
867 | } | 939 | } |
868 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 940 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
869 | if Self::can_cast(syntax.kind()) { Some(FieldPat { syntax }) } else { None } | 941 | if Self::can_cast(syntax.kind()) { |
942 | Some(Self { syntax }) | ||
943 | } else { | ||
944 | None | ||
945 | } | ||
946 | } | ||
947 | fn syntax(&self) -> &SyntaxNode { | ||
948 | &self.syntax | ||
870 | } | 949 | } |
871 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
872 | } | 950 | } |
873 | |||
874 | |||
875 | impl ast::NameOwner for FieldPat {} | 951 | impl ast::NameOwner for FieldPat {} |
876 | impl FieldPat { | 952 | impl FieldPat { |
877 | pub fn pat(&self) -> Option<Pat> { | 953 | pub fn pat(&self) -> Option<Pat> { |
878 | super::child_opt(self) | 954 | AstChildren::new(&self.syntax).next() |
879 | } | 955 | } |
880 | } | 956 | } |
881 | |||
882 | // FieldPatList | ||
883 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 957 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
884 | pub struct FieldPatList { | 958 | pub struct FieldPatList { |
885 | pub(crate) syntax: SyntaxNode, | 959 | pub(crate) syntax: SyntaxNode, |
886 | } | 960 | } |
887 | |||
888 | impl AstNode for FieldPatList { | 961 | impl AstNode for FieldPatList { |
889 | fn can_cast(kind: SyntaxKind) -> bool { | 962 | fn can_cast(kind: SyntaxKind) -> bool { |
890 | match kind { | 963 | match kind { |
@@ -893,28 +966,28 @@ impl AstNode for FieldPatList { | |||
893 | } | 966 | } |
894 | } | 967 | } |
895 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 968 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
896 | if Self::can_cast(syntax.kind()) { Some(FieldPatList { syntax }) } else { None } | 969 | if Self::can_cast(syntax.kind()) { |
970 | Some(Self { syntax }) | ||
971 | } else { | ||
972 | None | ||
973 | } | ||
974 | } | ||
975 | fn syntax(&self) -> &SyntaxNode { | ||
976 | &self.syntax | ||
897 | } | 977 | } |
898 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
899 | } | 978 | } |
900 | |||
901 | |||
902 | impl FieldPatList { | 979 | impl FieldPatList { |
903 | pub fn field_pats(&self) -> impl Iterator<Item = FieldPat> { | 980 | pub fn field_pats(&self) -> AstChildren<FieldPat> { |
904 | super::children(self) | 981 | AstChildren::new(&self.syntax) |
905 | } | 982 | } |
906 | 983 | pub fn bind_pats(&self) -> AstChildren<BindPat> { | |
907 | pub fn bind_pats(&self) -> impl Iterator<Item = BindPat> { | 984 | AstChildren::new(&self.syntax) |
908 | super::children(self) | ||
909 | } | 985 | } |
910 | } | 986 | } |
911 | |||
912 | // FnDef | ||
913 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 987 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
914 | pub struct FnDef { | 988 | pub struct FnDef { |
915 | pub(crate) syntax: SyntaxNode, | 989 | pub(crate) syntax: SyntaxNode, |
916 | } | 990 | } |
917 | |||
918 | impl AstNode for FnDef { | 991 | impl AstNode for FnDef { |
919 | fn can_cast(kind: SyntaxKind) -> bool { | 992 | fn can_cast(kind: SyntaxKind) -> bool { |
920 | match kind { | 993 | match kind { |
@@ -923,12 +996,16 @@ impl AstNode for FnDef { | |||
923 | } | 996 | } |
924 | } | 997 | } |
925 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 998 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
926 | if Self::can_cast(syntax.kind()) { Some(FnDef { syntax }) } else { None } | 999 | if Self::can_cast(syntax.kind()) { |
1000 | Some(Self { syntax }) | ||
1001 | } else { | ||
1002 | None | ||
1003 | } | ||
1004 | } | ||
1005 | fn syntax(&self) -> &SyntaxNode { | ||
1006 | &self.syntax | ||
927 | } | 1007 | } |
928 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
929 | } | 1008 | } |
930 | |||
931 | |||
932 | impl ast::VisibilityOwner for FnDef {} | 1009 | impl ast::VisibilityOwner for FnDef {} |
933 | impl ast::NameOwner for FnDef {} | 1010 | impl ast::NameOwner for FnDef {} |
934 | impl ast::TypeParamsOwner for FnDef {} | 1011 | impl ast::TypeParamsOwner for FnDef {} |
@@ -936,24 +1013,19 @@ impl ast::AttrsOwner for FnDef {} | |||
936 | impl ast::DocCommentsOwner for FnDef {} | 1013 | impl ast::DocCommentsOwner for FnDef {} |
937 | impl FnDef { | 1014 | impl FnDef { |
938 | pub fn param_list(&self) -> Option<ParamList> { | 1015 | pub fn param_list(&self) -> Option<ParamList> { |
939 | super::child_opt(self) | 1016 | AstChildren::new(&self.syntax).next() |
940 | } | 1017 | } |
941 | |||
942 | pub fn body(&self) -> Option<Block> { | 1018 | pub fn body(&self) -> Option<Block> { |
943 | super::child_opt(self) | 1019 | AstChildren::new(&self.syntax).next() |
944 | } | 1020 | } |
945 | |||
946 | pub fn ret_type(&self) -> Option<RetType> { | 1021 | pub fn ret_type(&self) -> Option<RetType> { |
947 | super::child_opt(self) | 1022 | AstChildren::new(&self.syntax).next() |
948 | } | 1023 | } |
949 | } | 1024 | } |
950 | |||
951 | // FnPointerType | ||
952 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1025 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
953 | pub struct FnPointerType { | 1026 | pub struct FnPointerType { |
954 | pub(crate) syntax: SyntaxNode, | 1027 | pub(crate) syntax: SyntaxNode, |
955 | } | 1028 | } |
956 | |||
957 | impl AstNode for FnPointerType { | 1029 | impl AstNode for FnPointerType { |
958 | fn can_cast(kind: SyntaxKind) -> bool { | 1030 | fn can_cast(kind: SyntaxKind) -> bool { |
959 | match kind { | 1031 | match kind { |
@@ -962,28 +1034,28 @@ impl AstNode for FnPointerType { | |||
962 | } | 1034 | } |
963 | } | 1035 | } |
964 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1036 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
965 | if Self::can_cast(syntax.kind()) { Some(FnPointerType { syntax }) } else { None } | 1037 | if Self::can_cast(syntax.kind()) { |
1038 | Some(Self { syntax }) | ||
1039 | } else { | ||
1040 | None | ||
1041 | } | ||
1042 | } | ||
1043 | fn syntax(&self) -> &SyntaxNode { | ||
1044 | &self.syntax | ||
966 | } | 1045 | } |
967 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
968 | } | 1046 | } |
969 | |||
970 | |||
971 | impl FnPointerType { | 1047 | impl FnPointerType { |
972 | pub fn param_list(&self) -> Option<ParamList> { | 1048 | pub fn param_list(&self) -> Option<ParamList> { |
973 | super::child_opt(self) | 1049 | AstChildren::new(&self.syntax).next() |
974 | } | 1050 | } |
975 | |||
976 | pub fn ret_type(&self) -> Option<RetType> { | 1051 | pub fn ret_type(&self) -> Option<RetType> { |
977 | super::child_opt(self) | 1052 | AstChildren::new(&self.syntax).next() |
978 | } | 1053 | } |
979 | } | 1054 | } |
980 | |||
981 | // ForExpr | ||
982 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1055 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
983 | pub struct ForExpr { | 1056 | pub struct ForExpr { |
984 | pub(crate) syntax: SyntaxNode, | 1057 | pub(crate) syntax: SyntaxNode, |
985 | } | 1058 | } |
986 | |||
987 | impl AstNode for ForExpr { | 1059 | impl AstNode for ForExpr { |
988 | fn can_cast(kind: SyntaxKind) -> bool { | 1060 | fn can_cast(kind: SyntaxKind) -> bool { |
989 | match kind { | 1061 | match kind { |
@@ -992,29 +1064,29 @@ impl AstNode for ForExpr { | |||
992 | } | 1064 | } |
993 | } | 1065 | } |
994 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1066 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
995 | if Self::can_cast(syntax.kind()) { Some(ForExpr { syntax }) } else { None } | 1067 | if Self::can_cast(syntax.kind()) { |
1068 | Some(Self { syntax }) | ||
1069 | } else { | ||
1070 | None | ||
1071 | } | ||
1072 | } | ||
1073 | fn syntax(&self) -> &SyntaxNode { | ||
1074 | &self.syntax | ||
996 | } | 1075 | } |
997 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
998 | } | 1076 | } |
999 | |||
1000 | |||
1001 | impl ast::LoopBodyOwner for ForExpr {} | 1077 | impl ast::LoopBodyOwner for ForExpr {} |
1002 | impl ForExpr { | 1078 | impl ForExpr { |
1003 | pub fn pat(&self) -> Option<Pat> { | 1079 | pub fn pat(&self) -> Option<Pat> { |
1004 | super::child_opt(self) | 1080 | AstChildren::new(&self.syntax).next() |
1005 | } | 1081 | } |
1006 | |||
1007 | pub fn iterable(&self) -> Option<Expr> { | 1082 | pub fn iterable(&self) -> Option<Expr> { |
1008 | super::child_opt(self) | 1083 | AstChildren::new(&self.syntax).next() |
1009 | } | 1084 | } |
1010 | } | 1085 | } |
1011 | |||
1012 | // ForType | ||
1013 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1086 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1014 | pub struct ForType { | 1087 | pub struct ForType { |
1015 | pub(crate) syntax: SyntaxNode, | 1088 | pub(crate) syntax: SyntaxNode, |
1016 | } | 1089 | } |
1017 | |||
1018 | impl AstNode for ForType { | 1090 | impl AstNode for ForType { |
1019 | fn can_cast(kind: SyntaxKind) -> bool { | 1091 | fn can_cast(kind: SyntaxKind) -> bool { |
1020 | match kind { | 1092 | match kind { |
@@ -1023,24 +1095,25 @@ impl AstNode for ForType { | |||
1023 | } | 1095 | } |
1024 | } | 1096 | } |
1025 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1097 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1026 | if Self::can_cast(syntax.kind()) { Some(ForType { syntax }) } else { None } | 1098 | if Self::can_cast(syntax.kind()) { |
1099 | Some(Self { syntax }) | ||
1100 | } else { | ||
1101 | None | ||
1102 | } | ||
1103 | } | ||
1104 | fn syntax(&self) -> &SyntaxNode { | ||
1105 | &self.syntax | ||
1027 | } | 1106 | } |
1028 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1029 | } | 1107 | } |
1030 | |||
1031 | |||
1032 | impl ForType { | 1108 | impl ForType { |
1033 | pub fn type_ref(&self) -> Option<TypeRef> { | 1109 | pub fn type_ref(&self) -> Option<TypeRef> { |
1034 | super::child_opt(self) | 1110 | AstChildren::new(&self.syntax).next() |
1035 | } | 1111 | } |
1036 | } | 1112 | } |
1037 | |||
1038 | // IfExpr | ||
1039 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1113 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1040 | pub struct IfExpr { | 1114 | pub struct IfExpr { |
1041 | pub(crate) syntax: SyntaxNode, | 1115 | pub(crate) syntax: SyntaxNode, |
1042 | } | 1116 | } |
1043 | |||
1044 | impl AstNode for IfExpr { | 1117 | impl AstNode for IfExpr { |
1045 | fn can_cast(kind: SyntaxKind) -> bool { | 1118 | fn can_cast(kind: SyntaxKind) -> bool { |
1046 | match kind { | 1119 | match kind { |
@@ -1049,24 +1122,25 @@ impl AstNode for IfExpr { | |||
1049 | } | 1122 | } |
1050 | } | 1123 | } |
1051 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1124 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1052 | if Self::can_cast(syntax.kind()) { Some(IfExpr { syntax }) } else { None } | 1125 | if Self::can_cast(syntax.kind()) { |
1126 | Some(Self { syntax }) | ||
1127 | } else { | ||
1128 | None | ||
1129 | } | ||
1130 | } | ||
1131 | fn syntax(&self) -> &SyntaxNode { | ||
1132 | &self.syntax | ||
1053 | } | 1133 | } |
1054 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1055 | } | 1134 | } |
1056 | |||
1057 | |||
1058 | impl IfExpr { | 1135 | impl IfExpr { |
1059 | pub fn condition(&self) -> Option<Condition> { | 1136 | pub fn condition(&self) -> Option<Condition> { |
1060 | super::child_opt(self) | 1137 | AstChildren::new(&self.syntax).next() |
1061 | } | 1138 | } |
1062 | } | 1139 | } |
1063 | |||
1064 | // ImplBlock | ||
1065 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1140 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1066 | pub struct ImplBlock { | 1141 | pub struct ImplBlock { |
1067 | pub(crate) syntax: SyntaxNode, | 1142 | pub(crate) syntax: SyntaxNode, |
1068 | } | 1143 | } |
1069 | |||
1070 | impl AstNode for ImplBlock { | 1144 | impl AstNode for ImplBlock { |
1071 | fn can_cast(kind: SyntaxKind) -> bool { | 1145 | fn can_cast(kind: SyntaxKind) -> bool { |
1072 | match kind { | 1146 | match kind { |
@@ -1075,74 +1149,81 @@ impl AstNode for ImplBlock { | |||
1075 | } | 1149 | } |
1076 | } | 1150 | } |
1077 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1151 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1078 | if Self::can_cast(syntax.kind()) { Some(ImplBlock { syntax }) } else { None } | 1152 | if Self::can_cast(syntax.kind()) { |
1153 | Some(Self { syntax }) | ||
1154 | } else { | ||
1155 | None | ||
1156 | } | ||
1157 | } | ||
1158 | fn syntax(&self) -> &SyntaxNode { | ||
1159 | &self.syntax | ||
1079 | } | 1160 | } |
1080 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1081 | } | 1161 | } |
1082 | |||
1083 | |||
1084 | impl ast::TypeParamsOwner for ImplBlock {} | 1162 | impl ast::TypeParamsOwner for ImplBlock {} |
1085 | impl ast::AttrsOwner for ImplBlock {} | 1163 | impl ast::AttrsOwner for ImplBlock {} |
1086 | impl ImplBlock { | 1164 | impl ImplBlock { |
1087 | pub fn item_list(&self) -> Option<ItemList> { | 1165 | pub fn item_list(&self) -> Option<ItemList> { |
1088 | super::child_opt(self) | 1166 | AstChildren::new(&self.syntax).next() |
1089 | } | 1167 | } |
1090 | } | 1168 | } |
1091 | |||
1092 | // ImplItem | ||
1093 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1169 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1094 | pub struct ImplItem { | 1170 | pub struct ImplItem { |
1095 | pub(crate) syntax: SyntaxNode, | 1171 | pub(crate) syntax: SyntaxNode, |
1096 | } | 1172 | } |
1097 | |||
1098 | impl AstNode for ImplItem { | 1173 | impl AstNode for ImplItem { |
1099 | fn can_cast(kind: SyntaxKind) -> bool { | 1174 | fn can_cast(kind: SyntaxKind) -> bool { |
1100 | match kind { | 1175 | match kind { |
1101 | | FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true, | 1176 | FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true, |
1102 | _ => false, | 1177 | _ => false, |
1103 | } | 1178 | } |
1104 | } | 1179 | } |
1105 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1180 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1106 | if Self::can_cast(syntax.kind()) { Some(ImplItem { syntax }) } else { None } | 1181 | if Self::can_cast(syntax.kind()) { |
1182 | Some(Self { syntax }) | ||
1183 | } else { | ||
1184 | None | ||
1185 | } | ||
1186 | } | ||
1187 | fn syntax(&self) -> &SyntaxNode { | ||
1188 | &self.syntax | ||
1107 | } | 1189 | } |
1108 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1109 | } | 1190 | } |
1110 | |||
1111 | |||
1112 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
1113 | pub enum ImplItemKind { | 1191 | pub enum ImplItemKind { |
1114 | FnDef(FnDef), | 1192 | FnDef(FnDef), |
1115 | TypeAliasDef(TypeAliasDef), | 1193 | TypeAliasDef(TypeAliasDef), |
1116 | ConstDef(ConstDef), | 1194 | ConstDef(ConstDef), |
1117 | } | 1195 | } |
1118 | impl From<FnDef> for ImplItem { | 1196 | impl From<FnDef> for ImplItem { |
1119 | fn from(n: FnDef) -> ImplItem { ImplItem { syntax: n.syntax } } | 1197 | fn from(node: FnDef) -> ImplItem { |
1198 | ImplItem { syntax: node.syntax } | ||
1199 | } | ||
1120 | } | 1200 | } |
1121 | impl From<TypeAliasDef> for ImplItem { | 1201 | impl From<TypeAliasDef> for ImplItem { |
1122 | fn from(n: TypeAliasDef) -> ImplItem { ImplItem { syntax: n.syntax } } | 1202 | fn from(node: TypeAliasDef) -> ImplItem { |
1203 | ImplItem { syntax: node.syntax } | ||
1204 | } | ||
1123 | } | 1205 | } |
1124 | impl From<ConstDef> for ImplItem { | 1206 | impl From<ConstDef> for ImplItem { |
1125 | fn from(n: ConstDef) -> ImplItem { ImplItem { syntax: n.syntax } } | 1207 | fn from(node: ConstDef) -> ImplItem { |
1208 | ImplItem { syntax: node.syntax } | ||
1209 | } | ||
1126 | } | 1210 | } |
1127 | impl ImplItem { | 1211 | impl ImplItem { |
1128 | pub fn kind(&self) -> ImplItemKind { | 1212 | pub fn kind(&self) -> ImplItemKind { |
1129 | match self.syntax.kind() { | 1213 | let syntax = self.syntax.clone(); |
1130 | FN_DEF => ImplItemKind::FnDef(FnDef::cast(self.syntax.clone()).unwrap()), | 1214 | match syntax.kind() { |
1131 | TYPE_ALIAS_DEF => ImplItemKind::TypeAliasDef(TypeAliasDef::cast(self.syntax.clone()).unwrap()), | 1215 | FN_DEF => ImplItemKind::FnDef(FnDef { syntax }), |
1132 | CONST_DEF => ImplItemKind::ConstDef(ConstDef::cast(self.syntax.clone()).unwrap()), | 1216 | TYPE_ALIAS_DEF => ImplItemKind::TypeAliasDef(TypeAliasDef { syntax }), |
1217 | CONST_DEF => ImplItemKind::ConstDef(ConstDef { syntax }), | ||
1133 | _ => unreachable!(), | 1218 | _ => unreachable!(), |
1134 | } | 1219 | } |
1135 | } | 1220 | } |
1136 | } | 1221 | } |
1137 | |||
1138 | impl ImplItem {} | 1222 | impl ImplItem {} |
1139 | |||
1140 | // ImplTraitType | ||
1141 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1223 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1142 | pub struct ImplTraitType { | 1224 | pub struct ImplTraitType { |
1143 | pub(crate) syntax: SyntaxNode, | 1225 | pub(crate) syntax: SyntaxNode, |
1144 | } | 1226 | } |
1145 | |||
1146 | impl AstNode for ImplTraitType { | 1227 | impl AstNode for ImplTraitType { |
1147 | fn can_cast(kind: SyntaxKind) -> bool { | 1228 | fn can_cast(kind: SyntaxKind) -> bool { |
1148 | match kind { | 1229 | match kind { |
@@ -1151,21 +1232,22 @@ impl AstNode for ImplTraitType { | |||
1151 | } | 1232 | } |
1152 | } | 1233 | } |
1153 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1234 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1154 | if Self::can_cast(syntax.kind()) { Some(ImplTraitType { syntax }) } else { None } | 1235 | if Self::can_cast(syntax.kind()) { |
1236 | Some(Self { syntax }) | ||
1237 | } else { | ||
1238 | None | ||
1239 | } | ||
1240 | } | ||
1241 | fn syntax(&self) -> &SyntaxNode { | ||
1242 | &self.syntax | ||
1155 | } | 1243 | } |
1156 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1157 | } | 1244 | } |
1158 | |||
1159 | |||
1160 | impl ast::TypeBoundsOwner for ImplTraitType {} | 1245 | impl ast::TypeBoundsOwner for ImplTraitType {} |
1161 | impl ImplTraitType {} | 1246 | impl ImplTraitType {} |
1162 | |||
1163 | // IndexExpr | ||
1164 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1247 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1165 | pub struct IndexExpr { | 1248 | pub struct IndexExpr { |
1166 | pub(crate) syntax: SyntaxNode, | 1249 | pub(crate) syntax: SyntaxNode, |
1167 | } | 1250 | } |
1168 | |||
1169 | impl AstNode for IndexExpr { | 1251 | impl AstNode for IndexExpr { |
1170 | fn can_cast(kind: SyntaxKind) -> bool { | 1252 | fn can_cast(kind: SyntaxKind) -> bool { |
1171 | match kind { | 1253 | match kind { |
@@ -1174,20 +1256,21 @@ impl AstNode for IndexExpr { | |||
1174 | } | 1256 | } |
1175 | } | 1257 | } |
1176 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1258 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1177 | if Self::can_cast(syntax.kind()) { Some(IndexExpr { syntax }) } else { None } | 1259 | if Self::can_cast(syntax.kind()) { |
1260 | Some(Self { syntax }) | ||
1261 | } else { | ||
1262 | None | ||
1263 | } | ||
1264 | } | ||
1265 | fn syntax(&self) -> &SyntaxNode { | ||
1266 | &self.syntax | ||
1178 | } | 1267 | } |
1179 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1180 | } | 1268 | } |
1181 | |||
1182 | |||
1183 | impl IndexExpr {} | 1269 | impl IndexExpr {} |
1184 | |||
1185 | // ItemList | ||
1186 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1270 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1187 | pub struct ItemList { | 1271 | pub struct ItemList { |
1188 | pub(crate) syntax: SyntaxNode, | 1272 | pub(crate) syntax: SyntaxNode, |
1189 | } | 1273 | } |
1190 | |||
1191 | impl AstNode for ItemList { | 1274 | impl AstNode for ItemList { |
1192 | fn can_cast(kind: SyntaxKind) -> bool { | 1275 | fn can_cast(kind: SyntaxKind) -> bool { |
1193 | match kind { | 1276 | match kind { |
@@ -1196,26 +1279,27 @@ impl AstNode for ItemList { | |||
1196 | } | 1279 | } |
1197 | } | 1280 | } |
1198 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1281 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1199 | if Self::can_cast(syntax.kind()) { Some(ItemList { syntax }) } else { None } | 1282 | if Self::can_cast(syntax.kind()) { |
1283 | Some(Self { syntax }) | ||
1284 | } else { | ||
1285 | None | ||
1286 | } | ||
1287 | } | ||
1288 | fn syntax(&self) -> &SyntaxNode { | ||
1289 | &self.syntax | ||
1200 | } | 1290 | } |
1201 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1202 | } | 1291 | } |
1203 | |||
1204 | |||
1205 | impl ast::FnDefOwner for ItemList {} | 1292 | impl ast::FnDefOwner for ItemList {} |
1206 | impl ast::ModuleItemOwner for ItemList {} | 1293 | impl ast::ModuleItemOwner for ItemList {} |
1207 | impl ItemList { | 1294 | impl ItemList { |
1208 | pub fn impl_items(&self) -> impl Iterator<Item = ImplItem> { | 1295 | pub fn impl_items(&self) -> AstChildren<ImplItem> { |
1209 | super::children(self) | 1296 | AstChildren::new(&self.syntax) |
1210 | } | 1297 | } |
1211 | } | 1298 | } |
1212 | |||
1213 | // Label | ||
1214 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1299 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1215 | pub struct Label { | 1300 | pub struct Label { |
1216 | pub(crate) syntax: SyntaxNode, | 1301 | pub(crate) syntax: SyntaxNode, |
1217 | } | 1302 | } |
1218 | |||
1219 | impl AstNode for Label { | 1303 | impl AstNode for Label { |
1220 | fn can_cast(kind: SyntaxKind) -> bool { | 1304 | fn can_cast(kind: SyntaxKind) -> bool { |
1221 | match kind { | 1305 | match kind { |
@@ -1224,20 +1308,21 @@ impl AstNode for Label { | |||
1224 | } | 1308 | } |
1225 | } | 1309 | } |
1226 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1310 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1227 | if Self::can_cast(syntax.kind()) { Some(Label { syntax }) } else { None } | 1311 | if Self::can_cast(syntax.kind()) { |
1312 | Some(Self { syntax }) | ||
1313 | } else { | ||
1314 | None | ||
1315 | } | ||
1316 | } | ||
1317 | fn syntax(&self) -> &SyntaxNode { | ||
1318 | &self.syntax | ||
1228 | } | 1319 | } |
1229 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1230 | } | 1320 | } |
1231 | |||
1232 | |||
1233 | impl Label {} | 1321 | impl Label {} |
1234 | |||
1235 | // LambdaExpr | ||
1236 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1322 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1237 | pub struct LambdaExpr { | 1323 | pub struct LambdaExpr { |
1238 | pub(crate) syntax: SyntaxNode, | 1324 | pub(crate) syntax: SyntaxNode, |
1239 | } | 1325 | } |
1240 | |||
1241 | impl AstNode for LambdaExpr { | 1326 | impl AstNode for LambdaExpr { |
1242 | fn can_cast(kind: SyntaxKind) -> bool { | 1327 | fn can_cast(kind: SyntaxKind) -> bool { |
1243 | match kind { | 1328 | match kind { |
@@ -1246,28 +1331,28 @@ impl AstNode for LambdaExpr { | |||
1246 | } | 1331 | } |
1247 | } | 1332 | } |
1248 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1333 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1249 | if Self::can_cast(syntax.kind()) { Some(LambdaExpr { syntax }) } else { None } | 1334 | if Self::can_cast(syntax.kind()) { |
1335 | Some(Self { syntax }) | ||
1336 | } else { | ||
1337 | None | ||
1338 | } | ||
1339 | } | ||
1340 | fn syntax(&self) -> &SyntaxNode { | ||
1341 | &self.syntax | ||
1250 | } | 1342 | } |
1251 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1252 | } | 1343 | } |
1253 | |||
1254 | |||
1255 | impl LambdaExpr { | 1344 | impl LambdaExpr { |
1256 | pub fn param_list(&self) -> Option<ParamList> { | 1345 | pub fn param_list(&self) -> Option<ParamList> { |
1257 | super::child_opt(self) | 1346 | AstChildren::new(&self.syntax).next() |
1258 | } | 1347 | } |
1259 | |||
1260 | pub fn body(&self) -> Option<Expr> { | 1348 | pub fn body(&self) -> Option<Expr> { |
1261 | super::child_opt(self) | 1349 | AstChildren::new(&self.syntax).next() |
1262 | } | 1350 | } |
1263 | } | 1351 | } |
1264 | |||
1265 | // LetStmt | ||
1266 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1352 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1267 | pub struct LetStmt { | 1353 | pub struct LetStmt { |
1268 | pub(crate) syntax: SyntaxNode, | 1354 | pub(crate) syntax: SyntaxNode, |
1269 | } | 1355 | } |
1270 | |||
1271 | impl AstNode for LetStmt { | 1356 | impl AstNode for LetStmt { |
1272 | fn can_cast(kind: SyntaxKind) -> bool { | 1357 | fn can_cast(kind: SyntaxKind) -> bool { |
1273 | match kind { | 1358 | match kind { |
@@ -1276,29 +1361,29 @@ impl AstNode for LetStmt { | |||
1276 | } | 1361 | } |
1277 | } | 1362 | } |
1278 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1363 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1279 | if Self::can_cast(syntax.kind()) { Some(LetStmt { syntax }) } else { None } | 1364 | if Self::can_cast(syntax.kind()) { |
1365 | Some(Self { syntax }) | ||
1366 | } else { | ||
1367 | None | ||
1368 | } | ||
1369 | } | ||
1370 | fn syntax(&self) -> &SyntaxNode { | ||
1371 | &self.syntax | ||
1280 | } | 1372 | } |
1281 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1282 | } | 1373 | } |
1283 | |||
1284 | |||
1285 | impl ast::TypeAscriptionOwner for LetStmt {} | 1374 | impl ast::TypeAscriptionOwner for LetStmt {} |
1286 | impl LetStmt { | 1375 | impl LetStmt { |
1287 | pub fn pat(&self) -> Option<Pat> { | 1376 | pub fn pat(&self) -> Option<Pat> { |
1288 | super::child_opt(self) | 1377 | AstChildren::new(&self.syntax).next() |
1289 | } | 1378 | } |
1290 | |||
1291 | pub fn initializer(&self) -> Option<Expr> { | 1379 | pub fn initializer(&self) -> Option<Expr> { |
1292 | super::child_opt(self) | 1380 | AstChildren::new(&self.syntax).next() |
1293 | } | 1381 | } |
1294 | } | 1382 | } |
1295 | |||
1296 | // LifetimeArg | ||
1297 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1383 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1298 | pub struct LifetimeArg { | 1384 | pub struct LifetimeArg { |
1299 | pub(crate) syntax: SyntaxNode, | 1385 | pub(crate) syntax: SyntaxNode, |
1300 | } | 1386 | } |
1301 | |||
1302 | impl AstNode for LifetimeArg { | 1387 | impl AstNode for LifetimeArg { |
1303 | fn can_cast(kind: SyntaxKind) -> bool { | 1388 | fn can_cast(kind: SyntaxKind) -> bool { |
1304 | match kind { | 1389 | match kind { |
@@ -1307,20 +1392,21 @@ impl AstNode for LifetimeArg { | |||
1307 | } | 1392 | } |
1308 | } | 1393 | } |
1309 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1394 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1310 | if Self::can_cast(syntax.kind()) { Some(LifetimeArg { syntax }) } else { None } | 1395 | if Self::can_cast(syntax.kind()) { |
1396 | Some(Self { syntax }) | ||
1397 | } else { | ||
1398 | None | ||
1399 | } | ||
1400 | } | ||
1401 | fn syntax(&self) -> &SyntaxNode { | ||
1402 | &self.syntax | ||
1311 | } | 1403 | } |
1312 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1313 | } | 1404 | } |
1314 | |||
1315 | |||
1316 | impl LifetimeArg {} | 1405 | impl LifetimeArg {} |
1317 | |||
1318 | // LifetimeParam | ||
1319 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1406 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1320 | pub struct LifetimeParam { | 1407 | pub struct LifetimeParam { |
1321 | pub(crate) syntax: SyntaxNode, | 1408 | pub(crate) syntax: SyntaxNode, |
1322 | } | 1409 | } |
1323 | |||
1324 | impl AstNode for LifetimeParam { | 1410 | impl AstNode for LifetimeParam { |
1325 | fn can_cast(kind: SyntaxKind) -> bool { | 1411 | fn can_cast(kind: SyntaxKind) -> bool { |
1326 | match kind { | 1412 | match kind { |
@@ -1329,21 +1415,22 @@ impl AstNode for LifetimeParam { | |||
1329 | } | 1415 | } |
1330 | } | 1416 | } |
1331 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1417 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1332 | if Self::can_cast(syntax.kind()) { Some(LifetimeParam { syntax }) } else { None } | 1418 | if Self::can_cast(syntax.kind()) { |
1419 | Some(Self { syntax }) | ||
1420 | } else { | ||
1421 | None | ||
1422 | } | ||
1423 | } | ||
1424 | fn syntax(&self) -> &SyntaxNode { | ||
1425 | &self.syntax | ||
1333 | } | 1426 | } |
1334 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1335 | } | 1427 | } |
1336 | |||
1337 | |||
1338 | impl ast::AttrsOwner for LifetimeParam {} | 1428 | impl ast::AttrsOwner for LifetimeParam {} |
1339 | impl LifetimeParam {} | 1429 | impl LifetimeParam {} |
1340 | |||
1341 | // Literal | ||
1342 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1430 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1343 | pub struct Literal { | 1431 | pub struct Literal { |
1344 | pub(crate) syntax: SyntaxNode, | 1432 | pub(crate) syntax: SyntaxNode, |
1345 | } | 1433 | } |
1346 | |||
1347 | impl AstNode for Literal { | 1434 | impl AstNode for Literal { |
1348 | fn can_cast(kind: SyntaxKind) -> bool { | 1435 | fn can_cast(kind: SyntaxKind) -> bool { |
1349 | match kind { | 1436 | match kind { |
@@ -1352,20 +1439,21 @@ impl AstNode for Literal { | |||
1352 | } | 1439 | } |
1353 | } | 1440 | } |
1354 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1441 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1355 | if Self::can_cast(syntax.kind()) { Some(Literal { syntax }) } else { None } | 1442 | if Self::can_cast(syntax.kind()) { |
1443 | Some(Self { syntax }) | ||
1444 | } else { | ||
1445 | None | ||
1446 | } | ||
1447 | } | ||
1448 | fn syntax(&self) -> &SyntaxNode { | ||
1449 | &self.syntax | ||
1356 | } | 1450 | } |
1357 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1358 | } | 1451 | } |
1359 | |||
1360 | |||
1361 | impl Literal {} | 1452 | impl Literal {} |
1362 | |||
1363 | // LiteralPat | ||
1364 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1453 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1365 | pub struct LiteralPat { | 1454 | pub struct LiteralPat { |
1366 | pub(crate) syntax: SyntaxNode, | 1455 | pub(crate) syntax: SyntaxNode, |
1367 | } | 1456 | } |
1368 | |||
1369 | impl AstNode for LiteralPat { | 1457 | impl AstNode for LiteralPat { |
1370 | fn can_cast(kind: SyntaxKind) -> bool { | 1458 | fn can_cast(kind: SyntaxKind) -> bool { |
1371 | match kind { | 1459 | match kind { |
@@ -1374,24 +1462,25 @@ impl AstNode for LiteralPat { | |||
1374 | } | 1462 | } |
1375 | } | 1463 | } |
1376 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1464 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1377 | if Self::can_cast(syntax.kind()) { Some(LiteralPat { syntax }) } else { None } | 1465 | if Self::can_cast(syntax.kind()) { |
1466 | Some(Self { syntax }) | ||
1467 | } else { | ||
1468 | None | ||
1469 | } | ||
1470 | } | ||
1471 | fn syntax(&self) -> &SyntaxNode { | ||
1472 | &self.syntax | ||
1378 | } | 1473 | } |
1379 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1380 | } | 1474 | } |
1381 | |||
1382 | |||
1383 | impl LiteralPat { | 1475 | impl LiteralPat { |
1384 | pub fn literal(&self) -> Option<Literal> { | 1476 | pub fn literal(&self) -> Option<Literal> { |
1385 | super::child_opt(self) | 1477 | AstChildren::new(&self.syntax).next() |
1386 | } | 1478 | } |
1387 | } | 1479 | } |
1388 | |||
1389 | // LoopExpr | ||
1390 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1480 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1391 | pub struct LoopExpr { | 1481 | pub struct LoopExpr { |
1392 | pub(crate) syntax: SyntaxNode, | 1482 | pub(crate) syntax: SyntaxNode, |
1393 | } | 1483 | } |
1394 | |||
1395 | impl AstNode for LoopExpr { | 1484 | impl AstNode for LoopExpr { |
1396 | fn can_cast(kind: SyntaxKind) -> bool { | 1485 | fn can_cast(kind: SyntaxKind) -> bool { |
1397 | match kind { | 1486 | match kind { |
@@ -1400,21 +1489,22 @@ impl AstNode for LoopExpr { | |||
1400 | } | 1489 | } |
1401 | } | 1490 | } |
1402 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1491 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1403 | if Self::can_cast(syntax.kind()) { Some(LoopExpr { syntax }) } else { None } | 1492 | if Self::can_cast(syntax.kind()) { |
1493 | Some(Self { syntax }) | ||
1494 | } else { | ||
1495 | None | ||
1496 | } | ||
1497 | } | ||
1498 | fn syntax(&self) -> &SyntaxNode { | ||
1499 | &self.syntax | ||
1404 | } | 1500 | } |
1405 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1406 | } | 1501 | } |
1407 | |||
1408 | |||
1409 | impl ast::LoopBodyOwner for LoopExpr {} | 1502 | impl ast::LoopBodyOwner for LoopExpr {} |
1410 | impl LoopExpr {} | 1503 | impl LoopExpr {} |
1411 | |||
1412 | // MacroCall | ||
1413 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1504 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1414 | pub struct MacroCall { | 1505 | pub struct MacroCall { |
1415 | pub(crate) syntax: SyntaxNode, | 1506 | pub(crate) syntax: SyntaxNode, |
1416 | } | 1507 | } |
1417 | |||
1418 | impl AstNode for MacroCall { | 1508 | impl AstNode for MacroCall { |
1419 | fn can_cast(kind: SyntaxKind) -> bool { | 1509 | fn can_cast(kind: SyntaxKind) -> bool { |
1420 | match kind { | 1510 | match kind { |
@@ -1423,31 +1513,31 @@ impl AstNode for MacroCall { | |||
1423 | } | 1513 | } |
1424 | } | 1514 | } |
1425 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1515 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1426 | if Self::can_cast(syntax.kind()) { Some(MacroCall { syntax }) } else { None } | 1516 | if Self::can_cast(syntax.kind()) { |
1517 | Some(Self { syntax }) | ||
1518 | } else { | ||
1519 | None | ||
1520 | } | ||
1521 | } | ||
1522 | fn syntax(&self) -> &SyntaxNode { | ||
1523 | &self.syntax | ||
1427 | } | 1524 | } |
1428 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1429 | } | 1525 | } |
1430 | |||
1431 | |||
1432 | impl ast::NameOwner for MacroCall {} | 1526 | impl ast::NameOwner for MacroCall {} |
1433 | impl ast::AttrsOwner for MacroCall {} | 1527 | impl ast::AttrsOwner for MacroCall {} |
1434 | impl ast::DocCommentsOwner for MacroCall {} | 1528 | impl ast::DocCommentsOwner for MacroCall {} |
1435 | impl MacroCall { | 1529 | impl MacroCall { |
1436 | pub fn token_tree(&self) -> Option<TokenTree> { | 1530 | pub fn token_tree(&self) -> Option<TokenTree> { |
1437 | super::child_opt(self) | 1531 | AstChildren::new(&self.syntax).next() |
1438 | } | 1532 | } |
1439 | |||
1440 | pub fn path(&self) -> Option<Path> { | 1533 | pub fn path(&self) -> Option<Path> { |
1441 | super::child_opt(self) | 1534 | AstChildren::new(&self.syntax).next() |
1442 | } | 1535 | } |
1443 | } | 1536 | } |
1444 | |||
1445 | // MacroItems | ||
1446 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1537 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1447 | pub struct MacroItems { | 1538 | pub struct MacroItems { |
1448 | pub(crate) syntax: SyntaxNode, | 1539 | pub(crate) syntax: SyntaxNode, |
1449 | } | 1540 | } |
1450 | |||
1451 | impl AstNode for MacroItems { | 1541 | impl AstNode for MacroItems { |
1452 | fn can_cast(kind: SyntaxKind) -> bool { | 1542 | fn can_cast(kind: SyntaxKind) -> bool { |
1453 | match kind { | 1543 | match kind { |
@@ -1456,22 +1546,23 @@ impl AstNode for MacroItems { | |||
1456 | } | 1546 | } |
1457 | } | 1547 | } |
1458 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1548 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1459 | if Self::can_cast(syntax.kind()) { Some(MacroItems { syntax }) } else { None } | 1549 | if Self::can_cast(syntax.kind()) { |
1550 | Some(Self { syntax }) | ||
1551 | } else { | ||
1552 | None | ||
1553 | } | ||
1554 | } | ||
1555 | fn syntax(&self) -> &SyntaxNode { | ||
1556 | &self.syntax | ||
1460 | } | 1557 | } |
1461 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1462 | } | 1558 | } |
1463 | |||
1464 | |||
1465 | impl ast::ModuleItemOwner for MacroItems {} | 1559 | impl ast::ModuleItemOwner for MacroItems {} |
1466 | impl ast::FnDefOwner for MacroItems {} | 1560 | impl ast::FnDefOwner for MacroItems {} |
1467 | impl MacroItems {} | 1561 | impl MacroItems {} |
1468 | |||
1469 | // MacroStmts | ||
1470 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1562 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1471 | pub struct MacroStmts { | 1563 | pub struct MacroStmts { |
1472 | pub(crate) syntax: SyntaxNode, | 1564 | pub(crate) syntax: SyntaxNode, |
1473 | } | 1565 | } |
1474 | |||
1475 | impl AstNode for MacroStmts { | 1566 | impl AstNode for MacroStmts { |
1476 | fn can_cast(kind: SyntaxKind) -> bool { | 1567 | fn can_cast(kind: SyntaxKind) -> bool { |
1477 | match kind { | 1568 | match kind { |
@@ -1480,28 +1571,28 @@ impl AstNode for MacroStmts { | |||
1480 | } | 1571 | } |
1481 | } | 1572 | } |
1482 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1573 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1483 | if Self::can_cast(syntax.kind()) { Some(MacroStmts { syntax }) } else { None } | 1574 | if Self::can_cast(syntax.kind()) { |
1575 | Some(Self { syntax }) | ||
1576 | } else { | ||
1577 | None | ||
1578 | } | ||
1579 | } | ||
1580 | fn syntax(&self) -> &SyntaxNode { | ||
1581 | &self.syntax | ||
1484 | } | 1582 | } |
1485 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1486 | } | 1583 | } |
1487 | |||
1488 | |||
1489 | impl MacroStmts { | 1584 | impl MacroStmts { |
1490 | pub fn statements(&self) -> impl Iterator<Item = Stmt> { | 1585 | pub fn statements(&self) -> AstChildren<Stmt> { |
1491 | super::children(self) | 1586 | AstChildren::new(&self.syntax) |
1492 | } | 1587 | } |
1493 | |||
1494 | pub fn expr(&self) -> Option<Expr> { | 1588 | pub fn expr(&self) -> Option<Expr> { |
1495 | super::child_opt(self) | 1589 | AstChildren::new(&self.syntax).next() |
1496 | } | 1590 | } |
1497 | } | 1591 | } |
1498 | |||
1499 | // MatchArm | ||
1500 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1592 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1501 | pub struct MatchArm { | 1593 | pub struct MatchArm { |
1502 | pub(crate) syntax: SyntaxNode, | 1594 | pub(crate) syntax: SyntaxNode, |
1503 | } | 1595 | } |
1504 | |||
1505 | impl AstNode for MatchArm { | 1596 | impl AstNode for MatchArm { |
1506 | fn can_cast(kind: SyntaxKind) -> bool { | 1597 | fn can_cast(kind: SyntaxKind) -> bool { |
1507 | match kind { | 1598 | match kind { |
@@ -1510,33 +1601,32 @@ impl AstNode for MatchArm { | |||
1510 | } | 1601 | } |
1511 | } | 1602 | } |
1512 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1603 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1513 | if Self::can_cast(syntax.kind()) { Some(MatchArm { syntax }) } else { None } | 1604 | if Self::can_cast(syntax.kind()) { |
1605 | Some(Self { syntax }) | ||
1606 | } else { | ||
1607 | None | ||
1608 | } | ||
1609 | } | ||
1610 | fn syntax(&self) -> &SyntaxNode { | ||
1611 | &self.syntax | ||
1514 | } | 1612 | } |
1515 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1516 | } | 1613 | } |
1517 | |||
1518 | |||
1519 | impl ast::AttrsOwner for MatchArm {} | 1614 | impl ast::AttrsOwner for MatchArm {} |
1520 | impl MatchArm { | 1615 | impl MatchArm { |
1521 | pub fn pats(&self) -> impl Iterator<Item = Pat> { | 1616 | pub fn pats(&self) -> AstChildren<Pat> { |
1522 | super::children(self) | 1617 | AstChildren::new(&self.syntax) |
1523 | } | 1618 | } |
1524 | |||
1525 | pub fn guard(&self) -> Option<MatchGuard> { | 1619 | pub fn guard(&self) -> Option<MatchGuard> { |
1526 | super::child_opt(self) | 1620 | AstChildren::new(&self.syntax).next() |
1527 | } | 1621 | } |
1528 | |||
1529 | pub fn expr(&self) -> Option<Expr> { | 1622 | pub fn expr(&self) -> Option<Expr> { |
1530 | super::child_opt(self) | 1623 | AstChildren::new(&self.syntax).next() |
1531 | } | 1624 | } |
1532 | } | 1625 | } |
1533 | |||
1534 | // MatchArmList | ||
1535 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1626 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1536 | pub struct MatchArmList { | 1627 | pub struct MatchArmList { |
1537 | pub(crate) syntax: SyntaxNode, | 1628 | pub(crate) syntax: SyntaxNode, |
1538 | } | 1629 | } |
1539 | |||
1540 | impl AstNode for MatchArmList { | 1630 | impl AstNode for MatchArmList { |
1541 | fn can_cast(kind: SyntaxKind) -> bool { | 1631 | fn can_cast(kind: SyntaxKind) -> bool { |
1542 | match kind { | 1632 | match kind { |
@@ -1545,25 +1635,26 @@ impl AstNode for MatchArmList { | |||
1545 | } | 1635 | } |
1546 | } | 1636 | } |
1547 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1637 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1548 | if Self::can_cast(syntax.kind()) { Some(MatchArmList { syntax }) } else { None } | 1638 | if Self::can_cast(syntax.kind()) { |
1639 | Some(Self { syntax }) | ||
1640 | } else { | ||
1641 | None | ||
1642 | } | ||
1643 | } | ||
1644 | fn syntax(&self) -> &SyntaxNode { | ||
1645 | &self.syntax | ||
1549 | } | 1646 | } |
1550 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1551 | } | 1647 | } |
1552 | |||
1553 | |||
1554 | impl ast::AttrsOwner for MatchArmList {} | 1648 | impl ast::AttrsOwner for MatchArmList {} |
1555 | impl MatchArmList { | 1649 | impl MatchArmList { |
1556 | pub fn arms(&self) -> impl Iterator<Item = MatchArm> { | 1650 | pub fn arms(&self) -> AstChildren<MatchArm> { |
1557 | super::children(self) | 1651 | AstChildren::new(&self.syntax) |
1558 | } | 1652 | } |
1559 | } | 1653 | } |
1560 | |||
1561 | // MatchExpr | ||
1562 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1654 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1563 | pub struct MatchExpr { | 1655 | pub struct MatchExpr { |
1564 | pub(crate) syntax: SyntaxNode, | 1656 | pub(crate) syntax: SyntaxNode, |
1565 | } | 1657 | } |
1566 | |||
1567 | impl AstNode for MatchExpr { | 1658 | impl AstNode for MatchExpr { |
1568 | fn can_cast(kind: SyntaxKind) -> bool { | 1659 | fn can_cast(kind: SyntaxKind) -> bool { |
1569 | match kind { | 1660 | match kind { |
@@ -1572,28 +1663,28 @@ impl AstNode for MatchExpr { | |||
1572 | } | 1663 | } |
1573 | } | 1664 | } |
1574 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1665 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1575 | if Self::can_cast(syntax.kind()) { Some(MatchExpr { syntax }) } else { None } | 1666 | if Self::can_cast(syntax.kind()) { |
1667 | Some(Self { syntax }) | ||
1668 | } else { | ||
1669 | None | ||
1670 | } | ||
1671 | } | ||
1672 | fn syntax(&self) -> &SyntaxNode { | ||
1673 | &self.syntax | ||
1576 | } | 1674 | } |
1577 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1578 | } | 1675 | } |
1579 | |||
1580 | |||
1581 | impl MatchExpr { | 1676 | impl MatchExpr { |
1582 | pub fn expr(&self) -> Option<Expr> { | 1677 | pub fn expr(&self) -> Option<Expr> { |
1583 | super::child_opt(self) | 1678 | AstChildren::new(&self.syntax).next() |
1584 | } | 1679 | } |
1585 | |||
1586 | pub fn match_arm_list(&self) -> Option<MatchArmList> { | 1680 | pub fn match_arm_list(&self) -> Option<MatchArmList> { |
1587 | super::child_opt(self) | 1681 | AstChildren::new(&self.syntax).next() |
1588 | } | 1682 | } |
1589 | } | 1683 | } |
1590 | |||
1591 | // MatchGuard | ||
1592 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1684 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1593 | pub struct MatchGuard { | 1685 | pub struct MatchGuard { |
1594 | pub(crate) syntax: SyntaxNode, | 1686 | pub(crate) syntax: SyntaxNode, |
1595 | } | 1687 | } |
1596 | |||
1597 | impl AstNode for MatchGuard { | 1688 | impl AstNode for MatchGuard { |
1598 | fn can_cast(kind: SyntaxKind) -> bool { | 1689 | fn can_cast(kind: SyntaxKind) -> bool { |
1599 | match kind { | 1690 | match kind { |
@@ -1602,24 +1693,25 @@ impl AstNode for MatchGuard { | |||
1602 | } | 1693 | } |
1603 | } | 1694 | } |
1604 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1695 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1605 | if Self::can_cast(syntax.kind()) { Some(MatchGuard { syntax }) } else { None } | 1696 | if Self::can_cast(syntax.kind()) { |
1697 | Some(Self { syntax }) | ||
1698 | } else { | ||
1699 | None | ||
1700 | } | ||
1701 | } | ||
1702 | fn syntax(&self) -> &SyntaxNode { | ||
1703 | &self.syntax | ||
1606 | } | 1704 | } |
1607 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1608 | } | 1705 | } |
1609 | |||
1610 | |||
1611 | impl MatchGuard { | 1706 | impl MatchGuard { |
1612 | pub fn expr(&self) -> Option<Expr> { | 1707 | pub fn expr(&self) -> Option<Expr> { |
1613 | super::child_opt(self) | 1708 | AstChildren::new(&self.syntax).next() |
1614 | } | 1709 | } |
1615 | } | 1710 | } |
1616 | |||
1617 | // MethodCallExpr | ||
1618 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1711 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1619 | pub struct MethodCallExpr { | 1712 | pub struct MethodCallExpr { |
1620 | pub(crate) syntax: SyntaxNode, | 1713 | pub(crate) syntax: SyntaxNode, |
1621 | } | 1714 | } |
1622 | |||
1623 | impl AstNode for MethodCallExpr { | 1715 | impl AstNode for MethodCallExpr { |
1624 | fn can_cast(kind: SyntaxKind) -> bool { | 1716 | fn can_cast(kind: SyntaxKind) -> bool { |
1625 | match kind { | 1717 | match kind { |
@@ -1628,33 +1720,32 @@ impl AstNode for MethodCallExpr { | |||
1628 | } | 1720 | } |
1629 | } | 1721 | } |
1630 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1722 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1631 | if Self::can_cast(syntax.kind()) { Some(MethodCallExpr { syntax }) } else { None } | 1723 | if Self::can_cast(syntax.kind()) { |
1724 | Some(Self { syntax }) | ||
1725 | } else { | ||
1726 | None | ||
1727 | } | ||
1728 | } | ||
1729 | fn syntax(&self) -> &SyntaxNode { | ||
1730 | &self.syntax | ||
1632 | } | 1731 | } |
1633 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1634 | } | 1732 | } |
1635 | |||
1636 | |||
1637 | impl ast::ArgListOwner for MethodCallExpr {} | 1733 | impl ast::ArgListOwner for MethodCallExpr {} |
1638 | impl MethodCallExpr { | 1734 | impl MethodCallExpr { |
1639 | pub fn expr(&self) -> Option<Expr> { | 1735 | pub fn expr(&self) -> Option<Expr> { |
1640 | super::child_opt(self) | 1736 | AstChildren::new(&self.syntax).next() |
1641 | } | 1737 | } |
1642 | |||
1643 | pub fn name_ref(&self) -> Option<NameRef> { | 1738 | pub fn name_ref(&self) -> Option<NameRef> { |
1644 | super::child_opt(self) | 1739 | AstChildren::new(&self.syntax).next() |
1645 | } | 1740 | } |
1646 | |||
1647 | pub fn type_arg_list(&self) -> Option<TypeArgList> { | 1741 | pub fn type_arg_list(&self) -> Option<TypeArgList> { |
1648 | super::child_opt(self) | 1742 | AstChildren::new(&self.syntax).next() |
1649 | } | 1743 | } |
1650 | } | 1744 | } |
1651 | |||
1652 | // Module | ||
1653 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1745 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1654 | pub struct Module { | 1746 | pub struct Module { |
1655 | pub(crate) syntax: SyntaxNode, | 1747 | pub(crate) syntax: SyntaxNode, |
1656 | } | 1748 | } |
1657 | |||
1658 | impl AstNode for Module { | 1749 | impl AstNode for Module { |
1659 | fn can_cast(kind: SyntaxKind) -> bool { | 1750 | fn can_cast(kind: SyntaxKind) -> bool { |
1660 | match kind { | 1751 | match kind { |
@@ -1663,43 +1754,48 @@ impl AstNode for Module { | |||
1663 | } | 1754 | } |
1664 | } | 1755 | } |
1665 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1756 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1666 | if Self::can_cast(syntax.kind()) { Some(Module { syntax }) } else { None } | 1757 | if Self::can_cast(syntax.kind()) { |
1758 | Some(Self { syntax }) | ||
1759 | } else { | ||
1760 | None | ||
1761 | } | ||
1762 | } | ||
1763 | fn syntax(&self) -> &SyntaxNode { | ||
1764 | &self.syntax | ||
1667 | } | 1765 | } |
1668 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1669 | } | 1766 | } |
1670 | |||
1671 | |||
1672 | impl ast::VisibilityOwner for Module {} | 1767 | impl ast::VisibilityOwner for Module {} |
1673 | impl ast::NameOwner for Module {} | 1768 | impl ast::NameOwner for Module {} |
1674 | impl ast::AttrsOwner for Module {} | 1769 | impl ast::AttrsOwner for Module {} |
1675 | impl ast::DocCommentsOwner for Module {} | 1770 | impl ast::DocCommentsOwner for Module {} |
1676 | impl Module { | 1771 | impl Module { |
1677 | pub fn item_list(&self) -> Option<ItemList> { | 1772 | pub fn item_list(&self) -> Option<ItemList> { |
1678 | super::child_opt(self) | 1773 | AstChildren::new(&self.syntax).next() |
1679 | } | 1774 | } |
1680 | } | 1775 | } |
1681 | |||
1682 | // ModuleItem | ||
1683 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1776 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1684 | pub struct ModuleItem { | 1777 | pub struct ModuleItem { |
1685 | pub(crate) syntax: SyntaxNode, | 1778 | pub(crate) syntax: SyntaxNode, |
1686 | } | 1779 | } |
1687 | |||
1688 | impl AstNode for ModuleItem { | 1780 | impl AstNode for ModuleItem { |
1689 | fn can_cast(kind: SyntaxKind) -> bool { | 1781 | fn can_cast(kind: SyntaxKind) -> bool { |
1690 | match kind { | 1782 | match kind { |
1691 | | STRUCT_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_BLOCK | USE_ITEM | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE => true, | 1783 | STRUCT_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_BLOCK | USE_ITEM |
1784 | | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE => true, | ||
1692 | _ => false, | 1785 | _ => false, |
1693 | } | 1786 | } |
1694 | } | 1787 | } |
1695 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1788 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1696 | if Self::can_cast(syntax.kind()) { Some(ModuleItem { syntax }) } else { None } | 1789 | if Self::can_cast(syntax.kind()) { |
1790 | Some(Self { syntax }) | ||
1791 | } else { | ||
1792 | None | ||
1793 | } | ||
1794 | } | ||
1795 | fn syntax(&self) -> &SyntaxNode { | ||
1796 | &self.syntax | ||
1697 | } | 1797 | } |
1698 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1699 | } | 1798 | } |
1700 | |||
1701 | |||
1702 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
1703 | pub enum ModuleItemKind { | 1799 | pub enum ModuleItemKind { |
1704 | StructDef(StructDef), | 1800 | StructDef(StructDef), |
1705 | EnumDef(EnumDef), | 1801 | EnumDef(EnumDef), |
@@ -1714,65 +1810,84 @@ pub enum ModuleItemKind { | |||
1714 | Module(Module), | 1810 | Module(Module), |
1715 | } | 1811 | } |
1716 | impl From<StructDef> for ModuleItem { | 1812 | impl From<StructDef> for ModuleItem { |
1717 | fn from(n: StructDef) -> ModuleItem { ModuleItem { syntax: n.syntax } } | 1813 | fn from(node: StructDef) -> ModuleItem { |
1814 | ModuleItem { syntax: node.syntax } | ||
1815 | } | ||
1718 | } | 1816 | } |
1719 | impl From<EnumDef> for ModuleItem { | 1817 | impl From<EnumDef> for ModuleItem { |
1720 | fn from(n: EnumDef) -> ModuleItem { ModuleItem { syntax: n.syntax } } | 1818 | fn from(node: EnumDef) -> ModuleItem { |
1819 | ModuleItem { syntax: node.syntax } | ||
1820 | } | ||
1721 | } | 1821 | } |
1722 | impl From<FnDef> for ModuleItem { | 1822 | impl From<FnDef> for ModuleItem { |
1723 | fn from(n: FnDef) -> ModuleItem { ModuleItem { syntax: n.syntax } } | 1823 | fn from(node: FnDef) -> ModuleItem { |
1824 | ModuleItem { syntax: node.syntax } | ||
1825 | } | ||
1724 | } | 1826 | } |
1725 | impl From<TraitDef> for ModuleItem { | 1827 | impl From<TraitDef> for ModuleItem { |
1726 | fn from(n: TraitDef) -> ModuleItem { ModuleItem { syntax: n.syntax } } | 1828 | fn from(node: TraitDef) -> ModuleItem { |
1829 | ModuleItem { syntax: node.syntax } | ||
1830 | } | ||
1727 | } | 1831 | } |
1728 | impl From<TypeAliasDef> for ModuleItem { | 1832 | impl From<TypeAliasDef> for ModuleItem { |
1729 | fn from(n: TypeAliasDef) -> ModuleItem { ModuleItem { syntax: n.syntax } } | 1833 | fn from(node: TypeAliasDef) -> ModuleItem { |
1834 | ModuleItem { syntax: node.syntax } | ||
1835 | } | ||
1730 | } | 1836 | } |
1731 | impl From<ImplBlock> for ModuleItem { | 1837 | impl From<ImplBlock> for ModuleItem { |
1732 | fn from(n: ImplBlock) -> ModuleItem { ModuleItem { syntax: n.syntax } } | 1838 | fn from(node: ImplBlock) -> ModuleItem { |
1839 | ModuleItem { syntax: node.syntax } | ||
1840 | } | ||
1733 | } | 1841 | } |
1734 | impl From<UseItem> for ModuleItem { | 1842 | impl From<UseItem> for ModuleItem { |
1735 | fn from(n: UseItem) -> ModuleItem { ModuleItem { syntax: n.syntax } } | 1843 | fn from(node: UseItem) -> ModuleItem { |
1844 | ModuleItem { syntax: node.syntax } | ||
1845 | } | ||
1736 | } | 1846 | } |
1737 | impl From<ExternCrateItem> for ModuleItem { | 1847 | impl From<ExternCrateItem> for ModuleItem { |
1738 | fn from(n: ExternCrateItem) -> ModuleItem { ModuleItem { syntax: n.syntax } } | 1848 | fn from(node: ExternCrateItem) -> ModuleItem { |
1849 | ModuleItem { syntax: node.syntax } | ||
1850 | } | ||
1739 | } | 1851 | } |
1740 | impl From<ConstDef> for ModuleItem { | 1852 | impl From<ConstDef> for ModuleItem { |
1741 | fn from(n: ConstDef) -> ModuleItem { ModuleItem { syntax: n.syntax } } | 1853 | fn from(node: ConstDef) -> ModuleItem { |
1854 | ModuleItem { syntax: node.syntax } | ||
1855 | } | ||
1742 | } | 1856 | } |
1743 | impl From<StaticDef> for ModuleItem { | 1857 | impl From<StaticDef> for ModuleItem { |
1744 | fn from(n: StaticDef) -> ModuleItem { ModuleItem { syntax: n.syntax } } | 1858 | fn from(node: StaticDef) -> ModuleItem { |
1859 | ModuleItem { syntax: node.syntax } | ||
1860 | } | ||
1745 | } | 1861 | } |
1746 | impl From<Module> for ModuleItem { | 1862 | impl From<Module> for ModuleItem { |
1747 | fn from(n: Module) -> ModuleItem { ModuleItem { syntax: n.syntax } } | 1863 | fn from(node: Module) -> ModuleItem { |
1864 | ModuleItem { syntax: node.syntax } | ||
1865 | } | ||
1748 | } | 1866 | } |
1749 | impl ModuleItem { | 1867 | impl ModuleItem { |
1750 | pub fn kind(&self) -> ModuleItemKind { | 1868 | pub fn kind(&self) -> ModuleItemKind { |
1751 | match self.syntax.kind() { | 1869 | let syntax = self.syntax.clone(); |
1752 | STRUCT_DEF => ModuleItemKind::StructDef(StructDef::cast(self.syntax.clone()).unwrap()), | 1870 | match syntax.kind() { |
1753 | ENUM_DEF => ModuleItemKind::EnumDef(EnumDef::cast(self.syntax.clone()).unwrap()), | 1871 | STRUCT_DEF => ModuleItemKind::StructDef(StructDef { syntax }), |
1754 | FN_DEF => ModuleItemKind::FnDef(FnDef::cast(self.syntax.clone()).unwrap()), | 1872 | ENUM_DEF => ModuleItemKind::EnumDef(EnumDef { syntax }), |
1755 | TRAIT_DEF => ModuleItemKind::TraitDef(TraitDef::cast(self.syntax.clone()).unwrap()), | 1873 | FN_DEF => ModuleItemKind::FnDef(FnDef { syntax }), |
1756 | TYPE_ALIAS_DEF => ModuleItemKind::TypeAliasDef(TypeAliasDef::cast(self.syntax.clone()).unwrap()), | 1874 | TRAIT_DEF => ModuleItemKind::TraitDef(TraitDef { syntax }), |
1757 | IMPL_BLOCK => ModuleItemKind::ImplBlock(ImplBlock::cast(self.syntax.clone()).unwrap()), | 1875 | TYPE_ALIAS_DEF => ModuleItemKind::TypeAliasDef(TypeAliasDef { syntax }), |
1758 | USE_ITEM => ModuleItemKind::UseItem(UseItem::cast(self.syntax.clone()).unwrap()), | 1876 | IMPL_BLOCK => ModuleItemKind::ImplBlock(ImplBlock { syntax }), |
1759 | EXTERN_CRATE_ITEM => ModuleItemKind::ExternCrateItem(ExternCrateItem::cast(self.syntax.clone()).unwrap()), | 1877 | USE_ITEM => ModuleItemKind::UseItem(UseItem { syntax }), |
1760 | CONST_DEF => ModuleItemKind::ConstDef(ConstDef::cast(self.syntax.clone()).unwrap()), | 1878 | EXTERN_CRATE_ITEM => ModuleItemKind::ExternCrateItem(ExternCrateItem { syntax }), |
1761 | STATIC_DEF => ModuleItemKind::StaticDef(StaticDef::cast(self.syntax.clone()).unwrap()), | 1879 | CONST_DEF => ModuleItemKind::ConstDef(ConstDef { syntax }), |
1762 | MODULE => ModuleItemKind::Module(Module::cast(self.syntax.clone()).unwrap()), | 1880 | STATIC_DEF => ModuleItemKind::StaticDef(StaticDef { syntax }), |
1881 | MODULE => ModuleItemKind::Module(Module { syntax }), | ||
1763 | _ => unreachable!(), | 1882 | _ => unreachable!(), |
1764 | } | 1883 | } |
1765 | } | 1884 | } |
1766 | } | 1885 | } |
1767 | |||
1768 | impl ModuleItem {} | 1886 | impl ModuleItem {} |
1769 | |||
1770 | // Name | ||
1771 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1887 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1772 | pub struct Name { | 1888 | pub struct Name { |
1773 | pub(crate) syntax: SyntaxNode, | 1889 | pub(crate) syntax: SyntaxNode, |
1774 | } | 1890 | } |
1775 | |||
1776 | impl AstNode for Name { | 1891 | impl AstNode for Name { |
1777 | fn can_cast(kind: SyntaxKind) -> bool { | 1892 | fn can_cast(kind: SyntaxKind) -> bool { |
1778 | match kind { | 1893 | match kind { |
@@ -1781,20 +1896,21 @@ impl AstNode for Name { | |||
1781 | } | 1896 | } |
1782 | } | 1897 | } |
1783 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1898 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1784 | if Self::can_cast(syntax.kind()) { Some(Name { syntax }) } else { None } | 1899 | if Self::can_cast(syntax.kind()) { |
1900 | Some(Self { syntax }) | ||
1901 | } else { | ||
1902 | None | ||
1903 | } | ||
1904 | } | ||
1905 | fn syntax(&self) -> &SyntaxNode { | ||
1906 | &self.syntax | ||
1785 | } | 1907 | } |
1786 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1787 | } | 1908 | } |
1788 | |||
1789 | |||
1790 | impl Name {} | 1909 | impl Name {} |
1791 | |||
1792 | // NameRef | ||
1793 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1910 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1794 | pub struct NameRef { | 1911 | pub struct NameRef { |
1795 | pub(crate) syntax: SyntaxNode, | 1912 | pub(crate) syntax: SyntaxNode, |
1796 | } | 1913 | } |
1797 | |||
1798 | impl AstNode for NameRef { | 1914 | impl AstNode for NameRef { |
1799 | fn can_cast(kind: SyntaxKind) -> bool { | 1915 | fn can_cast(kind: SyntaxKind) -> bool { |
1800 | match kind { | 1916 | match kind { |
@@ -1803,20 +1919,21 @@ impl AstNode for NameRef { | |||
1803 | } | 1919 | } |
1804 | } | 1920 | } |
1805 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1921 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1806 | if Self::can_cast(syntax.kind()) { Some(NameRef { syntax }) } else { None } | 1922 | if Self::can_cast(syntax.kind()) { |
1923 | Some(Self { syntax }) | ||
1924 | } else { | ||
1925 | None | ||
1926 | } | ||
1927 | } | ||
1928 | fn syntax(&self) -> &SyntaxNode { | ||
1929 | &self.syntax | ||
1807 | } | 1930 | } |
1808 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1809 | } | 1931 | } |
1810 | |||
1811 | |||
1812 | impl NameRef {} | 1932 | impl NameRef {} |
1813 | |||
1814 | // NamedField | ||
1815 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1933 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1816 | pub struct NamedField { | 1934 | pub struct NamedField { |
1817 | pub(crate) syntax: SyntaxNode, | 1935 | pub(crate) syntax: SyntaxNode, |
1818 | } | 1936 | } |
1819 | |||
1820 | impl AstNode for NamedField { | 1937 | impl AstNode for NamedField { |
1821 | fn can_cast(kind: SyntaxKind) -> bool { | 1938 | fn can_cast(kind: SyntaxKind) -> bool { |
1822 | match kind { | 1939 | match kind { |
@@ -1825,28 +1942,28 @@ impl AstNode for NamedField { | |||
1825 | } | 1942 | } |
1826 | } | 1943 | } |
1827 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1944 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1828 | if Self::can_cast(syntax.kind()) { Some(NamedField { syntax }) } else { None } | 1945 | if Self::can_cast(syntax.kind()) { |
1946 | Some(Self { syntax }) | ||
1947 | } else { | ||
1948 | None | ||
1949 | } | ||
1950 | } | ||
1951 | fn syntax(&self) -> &SyntaxNode { | ||
1952 | &self.syntax | ||
1829 | } | 1953 | } |
1830 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1831 | } | 1954 | } |
1832 | |||
1833 | |||
1834 | impl NamedField { | 1955 | impl NamedField { |
1835 | pub fn name_ref(&self) -> Option<NameRef> { | 1956 | pub fn name_ref(&self) -> Option<NameRef> { |
1836 | super::child_opt(self) | 1957 | AstChildren::new(&self.syntax).next() |
1837 | } | 1958 | } |
1838 | |||
1839 | pub fn expr(&self) -> Option<Expr> { | 1959 | pub fn expr(&self) -> Option<Expr> { |
1840 | super::child_opt(self) | 1960 | AstChildren::new(&self.syntax).next() |
1841 | } | 1961 | } |
1842 | } | 1962 | } |
1843 | |||
1844 | // NamedFieldDef | ||
1845 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1963 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1846 | pub struct NamedFieldDef { | 1964 | pub struct NamedFieldDef { |
1847 | pub(crate) syntax: SyntaxNode, | 1965 | pub(crate) syntax: SyntaxNode, |
1848 | } | 1966 | } |
1849 | |||
1850 | impl AstNode for NamedFieldDef { | 1967 | impl AstNode for NamedFieldDef { |
1851 | fn can_cast(kind: SyntaxKind) -> bool { | 1968 | fn can_cast(kind: SyntaxKind) -> bool { |
1852 | match kind { | 1969 | match kind { |
@@ -1855,25 +1972,26 @@ impl AstNode for NamedFieldDef { | |||
1855 | } | 1972 | } |
1856 | } | 1973 | } |
1857 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 1974 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1858 | if Self::can_cast(syntax.kind()) { Some(NamedFieldDef { syntax }) } else { None } | 1975 | if Self::can_cast(syntax.kind()) { |
1976 | Some(Self { syntax }) | ||
1977 | } else { | ||
1978 | None | ||
1979 | } | ||
1980 | } | ||
1981 | fn syntax(&self) -> &SyntaxNode { | ||
1982 | &self.syntax | ||
1859 | } | 1983 | } |
1860 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1861 | } | 1984 | } |
1862 | |||
1863 | |||
1864 | impl ast::VisibilityOwner for NamedFieldDef {} | 1985 | impl ast::VisibilityOwner for NamedFieldDef {} |
1865 | impl ast::NameOwner for NamedFieldDef {} | 1986 | impl ast::NameOwner for NamedFieldDef {} |
1866 | impl ast::AttrsOwner for NamedFieldDef {} | 1987 | impl ast::AttrsOwner for NamedFieldDef {} |
1867 | impl ast::DocCommentsOwner for NamedFieldDef {} | 1988 | impl ast::DocCommentsOwner for NamedFieldDef {} |
1868 | impl ast::TypeAscriptionOwner for NamedFieldDef {} | 1989 | impl ast::TypeAscriptionOwner for NamedFieldDef {} |
1869 | impl NamedFieldDef {} | 1990 | impl NamedFieldDef {} |
1870 | |||
1871 | // NamedFieldDefList | ||
1872 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1991 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1873 | pub struct NamedFieldDefList { | 1992 | pub struct NamedFieldDefList { |
1874 | pub(crate) syntax: SyntaxNode, | 1993 | pub(crate) syntax: SyntaxNode, |
1875 | } | 1994 | } |
1876 | |||
1877 | impl AstNode for NamedFieldDefList { | 1995 | impl AstNode for NamedFieldDefList { |
1878 | fn can_cast(kind: SyntaxKind) -> bool { | 1996 | fn can_cast(kind: SyntaxKind) -> bool { |
1879 | match kind { | 1997 | match kind { |
@@ -1882,24 +2000,25 @@ impl AstNode for NamedFieldDefList { | |||
1882 | } | 2000 | } |
1883 | } | 2001 | } |
1884 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2002 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1885 | if Self::can_cast(syntax.kind()) { Some(NamedFieldDefList { syntax }) } else { None } | 2003 | if Self::can_cast(syntax.kind()) { |
2004 | Some(Self { syntax }) | ||
2005 | } else { | ||
2006 | None | ||
2007 | } | ||
2008 | } | ||
2009 | fn syntax(&self) -> &SyntaxNode { | ||
2010 | &self.syntax | ||
1886 | } | 2011 | } |
1887 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1888 | } | 2012 | } |
1889 | |||
1890 | |||
1891 | impl NamedFieldDefList { | 2013 | impl NamedFieldDefList { |
1892 | pub fn fields(&self) -> impl Iterator<Item = NamedFieldDef> { | 2014 | pub fn fields(&self) -> AstChildren<NamedFieldDef> { |
1893 | super::children(self) | 2015 | AstChildren::new(&self.syntax) |
1894 | } | 2016 | } |
1895 | } | 2017 | } |
1896 | |||
1897 | // NamedFieldList | ||
1898 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2018 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1899 | pub struct NamedFieldList { | 2019 | pub struct NamedFieldList { |
1900 | pub(crate) syntax: SyntaxNode, | 2020 | pub(crate) syntax: SyntaxNode, |
1901 | } | 2021 | } |
1902 | |||
1903 | impl AstNode for NamedFieldList { | 2022 | impl AstNode for NamedFieldList { |
1904 | fn can_cast(kind: SyntaxKind) -> bool { | 2023 | fn can_cast(kind: SyntaxKind) -> bool { |
1905 | match kind { | 2024 | match kind { |
@@ -1908,28 +2027,28 @@ impl AstNode for NamedFieldList { | |||
1908 | } | 2027 | } |
1909 | } | 2028 | } |
1910 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2029 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1911 | if Self::can_cast(syntax.kind()) { Some(NamedFieldList { syntax }) } else { None } | 2030 | if Self::can_cast(syntax.kind()) { |
2031 | Some(Self { syntax }) | ||
2032 | } else { | ||
2033 | None | ||
2034 | } | ||
2035 | } | ||
2036 | fn syntax(&self) -> &SyntaxNode { | ||
2037 | &self.syntax | ||
1912 | } | 2038 | } |
1913 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1914 | } | 2039 | } |
1915 | |||
1916 | |||
1917 | impl NamedFieldList { | 2040 | impl NamedFieldList { |
1918 | pub fn fields(&self) -> impl Iterator<Item = NamedField> { | 2041 | pub fn fields(&self) -> AstChildren<NamedField> { |
1919 | super::children(self) | 2042 | AstChildren::new(&self.syntax) |
1920 | } | 2043 | } |
1921 | |||
1922 | pub fn spread(&self) -> Option<Expr> { | 2044 | pub fn spread(&self) -> Option<Expr> { |
1923 | super::child_opt(self) | 2045 | AstChildren::new(&self.syntax).next() |
1924 | } | 2046 | } |
1925 | } | 2047 | } |
1926 | |||
1927 | // NeverType | ||
1928 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2048 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1929 | pub struct NeverType { | 2049 | pub struct NeverType { |
1930 | pub(crate) syntax: SyntaxNode, | 2050 | pub(crate) syntax: SyntaxNode, |
1931 | } | 2051 | } |
1932 | |||
1933 | impl AstNode for NeverType { | 2052 | impl AstNode for NeverType { |
1934 | fn can_cast(kind: SyntaxKind) -> bool { | 2053 | fn can_cast(kind: SyntaxKind) -> bool { |
1935 | match kind { | 2054 | match kind { |
@@ -1938,66 +2057,71 @@ impl AstNode for NeverType { | |||
1938 | } | 2057 | } |
1939 | } | 2058 | } |
1940 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2059 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1941 | if Self::can_cast(syntax.kind()) { Some(NeverType { syntax }) } else { None } | 2060 | if Self::can_cast(syntax.kind()) { |
2061 | Some(Self { syntax }) | ||
2062 | } else { | ||
2063 | None | ||
2064 | } | ||
2065 | } | ||
2066 | fn syntax(&self) -> &SyntaxNode { | ||
2067 | &self.syntax | ||
1942 | } | 2068 | } |
1943 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1944 | } | 2069 | } |
1945 | |||
1946 | |||
1947 | impl NeverType {} | 2070 | impl NeverType {} |
1948 | |||
1949 | // NominalDef | ||
1950 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2071 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1951 | pub struct NominalDef { | 2072 | pub struct NominalDef { |
1952 | pub(crate) syntax: SyntaxNode, | 2073 | pub(crate) syntax: SyntaxNode, |
1953 | } | 2074 | } |
1954 | |||
1955 | impl AstNode for NominalDef { | 2075 | impl AstNode for NominalDef { |
1956 | fn can_cast(kind: SyntaxKind) -> bool { | 2076 | fn can_cast(kind: SyntaxKind) -> bool { |
1957 | match kind { | 2077 | match kind { |
1958 | | STRUCT_DEF | ENUM_DEF => true, | 2078 | STRUCT_DEF | ENUM_DEF => true, |
1959 | _ => false, | 2079 | _ => false, |
1960 | } | 2080 | } |
1961 | } | 2081 | } |
1962 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2082 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
1963 | if Self::can_cast(syntax.kind()) { Some(NominalDef { syntax }) } else { None } | 2083 | if Self::can_cast(syntax.kind()) { |
2084 | Some(Self { syntax }) | ||
2085 | } else { | ||
2086 | None | ||
2087 | } | ||
2088 | } | ||
2089 | fn syntax(&self) -> &SyntaxNode { | ||
2090 | &self.syntax | ||
1964 | } | 2091 | } |
1965 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1966 | } | 2092 | } |
1967 | |||
1968 | |||
1969 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
1970 | pub enum NominalDefKind { | 2093 | pub enum NominalDefKind { |
1971 | StructDef(StructDef), | 2094 | StructDef(StructDef), |
1972 | EnumDef(EnumDef), | 2095 | EnumDef(EnumDef), |
1973 | } | 2096 | } |
1974 | impl From<StructDef> for NominalDef { | 2097 | impl From<StructDef> for NominalDef { |
1975 | fn from(n: StructDef) -> NominalDef { NominalDef { syntax: n.syntax } } | 2098 | fn from(node: StructDef) -> NominalDef { |
2099 | NominalDef { syntax: node.syntax } | ||
2100 | } | ||
1976 | } | 2101 | } |
1977 | impl From<EnumDef> for NominalDef { | 2102 | impl From<EnumDef> for NominalDef { |
1978 | fn from(n: EnumDef) -> NominalDef { NominalDef { syntax: n.syntax } } | 2103 | fn from(node: EnumDef) -> NominalDef { |
2104 | NominalDef { syntax: node.syntax } | ||
2105 | } | ||
1979 | } | 2106 | } |
1980 | impl NominalDef { | 2107 | impl NominalDef { |
1981 | pub fn kind(&self) -> NominalDefKind { | 2108 | pub fn kind(&self) -> NominalDefKind { |
1982 | match self.syntax.kind() { | 2109 | let syntax = self.syntax.clone(); |
1983 | STRUCT_DEF => NominalDefKind::StructDef(StructDef::cast(self.syntax.clone()).unwrap()), | 2110 | match syntax.kind() { |
1984 | ENUM_DEF => NominalDefKind::EnumDef(EnumDef::cast(self.syntax.clone()).unwrap()), | 2111 | STRUCT_DEF => NominalDefKind::StructDef(StructDef { syntax }), |
2112 | ENUM_DEF => NominalDefKind::EnumDef(EnumDef { syntax }), | ||
1985 | _ => unreachable!(), | 2113 | _ => unreachable!(), |
1986 | } | 2114 | } |
1987 | } | 2115 | } |
1988 | } | 2116 | } |
1989 | |||
1990 | impl ast::NameOwner for NominalDef {} | 2117 | impl ast::NameOwner for NominalDef {} |
1991 | impl ast::TypeParamsOwner for NominalDef {} | 2118 | impl ast::TypeParamsOwner for NominalDef {} |
1992 | impl ast::AttrsOwner for NominalDef {} | 2119 | impl ast::AttrsOwner for NominalDef {} |
1993 | impl NominalDef {} | 2120 | impl NominalDef {} |
1994 | |||
1995 | // Param | ||
1996 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2121 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1997 | pub struct Param { | 2122 | pub struct Param { |
1998 | pub(crate) syntax: SyntaxNode, | 2123 | pub(crate) syntax: SyntaxNode, |
1999 | } | 2124 | } |
2000 | |||
2001 | impl AstNode for Param { | 2125 | impl AstNode for Param { |
2002 | fn can_cast(kind: SyntaxKind) -> bool { | 2126 | fn can_cast(kind: SyntaxKind) -> bool { |
2003 | match kind { | 2127 | match kind { |
@@ -2006,26 +2130,27 @@ impl AstNode for Param { | |||
2006 | } | 2130 | } |
2007 | } | 2131 | } |
2008 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2132 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2009 | if Self::can_cast(syntax.kind()) { Some(Param { syntax }) } else { None } | 2133 | if Self::can_cast(syntax.kind()) { |
2134 | Some(Self { syntax }) | ||
2135 | } else { | ||
2136 | None | ||
2137 | } | ||
2138 | } | ||
2139 | fn syntax(&self) -> &SyntaxNode { | ||
2140 | &self.syntax | ||
2010 | } | 2141 | } |
2011 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2012 | } | 2142 | } |
2013 | |||
2014 | |||
2015 | impl ast::TypeAscriptionOwner for Param {} | 2143 | impl ast::TypeAscriptionOwner for Param {} |
2016 | impl ast::AttrsOwner for Param {} | 2144 | impl ast::AttrsOwner for Param {} |
2017 | impl Param { | 2145 | impl Param { |
2018 | pub fn pat(&self) -> Option<Pat> { | 2146 | pub fn pat(&self) -> Option<Pat> { |
2019 | super::child_opt(self) | 2147 | AstChildren::new(&self.syntax).next() |
2020 | } | 2148 | } |
2021 | } | 2149 | } |
2022 | |||
2023 | // ParamList | ||
2024 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2150 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2025 | pub struct ParamList { | 2151 | pub struct ParamList { |
2026 | pub(crate) syntax: SyntaxNode, | 2152 | pub(crate) syntax: SyntaxNode, |
2027 | } | 2153 | } |
2028 | |||
2029 | impl AstNode for ParamList { | 2154 | impl AstNode for ParamList { |
2030 | fn can_cast(kind: SyntaxKind) -> bool { | 2155 | fn can_cast(kind: SyntaxKind) -> bool { |
2031 | match kind { | 2156 | match kind { |
@@ -2034,28 +2159,28 @@ impl AstNode for ParamList { | |||
2034 | } | 2159 | } |
2035 | } | 2160 | } |
2036 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2161 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2037 | if Self::can_cast(syntax.kind()) { Some(ParamList { syntax }) } else { None } | 2162 | if Self::can_cast(syntax.kind()) { |
2163 | Some(Self { syntax }) | ||
2164 | } else { | ||
2165 | None | ||
2166 | } | ||
2167 | } | ||
2168 | fn syntax(&self) -> &SyntaxNode { | ||
2169 | &self.syntax | ||
2038 | } | 2170 | } |
2039 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2040 | } | 2171 | } |
2041 | |||
2042 | |||
2043 | impl ParamList { | 2172 | impl ParamList { |
2044 | pub fn params(&self) -> impl Iterator<Item = Param> { | 2173 | pub fn params(&self) -> AstChildren<Param> { |
2045 | super::children(self) | 2174 | AstChildren::new(&self.syntax) |
2046 | } | 2175 | } |
2047 | |||
2048 | pub fn self_param(&self) -> Option<SelfParam> { | 2176 | pub fn self_param(&self) -> Option<SelfParam> { |
2049 | super::child_opt(self) | 2177 | AstChildren::new(&self.syntax).next() |
2050 | } | 2178 | } |
2051 | } | 2179 | } |
2052 | |||
2053 | // ParenExpr | ||
2054 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2180 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2055 | pub struct ParenExpr { | 2181 | pub struct ParenExpr { |
2056 | pub(crate) syntax: SyntaxNode, | 2182 | pub(crate) syntax: SyntaxNode, |
2057 | } | 2183 | } |
2058 | |||
2059 | impl AstNode for ParenExpr { | 2184 | impl AstNode for ParenExpr { |
2060 | fn can_cast(kind: SyntaxKind) -> bool { | 2185 | fn can_cast(kind: SyntaxKind) -> bool { |
2061 | match kind { | 2186 | match kind { |
@@ -2064,24 +2189,25 @@ impl AstNode for ParenExpr { | |||
2064 | } | 2189 | } |
2065 | } | 2190 | } |
2066 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2191 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2067 | if Self::can_cast(syntax.kind()) { Some(ParenExpr { syntax }) } else { None } | 2192 | if Self::can_cast(syntax.kind()) { |
2193 | Some(Self { syntax }) | ||
2194 | } else { | ||
2195 | None | ||
2196 | } | ||
2197 | } | ||
2198 | fn syntax(&self) -> &SyntaxNode { | ||
2199 | &self.syntax | ||
2068 | } | 2200 | } |
2069 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2070 | } | 2201 | } |
2071 | |||
2072 | |||
2073 | impl ParenExpr { | 2202 | impl ParenExpr { |
2074 | pub fn expr(&self) -> Option<Expr> { | 2203 | pub fn expr(&self) -> Option<Expr> { |
2075 | super::child_opt(self) | 2204 | AstChildren::new(&self.syntax).next() |
2076 | } | 2205 | } |
2077 | } | 2206 | } |
2078 | |||
2079 | // ParenType | ||
2080 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2207 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2081 | pub struct ParenType { | 2208 | pub struct ParenType { |
2082 | pub(crate) syntax: SyntaxNode, | 2209 | pub(crate) syntax: SyntaxNode, |
2083 | } | 2210 | } |
2084 | |||
2085 | impl AstNode for ParenType { | 2211 | impl AstNode for ParenType { |
2086 | fn can_cast(kind: SyntaxKind) -> bool { | 2212 | fn can_cast(kind: SyntaxKind) -> bool { |
2087 | match kind { | 2213 | match kind { |
@@ -2090,39 +2216,44 @@ impl AstNode for ParenType { | |||
2090 | } | 2216 | } |
2091 | } | 2217 | } |
2092 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2218 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2093 | if Self::can_cast(syntax.kind()) { Some(ParenType { syntax }) } else { None } | 2219 | if Self::can_cast(syntax.kind()) { |
2220 | Some(Self { syntax }) | ||
2221 | } else { | ||
2222 | None | ||
2223 | } | ||
2224 | } | ||
2225 | fn syntax(&self) -> &SyntaxNode { | ||
2226 | &self.syntax | ||
2094 | } | 2227 | } |
2095 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2096 | } | 2228 | } |
2097 | |||
2098 | |||
2099 | impl ParenType { | 2229 | impl ParenType { |
2100 | pub fn type_ref(&self) -> Option<TypeRef> { | 2230 | pub fn type_ref(&self) -> Option<TypeRef> { |
2101 | super::child_opt(self) | 2231 | AstChildren::new(&self.syntax).next() |
2102 | } | 2232 | } |
2103 | } | 2233 | } |
2104 | |||
2105 | // Pat | ||
2106 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2234 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2107 | pub struct Pat { | 2235 | pub struct Pat { |
2108 | pub(crate) syntax: SyntaxNode, | 2236 | pub(crate) syntax: SyntaxNode, |
2109 | } | 2237 | } |
2110 | |||
2111 | impl AstNode for Pat { | 2238 | impl AstNode for Pat { |
2112 | fn can_cast(kind: SyntaxKind) -> bool { | 2239 | fn can_cast(kind: SyntaxKind) -> bool { |
2113 | match kind { | 2240 | match kind { |
2114 | | REF_PAT | BIND_PAT | PLACEHOLDER_PAT | PATH_PAT | STRUCT_PAT | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => true, | 2241 | REF_PAT | BIND_PAT | PLACEHOLDER_PAT | PATH_PAT | STRUCT_PAT | TUPLE_STRUCT_PAT |
2242 | | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => true, | ||
2115 | _ => false, | 2243 | _ => false, |
2116 | } | 2244 | } |
2117 | } | 2245 | } |
2118 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2246 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2119 | if Self::can_cast(syntax.kind()) { Some(Pat { syntax }) } else { None } | 2247 | if Self::can_cast(syntax.kind()) { |
2248 | Some(Self { syntax }) | ||
2249 | } else { | ||
2250 | None | ||
2251 | } | ||
2252 | } | ||
2253 | fn syntax(&self) -> &SyntaxNode { | ||
2254 | &self.syntax | ||
2120 | } | 2255 | } |
2121 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2122 | } | 2256 | } |
2123 | |||
2124 | |||
2125 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
2126 | pub enum PatKind { | 2257 | pub enum PatKind { |
2127 | RefPat(RefPat), | 2258 | RefPat(RefPat), |
2128 | BindPat(BindPat), | 2259 | BindPat(BindPat), |
@@ -2136,61 +2267,78 @@ pub enum PatKind { | |||
2136 | LiteralPat(LiteralPat), | 2267 | LiteralPat(LiteralPat), |
2137 | } | 2268 | } |
2138 | impl From<RefPat> for Pat { | 2269 | impl From<RefPat> for Pat { |
2139 | fn from(n: RefPat) -> Pat { Pat { syntax: n.syntax } } | 2270 | fn from(node: RefPat) -> Pat { |
2271 | Pat { syntax: node.syntax } | ||
2272 | } | ||
2140 | } | 2273 | } |
2141 | impl From<BindPat> for Pat { | 2274 | impl From<BindPat> for Pat { |
2142 | fn from(n: BindPat) -> Pat { Pat { syntax: n.syntax } } | 2275 | fn from(node: BindPat) -> Pat { |
2276 | Pat { syntax: node.syntax } | ||
2277 | } | ||
2143 | } | 2278 | } |
2144 | impl From<PlaceholderPat> for Pat { | 2279 | impl From<PlaceholderPat> for Pat { |
2145 | fn from(n: PlaceholderPat) -> Pat { Pat { syntax: n.syntax } } | 2280 | fn from(node: PlaceholderPat) -> Pat { |
2281 | Pat { syntax: node.syntax } | ||
2282 | } | ||
2146 | } | 2283 | } |
2147 | impl From<PathPat> for Pat { | 2284 | impl From<PathPat> for Pat { |
2148 | fn from(n: PathPat) -> Pat { Pat { syntax: n.syntax } } | 2285 | fn from(node: PathPat) -> Pat { |
2286 | Pat { syntax: node.syntax } | ||
2287 | } | ||
2149 | } | 2288 | } |
2150 | impl From<StructPat> for Pat { | 2289 | impl From<StructPat> for Pat { |
2151 | fn from(n: StructPat) -> Pat { Pat { syntax: n.syntax } } | 2290 | fn from(node: StructPat) -> Pat { |
2291 | Pat { syntax: node.syntax } | ||
2292 | } | ||
2152 | } | 2293 | } |
2153 | impl From<TupleStructPat> for Pat { | 2294 | impl From<TupleStructPat> for Pat { |
2154 | fn from(n: TupleStructPat) -> Pat { Pat { syntax: n.syntax } } | 2295 | fn from(node: TupleStructPat) -> Pat { |
2296 | Pat { syntax: node.syntax } | ||
2297 | } | ||
2155 | } | 2298 | } |
2156 | impl From<TuplePat> for Pat { | 2299 | impl From<TuplePat> for Pat { |
2157 | fn from(n: TuplePat) -> Pat { Pat { syntax: n.syntax } } | 2300 | fn from(node: TuplePat) -> Pat { |
2301 | Pat { syntax: node.syntax } | ||
2302 | } | ||
2158 | } | 2303 | } |
2159 | impl From<SlicePat> for Pat { | 2304 | impl From<SlicePat> for Pat { |
2160 | fn from(n: SlicePat) -> Pat { Pat { syntax: n.syntax } } | 2305 | fn from(node: SlicePat) -> Pat { |
2306 | Pat { syntax: node.syntax } | ||
2307 | } | ||
2161 | } | 2308 | } |
2162 | impl From<RangePat> for Pat { | 2309 | impl From<RangePat> for Pat { |
2163 | fn from(n: RangePat) -> Pat { Pat { syntax: n.syntax } } | 2310 | fn from(node: RangePat) -> Pat { |
2311 | Pat { syntax: node.syntax } | ||
2312 | } | ||
2164 | } | 2313 | } |
2165 | impl From<LiteralPat> for Pat { | 2314 | impl From<LiteralPat> for Pat { |
2166 | fn from(n: LiteralPat) -> Pat { Pat { syntax: n.syntax } } | 2315 | fn from(node: LiteralPat) -> Pat { |
2316 | Pat { syntax: node.syntax } | ||
2317 | } | ||
2167 | } | 2318 | } |
2168 | impl Pat { | 2319 | impl Pat { |
2169 | pub fn kind(&self) -> PatKind { | 2320 | pub fn kind(&self) -> PatKind { |
2170 | match self.syntax.kind() { | 2321 | let syntax = self.syntax.clone(); |
2171 | REF_PAT => PatKind::RefPat(RefPat::cast(self.syntax.clone()).unwrap()), | 2322 | match syntax.kind() { |
2172 | BIND_PAT => PatKind::BindPat(BindPat::cast(self.syntax.clone()).unwrap()), | 2323 | REF_PAT => PatKind::RefPat(RefPat { syntax }), |
2173 | PLACEHOLDER_PAT => PatKind::PlaceholderPat(PlaceholderPat::cast(self.syntax.clone()).unwrap()), | 2324 | BIND_PAT => PatKind::BindPat(BindPat { syntax }), |
2174 | PATH_PAT => PatKind::PathPat(PathPat::cast(self.syntax.clone()).unwrap()), | 2325 | PLACEHOLDER_PAT => PatKind::PlaceholderPat(PlaceholderPat { syntax }), |
2175 | STRUCT_PAT => PatKind::StructPat(StructPat::cast(self.syntax.clone()).unwrap()), | 2326 | PATH_PAT => PatKind::PathPat(PathPat { syntax }), |
2176 | TUPLE_STRUCT_PAT => PatKind::TupleStructPat(TupleStructPat::cast(self.syntax.clone()).unwrap()), | 2327 | STRUCT_PAT => PatKind::StructPat(StructPat { syntax }), |
2177 | TUPLE_PAT => PatKind::TuplePat(TuplePat::cast(self.syntax.clone()).unwrap()), | 2328 | TUPLE_STRUCT_PAT => PatKind::TupleStructPat(TupleStructPat { syntax }), |
2178 | SLICE_PAT => PatKind::SlicePat(SlicePat::cast(self.syntax.clone()).unwrap()), | 2329 | TUPLE_PAT => PatKind::TuplePat(TuplePat { syntax }), |
2179 | RANGE_PAT => PatKind::RangePat(RangePat::cast(self.syntax.clone()).unwrap()), | 2330 | SLICE_PAT => PatKind::SlicePat(SlicePat { syntax }), |
2180 | LITERAL_PAT => PatKind::LiteralPat(LiteralPat::cast(self.syntax.clone()).unwrap()), | 2331 | RANGE_PAT => PatKind::RangePat(RangePat { syntax }), |
2332 | LITERAL_PAT => PatKind::LiteralPat(LiteralPat { syntax }), | ||
2181 | _ => unreachable!(), | 2333 | _ => unreachable!(), |
2182 | } | 2334 | } |
2183 | } | 2335 | } |
2184 | } | 2336 | } |
2185 | |||
2186 | impl Pat {} | 2337 | impl Pat {} |
2187 | |||
2188 | // Path | ||
2189 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2338 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2190 | pub struct Path { | 2339 | pub struct Path { |
2191 | pub(crate) syntax: SyntaxNode, | 2340 | pub(crate) syntax: SyntaxNode, |
2192 | } | 2341 | } |
2193 | |||
2194 | impl AstNode for Path { | 2342 | impl AstNode for Path { |
2195 | fn can_cast(kind: SyntaxKind) -> bool { | 2343 | fn can_cast(kind: SyntaxKind) -> bool { |
2196 | match kind { | 2344 | match kind { |
@@ -2199,28 +2347,28 @@ impl AstNode for Path { | |||
2199 | } | 2347 | } |
2200 | } | 2348 | } |
2201 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2349 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2202 | if Self::can_cast(syntax.kind()) { Some(Path { syntax }) } else { None } | 2350 | if Self::can_cast(syntax.kind()) { |
2351 | Some(Self { syntax }) | ||
2352 | } else { | ||
2353 | None | ||
2354 | } | ||
2355 | } | ||
2356 | fn syntax(&self) -> &SyntaxNode { | ||
2357 | &self.syntax | ||
2203 | } | 2358 | } |
2204 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2205 | } | 2359 | } |
2206 | |||
2207 | |||
2208 | impl Path { | 2360 | impl Path { |
2209 | pub fn segment(&self) -> Option<PathSegment> { | 2361 | pub fn segment(&self) -> Option<PathSegment> { |
2210 | super::child_opt(self) | 2362 | AstChildren::new(&self.syntax).next() |
2211 | } | 2363 | } |
2212 | |||
2213 | pub fn qualifier(&self) -> Option<Path> { | 2364 | pub fn qualifier(&self) -> Option<Path> { |
2214 | super::child_opt(self) | 2365 | AstChildren::new(&self.syntax).next() |
2215 | } | 2366 | } |
2216 | } | 2367 | } |
2217 | |||
2218 | // PathExpr | ||
2219 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2368 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2220 | pub struct PathExpr { | 2369 | pub struct PathExpr { |
2221 | pub(crate) syntax: SyntaxNode, | 2370 | pub(crate) syntax: SyntaxNode, |
2222 | } | 2371 | } |
2223 | |||
2224 | impl AstNode for PathExpr { | 2372 | impl AstNode for PathExpr { |
2225 | fn can_cast(kind: SyntaxKind) -> bool { | 2373 | fn can_cast(kind: SyntaxKind) -> bool { |
2226 | match kind { | 2374 | match kind { |
@@ -2229,24 +2377,25 @@ impl AstNode for PathExpr { | |||
2229 | } | 2377 | } |
2230 | } | 2378 | } |
2231 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2379 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2232 | if Self::can_cast(syntax.kind()) { Some(PathExpr { syntax }) } else { None } | 2380 | if Self::can_cast(syntax.kind()) { |
2381 | Some(Self { syntax }) | ||
2382 | } else { | ||
2383 | None | ||
2384 | } | ||
2385 | } | ||
2386 | fn syntax(&self) -> &SyntaxNode { | ||
2387 | &self.syntax | ||
2233 | } | 2388 | } |
2234 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2235 | } | 2389 | } |
2236 | |||
2237 | |||
2238 | impl PathExpr { | 2390 | impl PathExpr { |
2239 | pub fn path(&self) -> Option<Path> { | 2391 | pub fn path(&self) -> Option<Path> { |
2240 | super::child_opt(self) | 2392 | AstChildren::new(&self.syntax).next() |
2241 | } | 2393 | } |
2242 | } | 2394 | } |
2243 | |||
2244 | // PathPat | ||
2245 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2395 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2246 | pub struct PathPat { | 2396 | pub struct PathPat { |
2247 | pub(crate) syntax: SyntaxNode, | 2397 | pub(crate) syntax: SyntaxNode, |
2248 | } | 2398 | } |
2249 | |||
2250 | impl AstNode for PathPat { | 2399 | impl AstNode for PathPat { |
2251 | fn can_cast(kind: SyntaxKind) -> bool { | 2400 | fn can_cast(kind: SyntaxKind) -> bool { |
2252 | match kind { | 2401 | match kind { |
@@ -2255,24 +2404,25 @@ impl AstNode for PathPat { | |||
2255 | } | 2404 | } |
2256 | } | 2405 | } |
2257 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2406 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2258 | if Self::can_cast(syntax.kind()) { Some(PathPat { syntax }) } else { None } | 2407 | if Self::can_cast(syntax.kind()) { |
2408 | Some(Self { syntax }) | ||
2409 | } else { | ||
2410 | None | ||
2411 | } | ||
2412 | } | ||
2413 | fn syntax(&self) -> &SyntaxNode { | ||
2414 | &self.syntax | ||
2259 | } | 2415 | } |
2260 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2261 | } | 2416 | } |
2262 | |||
2263 | |||
2264 | impl PathPat { | 2417 | impl PathPat { |
2265 | pub fn path(&self) -> Option<Path> { | 2418 | pub fn path(&self) -> Option<Path> { |
2266 | super::child_opt(self) | 2419 | AstChildren::new(&self.syntax).next() |
2267 | } | 2420 | } |
2268 | } | 2421 | } |
2269 | |||
2270 | // PathSegment | ||
2271 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2422 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2272 | pub struct PathSegment { | 2423 | pub struct PathSegment { |
2273 | pub(crate) syntax: SyntaxNode, | 2424 | pub(crate) syntax: SyntaxNode, |
2274 | } | 2425 | } |
2275 | |||
2276 | impl AstNode for PathSegment { | 2426 | impl AstNode for PathSegment { |
2277 | fn can_cast(kind: SyntaxKind) -> bool { | 2427 | fn can_cast(kind: SyntaxKind) -> bool { |
2278 | match kind { | 2428 | match kind { |
@@ -2281,28 +2431,28 @@ impl AstNode for PathSegment { | |||
2281 | } | 2431 | } |
2282 | } | 2432 | } |
2283 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2433 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2284 | if Self::can_cast(syntax.kind()) { Some(PathSegment { syntax }) } else { None } | 2434 | if Self::can_cast(syntax.kind()) { |
2435 | Some(Self { syntax }) | ||
2436 | } else { | ||
2437 | None | ||
2438 | } | ||
2439 | } | ||
2440 | fn syntax(&self) -> &SyntaxNode { | ||
2441 | &self.syntax | ||
2285 | } | 2442 | } |
2286 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2287 | } | 2443 | } |
2288 | |||
2289 | |||
2290 | impl PathSegment { | 2444 | impl PathSegment { |
2291 | pub fn name_ref(&self) -> Option<NameRef> { | 2445 | pub fn name_ref(&self) -> Option<NameRef> { |
2292 | super::child_opt(self) | 2446 | AstChildren::new(&self.syntax).next() |
2293 | } | 2447 | } |
2294 | |||
2295 | pub fn type_arg_list(&self) -> Option<TypeArgList> { | 2448 | pub fn type_arg_list(&self) -> Option<TypeArgList> { |
2296 | super::child_opt(self) | 2449 | AstChildren::new(&self.syntax).next() |
2297 | } | 2450 | } |
2298 | } | 2451 | } |
2299 | |||
2300 | // PathType | ||
2301 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2452 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2302 | pub struct PathType { | 2453 | pub struct PathType { |
2303 | pub(crate) syntax: SyntaxNode, | 2454 | pub(crate) syntax: SyntaxNode, |
2304 | } | 2455 | } |
2305 | |||
2306 | impl AstNode for PathType { | 2456 | impl AstNode for PathType { |
2307 | fn can_cast(kind: SyntaxKind) -> bool { | 2457 | fn can_cast(kind: SyntaxKind) -> bool { |
2308 | match kind { | 2458 | match kind { |
@@ -2311,24 +2461,25 @@ impl AstNode for PathType { | |||
2311 | } | 2461 | } |
2312 | } | 2462 | } |
2313 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2463 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2314 | if Self::can_cast(syntax.kind()) { Some(PathType { syntax }) } else { None } | 2464 | if Self::can_cast(syntax.kind()) { |
2465 | Some(Self { syntax }) | ||
2466 | } else { | ||
2467 | None | ||
2468 | } | ||
2469 | } | ||
2470 | fn syntax(&self) -> &SyntaxNode { | ||
2471 | &self.syntax | ||
2315 | } | 2472 | } |
2316 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2317 | } | 2473 | } |
2318 | |||
2319 | |||
2320 | impl PathType { | 2474 | impl PathType { |
2321 | pub fn path(&self) -> Option<Path> { | 2475 | pub fn path(&self) -> Option<Path> { |
2322 | super::child_opt(self) | 2476 | AstChildren::new(&self.syntax).next() |
2323 | } | 2477 | } |
2324 | } | 2478 | } |
2325 | |||
2326 | // PlaceholderPat | ||
2327 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2479 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2328 | pub struct PlaceholderPat { | 2480 | pub struct PlaceholderPat { |
2329 | pub(crate) syntax: SyntaxNode, | 2481 | pub(crate) syntax: SyntaxNode, |
2330 | } | 2482 | } |
2331 | |||
2332 | impl AstNode for PlaceholderPat { | 2483 | impl AstNode for PlaceholderPat { |
2333 | fn can_cast(kind: SyntaxKind) -> bool { | 2484 | fn can_cast(kind: SyntaxKind) -> bool { |
2334 | match kind { | 2485 | match kind { |
@@ -2337,20 +2488,21 @@ impl AstNode for PlaceholderPat { | |||
2337 | } | 2488 | } |
2338 | } | 2489 | } |
2339 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2490 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2340 | if Self::can_cast(syntax.kind()) { Some(PlaceholderPat { syntax }) } else { None } | 2491 | if Self::can_cast(syntax.kind()) { |
2492 | Some(Self { syntax }) | ||
2493 | } else { | ||
2494 | None | ||
2495 | } | ||
2496 | } | ||
2497 | fn syntax(&self) -> &SyntaxNode { | ||
2498 | &self.syntax | ||
2341 | } | 2499 | } |
2342 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2343 | } | 2500 | } |
2344 | |||
2345 | |||
2346 | impl PlaceholderPat {} | 2501 | impl PlaceholderPat {} |
2347 | |||
2348 | // PlaceholderType | ||
2349 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2502 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2350 | pub struct PlaceholderType { | 2503 | pub struct PlaceholderType { |
2351 | pub(crate) syntax: SyntaxNode, | 2504 | pub(crate) syntax: SyntaxNode, |
2352 | } | 2505 | } |
2353 | |||
2354 | impl AstNode for PlaceholderType { | 2506 | impl AstNode for PlaceholderType { |
2355 | fn can_cast(kind: SyntaxKind) -> bool { | 2507 | fn can_cast(kind: SyntaxKind) -> bool { |
2356 | match kind { | 2508 | match kind { |
@@ -2359,20 +2511,21 @@ impl AstNode for PlaceholderType { | |||
2359 | } | 2511 | } |
2360 | } | 2512 | } |
2361 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2513 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2362 | if Self::can_cast(syntax.kind()) { Some(PlaceholderType { syntax }) } else { None } | 2514 | if Self::can_cast(syntax.kind()) { |
2515 | Some(Self { syntax }) | ||
2516 | } else { | ||
2517 | None | ||
2518 | } | ||
2519 | } | ||
2520 | fn syntax(&self) -> &SyntaxNode { | ||
2521 | &self.syntax | ||
2363 | } | 2522 | } |
2364 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2365 | } | 2523 | } |
2366 | |||
2367 | |||
2368 | impl PlaceholderType {} | 2524 | impl PlaceholderType {} |
2369 | |||
2370 | // PointerType | ||
2371 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2525 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2372 | pub struct PointerType { | 2526 | pub struct PointerType { |
2373 | pub(crate) syntax: SyntaxNode, | 2527 | pub(crate) syntax: SyntaxNode, |
2374 | } | 2528 | } |
2375 | |||
2376 | impl AstNode for PointerType { | 2529 | impl AstNode for PointerType { |
2377 | fn can_cast(kind: SyntaxKind) -> bool { | 2530 | fn can_cast(kind: SyntaxKind) -> bool { |
2378 | match kind { | 2531 | match kind { |
@@ -2381,24 +2534,25 @@ impl AstNode for PointerType { | |||
2381 | } | 2534 | } |
2382 | } | 2535 | } |
2383 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2536 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2384 | if Self::can_cast(syntax.kind()) { Some(PointerType { syntax }) } else { None } | 2537 | if Self::can_cast(syntax.kind()) { |
2538 | Some(Self { syntax }) | ||
2539 | } else { | ||
2540 | None | ||
2541 | } | ||
2542 | } | ||
2543 | fn syntax(&self) -> &SyntaxNode { | ||
2544 | &self.syntax | ||
2385 | } | 2545 | } |
2386 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2387 | } | 2546 | } |
2388 | |||
2389 | |||
2390 | impl PointerType { | 2547 | impl PointerType { |
2391 | pub fn type_ref(&self) -> Option<TypeRef> { | 2548 | pub fn type_ref(&self) -> Option<TypeRef> { |
2392 | super::child_opt(self) | 2549 | AstChildren::new(&self.syntax).next() |
2393 | } | 2550 | } |
2394 | } | 2551 | } |
2395 | |||
2396 | // PosFieldDef | ||
2397 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2552 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2398 | pub struct PosFieldDef { | 2553 | pub struct PosFieldDef { |
2399 | pub(crate) syntax: SyntaxNode, | 2554 | pub(crate) syntax: SyntaxNode, |
2400 | } | 2555 | } |
2401 | |||
2402 | impl AstNode for PosFieldDef { | 2556 | impl AstNode for PosFieldDef { |
2403 | fn can_cast(kind: SyntaxKind) -> bool { | 2557 | fn can_cast(kind: SyntaxKind) -> bool { |
2404 | match kind { | 2558 | match kind { |
@@ -2407,26 +2561,27 @@ impl AstNode for PosFieldDef { | |||
2407 | } | 2561 | } |
2408 | } | 2562 | } |
2409 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2563 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2410 | if Self::can_cast(syntax.kind()) { Some(PosFieldDef { syntax }) } else { None } | 2564 | if Self::can_cast(syntax.kind()) { |
2565 | Some(Self { syntax }) | ||
2566 | } else { | ||
2567 | None | ||
2568 | } | ||
2569 | } | ||
2570 | fn syntax(&self) -> &SyntaxNode { | ||
2571 | &self.syntax | ||
2411 | } | 2572 | } |
2412 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2413 | } | 2573 | } |
2414 | |||
2415 | |||
2416 | impl ast::VisibilityOwner for PosFieldDef {} | 2574 | impl ast::VisibilityOwner for PosFieldDef {} |
2417 | impl ast::AttrsOwner for PosFieldDef {} | 2575 | impl ast::AttrsOwner for PosFieldDef {} |
2418 | impl PosFieldDef { | 2576 | impl PosFieldDef { |
2419 | pub fn type_ref(&self) -> Option<TypeRef> { | 2577 | pub fn type_ref(&self) -> Option<TypeRef> { |
2420 | super::child_opt(self) | 2578 | AstChildren::new(&self.syntax).next() |
2421 | } | 2579 | } |
2422 | } | 2580 | } |
2423 | |||
2424 | // PosFieldDefList | ||
2425 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2581 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2426 | pub struct PosFieldDefList { | 2582 | pub struct PosFieldDefList { |
2427 | pub(crate) syntax: SyntaxNode, | 2583 | pub(crate) syntax: SyntaxNode, |
2428 | } | 2584 | } |
2429 | |||
2430 | impl AstNode for PosFieldDefList { | 2585 | impl AstNode for PosFieldDefList { |
2431 | fn can_cast(kind: SyntaxKind) -> bool { | 2586 | fn can_cast(kind: SyntaxKind) -> bool { |
2432 | match kind { | 2587 | match kind { |
@@ -2435,24 +2590,25 @@ impl AstNode for PosFieldDefList { | |||
2435 | } | 2590 | } |
2436 | } | 2591 | } |
2437 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2592 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2438 | if Self::can_cast(syntax.kind()) { Some(PosFieldDefList { syntax }) } else { None } | 2593 | if Self::can_cast(syntax.kind()) { |
2594 | Some(Self { syntax }) | ||
2595 | } else { | ||
2596 | None | ||
2597 | } | ||
2598 | } | ||
2599 | fn syntax(&self) -> &SyntaxNode { | ||
2600 | &self.syntax | ||
2439 | } | 2601 | } |
2440 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2441 | } | 2602 | } |
2442 | |||
2443 | |||
2444 | impl PosFieldDefList { | 2603 | impl PosFieldDefList { |
2445 | pub fn fields(&self) -> impl Iterator<Item = PosFieldDef> { | 2604 | pub fn fields(&self) -> AstChildren<PosFieldDef> { |
2446 | super::children(self) | 2605 | AstChildren::new(&self.syntax) |
2447 | } | 2606 | } |
2448 | } | 2607 | } |
2449 | |||
2450 | // PrefixExpr | ||
2451 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2608 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2452 | pub struct PrefixExpr { | 2609 | pub struct PrefixExpr { |
2453 | pub(crate) syntax: SyntaxNode, | 2610 | pub(crate) syntax: SyntaxNode, |
2454 | } | 2611 | } |
2455 | |||
2456 | impl AstNode for PrefixExpr { | 2612 | impl AstNode for PrefixExpr { |
2457 | fn can_cast(kind: SyntaxKind) -> bool { | 2613 | fn can_cast(kind: SyntaxKind) -> bool { |
2458 | match kind { | 2614 | match kind { |
@@ -2461,24 +2617,25 @@ impl AstNode for PrefixExpr { | |||
2461 | } | 2617 | } |
2462 | } | 2618 | } |
2463 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2619 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2464 | if Self::can_cast(syntax.kind()) { Some(PrefixExpr { syntax }) } else { None } | 2620 | if Self::can_cast(syntax.kind()) { |
2621 | Some(Self { syntax }) | ||
2622 | } else { | ||
2623 | None | ||
2624 | } | ||
2625 | } | ||
2626 | fn syntax(&self) -> &SyntaxNode { | ||
2627 | &self.syntax | ||
2465 | } | 2628 | } |
2466 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2467 | } | 2629 | } |
2468 | |||
2469 | |||
2470 | impl PrefixExpr { | 2630 | impl PrefixExpr { |
2471 | pub fn expr(&self) -> Option<Expr> { | 2631 | pub fn expr(&self) -> Option<Expr> { |
2472 | super::child_opt(self) | 2632 | AstChildren::new(&self.syntax).next() |
2473 | } | 2633 | } |
2474 | } | 2634 | } |
2475 | |||
2476 | // RangeExpr | ||
2477 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2635 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2478 | pub struct RangeExpr { | 2636 | pub struct RangeExpr { |
2479 | pub(crate) syntax: SyntaxNode, | 2637 | pub(crate) syntax: SyntaxNode, |
2480 | } | 2638 | } |
2481 | |||
2482 | impl AstNode for RangeExpr { | 2639 | impl AstNode for RangeExpr { |
2483 | fn can_cast(kind: SyntaxKind) -> bool { | 2640 | fn can_cast(kind: SyntaxKind) -> bool { |
2484 | match kind { | 2641 | match kind { |
@@ -2487,20 +2644,21 @@ impl AstNode for RangeExpr { | |||
2487 | } | 2644 | } |
2488 | } | 2645 | } |
2489 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2646 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2490 | if Self::can_cast(syntax.kind()) { Some(RangeExpr { syntax }) } else { None } | 2647 | if Self::can_cast(syntax.kind()) { |
2648 | Some(Self { syntax }) | ||
2649 | } else { | ||
2650 | None | ||
2651 | } | ||
2652 | } | ||
2653 | fn syntax(&self) -> &SyntaxNode { | ||
2654 | &self.syntax | ||
2491 | } | 2655 | } |
2492 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2493 | } | 2656 | } |
2494 | |||
2495 | |||
2496 | impl RangeExpr {} | 2657 | impl RangeExpr {} |
2497 | |||
2498 | // RangePat | ||
2499 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2658 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2500 | pub struct RangePat { | 2659 | pub struct RangePat { |
2501 | pub(crate) syntax: SyntaxNode, | 2660 | pub(crate) syntax: SyntaxNode, |
2502 | } | 2661 | } |
2503 | |||
2504 | impl AstNode for RangePat { | 2662 | impl AstNode for RangePat { |
2505 | fn can_cast(kind: SyntaxKind) -> bool { | 2663 | fn can_cast(kind: SyntaxKind) -> bool { |
2506 | match kind { | 2664 | match kind { |
@@ -2509,20 +2667,21 @@ impl AstNode for RangePat { | |||
2509 | } | 2667 | } |
2510 | } | 2668 | } |
2511 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2669 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2512 | if Self::can_cast(syntax.kind()) { Some(RangePat { syntax }) } else { None } | 2670 | if Self::can_cast(syntax.kind()) { |
2671 | Some(Self { syntax }) | ||
2672 | } else { | ||
2673 | None | ||
2674 | } | ||
2675 | } | ||
2676 | fn syntax(&self) -> &SyntaxNode { | ||
2677 | &self.syntax | ||
2513 | } | 2678 | } |
2514 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2515 | } | 2679 | } |
2516 | |||
2517 | |||
2518 | impl RangePat {} | 2680 | impl RangePat {} |
2519 | |||
2520 | // RefExpr | ||
2521 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2681 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2522 | pub struct RefExpr { | 2682 | pub struct RefExpr { |
2523 | pub(crate) syntax: SyntaxNode, | 2683 | pub(crate) syntax: SyntaxNode, |
2524 | } | 2684 | } |
2525 | |||
2526 | impl AstNode for RefExpr { | 2685 | impl AstNode for RefExpr { |
2527 | fn can_cast(kind: SyntaxKind) -> bool { | 2686 | fn can_cast(kind: SyntaxKind) -> bool { |
2528 | match kind { | 2687 | match kind { |
@@ -2531,24 +2690,25 @@ impl AstNode for RefExpr { | |||
2531 | } | 2690 | } |
2532 | } | 2691 | } |
2533 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2692 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2534 | if Self::can_cast(syntax.kind()) { Some(RefExpr { syntax }) } else { None } | 2693 | if Self::can_cast(syntax.kind()) { |
2694 | Some(Self { syntax }) | ||
2695 | } else { | ||
2696 | None | ||
2697 | } | ||
2698 | } | ||
2699 | fn syntax(&self) -> &SyntaxNode { | ||
2700 | &self.syntax | ||
2535 | } | 2701 | } |
2536 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2537 | } | 2702 | } |
2538 | |||
2539 | |||
2540 | impl RefExpr { | 2703 | impl RefExpr { |
2541 | pub fn expr(&self) -> Option<Expr> { | 2704 | pub fn expr(&self) -> Option<Expr> { |
2542 | super::child_opt(self) | 2705 | AstChildren::new(&self.syntax).next() |
2543 | } | 2706 | } |
2544 | } | 2707 | } |
2545 | |||
2546 | // RefPat | ||
2547 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2708 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2548 | pub struct RefPat { | 2709 | pub struct RefPat { |
2549 | pub(crate) syntax: SyntaxNode, | 2710 | pub(crate) syntax: SyntaxNode, |
2550 | } | 2711 | } |
2551 | |||
2552 | impl AstNode for RefPat { | 2712 | impl AstNode for RefPat { |
2553 | fn can_cast(kind: SyntaxKind) -> bool { | 2713 | fn can_cast(kind: SyntaxKind) -> bool { |
2554 | match kind { | 2714 | match kind { |
@@ -2557,24 +2717,25 @@ impl AstNode for RefPat { | |||
2557 | } | 2717 | } |
2558 | } | 2718 | } |
2559 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2719 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2560 | if Self::can_cast(syntax.kind()) { Some(RefPat { syntax }) } else { None } | 2720 | if Self::can_cast(syntax.kind()) { |
2721 | Some(Self { syntax }) | ||
2722 | } else { | ||
2723 | None | ||
2724 | } | ||
2725 | } | ||
2726 | fn syntax(&self) -> &SyntaxNode { | ||
2727 | &self.syntax | ||
2561 | } | 2728 | } |
2562 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2563 | } | 2729 | } |
2564 | |||
2565 | |||
2566 | impl RefPat { | 2730 | impl RefPat { |
2567 | pub fn pat(&self) -> Option<Pat> { | 2731 | pub fn pat(&self) -> Option<Pat> { |
2568 | super::child_opt(self) | 2732 | AstChildren::new(&self.syntax).next() |
2569 | } | 2733 | } |
2570 | } | 2734 | } |
2571 | |||
2572 | // ReferenceType | ||
2573 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2735 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2574 | pub struct ReferenceType { | 2736 | pub struct ReferenceType { |
2575 | pub(crate) syntax: SyntaxNode, | 2737 | pub(crate) syntax: SyntaxNode, |
2576 | } | 2738 | } |
2577 | |||
2578 | impl AstNode for ReferenceType { | 2739 | impl AstNode for ReferenceType { |
2579 | fn can_cast(kind: SyntaxKind) -> bool { | 2740 | fn can_cast(kind: SyntaxKind) -> bool { |
2580 | match kind { | 2741 | match kind { |
@@ -2583,24 +2744,25 @@ impl AstNode for ReferenceType { | |||
2583 | } | 2744 | } |
2584 | } | 2745 | } |
2585 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2746 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2586 | if Self::can_cast(syntax.kind()) { Some(ReferenceType { syntax }) } else { None } | 2747 | if Self::can_cast(syntax.kind()) { |
2748 | Some(Self { syntax }) | ||
2749 | } else { | ||
2750 | None | ||
2751 | } | ||
2752 | } | ||
2753 | fn syntax(&self) -> &SyntaxNode { | ||
2754 | &self.syntax | ||
2587 | } | 2755 | } |
2588 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2589 | } | 2756 | } |
2590 | |||
2591 | |||
2592 | impl ReferenceType { | 2757 | impl ReferenceType { |
2593 | pub fn type_ref(&self) -> Option<TypeRef> { | 2758 | pub fn type_ref(&self) -> Option<TypeRef> { |
2594 | super::child_opt(self) | 2759 | AstChildren::new(&self.syntax).next() |
2595 | } | 2760 | } |
2596 | } | 2761 | } |
2597 | |||
2598 | // RetType | ||
2599 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2762 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2600 | pub struct RetType { | 2763 | pub struct RetType { |
2601 | pub(crate) syntax: SyntaxNode, | 2764 | pub(crate) syntax: SyntaxNode, |
2602 | } | 2765 | } |
2603 | |||
2604 | impl AstNode for RetType { | 2766 | impl AstNode for RetType { |
2605 | fn can_cast(kind: SyntaxKind) -> bool { | 2767 | fn can_cast(kind: SyntaxKind) -> bool { |
2606 | match kind { | 2768 | match kind { |
@@ -2609,24 +2771,25 @@ impl AstNode for RetType { | |||
2609 | } | 2771 | } |
2610 | } | 2772 | } |
2611 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2773 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2612 | if Self::can_cast(syntax.kind()) { Some(RetType { syntax }) } else { None } | 2774 | if Self::can_cast(syntax.kind()) { |
2775 | Some(Self { syntax }) | ||
2776 | } else { | ||
2777 | None | ||
2778 | } | ||
2779 | } | ||
2780 | fn syntax(&self) -> &SyntaxNode { | ||
2781 | &self.syntax | ||
2613 | } | 2782 | } |
2614 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2615 | } | 2783 | } |
2616 | |||
2617 | |||
2618 | impl RetType { | 2784 | impl RetType { |
2619 | pub fn type_ref(&self) -> Option<TypeRef> { | 2785 | pub fn type_ref(&self) -> Option<TypeRef> { |
2620 | super::child_opt(self) | 2786 | AstChildren::new(&self.syntax).next() |
2621 | } | 2787 | } |
2622 | } | 2788 | } |
2623 | |||
2624 | // ReturnExpr | ||
2625 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2789 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2626 | pub struct ReturnExpr { | 2790 | pub struct ReturnExpr { |
2627 | pub(crate) syntax: SyntaxNode, | 2791 | pub(crate) syntax: SyntaxNode, |
2628 | } | 2792 | } |
2629 | |||
2630 | impl AstNode for ReturnExpr { | 2793 | impl AstNode for ReturnExpr { |
2631 | fn can_cast(kind: SyntaxKind) -> bool { | 2794 | fn can_cast(kind: SyntaxKind) -> bool { |
2632 | match kind { | 2795 | match kind { |
@@ -2635,24 +2798,25 @@ impl AstNode for ReturnExpr { | |||
2635 | } | 2798 | } |
2636 | } | 2799 | } |
2637 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2800 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2638 | if Self::can_cast(syntax.kind()) { Some(ReturnExpr { syntax }) } else { None } | 2801 | if Self::can_cast(syntax.kind()) { |
2802 | Some(Self { syntax }) | ||
2803 | } else { | ||
2804 | None | ||
2805 | } | ||
2806 | } | ||
2807 | fn syntax(&self) -> &SyntaxNode { | ||
2808 | &self.syntax | ||
2639 | } | 2809 | } |
2640 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2641 | } | 2810 | } |
2642 | |||
2643 | |||
2644 | impl ReturnExpr { | 2811 | impl ReturnExpr { |
2645 | pub fn expr(&self) -> Option<Expr> { | 2812 | pub fn expr(&self) -> Option<Expr> { |
2646 | super::child_opt(self) | 2813 | AstChildren::new(&self.syntax).next() |
2647 | } | 2814 | } |
2648 | } | 2815 | } |
2649 | |||
2650 | // SelfParam | ||
2651 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2816 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2652 | pub struct SelfParam { | 2817 | pub struct SelfParam { |
2653 | pub(crate) syntax: SyntaxNode, | 2818 | pub(crate) syntax: SyntaxNode, |
2654 | } | 2819 | } |
2655 | |||
2656 | impl AstNode for SelfParam { | 2820 | impl AstNode for SelfParam { |
2657 | fn can_cast(kind: SyntaxKind) -> bool { | 2821 | fn can_cast(kind: SyntaxKind) -> bool { |
2658 | match kind { | 2822 | match kind { |
@@ -2661,22 +2825,23 @@ impl AstNode for SelfParam { | |||
2661 | } | 2825 | } |
2662 | } | 2826 | } |
2663 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2827 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2664 | if Self::can_cast(syntax.kind()) { Some(SelfParam { syntax }) } else { None } | 2828 | if Self::can_cast(syntax.kind()) { |
2829 | Some(Self { syntax }) | ||
2830 | } else { | ||
2831 | None | ||
2832 | } | ||
2833 | } | ||
2834 | fn syntax(&self) -> &SyntaxNode { | ||
2835 | &self.syntax | ||
2665 | } | 2836 | } |
2666 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2667 | } | 2837 | } |
2668 | |||
2669 | |||
2670 | impl ast::TypeAscriptionOwner for SelfParam {} | 2838 | impl ast::TypeAscriptionOwner for SelfParam {} |
2671 | impl ast::AttrsOwner for SelfParam {} | 2839 | impl ast::AttrsOwner for SelfParam {} |
2672 | impl SelfParam {} | 2840 | impl SelfParam {} |
2673 | |||
2674 | // SlicePat | ||
2675 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2841 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2676 | pub struct SlicePat { | 2842 | pub struct SlicePat { |
2677 | pub(crate) syntax: SyntaxNode, | 2843 | pub(crate) syntax: SyntaxNode, |
2678 | } | 2844 | } |
2679 | |||
2680 | impl AstNode for SlicePat { | 2845 | impl AstNode for SlicePat { |
2681 | fn can_cast(kind: SyntaxKind) -> bool { | 2846 | fn can_cast(kind: SyntaxKind) -> bool { |
2682 | match kind { | 2847 | match kind { |
@@ -2685,20 +2850,21 @@ impl AstNode for SlicePat { | |||
2685 | } | 2850 | } |
2686 | } | 2851 | } |
2687 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2852 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2688 | if Self::can_cast(syntax.kind()) { Some(SlicePat { syntax }) } else { None } | 2853 | if Self::can_cast(syntax.kind()) { |
2854 | Some(Self { syntax }) | ||
2855 | } else { | ||
2856 | None | ||
2857 | } | ||
2858 | } | ||
2859 | fn syntax(&self) -> &SyntaxNode { | ||
2860 | &self.syntax | ||
2689 | } | 2861 | } |
2690 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2691 | } | 2862 | } |
2692 | |||
2693 | |||
2694 | impl SlicePat {} | 2863 | impl SlicePat {} |
2695 | |||
2696 | // SliceType | ||
2697 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2864 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2698 | pub struct SliceType { | 2865 | pub struct SliceType { |
2699 | pub(crate) syntax: SyntaxNode, | 2866 | pub(crate) syntax: SyntaxNode, |
2700 | } | 2867 | } |
2701 | |||
2702 | impl AstNode for SliceType { | 2868 | impl AstNode for SliceType { |
2703 | fn can_cast(kind: SyntaxKind) -> bool { | 2869 | fn can_cast(kind: SyntaxKind) -> bool { |
2704 | match kind { | 2870 | match kind { |
@@ -2707,24 +2873,25 @@ impl AstNode for SliceType { | |||
2707 | } | 2873 | } |
2708 | } | 2874 | } |
2709 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2875 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2710 | if Self::can_cast(syntax.kind()) { Some(SliceType { syntax }) } else { None } | 2876 | if Self::can_cast(syntax.kind()) { |
2877 | Some(Self { syntax }) | ||
2878 | } else { | ||
2879 | None | ||
2880 | } | ||
2881 | } | ||
2882 | fn syntax(&self) -> &SyntaxNode { | ||
2883 | &self.syntax | ||
2711 | } | 2884 | } |
2712 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2713 | } | 2885 | } |
2714 | |||
2715 | |||
2716 | impl SliceType { | 2886 | impl SliceType { |
2717 | pub fn type_ref(&self) -> Option<TypeRef> { | 2887 | pub fn type_ref(&self) -> Option<TypeRef> { |
2718 | super::child_opt(self) | 2888 | AstChildren::new(&self.syntax).next() |
2719 | } | 2889 | } |
2720 | } | 2890 | } |
2721 | |||
2722 | // SourceFile | ||
2723 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2891 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2724 | pub struct SourceFile { | 2892 | pub struct SourceFile { |
2725 | pub(crate) syntax: SyntaxNode, | 2893 | pub(crate) syntax: SyntaxNode, |
2726 | } | 2894 | } |
2727 | |||
2728 | impl AstNode for SourceFile { | 2895 | impl AstNode for SourceFile { |
2729 | fn can_cast(kind: SyntaxKind) -> bool { | 2896 | fn can_cast(kind: SyntaxKind) -> bool { |
2730 | match kind { | 2897 | match kind { |
@@ -2733,26 +2900,27 @@ impl AstNode for SourceFile { | |||
2733 | } | 2900 | } |
2734 | } | 2901 | } |
2735 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2902 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2736 | if Self::can_cast(syntax.kind()) { Some(SourceFile { syntax }) } else { None } | 2903 | if Self::can_cast(syntax.kind()) { |
2904 | Some(Self { syntax }) | ||
2905 | } else { | ||
2906 | None | ||
2907 | } | ||
2908 | } | ||
2909 | fn syntax(&self) -> &SyntaxNode { | ||
2910 | &self.syntax | ||
2737 | } | 2911 | } |
2738 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2739 | } | 2912 | } |
2740 | |||
2741 | |||
2742 | impl ast::ModuleItemOwner for SourceFile {} | 2913 | impl ast::ModuleItemOwner for SourceFile {} |
2743 | impl ast::FnDefOwner for SourceFile {} | 2914 | impl ast::FnDefOwner for SourceFile {} |
2744 | impl SourceFile { | 2915 | impl SourceFile { |
2745 | pub fn modules(&self) -> impl Iterator<Item = Module> { | 2916 | pub fn modules(&self) -> AstChildren<Module> { |
2746 | super::children(self) | 2917 | AstChildren::new(&self.syntax) |
2747 | } | 2918 | } |
2748 | } | 2919 | } |
2749 | |||
2750 | // StaticDef | ||
2751 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2920 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2752 | pub struct StaticDef { | 2921 | pub struct StaticDef { |
2753 | pub(crate) syntax: SyntaxNode, | 2922 | pub(crate) syntax: SyntaxNode, |
2754 | } | 2923 | } |
2755 | |||
2756 | impl AstNode for StaticDef { | 2924 | impl AstNode for StaticDef { |
2757 | fn can_cast(kind: SyntaxKind) -> bool { | 2925 | fn can_cast(kind: SyntaxKind) -> bool { |
2758 | match kind { | 2926 | match kind { |
@@ -2761,12 +2929,16 @@ impl AstNode for StaticDef { | |||
2761 | } | 2929 | } |
2762 | } | 2930 | } |
2763 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2931 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2764 | if Self::can_cast(syntax.kind()) { Some(StaticDef { syntax }) } else { None } | 2932 | if Self::can_cast(syntax.kind()) { |
2933 | Some(Self { syntax }) | ||
2934 | } else { | ||
2935 | None | ||
2936 | } | ||
2937 | } | ||
2938 | fn syntax(&self) -> &SyntaxNode { | ||
2939 | &self.syntax | ||
2765 | } | 2940 | } |
2766 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2767 | } | 2941 | } |
2768 | |||
2769 | |||
2770 | impl ast::VisibilityOwner for StaticDef {} | 2942 | impl ast::VisibilityOwner for StaticDef {} |
2771 | impl ast::NameOwner for StaticDef {} | 2943 | impl ast::NameOwner for StaticDef {} |
2772 | impl ast::TypeParamsOwner for StaticDef {} | 2944 | impl ast::TypeParamsOwner for StaticDef {} |
@@ -2775,59 +2947,60 @@ impl ast::DocCommentsOwner for StaticDef {} | |||
2775 | impl ast::TypeAscriptionOwner for StaticDef {} | 2947 | impl ast::TypeAscriptionOwner for StaticDef {} |
2776 | impl StaticDef { | 2948 | impl StaticDef { |
2777 | pub fn body(&self) -> Option<Expr> { | 2949 | pub fn body(&self) -> Option<Expr> { |
2778 | super::child_opt(self) | 2950 | AstChildren::new(&self.syntax).next() |
2779 | } | 2951 | } |
2780 | } | 2952 | } |
2781 | |||
2782 | // Stmt | ||
2783 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2953 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2784 | pub struct Stmt { | 2954 | pub struct Stmt { |
2785 | pub(crate) syntax: SyntaxNode, | 2955 | pub(crate) syntax: SyntaxNode, |
2786 | } | 2956 | } |
2787 | |||
2788 | impl AstNode for Stmt { | 2957 | impl AstNode for Stmt { |
2789 | fn can_cast(kind: SyntaxKind) -> bool { | 2958 | fn can_cast(kind: SyntaxKind) -> bool { |
2790 | match kind { | 2959 | match kind { |
2791 | | EXPR_STMT | LET_STMT => true, | 2960 | EXPR_STMT | LET_STMT => true, |
2792 | _ => false, | 2961 | _ => false, |
2793 | } | 2962 | } |
2794 | } | 2963 | } |
2795 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 2964 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2796 | if Self::can_cast(syntax.kind()) { Some(Stmt { syntax }) } else { None } | 2965 | if Self::can_cast(syntax.kind()) { |
2966 | Some(Self { syntax }) | ||
2967 | } else { | ||
2968 | None | ||
2969 | } | ||
2970 | } | ||
2971 | fn syntax(&self) -> &SyntaxNode { | ||
2972 | &self.syntax | ||
2797 | } | 2973 | } |
2798 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2799 | } | 2974 | } |
2800 | |||
2801 | |||
2802 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
2803 | pub enum StmtKind { | 2975 | pub enum StmtKind { |
2804 | ExprStmt(ExprStmt), | 2976 | ExprStmt(ExprStmt), |
2805 | LetStmt(LetStmt), | 2977 | LetStmt(LetStmt), |
2806 | } | 2978 | } |
2807 | impl From<ExprStmt> for Stmt { | 2979 | impl From<ExprStmt> for Stmt { |
2808 | fn from(n: ExprStmt) -> Stmt { Stmt { syntax: n.syntax } } | 2980 | fn from(node: ExprStmt) -> Stmt { |
2981 | Stmt { syntax: node.syntax } | ||
2982 | } | ||
2809 | } | 2983 | } |
2810 | impl From<LetStmt> for Stmt { | 2984 | impl From<LetStmt> for Stmt { |
2811 | fn from(n: LetStmt) -> Stmt { Stmt { syntax: n.syntax } } | 2985 | fn from(node: LetStmt) -> Stmt { |
2986 | Stmt { syntax: node.syntax } | ||
2987 | } | ||
2812 | } | 2988 | } |
2813 | impl Stmt { | 2989 | impl Stmt { |
2814 | pub fn kind(&self) -> StmtKind { | 2990 | pub fn kind(&self) -> StmtKind { |
2815 | match self.syntax.kind() { | 2991 | let syntax = self.syntax.clone(); |
2816 | EXPR_STMT => StmtKind::ExprStmt(ExprStmt::cast(self.syntax.clone()).unwrap()), | 2992 | match syntax.kind() { |
2817 | LET_STMT => StmtKind::LetStmt(LetStmt::cast(self.syntax.clone()).unwrap()), | 2993 | EXPR_STMT => StmtKind::ExprStmt(ExprStmt { syntax }), |
2994 | LET_STMT => StmtKind::LetStmt(LetStmt { syntax }), | ||
2818 | _ => unreachable!(), | 2995 | _ => unreachable!(), |
2819 | } | 2996 | } |
2820 | } | 2997 | } |
2821 | } | 2998 | } |
2822 | |||
2823 | impl Stmt {} | 2999 | impl Stmt {} |
2824 | |||
2825 | // StructDef | ||
2826 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 3000 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2827 | pub struct StructDef { | 3001 | pub struct StructDef { |
2828 | pub(crate) syntax: SyntaxNode, | 3002 | pub(crate) syntax: SyntaxNode, |
2829 | } | 3003 | } |
2830 | |||
2831 | impl AstNode for StructDef { | 3004 | impl AstNode for StructDef { |
2832 | fn can_cast(kind: SyntaxKind) -> bool { | 3005 | fn can_cast(kind: SyntaxKind) -> bool { |
2833 | match kind { | 3006 | match kind { |
@@ -2836,25 +3009,26 @@ impl AstNode for StructDef { | |||
2836 | } | 3009 | } |
2837 | } | 3010 | } |
2838 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3011 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2839 | if Self::can_cast(syntax.kind()) { Some(StructDef { syntax }) } else { None } | 3012 | if Self::can_cast(syntax.kind()) { |
3013 | Some(Self { syntax }) | ||
3014 | } else { | ||
3015 | None | ||
3016 | } | ||
3017 | } | ||
3018 | fn syntax(&self) -> &SyntaxNode { | ||
3019 | &self.syntax | ||
2840 | } | 3020 | } |
2841 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2842 | } | 3021 | } |
2843 | |||
2844 | |||
2845 | impl ast::VisibilityOwner for StructDef {} | 3022 | impl ast::VisibilityOwner for StructDef {} |
2846 | impl ast::NameOwner for StructDef {} | 3023 | impl ast::NameOwner for StructDef {} |
2847 | impl ast::TypeParamsOwner for StructDef {} | 3024 | impl ast::TypeParamsOwner for StructDef {} |
2848 | impl ast::AttrsOwner for StructDef {} | 3025 | impl ast::AttrsOwner for StructDef {} |
2849 | impl ast::DocCommentsOwner for StructDef {} | 3026 | impl ast::DocCommentsOwner for StructDef {} |
2850 | impl StructDef {} | 3027 | impl StructDef {} |
2851 | |||
2852 | // StructLit | ||
2853 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 3028 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2854 | pub struct StructLit { | 3029 | pub struct StructLit { |
2855 | pub(crate) syntax: SyntaxNode, | 3030 | pub(crate) syntax: SyntaxNode, |
2856 | } | 3031 | } |
2857 | |||
2858 | impl AstNode for StructLit { | 3032 | impl AstNode for StructLit { |
2859 | fn can_cast(kind: SyntaxKind) -> bool { | 3033 | fn can_cast(kind: SyntaxKind) -> bool { |
2860 | match kind { | 3034 | match kind { |
@@ -2863,28 +3037,28 @@ impl AstNode for StructLit { | |||
2863 | } | 3037 | } |
2864 | } | 3038 | } |
2865 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3039 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2866 | if Self::can_cast(syntax.kind()) { Some(StructLit { syntax }) } else { None } | 3040 | if Self::can_cast(syntax.kind()) { |
3041 | Some(Self { syntax }) | ||
3042 | } else { | ||
3043 | None | ||
3044 | } | ||
3045 | } | ||
3046 | fn syntax(&self) -> &SyntaxNode { | ||
3047 | &self.syntax | ||
2867 | } | 3048 | } |
2868 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2869 | } | 3049 | } |
2870 | |||
2871 | |||
2872 | impl StructLit { | 3050 | impl StructLit { |
2873 | pub fn path(&self) -> Option<Path> { | 3051 | pub fn path(&self) -> Option<Path> { |
2874 | super::child_opt(self) | 3052 | AstChildren::new(&self.syntax).next() |
2875 | } | 3053 | } |
2876 | |||
2877 | pub fn named_field_list(&self) -> Option<NamedFieldList> { | 3054 | pub fn named_field_list(&self) -> Option<NamedFieldList> { |
2878 | super::child_opt(self) | 3055 | AstChildren::new(&self.syntax).next() |
2879 | } | 3056 | } |
2880 | } | 3057 | } |
2881 | |||
2882 | // StructPat | ||
2883 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 3058 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2884 | pub struct StructPat { | 3059 | pub struct StructPat { |
2885 | pub(crate) syntax: SyntaxNode, | 3060 | pub(crate) syntax: SyntaxNode, |
2886 | } | 3061 | } |
2887 | |||
2888 | impl AstNode for StructPat { | 3062 | impl AstNode for StructPat { |
2889 | fn can_cast(kind: SyntaxKind) -> bool { | 3063 | fn can_cast(kind: SyntaxKind) -> bool { |
2890 | match kind { | 3064 | match kind { |
@@ -2893,28 +3067,28 @@ impl AstNode for StructPat { | |||
2893 | } | 3067 | } |
2894 | } | 3068 | } |
2895 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3069 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2896 | if Self::can_cast(syntax.kind()) { Some(StructPat { syntax }) } else { None } | 3070 | if Self::can_cast(syntax.kind()) { |
3071 | Some(Self { syntax }) | ||
3072 | } else { | ||
3073 | None | ||
3074 | } | ||
3075 | } | ||
3076 | fn syntax(&self) -> &SyntaxNode { | ||
3077 | &self.syntax | ||
2897 | } | 3078 | } |
2898 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2899 | } | 3079 | } |
2900 | |||
2901 | |||
2902 | impl StructPat { | 3080 | impl StructPat { |
2903 | pub fn field_pat_list(&self) -> Option<FieldPatList> { | 3081 | pub fn field_pat_list(&self) -> Option<FieldPatList> { |
2904 | super::child_opt(self) | 3082 | AstChildren::new(&self.syntax).next() |
2905 | } | 3083 | } |
2906 | |||
2907 | pub fn path(&self) -> Option<Path> { | 3084 | pub fn path(&self) -> Option<Path> { |
2908 | super::child_opt(self) | 3085 | AstChildren::new(&self.syntax).next() |
2909 | } | 3086 | } |
2910 | } | 3087 | } |
2911 | |||
2912 | // TokenTree | ||
2913 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 3088 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2914 | pub struct TokenTree { | 3089 | pub struct TokenTree { |
2915 | pub(crate) syntax: SyntaxNode, | 3090 | pub(crate) syntax: SyntaxNode, |
2916 | } | 3091 | } |
2917 | |||
2918 | impl AstNode for TokenTree { | 3092 | impl AstNode for TokenTree { |
2919 | fn can_cast(kind: SyntaxKind) -> bool { | 3093 | fn can_cast(kind: SyntaxKind) -> bool { |
2920 | match kind { | 3094 | match kind { |
@@ -2923,20 +3097,21 @@ impl AstNode for TokenTree { | |||
2923 | } | 3097 | } |
2924 | } | 3098 | } |
2925 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3099 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2926 | if Self::can_cast(syntax.kind()) { Some(TokenTree { syntax }) } else { None } | 3100 | if Self::can_cast(syntax.kind()) { |
3101 | Some(Self { syntax }) | ||
3102 | } else { | ||
3103 | None | ||
3104 | } | ||
3105 | } | ||
3106 | fn syntax(&self) -> &SyntaxNode { | ||
3107 | &self.syntax | ||
2927 | } | 3108 | } |
2928 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2929 | } | 3109 | } |
2930 | |||
2931 | |||
2932 | impl TokenTree {} | 3110 | impl TokenTree {} |
2933 | |||
2934 | // TraitDef | ||
2935 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 3111 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2936 | pub struct TraitDef { | 3112 | pub struct TraitDef { |
2937 | pub(crate) syntax: SyntaxNode, | 3113 | pub(crate) syntax: SyntaxNode, |
2938 | } | 3114 | } |
2939 | |||
2940 | impl AstNode for TraitDef { | 3115 | impl AstNode for TraitDef { |
2941 | fn can_cast(kind: SyntaxKind) -> bool { | 3116 | fn can_cast(kind: SyntaxKind) -> bool { |
2942 | match kind { | 3117 | match kind { |
@@ -2945,12 +3120,16 @@ impl AstNode for TraitDef { | |||
2945 | } | 3120 | } |
2946 | } | 3121 | } |
2947 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3122 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2948 | if Self::can_cast(syntax.kind()) { Some(TraitDef { syntax }) } else { None } | 3123 | if Self::can_cast(syntax.kind()) { |
3124 | Some(Self { syntax }) | ||
3125 | } else { | ||
3126 | None | ||
3127 | } | ||
3128 | } | ||
3129 | fn syntax(&self) -> &SyntaxNode { | ||
3130 | &self.syntax | ||
2949 | } | 3131 | } |
2950 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2951 | } | 3132 | } |
2952 | |||
2953 | |||
2954 | impl ast::VisibilityOwner for TraitDef {} | 3133 | impl ast::VisibilityOwner for TraitDef {} |
2955 | impl ast::NameOwner for TraitDef {} | 3134 | impl ast::NameOwner for TraitDef {} |
2956 | impl ast::AttrsOwner for TraitDef {} | 3135 | impl ast::AttrsOwner for TraitDef {} |
@@ -2959,16 +3138,13 @@ impl ast::TypeParamsOwner for TraitDef {} | |||
2959 | impl ast::TypeBoundsOwner for TraitDef {} | 3138 | impl ast::TypeBoundsOwner for TraitDef {} |
2960 | impl TraitDef { | 3139 | impl TraitDef { |
2961 | pub fn item_list(&self) -> Option<ItemList> { | 3140 | pub fn item_list(&self) -> Option<ItemList> { |
2962 | super::child_opt(self) | 3141 | AstChildren::new(&self.syntax).next() |
2963 | } | 3142 | } |
2964 | } | 3143 | } |
2965 | |||
2966 | // TryBlockExpr | ||
2967 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 3144 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2968 | pub struct TryBlockExpr { | 3145 | pub struct TryBlockExpr { |
2969 | pub(crate) syntax: SyntaxNode, | 3146 | pub(crate) syntax: SyntaxNode, |
2970 | } | 3147 | } |
2971 | |||
2972 | impl AstNode for TryBlockExpr { | 3148 | impl AstNode for TryBlockExpr { |
2973 | fn can_cast(kind: SyntaxKind) -> bool { | 3149 | fn can_cast(kind: SyntaxKind) -> bool { |
2974 | match kind { | 3150 | match kind { |
@@ -2977,21 +3153,22 @@ impl AstNode for TryBlockExpr { | |||
2977 | } | 3153 | } |
2978 | } | 3154 | } |
2979 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3155 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
2980 | if Self::can_cast(syntax.kind()) { Some(TryBlockExpr { syntax }) } else { None } | 3156 | if Self::can_cast(syntax.kind()) { |
3157 | Some(Self { syntax }) | ||
3158 | } else { | ||
3159 | None | ||
3160 | } | ||
3161 | } | ||
3162 | fn syntax(&self) -> &SyntaxNode { | ||
3163 | &self.syntax | ||
2981 | } | 3164 | } |
2982 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2983 | } | 3165 | } |
2984 | |||
2985 | |||
2986 | impl ast::TryBlockBodyOwner for TryBlockExpr {} | 3166 | impl ast::TryBlockBodyOwner for TryBlockExpr {} |
2987 | impl TryBlockExpr {} | 3167 | impl TryBlockExpr {} |
2988 | |||
2989 | // TryExpr | ||
2990 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 3168 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2991 | pub struct TryExpr { | 3169 | pub struct TryExpr { |
2992 | pub(crate) syntax: SyntaxNode, | 3170 | pub(crate) syntax: SyntaxNode, |
2993 | } | 3171 | } |
2994 | |||
2995 | impl AstNode for TryExpr { | 3172 | impl AstNode for TryExpr { |
2996 | fn can_cast(kind: SyntaxKind) -> bool { | 3173 | fn can_cast(kind: SyntaxKind) -> bool { |
2997 | match kind { | 3174 | match kind { |
@@ -3000,24 +3177,25 @@ impl AstNode for TryExpr { | |||
3000 | } | 3177 | } |
3001 | } | 3178 | } |
3002 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3179 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3003 | if Self::can_cast(syntax.kind()) { Some(TryExpr { syntax }) } else { None } | 3180 | if Self::can_cast(syntax.kind()) { |
3181 | Some(Self { syntax }) | ||
3182 | } else { | ||
3183 | None | ||
3184 | } | ||
3185 | } | ||
3186 | fn syntax(&self) -> &SyntaxNode { | ||
3187 | &self.syntax | ||
3004 | } | 3188 | } |
3005 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3006 | } | 3189 | } |
3007 | |||
3008 | |||
3009 | impl TryExpr { | 3190 | impl TryExpr { |
3010 | pub fn expr(&self) -> Option<Expr> { | 3191 | pub fn expr(&self) -> Option<Expr> { |
3011 | super::child_opt(self) | 3192 | AstChildren::new(&self.syntax).next() |
3012 | } | 3193 | } |
3013 | } | 3194 | } |
3014 | |||
3015 | // TupleExpr | ||
3016 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 3195 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
3017 | pub struct TupleExpr { | 3196 | pub struct TupleExpr { |
3018 | pub(crate) syntax: SyntaxNode, | 3197 | pub(crate) syntax: SyntaxNode, |
3019 | } | 3198 | } |
3020 | |||
3021 | impl AstNode for TupleExpr { | 3199 | impl AstNode for TupleExpr { |
3022 | fn can_cast(kind: SyntaxKind) -> bool { | 3200 | fn can_cast(kind: SyntaxKind) -> bool { |
3023 | match kind { | 3201 | match kind { |
@@ -3026,24 +3204,25 @@ impl AstNode for TupleExpr { | |||
3026 | } | 3204 | } |
3027 | } | 3205 | } |
3028 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3206 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3029 | if Self::can_cast(syntax.kind()) { Some(TupleExpr { syntax }) } else { None } | 3207 | if Self::can_cast(syntax.kind()) { |
3208 | Some(Self { syntax }) | ||
3209 | } else { | ||
3210 | None | ||
3211 | } | ||
3212 | } | ||
3213 | fn syntax(&self) -> &SyntaxNode { | ||
3214 | &self.syntax | ||
3030 | } | 3215 | } |
3031 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3032 | } | 3216 | } |
3033 | |||
3034 | |||
3035 | impl TupleExpr { | 3217 | impl TupleExpr { |
3036 | pub fn exprs(&self) -> impl Iterator<Item = Expr> { | 3218 | pub fn exprs(&self) -> AstChildren<Expr> { |
3037 | super::children(self) | 3219 | AstChildren::new(&self.syntax) |
3038 | } | 3220 | } |
3039 | } | 3221 | } |
3040 | |||
3041 | // TuplePat | ||
3042 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 3222 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
3043 | pub struct TuplePat { | 3223 | pub struct TuplePat { |
3044 | pub(crate) syntax: SyntaxNode, | 3224 | pub(crate) syntax: SyntaxNode, |
3045 | } | 3225 | } |
3046 | |||
3047 | impl AstNode for TuplePat { | 3226 | impl AstNode for TuplePat { |
3048 | fn can_cast(kind: SyntaxKind) -> bool { | 3227 | fn can_cast(kind: SyntaxKind) -> bool { |
3049 | match kind { | 3228 | match kind { |
@@ -3052,24 +3231,25 @@ impl AstNode for TuplePat { | |||
3052 | } | 3231 | } |
3053 | } | 3232 | } |
3054 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3233 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3055 | if Self::can_cast(syntax.kind()) { Some(TuplePat { syntax }) } else { None } | 3234 | if Self::can_cast(syntax.kind()) { |
3235 | Some(Self { syntax }) | ||
3236 | } else { | ||
3237 | None | ||
3238 | } | ||
3239 | } | ||
3240 | fn syntax(&self) -> &SyntaxNode { | ||
3241 | &self.syntax | ||
3056 | } | 3242 | } |
3057 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3058 | } | 3243 | } |
3059 | |||
3060 | |||
3061 | impl TuplePat { | 3244 | impl TuplePat { |
3062 | pub fn args(&self) -> impl Iterator<Item = Pat> { | 3245 | pub fn args(&self) -> AstChildren<Pat> { |
3063 | super::children(self) | 3246 | AstChildren::new(&self.syntax) |
3064 | } | 3247 | } |
3065 | } | 3248 | } |
3066 | |||
3067 | // TupleStructPat | ||
3068 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 3249 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
3069 | pub struct TupleStructPat { | 3250 | pub struct TupleStructPat { |
3070 | pub(crate) syntax: SyntaxNode, | 3251 | pub(crate) syntax: SyntaxNode, |
3071 | } | 3252 | } |
3072 | |||
3073 | impl AstNode for TupleStructPat { | 3253 | impl AstNode for TupleStructPat { |
3074 | fn can_cast(kind: SyntaxKind) -> bool { | 3254 | fn can_cast(kind: SyntaxKind) -> bool { |
3075 | match kind { | 3255 | match kind { |
@@ -3078,28 +3258,28 @@ impl AstNode for TupleStructPat { | |||
3078 | } | 3258 | } |
3079 | } | 3259 | } |
3080 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3260 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3081 | if Self::can_cast(syntax.kind()) { Some(TupleStructPat { syntax }) } else { None } | 3261 | if Self::can_cast(syntax.kind()) { |
3262 | Some(Self { syntax }) | ||
3263 | } else { | ||
3264 | None | ||
3265 | } | ||
3266 | } | ||
3267 | fn syntax(&self) -> &SyntaxNode { | ||
3268 | &self.syntax | ||
3082 | } | 3269 | } |
3083 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3084 | } | 3270 | } |
3085 | |||
3086 | |||
3087 | impl TupleStructPat { | 3271 | impl TupleStructPat { |
3088 | pub fn args(&self) -> impl Iterator<Item = Pat> { | 3272 | pub fn args(&self) -> AstChildren<Pat> { |
3089 | super::children(self) | 3273 | AstChildren::new(&self.syntax) |
3090 | } | 3274 | } |
3091 | |||
3092 | pub fn path(&self) -> Option<Path> { | 3275 | pub fn path(&self) -> Option<Path> { |
3093 | super::child_opt(self) | 3276 | AstChildren::new(&self.syntax).next() |
3094 | } | 3277 | } |
3095 | } | 3278 | } |
3096 | |||
3097 | // TupleType | ||
3098 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 3279 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
3099 | pub struct TupleType { | 3280 | pub struct TupleType { |
3100 | pub(crate) syntax: SyntaxNode, | 3281 | pub(crate) syntax: SyntaxNode, |
3101 | } | 3282 | } |
3102 | |||
3103 | impl AstNode for TupleType { | 3283 | impl AstNode for TupleType { |
3104 | fn can_cast(kind: SyntaxKind) -> bool { | 3284 | fn can_cast(kind: SyntaxKind) -> bool { |
3105 | match kind { | 3285 | match kind { |
@@ -3108,24 +3288,25 @@ impl AstNode for TupleType { | |||
3108 | } | 3288 | } |
3109 | } | 3289 | } |
3110 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3290 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3111 | if Self::can_cast(syntax.kind()) { Some(TupleType { syntax }) } else { None } | 3291 | if Self::can_cast(syntax.kind()) { |
3292 | Some(Self { syntax }) | ||
3293 | } else { | ||
3294 | None | ||
3295 | } | ||
3296 | } | ||
3297 | fn syntax(&self) -> &SyntaxNode { | ||
3298 | &self.syntax | ||
3112 | } | 3299 | } |
3113 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3114 | } | 3300 | } |
3115 | |||
3116 | |||
3117 | impl TupleType { | 3301 | impl TupleType { |
3118 | pub fn fields(&self) -> impl Iterator<Item = TypeRef> { | 3302 | pub fn fields(&self) -> AstChildren<TypeRef> { |
3119 | super::children(self) | 3303 | AstChildren::new(&self.syntax) |
3120 | } | 3304 | } |
3121 | } | 3305 | } |
3122 | |||
3123 | // TypeAliasDef | ||
3124 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 3306 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
3125 | pub struct TypeAliasDef { | 3307 | pub struct TypeAliasDef { |
3126 | pub(crate) syntax: SyntaxNode, | 3308 | pub(crate) syntax: SyntaxNode, |
3127 | } | 3309 | } |
3128 | |||
3129 | impl AstNode for TypeAliasDef { | 3310 | impl AstNode for TypeAliasDef { |
3130 | fn can_cast(kind: SyntaxKind) -> bool { | 3311 | fn can_cast(kind: SyntaxKind) -> bool { |
3131 | match kind { | 3312 | match kind { |
@@ -3134,12 +3315,16 @@ impl AstNode for TypeAliasDef { | |||
3134 | } | 3315 | } |
3135 | } | 3316 | } |
3136 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3317 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3137 | if Self::can_cast(syntax.kind()) { Some(TypeAliasDef { syntax }) } else { None } | 3318 | if Self::can_cast(syntax.kind()) { |
3319 | Some(Self { syntax }) | ||
3320 | } else { | ||
3321 | None | ||
3322 | } | ||
3323 | } | ||
3324 | fn syntax(&self) -> &SyntaxNode { | ||
3325 | &self.syntax | ||
3138 | } | 3326 | } |
3139 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3140 | } | 3327 | } |
3141 | |||
3142 | |||
3143 | impl ast::VisibilityOwner for TypeAliasDef {} | 3328 | impl ast::VisibilityOwner for TypeAliasDef {} |
3144 | impl ast::NameOwner for TypeAliasDef {} | 3329 | impl ast::NameOwner for TypeAliasDef {} |
3145 | impl ast::TypeParamsOwner for TypeAliasDef {} | 3330 | impl ast::TypeParamsOwner for TypeAliasDef {} |
@@ -3148,16 +3333,13 @@ impl ast::DocCommentsOwner for TypeAliasDef {} | |||
3148 | impl ast::TypeBoundsOwner for TypeAliasDef {} | 3333 | impl ast::TypeBoundsOwner for TypeAliasDef {} |
3149 | impl TypeAliasDef { | 3334 | impl TypeAliasDef { |
3150 | pub fn type_ref(&self) -> Option<TypeRef> { | 3335 | pub fn type_ref(&self) -> Option<TypeRef> { |
3151 | super::child_opt(self) | 3336 | AstChildren::new(&self.syntax).next() |
3152 | } | 3337 | } |
3153 | } | 3338 | } |
3154 | |||
3155 | // TypeArg | ||
3156 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 3339 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
3157 | pub struct TypeArg { | 3340 | pub struct TypeArg { |
3158 | pub(crate) syntax: SyntaxNode, | 3341 | pub(crate) syntax: SyntaxNode, |
3159 | } | 3342 | } |
3160 | |||
3161 | impl AstNode for TypeArg { | 3343 | impl AstNode for TypeArg { |
3162 | fn can_cast(kind: SyntaxKind) -> bool { | 3344 | fn can_cast(kind: SyntaxKind) -> bool { |
3163 | match kind { | 3345 | match kind { |
@@ -3166,24 +3348,25 @@ impl AstNode for TypeArg { | |||
3166 | } | 3348 | } |
3167 | } | 3349 | } |
3168 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3350 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3169 | if Self::can_cast(syntax.kind()) { Some(TypeArg { syntax }) } else { None } | 3351 | if Self::can_cast(syntax.kind()) { |
3352 | Some(Self { syntax }) | ||
3353 | } else { | ||
3354 | None | ||
3355 | } | ||
3356 | } | ||
3357 | fn syntax(&self) -> &SyntaxNode { | ||
3358 | &self.syntax | ||
3170 | } | 3359 | } |
3171 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3172 | } | 3360 | } |
3173 | |||
3174 | |||
3175 | impl TypeArg { | 3361 | impl TypeArg { |
3176 | pub fn type_ref(&self) -> Option<TypeRef> { | 3362 | pub fn type_ref(&self) -> Option<TypeRef> { |
3177 | super::child_opt(self) | 3363 | AstChildren::new(&self.syntax).next() |
3178 | } | 3364 | } |
3179 | } | 3365 | } |
3180 | |||
3181 | // TypeArgList | ||
3182 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 3366 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
3183 | pub struct TypeArgList { | 3367 | pub struct TypeArgList { |
3184 | pub(crate) syntax: SyntaxNode, | 3368 | pub(crate) syntax: SyntaxNode, |
3185 | } | 3369 | } |
3186 | |||
3187 | impl AstNode for TypeArgList { | 3370 | impl AstNode for TypeArgList { |
3188 | fn can_cast(kind: SyntaxKind) -> bool { | 3371 | fn can_cast(kind: SyntaxKind) -> bool { |
3189 | match kind { | 3372 | match kind { |
@@ -3192,32 +3375,31 @@ impl AstNode for TypeArgList { | |||
3192 | } | 3375 | } |
3193 | } | 3376 | } |
3194 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3377 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3195 | if Self::can_cast(syntax.kind()) { Some(TypeArgList { syntax }) } else { None } | 3378 | if Self::can_cast(syntax.kind()) { |
3379 | Some(Self { syntax }) | ||
3380 | } else { | ||
3381 | None | ||
3382 | } | ||
3383 | } | ||
3384 | fn syntax(&self) -> &SyntaxNode { | ||
3385 | &self.syntax | ||
3196 | } | 3386 | } |
3197 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3198 | } | 3387 | } |
3199 | |||
3200 | |||
3201 | impl TypeArgList { | 3388 | impl TypeArgList { |
3202 | pub fn type_args(&self) -> impl Iterator<Item = TypeArg> { | 3389 | pub fn type_args(&self) -> AstChildren<TypeArg> { |
3203 | super::children(self) | 3390 | AstChildren::new(&self.syntax) |
3204 | } | 3391 | } |
3205 | 3392 | pub fn lifetime_args(&self) -> AstChildren<LifetimeArg> { | |
3206 | pub fn lifetime_args(&self) -> impl Iterator<Item = LifetimeArg> { | 3393 | AstChildren::new(&self.syntax) |
3207 | super::children(self) | ||
3208 | } | 3394 | } |
3209 | 3395 | pub fn assoc_type_args(&self) -> AstChildren<AssocTypeArg> { | |
3210 | pub fn assoc_type_args(&self) -> impl Iterator<Item = AssocTypeArg> { | 3396 | AstChildren::new(&self.syntax) |
3211 | super::children(self) | ||
3212 | } | 3397 | } |
3213 | } | 3398 | } |
3214 | |||
3215 | // TypeBound | ||
3216 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 3399 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
3217 | pub struct TypeBound { | 3400 | pub struct TypeBound { |
3218 | pub(crate) syntax: SyntaxNode, | 3401 | pub(crate) syntax: SyntaxNode, |
3219 | } | 3402 | } |
3220 | |||
3221 | impl AstNode for TypeBound { | 3403 | impl AstNode for TypeBound { |
3222 | fn can_cast(kind: SyntaxKind) -> bool { | 3404 | fn can_cast(kind: SyntaxKind) -> bool { |
3223 | match kind { | 3405 | match kind { |
@@ -3226,24 +3408,25 @@ impl AstNode for TypeBound { | |||
3226 | } | 3408 | } |
3227 | } | 3409 | } |
3228 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3410 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3229 | if Self::can_cast(syntax.kind()) { Some(TypeBound { syntax }) } else { None } | 3411 | if Self::can_cast(syntax.kind()) { |
3412 | Some(Self { syntax }) | ||
3413 | } else { | ||
3414 | None | ||
3415 | } | ||
3416 | } | ||
3417 | fn syntax(&self) -> &SyntaxNode { | ||
3418 | &self.syntax | ||
3230 | } | 3419 | } |
3231 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3232 | } | 3420 | } |
3233 | |||
3234 | |||
3235 | impl TypeBound { | 3421 | impl TypeBound { |
3236 | pub fn type_ref(&self) -> Option<TypeRef> { | 3422 | pub fn type_ref(&self) -> Option<TypeRef> { |
3237 | super::child_opt(self) | 3423 | AstChildren::new(&self.syntax).next() |
3238 | } | 3424 | } |
3239 | } | 3425 | } |
3240 | |||
3241 | // TypeBoundList | ||
3242 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 3426 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
3243 | pub struct TypeBoundList { | 3427 | pub struct TypeBoundList { |
3244 | pub(crate) syntax: SyntaxNode, | 3428 | pub(crate) syntax: SyntaxNode, |
3245 | } | 3429 | } |
3246 | |||
3247 | impl AstNode for TypeBoundList { | 3430 | impl AstNode for TypeBoundList { |
3248 | fn can_cast(kind: SyntaxKind) -> bool { | 3431 | fn can_cast(kind: SyntaxKind) -> bool { |
3249 | match kind { | 3432 | match kind { |
@@ -3252,24 +3435,25 @@ impl AstNode for TypeBoundList { | |||
3252 | } | 3435 | } |
3253 | } | 3436 | } |
3254 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3437 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3255 | if Self::can_cast(syntax.kind()) { Some(TypeBoundList { syntax }) } else { None } | 3438 | if Self::can_cast(syntax.kind()) { |
3439 | Some(Self { syntax }) | ||
3440 | } else { | ||
3441 | None | ||
3442 | } | ||
3443 | } | ||
3444 | fn syntax(&self) -> &SyntaxNode { | ||
3445 | &self.syntax | ||
3256 | } | 3446 | } |
3257 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3258 | } | 3447 | } |
3259 | |||
3260 | |||
3261 | impl TypeBoundList { | 3448 | impl TypeBoundList { |
3262 | pub fn bounds(&self) -> impl Iterator<Item = TypeBound> { | 3449 | pub fn bounds(&self) -> AstChildren<TypeBound> { |
3263 | super::children(self) | 3450 | AstChildren::new(&self.syntax) |
3264 | } | 3451 | } |
3265 | } | 3452 | } |
3266 | |||
3267 | // TypeParam | ||
3268 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 3453 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
3269 | pub struct TypeParam { | 3454 | pub struct TypeParam { |
3270 | pub(crate) syntax: SyntaxNode, | 3455 | pub(crate) syntax: SyntaxNode, |
3271 | } | 3456 | } |
3272 | |||
3273 | impl AstNode for TypeParam { | 3457 | impl AstNode for TypeParam { |
3274 | fn can_cast(kind: SyntaxKind) -> bool { | 3458 | fn can_cast(kind: SyntaxKind) -> bool { |
3275 | match kind { | 3459 | match kind { |
@@ -3278,24 +3462,25 @@ impl AstNode for TypeParam { | |||
3278 | } | 3462 | } |
3279 | } | 3463 | } |
3280 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3464 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3281 | if Self::can_cast(syntax.kind()) { Some(TypeParam { syntax }) } else { None } | 3465 | if Self::can_cast(syntax.kind()) { |
3466 | Some(Self { syntax }) | ||
3467 | } else { | ||
3468 | None | ||
3469 | } | ||
3470 | } | ||
3471 | fn syntax(&self) -> &SyntaxNode { | ||
3472 | &self.syntax | ||
3282 | } | 3473 | } |
3283 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3284 | } | 3474 | } |
3285 | |||
3286 | |||
3287 | impl ast::NameOwner for TypeParam {} | 3475 | impl ast::NameOwner for TypeParam {} |
3288 | impl ast::AttrsOwner for TypeParam {} | 3476 | impl ast::AttrsOwner for TypeParam {} |
3289 | impl ast::TypeBoundsOwner for TypeParam {} | 3477 | impl ast::TypeBoundsOwner for TypeParam {} |
3290 | impl ast::DefaultTypeParamOwner for TypeParam {} | 3478 | impl ast::DefaultTypeParamOwner for TypeParam {} |
3291 | impl TypeParam {} | 3479 | impl TypeParam {} |
3292 | |||
3293 | // TypeParamList | ||
3294 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 3480 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
3295 | pub struct TypeParamList { | 3481 | pub struct TypeParamList { |
3296 | pub(crate) syntax: SyntaxNode, | 3482 | pub(crate) syntax: SyntaxNode, |
3297 | } | 3483 | } |
3298 | |||
3299 | impl AstNode for TypeParamList { | 3484 | impl AstNode for TypeParamList { |
3300 | fn can_cast(kind: SyntaxKind) -> bool { | 3485 | fn can_cast(kind: SyntaxKind) -> bool { |
3301 | match kind { | 3486 | match kind { |
@@ -3304,43 +3489,48 @@ impl AstNode for TypeParamList { | |||
3304 | } | 3489 | } |
3305 | } | 3490 | } |
3306 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3491 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3307 | if Self::can_cast(syntax.kind()) { Some(TypeParamList { syntax }) } else { None } | 3492 | if Self::can_cast(syntax.kind()) { |
3493 | Some(Self { syntax }) | ||
3494 | } else { | ||
3495 | None | ||
3496 | } | ||
3497 | } | ||
3498 | fn syntax(&self) -> &SyntaxNode { | ||
3499 | &self.syntax | ||
3308 | } | 3500 | } |
3309 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3310 | } | 3501 | } |
3311 | |||
3312 | |||
3313 | impl TypeParamList { | 3502 | impl TypeParamList { |
3314 | pub fn type_params(&self) -> impl Iterator<Item = TypeParam> { | 3503 | pub fn type_params(&self) -> AstChildren<TypeParam> { |
3315 | super::children(self) | 3504 | AstChildren::new(&self.syntax) |
3316 | } | 3505 | } |
3317 | 3506 | pub fn lifetime_params(&self) -> AstChildren<LifetimeParam> { | |
3318 | pub fn lifetime_params(&self) -> impl Iterator<Item = LifetimeParam> { | 3507 | AstChildren::new(&self.syntax) |
3319 | super::children(self) | ||
3320 | } | 3508 | } |
3321 | } | 3509 | } |
3322 | |||
3323 | // TypeRef | ||
3324 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 3510 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
3325 | pub struct TypeRef { | 3511 | pub struct TypeRef { |
3326 | pub(crate) syntax: SyntaxNode, | 3512 | pub(crate) syntax: SyntaxNode, |
3327 | } | 3513 | } |
3328 | |||
3329 | impl AstNode for TypeRef { | 3514 | impl AstNode for TypeRef { |
3330 | fn can_cast(kind: SyntaxKind) -> bool { | 3515 | fn can_cast(kind: SyntaxKind) -> bool { |
3331 | match kind { | 3516 | match kind { |
3332 | | PAREN_TYPE | TUPLE_TYPE | NEVER_TYPE | PATH_TYPE | POINTER_TYPE | ARRAY_TYPE | SLICE_TYPE | REFERENCE_TYPE | PLACEHOLDER_TYPE | FN_POINTER_TYPE | FOR_TYPE | IMPL_TRAIT_TYPE | DYN_TRAIT_TYPE => true, | 3517 | PAREN_TYPE | TUPLE_TYPE | NEVER_TYPE | PATH_TYPE | POINTER_TYPE | ARRAY_TYPE |
3518 | | SLICE_TYPE | REFERENCE_TYPE | PLACEHOLDER_TYPE | FN_POINTER_TYPE | FOR_TYPE | ||
3519 | | IMPL_TRAIT_TYPE | DYN_TRAIT_TYPE => true, | ||
3333 | _ => false, | 3520 | _ => false, |
3334 | } | 3521 | } |
3335 | } | 3522 | } |
3336 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3523 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3337 | if Self::can_cast(syntax.kind()) { Some(TypeRef { syntax }) } else { None } | 3524 | if Self::can_cast(syntax.kind()) { |
3525 | Some(Self { syntax }) | ||
3526 | } else { | ||
3527 | None | ||
3528 | } | ||
3529 | } | ||
3530 | fn syntax(&self) -> &SyntaxNode { | ||
3531 | &self.syntax | ||
3338 | } | 3532 | } |
3339 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3340 | } | 3533 | } |
3341 | |||
3342 | |||
3343 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
3344 | pub enum TypeRefKind { | 3534 | pub enum TypeRefKind { |
3345 | ParenType(ParenType), | 3535 | ParenType(ParenType), |
3346 | TupleType(TupleType), | 3536 | TupleType(TupleType), |
@@ -3357,73 +3547,96 @@ pub enum TypeRefKind { | |||
3357 | DynTraitType(DynTraitType), | 3547 | DynTraitType(DynTraitType), |
3358 | } | 3548 | } |
3359 | impl From<ParenType> for TypeRef { | 3549 | impl From<ParenType> for TypeRef { |
3360 | fn from(n: ParenType) -> TypeRef { TypeRef { syntax: n.syntax } } | 3550 | fn from(node: ParenType) -> TypeRef { |
3551 | TypeRef { syntax: node.syntax } | ||
3552 | } | ||
3361 | } | 3553 | } |
3362 | impl From<TupleType> for TypeRef { | 3554 | impl From<TupleType> for TypeRef { |
3363 | fn from(n: TupleType) -> TypeRef { TypeRef { syntax: n.syntax } } | 3555 | fn from(node: TupleType) -> TypeRef { |
3556 | TypeRef { syntax: node.syntax } | ||
3557 | } | ||
3364 | } | 3558 | } |
3365 | impl From<NeverType> for TypeRef { | 3559 | impl From<NeverType> for TypeRef { |
3366 | fn from(n: NeverType) -> TypeRef { TypeRef { syntax: n.syntax } } | 3560 | fn from(node: NeverType) -> TypeRef { |
3561 | TypeRef { syntax: node.syntax } | ||
3562 | } | ||
3367 | } | 3563 | } |
3368 | impl From<PathType> for TypeRef { | 3564 | impl From<PathType> for TypeRef { |
3369 | fn from(n: PathType) -> TypeRef { TypeRef { syntax: n.syntax } } | 3565 | fn from(node: PathType) -> TypeRef { |
3566 | TypeRef { syntax: node.syntax } | ||
3567 | } | ||
3370 | } | 3568 | } |
3371 | impl From<PointerType> for TypeRef { | 3569 | impl From<PointerType> for TypeRef { |
3372 | fn from(n: PointerType) -> TypeRef { TypeRef { syntax: n.syntax } } | 3570 | fn from(node: PointerType) -> TypeRef { |
3571 | TypeRef { syntax: node.syntax } | ||
3572 | } | ||
3373 | } | 3573 | } |
3374 | impl From<ArrayType> for TypeRef { | 3574 | impl From<ArrayType> for TypeRef { |
3375 | fn from(n: ArrayType) -> TypeRef { TypeRef { syntax: n.syntax } } | 3575 | fn from(node: ArrayType) -> TypeRef { |
3576 | TypeRef { syntax: node.syntax } | ||
3577 | } | ||
3376 | } | 3578 | } |
3377 | impl From<SliceType> for TypeRef { | 3579 | impl From<SliceType> for TypeRef { |
3378 | fn from(n: SliceType) -> TypeRef { TypeRef { syntax: n.syntax } } | 3580 | fn from(node: SliceType) -> TypeRef { |
3581 | TypeRef { syntax: node.syntax } | ||
3582 | } | ||
3379 | } | 3583 | } |
3380 | impl From<ReferenceType> for TypeRef { | 3584 | impl From<ReferenceType> for TypeRef { |
3381 | fn from(n: ReferenceType) -> TypeRef { TypeRef { syntax: n.syntax } } | 3585 | fn from(node: ReferenceType) -> TypeRef { |
3586 | TypeRef { syntax: node.syntax } | ||
3587 | } | ||
3382 | } | 3588 | } |
3383 | impl From<PlaceholderType> for TypeRef { | 3589 | impl From<PlaceholderType> for TypeRef { |
3384 | fn from(n: PlaceholderType) -> TypeRef { TypeRef { syntax: n.syntax } } | 3590 | fn from(node: PlaceholderType) -> TypeRef { |
3591 | TypeRef { syntax: node.syntax } | ||
3592 | } | ||
3385 | } | 3593 | } |
3386 | impl From<FnPointerType> for TypeRef { | 3594 | impl From<FnPointerType> for TypeRef { |
3387 | fn from(n: FnPointerType) -> TypeRef { TypeRef { syntax: n.syntax } } | 3595 | fn from(node: FnPointerType) -> TypeRef { |
3596 | TypeRef { syntax: node.syntax } | ||
3597 | } | ||
3388 | } | 3598 | } |
3389 | impl From<ForType> for TypeRef { | 3599 | impl From<ForType> for TypeRef { |
3390 | fn from(n: ForType) -> TypeRef { TypeRef { syntax: n.syntax } } | 3600 | fn from(node: ForType) -> TypeRef { |
3601 | TypeRef { syntax: node.syntax } | ||
3602 | } | ||
3391 | } | 3603 | } |
3392 | impl From<ImplTraitType> for TypeRef { | 3604 | impl From<ImplTraitType> for TypeRef { |
3393 | fn from(n: ImplTraitType) -> TypeRef { TypeRef { syntax: n.syntax } } | 3605 | fn from(node: ImplTraitType) -> TypeRef { |
3606 | TypeRef { syntax: node.syntax } | ||
3607 | } | ||
3394 | } | 3608 | } |
3395 | impl From<DynTraitType> for TypeRef { | 3609 | impl From<DynTraitType> for TypeRef { |
3396 | fn from(n: DynTraitType) -> TypeRef { TypeRef { syntax: n.syntax } } | 3610 | fn from(node: DynTraitType) -> TypeRef { |
3611 | TypeRef { syntax: node.syntax } | ||
3612 | } | ||
3397 | } | 3613 | } |
3398 | impl TypeRef { | 3614 | impl TypeRef { |
3399 | pub fn kind(&self) -> TypeRefKind { | 3615 | pub fn kind(&self) -> TypeRefKind { |
3400 | match self.syntax.kind() { | 3616 | let syntax = self.syntax.clone(); |
3401 | PAREN_TYPE => TypeRefKind::ParenType(ParenType::cast(self.syntax.clone()).unwrap()), | 3617 | match syntax.kind() { |
3402 | TUPLE_TYPE => TypeRefKind::TupleType(TupleType::cast(self.syntax.clone()).unwrap()), | 3618 | PAREN_TYPE => TypeRefKind::ParenType(ParenType { syntax }), |
3403 | NEVER_TYPE => TypeRefKind::NeverType(NeverType::cast(self.syntax.clone()).unwrap()), | 3619 | TUPLE_TYPE => TypeRefKind::TupleType(TupleType { syntax }), |
3404 | PATH_TYPE => TypeRefKind::PathType(PathType::cast(self.syntax.clone()).unwrap()), | 3620 | NEVER_TYPE => TypeRefKind::NeverType(NeverType { syntax }), |
3405 | POINTER_TYPE => TypeRefKind::PointerType(PointerType::cast(self.syntax.clone()).unwrap()), | 3621 | PATH_TYPE => TypeRefKind::PathType(PathType { syntax }), |
3406 | ARRAY_TYPE => TypeRefKind::ArrayType(ArrayType::cast(self.syntax.clone()).unwrap()), | 3622 | POINTER_TYPE => TypeRefKind::PointerType(PointerType { syntax }), |
3407 | SLICE_TYPE => TypeRefKind::SliceType(SliceType::cast(self.syntax.clone()).unwrap()), | 3623 | ARRAY_TYPE => TypeRefKind::ArrayType(ArrayType { syntax }), |
3408 | REFERENCE_TYPE => TypeRefKind::ReferenceType(ReferenceType::cast(self.syntax.clone()).unwrap()), | 3624 | SLICE_TYPE => TypeRefKind::SliceType(SliceType { syntax }), |
3409 | PLACEHOLDER_TYPE => TypeRefKind::PlaceholderType(PlaceholderType::cast(self.syntax.clone()).unwrap()), | 3625 | REFERENCE_TYPE => TypeRefKind::ReferenceType(ReferenceType { syntax }), |
3410 | FN_POINTER_TYPE => TypeRefKind::FnPointerType(FnPointerType::cast(self.syntax.clone()).unwrap()), | 3626 | PLACEHOLDER_TYPE => TypeRefKind::PlaceholderType(PlaceholderType { syntax }), |
3411 | FOR_TYPE => TypeRefKind::ForType(ForType::cast(self.syntax.clone()).unwrap()), | 3627 | FN_POINTER_TYPE => TypeRefKind::FnPointerType(FnPointerType { syntax }), |
3412 | IMPL_TRAIT_TYPE => TypeRefKind::ImplTraitType(ImplTraitType::cast(self.syntax.clone()).unwrap()), | 3628 | FOR_TYPE => TypeRefKind::ForType(ForType { syntax }), |
3413 | DYN_TRAIT_TYPE => TypeRefKind::DynTraitType(DynTraitType::cast(self.syntax.clone()).unwrap()), | 3629 | IMPL_TRAIT_TYPE => TypeRefKind::ImplTraitType(ImplTraitType { syntax }), |
3630 | DYN_TRAIT_TYPE => TypeRefKind::DynTraitType(DynTraitType { syntax }), | ||
3414 | _ => unreachable!(), | 3631 | _ => unreachable!(), |
3415 | } | 3632 | } |
3416 | } | 3633 | } |
3417 | } | 3634 | } |
3418 | |||
3419 | impl TypeRef {} | 3635 | impl TypeRef {} |
3420 | |||
3421 | // UseItem | ||
3422 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 3636 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
3423 | pub struct UseItem { | 3637 | pub struct UseItem { |
3424 | pub(crate) syntax: SyntaxNode, | 3638 | pub(crate) syntax: SyntaxNode, |
3425 | } | 3639 | } |
3426 | |||
3427 | impl AstNode for UseItem { | 3640 | impl AstNode for UseItem { |
3428 | fn can_cast(kind: SyntaxKind) -> bool { | 3641 | fn can_cast(kind: SyntaxKind) -> bool { |
3429 | match kind { | 3642 | match kind { |
@@ -3432,25 +3645,26 @@ impl AstNode for UseItem { | |||
3432 | } | 3645 | } |
3433 | } | 3646 | } |
3434 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3647 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3435 | if Self::can_cast(syntax.kind()) { Some(UseItem { syntax }) } else { None } | 3648 | if Self::can_cast(syntax.kind()) { |
3649 | Some(Self { syntax }) | ||
3650 | } else { | ||
3651 | None | ||
3652 | } | ||
3653 | } | ||
3654 | fn syntax(&self) -> &SyntaxNode { | ||
3655 | &self.syntax | ||
3436 | } | 3656 | } |
3437 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3438 | } | 3657 | } |
3439 | |||
3440 | |||
3441 | impl ast::AttrsOwner for UseItem {} | 3658 | impl ast::AttrsOwner for UseItem {} |
3442 | impl UseItem { | 3659 | impl UseItem { |
3443 | pub fn use_tree(&self) -> Option<UseTree> { | 3660 | pub fn use_tree(&self) -> Option<UseTree> { |
3444 | super::child_opt(self) | 3661 | AstChildren::new(&self.syntax).next() |
3445 | } | 3662 | } |
3446 | } | 3663 | } |
3447 | |||
3448 | // UseTree | ||
3449 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 3664 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
3450 | pub struct UseTree { | 3665 | pub struct UseTree { |
3451 | pub(crate) syntax: SyntaxNode, | 3666 | pub(crate) syntax: SyntaxNode, |
3452 | } | 3667 | } |
3453 | |||
3454 | impl AstNode for UseTree { | 3668 | impl AstNode for UseTree { |
3455 | fn can_cast(kind: SyntaxKind) -> bool { | 3669 | fn can_cast(kind: SyntaxKind) -> bool { |
3456 | match kind { | 3670 | match kind { |
@@ -3459,32 +3673,31 @@ impl AstNode for UseTree { | |||
3459 | } | 3673 | } |
3460 | } | 3674 | } |
3461 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3675 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3462 | if Self::can_cast(syntax.kind()) { Some(UseTree { syntax }) } else { None } | 3676 | if Self::can_cast(syntax.kind()) { |
3677 | Some(Self { syntax }) | ||
3678 | } else { | ||
3679 | None | ||
3680 | } | ||
3681 | } | ||
3682 | fn syntax(&self) -> &SyntaxNode { | ||
3683 | &self.syntax | ||
3463 | } | 3684 | } |
3464 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3465 | } | 3685 | } |
3466 | |||
3467 | |||
3468 | impl UseTree { | 3686 | impl UseTree { |
3469 | pub fn path(&self) -> Option<Path> { | 3687 | pub fn path(&self) -> Option<Path> { |
3470 | super::child_opt(self) | 3688 | AstChildren::new(&self.syntax).next() |
3471 | } | 3689 | } |
3472 | |||
3473 | pub fn use_tree_list(&self) -> Option<UseTreeList> { | 3690 | pub fn use_tree_list(&self) -> Option<UseTreeList> { |
3474 | super::child_opt(self) | 3691 | AstChildren::new(&self.syntax).next() |
3475 | } | 3692 | } |
3476 | |||
3477 | pub fn alias(&self) -> Option<Alias> { | 3693 | pub fn alias(&self) -> Option<Alias> { |
3478 | super::child_opt(self) | 3694 | AstChildren::new(&self.syntax).next() |
3479 | } | 3695 | } |
3480 | } | 3696 | } |
3481 | |||
3482 | // UseTreeList | ||
3483 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 3697 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
3484 | pub struct UseTreeList { | 3698 | pub struct UseTreeList { |
3485 | pub(crate) syntax: SyntaxNode, | 3699 | pub(crate) syntax: SyntaxNode, |
3486 | } | 3700 | } |
3487 | |||
3488 | impl AstNode for UseTreeList { | 3701 | impl AstNode for UseTreeList { |
3489 | fn can_cast(kind: SyntaxKind) -> bool { | 3702 | fn can_cast(kind: SyntaxKind) -> bool { |
3490 | match kind { | 3703 | match kind { |
@@ -3493,24 +3706,25 @@ impl AstNode for UseTreeList { | |||
3493 | } | 3706 | } |
3494 | } | 3707 | } |
3495 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3708 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3496 | if Self::can_cast(syntax.kind()) { Some(UseTreeList { syntax }) } else { None } | 3709 | if Self::can_cast(syntax.kind()) { |
3710 | Some(Self { syntax }) | ||
3711 | } else { | ||
3712 | None | ||
3713 | } | ||
3714 | } | ||
3715 | fn syntax(&self) -> &SyntaxNode { | ||
3716 | &self.syntax | ||
3497 | } | 3717 | } |
3498 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3499 | } | 3718 | } |
3500 | |||
3501 | |||
3502 | impl UseTreeList { | 3719 | impl UseTreeList { |
3503 | pub fn use_trees(&self) -> impl Iterator<Item = UseTree> { | 3720 | pub fn use_trees(&self) -> AstChildren<UseTree> { |
3504 | super::children(self) | 3721 | AstChildren::new(&self.syntax) |
3505 | } | 3722 | } |
3506 | } | 3723 | } |
3507 | |||
3508 | // Visibility | ||
3509 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 3724 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
3510 | pub struct Visibility { | 3725 | pub struct Visibility { |
3511 | pub(crate) syntax: SyntaxNode, | 3726 | pub(crate) syntax: SyntaxNode, |
3512 | } | 3727 | } |
3513 | |||
3514 | impl AstNode for Visibility { | 3728 | impl AstNode for Visibility { |
3515 | fn can_cast(kind: SyntaxKind) -> bool { | 3729 | fn can_cast(kind: SyntaxKind) -> bool { |
3516 | match kind { | 3730 | match kind { |
@@ -3519,20 +3733,21 @@ impl AstNode for Visibility { | |||
3519 | } | 3733 | } |
3520 | } | 3734 | } |
3521 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3735 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3522 | if Self::can_cast(syntax.kind()) { Some(Visibility { syntax }) } else { None } | 3736 | if Self::can_cast(syntax.kind()) { |
3737 | Some(Self { syntax }) | ||
3738 | } else { | ||
3739 | None | ||
3740 | } | ||
3741 | } | ||
3742 | fn syntax(&self) -> &SyntaxNode { | ||
3743 | &self.syntax | ||
3523 | } | 3744 | } |
3524 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3525 | } | 3745 | } |
3526 | |||
3527 | |||
3528 | impl Visibility {} | 3746 | impl Visibility {} |
3529 | |||
3530 | // WhereClause | ||
3531 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 3747 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
3532 | pub struct WhereClause { | 3748 | pub struct WhereClause { |
3533 | pub(crate) syntax: SyntaxNode, | 3749 | pub(crate) syntax: SyntaxNode, |
3534 | } | 3750 | } |
3535 | |||
3536 | impl AstNode for WhereClause { | 3751 | impl AstNode for WhereClause { |
3537 | fn can_cast(kind: SyntaxKind) -> bool { | 3752 | fn can_cast(kind: SyntaxKind) -> bool { |
3538 | match kind { | 3753 | match kind { |
@@ -3541,24 +3756,25 @@ impl AstNode for WhereClause { | |||
3541 | } | 3756 | } |
3542 | } | 3757 | } |
3543 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3758 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3544 | if Self::can_cast(syntax.kind()) { Some(WhereClause { syntax }) } else { None } | 3759 | if Self::can_cast(syntax.kind()) { |
3760 | Some(Self { syntax }) | ||
3761 | } else { | ||
3762 | None | ||
3763 | } | ||
3764 | } | ||
3765 | fn syntax(&self) -> &SyntaxNode { | ||
3766 | &self.syntax | ||
3545 | } | 3767 | } |
3546 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3547 | } | 3768 | } |
3548 | |||
3549 | |||
3550 | impl WhereClause { | 3769 | impl WhereClause { |
3551 | pub fn predicates(&self) -> impl Iterator<Item = WherePred> { | 3770 | pub fn predicates(&self) -> AstChildren<WherePred> { |
3552 | super::children(self) | 3771 | AstChildren::new(&self.syntax) |
3553 | } | 3772 | } |
3554 | } | 3773 | } |
3555 | |||
3556 | // WherePred | ||
3557 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 3774 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
3558 | pub struct WherePred { | 3775 | pub struct WherePred { |
3559 | pub(crate) syntax: SyntaxNode, | 3776 | pub(crate) syntax: SyntaxNode, |
3560 | } | 3777 | } |
3561 | |||
3562 | impl AstNode for WherePred { | 3778 | impl AstNode for WherePred { |
3563 | fn can_cast(kind: SyntaxKind) -> bool { | 3779 | fn can_cast(kind: SyntaxKind) -> bool { |
3564 | match kind { | 3780 | match kind { |
@@ -3567,25 +3783,26 @@ impl AstNode for WherePred { | |||
3567 | } | 3783 | } |
3568 | } | 3784 | } |
3569 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3785 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3570 | if Self::can_cast(syntax.kind()) { Some(WherePred { syntax }) } else { None } | 3786 | if Self::can_cast(syntax.kind()) { |
3787 | Some(Self { syntax }) | ||
3788 | } else { | ||
3789 | None | ||
3790 | } | ||
3791 | } | ||
3792 | fn syntax(&self) -> &SyntaxNode { | ||
3793 | &self.syntax | ||
3571 | } | 3794 | } |
3572 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3573 | } | 3795 | } |
3574 | |||
3575 | |||
3576 | impl ast::TypeBoundsOwner for WherePred {} | 3796 | impl ast::TypeBoundsOwner for WherePred {} |
3577 | impl WherePred { | 3797 | impl WherePred { |
3578 | pub fn type_ref(&self) -> Option<TypeRef> { | 3798 | pub fn type_ref(&self) -> Option<TypeRef> { |
3579 | super::child_opt(self) | 3799 | AstChildren::new(&self.syntax).next() |
3580 | } | 3800 | } |
3581 | } | 3801 | } |
3582 | |||
3583 | // WhileExpr | ||
3584 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 3802 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
3585 | pub struct WhileExpr { | 3803 | pub struct WhileExpr { |
3586 | pub(crate) syntax: SyntaxNode, | 3804 | pub(crate) syntax: SyntaxNode, |
3587 | } | 3805 | } |
3588 | |||
3589 | impl AstNode for WhileExpr { | 3806 | impl AstNode for WhileExpr { |
3590 | fn can_cast(kind: SyntaxKind) -> bool { | 3807 | fn can_cast(kind: SyntaxKind) -> bool { |
3591 | match kind { | 3808 | match kind { |
@@ -3594,16 +3811,19 @@ impl AstNode for WhileExpr { | |||
3594 | } | 3811 | } |
3595 | } | 3812 | } |
3596 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3813 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3597 | if Self::can_cast(syntax.kind()) { Some(WhileExpr { syntax }) } else { None } | 3814 | if Self::can_cast(syntax.kind()) { |
3815 | Some(Self { syntax }) | ||
3816 | } else { | ||
3817 | None | ||
3818 | } | ||
3819 | } | ||
3820 | fn syntax(&self) -> &SyntaxNode { | ||
3821 | &self.syntax | ||
3598 | } | 3822 | } |
3599 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3600 | } | 3823 | } |
3601 | |||
3602 | |||
3603 | impl ast::LoopBodyOwner for WhileExpr {} | 3824 | impl ast::LoopBodyOwner for WhileExpr {} |
3604 | impl WhileExpr { | 3825 | impl WhileExpr { |
3605 | pub fn condition(&self) -> Option<Condition> { | 3826 | pub fn condition(&self) -> Option<Condition> { |
3606 | super::child_opt(self) | 3827 | AstChildren::new(&self.syntax).next() |
3607 | } | 3828 | } |
3608 | } | 3829 | } |
3609 | |||
diff --git a/crates/ra_syntax/src/ast/generated.rs.tera b/crates/ra_syntax/src/ast/generated.rs.tera deleted file mode 100644 index 03b4bf3a1..000000000 --- a/crates/ra_syntax/src/ast/generated.rs.tera +++ /dev/null | |||
@@ -1,101 +0,0 @@ | |||
1 | {# THIS File is not automatically generated: | ||
2 | the below applies to the result of this template | ||
3 | #}// This file is automatically generated based on the file `./generated.rs.tera` when `cargo gen-syntax` is run | ||
4 | // Do not edit manually | ||
5 | |||
6 | //! This module contains auto-generated Rust AST. Like `SyntaxNode`s, AST nodes | ||
7 | //! are generic over ownership: `X<'a>` things are `Copy` references, `XNode` | ||
8 | //! are Arc-based. You can switch between the two variants using `.owned` and | ||
9 | //! `.borrowed` functions. Most of the code works with borowed mode, and only | ||
10 | //! this mode has all AST accessors. | ||
11 | |||
12 | #![cfg_attr(rustfmt, rustfmt_skip)] | ||
13 | |||
14 | use crate::{ | ||
15 | SyntaxNode, SyntaxKind::{self, *}, | ||
16 | ast::{self, AstNode}, | ||
17 | }; | ||
18 | {% for node, methods in ast %} | ||
19 | // {{ node }} | ||
20 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
21 | pub struct {{ node }} { | ||
22 | pub(crate) syntax: SyntaxNode, | ||
23 | } | ||
24 | |||
25 | impl AstNode for {{ node }} { | ||
26 | fn can_cast(kind: SyntaxKind) -> bool { | ||
27 | match kind { | ||
28 | {%- if methods.enum %} | ||
29 | {% for kind in methods.enum %} | {{ kind | SCREAM }} {%- endfor -%} | ||
30 | {% else %} | ||
31 | {{ node | SCREAM }} | ||
32 | {%- endif %} => true, | ||
33 | _ => false, | ||
34 | } | ||
35 | } | ||
36 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
37 | if Self::can_cast(syntax.kind()) { Some({{ node }} { syntax }) } else { None } | ||
38 | } | ||
39 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
40 | } | ||
41 | |||
42 | {% if methods.enum %} | ||
43 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
44 | pub enum {{ node }}Kind { | ||
45 | {%- for kind in methods.enum %} | ||
46 | {{ kind }}({{ kind }}), | ||
47 | {%- endfor %} | ||
48 | } | ||
49 | |||
50 | {%- for kind in methods.enum %} | ||
51 | impl From<{{ kind }}> for {{ node }} { | ||
52 | fn from(n: {{ kind }}) -> {{ node }} { {{ node }} { syntax: n.syntax } } | ||
53 | } | ||
54 | {%- endfor %} | ||
55 | impl {{ node }} { | ||
56 | pub fn kind(&self) -> {{ node }}Kind { | ||
57 | match self.syntax.kind() { | ||
58 | {%- for kind in methods.enum %} | ||
59 | {{ kind | SCREAM }} => {{ node }}Kind::{{ kind }}({{ kind }}::cast(self.syntax.clone()).unwrap()), | ||
60 | {%- endfor %} | ||
61 | _ => unreachable!(), | ||
62 | } | ||
63 | } | ||
64 | } | ||
65 | {% endif %} | ||
66 | {% if methods.traits -%} | ||
67 | |||
68 | {%- for t in methods.traits -%} | ||
69 | impl ast::{{ t }} for {{ node }} {} | ||
70 | {% endfor -%} | ||
71 | |||
72 | {%- endif -%} | ||
73 | |||
74 | impl {{ node }} { | ||
75 | {%- if methods.collections -%} | ||
76 | {%- for m in methods.collections -%} | ||
77 | {%- set method_name = m.0 -%} | ||
78 | {%- set ChildName = m.1 %} | ||
79 | pub fn {{ method_name }}(&self) -> impl Iterator<Item = {{ ChildName }}> { | ||
80 | super::children(self) | ||
81 | } | ||
82 | {% endfor -%} | ||
83 | {%- endif -%} | ||
84 | |||
85 | {%- if methods.options -%} | ||
86 | {%- for m in methods.options -%} | ||
87 | |||
88 | {%- if m is string -%} | ||
89 | {%- set method_name = m | snake -%} | ||
90 | {%- set ChildName = m %} | ||
91 | {%- else -%} | ||
92 | {%- set method_name = m.0 -%} | ||
93 | {%- set ChildName = m.1 %} | ||
94 | {%- endif %} | ||
95 | pub fn {{ method_name }}(&self) -> Option<{{ ChildName }}> { | ||
96 | super::child_opt(self) | ||
97 | } | ||
98 | {% endfor -%} | ||
99 | {%- endif -%} | ||
100 | } | ||
101 | {% endfor %} | ||
diff --git a/crates/ra_tools/src/codegen.rs b/crates/ra_tools/src/codegen.rs index e14092704..6fd672290 100644 --- a/crates/ra_tools/src/codegen.rs +++ b/crates/ra_tools/src/codegen.rs | |||
@@ -154,7 +154,8 @@ fn reformat(text: impl std::fmt::Display) -> Result<String> { | |||
154 | write!(rustfmt.stdin.take().unwrap(), "{}", text)?; | 154 | write!(rustfmt.stdin.take().unwrap(), "{}", text)?; |
155 | let output = rustfmt.wait_with_output()?; | 155 | let output = rustfmt.wait_with_output()?; |
156 | let stdout = String::from_utf8(output.stdout)?; | 156 | let stdout = String::from_utf8(output.stdout)?; |
157 | Ok(stdout) | 157 | let preamble = "Generated file, do not edit by hand, see `crate/ra_tools/src/codegen`"; |
158 | Ok(format!("// {}\n\n{}", preamble, stdout)) | ||
158 | } | 159 | } |
159 | 160 | ||
160 | #[derive(Deserialize, Debug)] | 161 | #[derive(Deserialize, Debug)] |