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