aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/generated/nodes.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/ast/generated/nodes.rs')
-rw-r--r--crates/ra_syntax/src/ast/generated/nodes.rs1621
1 files changed, 1430 insertions, 191 deletions
diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs
index 3f16592b6..cf6067e57 100644
--- a/crates/ra_syntax/src/ast/generated/nodes.rs
+++ b/crates/ra_syntax/src/ast/generated/nodes.rs
@@ -5,17 +5,41 @@ use crate::{
5 SyntaxKind::{self, *}, 5 SyntaxKind::{self, *},
6 SyntaxNode, SyntaxToken, T, 6 SyntaxNode, SyntaxToken, T,
7}; 7};
8 8/// The entire Rust source file. Includes all top-level inner attributes and module items.
9///
10/// [Reference](https://doc.rust-lang.org/reference/crates-and-source-files.html)
9#[derive(Debug, Clone, PartialEq, Eq, Hash)] 11#[derive(Debug, Clone, PartialEq, Eq, Hash)]
10pub struct SourceFile { 12pub struct SourceFile {
11 pub(crate) syntax: SyntaxNode, 13 pub(crate) syntax: SyntaxNode,
12} 14}
13impl ast::ModuleItemOwner for SourceFile {} 15impl ast::ModuleItemOwner for SourceFile {}
14impl ast::AttrsOwner for SourceFile {} 16impl ast::AttrsOwner for SourceFile {}
17impl ast::DocCommentsOwner for SourceFile {}
15impl SourceFile { 18impl SourceFile {
16 pub fn modules(&self) -> AstChildren<Module> { support::children(&self.syntax) } 19 pub fn modules(&self) -> AstChildren<Module> { support::children(&self.syntax) }
17} 20}
18 21/// Function definition either with body or not.
22/// Includes all of its attributes and doc comments.
23///
24/// ```
25/// ❰
26/// /// Docs
27/// #[attr]
28/// pub extern "C" fn foo<T>(#[attr] Patern {p}: Pattern) -> u32
29/// where
30/// T: Debug
31/// {
32/// 42
33/// }
34/// ❱
35///
36/// extern "C" {
37/// ❰ fn fn_decl(also_variadic_ffi: u32, ...) -> u32; ❱
38/// }
39/// ```
40///
41/// - [Reference](https://doc.rust-lang.org/reference/items/functions.html)
42/// - [Nomicon](https://doc.rust-lang.org/nomicon/ffi.html#variadic-functions)
19#[derive(Debug, Clone, PartialEq, Eq, Hash)] 43#[derive(Debug, Clone, PartialEq, Eq, Hash)]
20pub struct FnDef { 44pub struct FnDef {
21 pub(crate) syntax: SyntaxNode, 45 pub(crate) syntax: SyntaxNode,
@@ -37,7 +61,13 @@ impl FnDef {
37 pub fn body(&self) -> Option<BlockExpr> { support::child(&self.syntax) } 61 pub fn body(&self) -> Option<BlockExpr> { support::child(&self.syntax) }
38 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 62 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
39} 63}
40 64/// Return type annotation.
65///
66/// ```
67/// fn foo(a: u32) ❰ -> Option<u32> ❱ { Some(a) }
68/// ```
69///
70/// [Reference](https://doc.rust-lang.org/reference/items/functions.html)
41#[derive(Debug, Clone, PartialEq, Eq, Hash)] 71#[derive(Debug, Clone, PartialEq, Eq, Hash)]
42pub struct RetType { 72pub struct RetType {
43 pub(crate) syntax: SyntaxNode, 73 pub(crate) syntax: SyntaxNode,
@@ -46,7 +76,26 @@ impl RetType {
46 pub fn thin_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![->]) } 76 pub fn thin_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![->]) }
47 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 77 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
48} 78}
49 79/// Struct definition.
80/// Includes all of its attributes and doc comments.
81///
82/// ```
83/// ❰
84/// /// Docs
85/// #[attr]
86/// struct Foo<T> where T: Debug {
87/// /// Docs
88/// #[attr]
89/// pub a: u32,
90/// b: T,
91/// }
92/// ❱
93///
94/// ❰ struct Foo; ❱
95/// ❰ struct Foo<T>(#[attr] T) where T: Debug; ❱
96/// ```
97///
98/// [Reference](https://doc.rust-lang.org/reference/items/structs.html)
50#[derive(Debug, Clone, PartialEq, Eq, Hash)] 99#[derive(Debug, Clone, PartialEq, Eq, Hash)]
51pub struct StructDef { 100pub struct StructDef {
52 pub(crate) syntax: SyntaxNode, 101 pub(crate) syntax: SyntaxNode,
@@ -61,7 +110,23 @@ impl StructDef {
61 pub fn field_def_list(&self) -> Option<FieldDefList> { support::child(&self.syntax) } 110 pub fn field_def_list(&self) -> Option<FieldDefList> { support::child(&self.syntax) }
62 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 111 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
63} 112}
64 113/// Union definition.
114/// Includes all of its attributes and doc comments.
115///
116/// ```
117/// ❰
118/// /// Docs
119/// #[attr]
120/// pub union Foo<T> where T: Debug {
121/// /// Docs
122/// #[attr]
123/// a: T,
124/// b: u32,
125/// }
126/// ❱
127/// ```
128///
129/// [Reference](https://doc.rust-lang.org/reference/items/unions.html)
65#[derive(Debug, Clone, PartialEq, Eq, Hash)] 130#[derive(Debug, Clone, PartialEq, Eq, Hash)]
66pub struct UnionDef { 131pub struct UnionDef {
67 pub(crate) syntax: SyntaxNode, 132 pub(crate) syntax: SyntaxNode,
@@ -77,7 +142,19 @@ impl UnionDef {
77 support::child(&self.syntax) 142 support::child(&self.syntax)
78 } 143 }
79} 144}
80 145/// Record field definition list including enclosing curly braces.
146///
147/// ```
148/// struct Foo // same for union
149/// ❰
150/// {
151/// a: u32,
152/// b: bool,
153/// }
154/// ❱
155/// ```
156///
157/// [Reference](https://doc.rust-lang.org/reference/items/structs.html)
81#[derive(Debug, Clone, PartialEq, Eq, Hash)] 158#[derive(Debug, Clone, PartialEq, Eq, Hash)]
82pub struct RecordFieldDefList { 159pub struct RecordFieldDefList {
83 pub(crate) syntax: SyntaxNode, 160 pub(crate) syntax: SyntaxNode,
@@ -87,7 +164,22 @@ impl RecordFieldDefList {
87 pub fn fields(&self) -> AstChildren<RecordFieldDef> { support::children(&self.syntax) } 164 pub fn fields(&self) -> AstChildren<RecordFieldDef> { support::children(&self.syntax) }
88 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } 165 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
89} 166}
90 167/// Record field definition including its attributes and doc comments.
168///
169/// ` ``
170/// same for union
171/// struct Foo {
172/// ❰
173/// /// Docs
174/// #[attr]
175/// pub a: u32
176/// ❱
177///
178/// ❰ b: bool ❱
179/// }
180/// ```
181///
182/// [Reference](https://doc.rust-lang.org/reference/items/structs.html)
91#[derive(Debug, Clone, PartialEq, Eq, Hash)] 183#[derive(Debug, Clone, PartialEq, Eq, Hash)]
92pub struct RecordFieldDef { 184pub struct RecordFieldDef {
93 pub(crate) syntax: SyntaxNode, 185 pub(crate) syntax: SyntaxNode,
@@ -98,7 +190,13 @@ impl ast::AttrsOwner for RecordFieldDef {}
98impl ast::DocCommentsOwner for RecordFieldDef {} 190impl ast::DocCommentsOwner for RecordFieldDef {}
99impl ast::TypeAscriptionOwner for RecordFieldDef {} 191impl ast::TypeAscriptionOwner for RecordFieldDef {}
100impl RecordFieldDef {} 192impl RecordFieldDef {}
101 193/// Tuple field definition list including enclosing parens.
194///
195/// ```
196/// struct Foo ❰ (u32, String, Vec<u32>) ❱;
197/// ```
198///
199/// [Reference](https://doc.rust-lang.org/reference/items/structs.html)
102#[derive(Debug, Clone, PartialEq, Eq, Hash)] 200#[derive(Debug, Clone, PartialEq, Eq, Hash)]
103pub struct TupleFieldDefList { 201pub struct TupleFieldDefList {
104 pub(crate) syntax: SyntaxNode, 202 pub(crate) syntax: SyntaxNode,
@@ -108,7 +206,13 @@ impl TupleFieldDefList {
108 pub fn fields(&self) -> AstChildren<TupleFieldDef> { support::children(&self.syntax) } 206 pub fn fields(&self) -> AstChildren<TupleFieldDef> { support::children(&self.syntax) }
109 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 207 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
110} 208}
111 209/// Tuple field definition including its attributes.
210///
211/// ```
212/// struct Foo(❰ #[attr] u32 ❱);
213/// ```
214///
215/// [Reference](https://doc.rust-lang.org/reference/items/structs.html)
112#[derive(Debug, Clone, PartialEq, Eq, Hash)] 216#[derive(Debug, Clone, PartialEq, Eq, Hash)]
113pub struct TupleFieldDef { 217pub struct TupleFieldDef {
114 pub(crate) syntax: SyntaxNode, 218 pub(crate) syntax: SyntaxNode,
@@ -118,7 +222,29 @@ impl ast::AttrsOwner for TupleFieldDef {}
118impl TupleFieldDef { 222impl TupleFieldDef {
119 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 223 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
120} 224}
121 225/// Enum definition.
226/// Includes all of its attributes and doc comments.
227///
228/// ```
229/// ❰
230/// /// Docs
231/// #[attr]
232/// pub enum Foo<T> where T: Debug {
233/// /// Docs
234/// #[attr]
235/// Bar,
236/// Baz(#[attr] u32),
237/// Bruh {
238/// a: u32,
239/// /// Docs
240/// #[attr]
241/// b: T,
242/// }
243/// }
244/// ❱
245/// ```
246///
247/// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html)
122#[derive(Debug, Clone, PartialEq, Eq, Hash)] 248#[derive(Debug, Clone, PartialEq, Eq, Hash)]
123pub struct EnumDef { 249pub struct EnumDef {
124 pub(crate) syntax: SyntaxNode, 250 pub(crate) syntax: SyntaxNode,
@@ -132,7 +258,22 @@ impl EnumDef {
132 pub fn enum_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![enum]) } 258 pub fn enum_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![enum]) }
133 pub fn variant_list(&self) -> Option<EnumVariantList> { support::child(&self.syntax) } 259 pub fn variant_list(&self) -> Option<EnumVariantList> { support::child(&self.syntax) }
134} 260}
135 261/// Enum variant definition list including enclosing curly braces.
262///
263/// ```
264/// enum Foo
265/// ❰
266/// {
267/// Bar,
268/// Baz(u32),
269/// Bruh {
270/// a: u32
271/// }
272/// }
273/// ❱
274/// ```
275///
276/// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html)
136#[derive(Debug, Clone, PartialEq, Eq, Hash)] 277#[derive(Debug, Clone, PartialEq, Eq, Hash)]
137pub struct EnumVariantList { 278pub struct EnumVariantList {
138 pub(crate) syntax: SyntaxNode, 279 pub(crate) syntax: SyntaxNode,
@@ -142,7 +283,21 @@ impl EnumVariantList {
142 pub fn variants(&self) -> AstChildren<EnumVariant> { support::children(&self.syntax) } 283 pub fn variants(&self) -> AstChildren<EnumVariant> { support::children(&self.syntax) }
143 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } 284 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
144} 285}
145 286/// Enum variant definition including its attributes and discriminant value definition.
287///
288/// ```
289/// enum Foo {
290/// ❰
291/// /// Docs
292/// #[attr]
293/// Bar
294/// ❱
295///
296/// // same for tuple and record variants
297/// }
298/// ```
299///
300/// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html)
146#[derive(Debug, Clone, PartialEq, Eq, Hash)] 301#[derive(Debug, Clone, PartialEq, Eq, Hash)]
147pub struct EnumVariant { 302pub struct EnumVariant {
148 pub(crate) syntax: SyntaxNode, 303 pub(crate) syntax: SyntaxNode,
@@ -156,7 +311,20 @@ impl EnumVariant {
156 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } 311 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
157 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 312 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
158} 313}
159 314/// Trait definition.
315/// Includes all of its attributes and doc comments.
316///
317/// ```
318/// ❰
319/// /// Docs
320/// #[attr]
321/// pub unsafe trait Foo<T>: Debug where T: Debug {
322/// // ...
323/// }
324/// ❱
325/// ```
326///
327/// [Reference](https://doc.rust-lang.org/reference/items/traits.html)
160#[derive(Debug, Clone, PartialEq, Eq, Hash)] 328#[derive(Debug, Clone, PartialEq, Eq, Hash)]
161pub struct TraitDef { 329pub struct TraitDef {
162 pub(crate) syntax: SyntaxNode, 330 pub(crate) syntax: SyntaxNode,
@@ -173,7 +341,27 @@ impl TraitDef {
173 pub fn trait_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![trait]) } 341 pub fn trait_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![trait]) }
174 pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } 342 pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) }
175} 343}
176 344/// Module definition either with body or not.
345/// Includes all of its inner and outer attributes, module items, doc comments.
346///
347/// ```
348/// ❰
349/// /// Docs
350/// #[attr]
351/// pub mod foo;
352/// ❱
353///
354/// ❰
355/// /// Docs
356/// #[attr]
357/// pub mod bar {
358/// //! Inner docs
359/// #![inner_attr]
360/// }
361/// ❱
362/// ```
363///
364/// [Reference](https://doc.rust-lang.org/reference/items/modules.html)
177#[derive(Debug, Clone, PartialEq, Eq, Hash)] 365#[derive(Debug, Clone, PartialEq, Eq, Hash)]
178pub struct Module { 366pub struct Module {
179 pub(crate) syntax: SyntaxNode, 367 pub(crate) syntax: SyntaxNode,
@@ -187,7 +375,28 @@ impl Module {
187 pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } 375 pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) }
188 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 376 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
189} 377}
190 378/// Item defintion list.
379/// This is used for both top-level items and impl block items.
380///
381/// ```
382/// ❰
383/// fn foo {}
384/// struct Bar;
385/// enum Baz;
386/// trait Bruh;
387/// const BRUUH: u32 = 42;
388/// ❱
389///
390/// impl Foo
391/// ❰
392/// {
393/// fn bar() {}
394/// const BAZ: u32 = 42;
395/// }
396/// ❱
397/// ```
398///
399/// [Reference](https://doc.rust-lang.org/reference/items.html)
191#[derive(Debug, Clone, PartialEq, Eq, Hash)] 400#[derive(Debug, Clone, PartialEq, Eq, Hash)]
192pub struct ItemList { 401pub struct ItemList {
193 pub(crate) syntax: SyntaxNode, 402 pub(crate) syntax: SyntaxNode,
@@ -195,10 +404,21 @@ pub struct ItemList {
195impl ast::ModuleItemOwner for ItemList {} 404impl ast::ModuleItemOwner for ItemList {}
196impl ItemList { 405impl ItemList {
197 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } 406 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
198 pub fn impl_items(&self) -> AstChildren<ImplItem> { support::children(&self.syntax) } 407 pub fn assoc_items(&self) -> AstChildren<AssocItem> { support::children(&self.syntax) }
199 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } 408 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
200} 409}
201 410/// Constant variable definition.
411/// Includes all of its attributes and doc comments.
412///
413/// ```
414/// ❰
415/// /// Docs
416/// #[attr]
417/// pub const FOO: u32 = 42;
418/// ❱
419/// ```
420///
421/// [Reference](https://doc.rust-lang.org/reference/items/constant-items.html)
202#[derive(Debug, Clone, PartialEq, Eq, Hash)] 422#[derive(Debug, Clone, PartialEq, Eq, Hash)]
203pub struct ConstDef { 423pub struct ConstDef {
204 pub(crate) syntax: SyntaxNode, 424 pub(crate) syntax: SyntaxNode,
@@ -216,7 +436,18 @@ impl ConstDef {
216 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } 436 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) }
217 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 437 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
218} 438}
219 439/// Static variable definition.
440/// Includes all of its attributes and doc comments.
441///
442/// ```
443/// ❰
444/// /// Docs
445/// #[attr]
446/// pub static mut FOO: u32 = 42;
447/// ❱
448/// ```
449///
450/// [Reference](https://doc.rust-lang.org/reference/items/static-items.html)
220#[derive(Debug, Clone, PartialEq, Eq, Hash)] 451#[derive(Debug, Clone, PartialEq, Eq, Hash)]
221pub struct StaticDef { 452pub struct StaticDef {
222 pub(crate) syntax: SyntaxNode, 453 pub(crate) syntax: SyntaxNode,
@@ -234,7 +465,24 @@ impl StaticDef {
234 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } 465 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) }
235 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 466 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
236} 467}
237 468/// Type alias definition.
469/// Includes associated type clauses with type bounds.
470///
471/// ```
472/// ❰
473/// /// Docs
474/// #[attr]
475/// pub type Foo<T> where T: Debug = T;
476/// ❱
477///
478/// trait Bar {
479/// ❰ type Baz: Debug; ❱
480/// ❰ type Bruh = String; ❱
481/// ❰ type Bruuh: Debug = u32; ❱
482/// }
483/// ```
484///
485/// [Reference](https://doc.rust-lang.org/reference/items/type-aliases.html)
238#[derive(Debug, Clone, PartialEq, Eq, Hash)] 486#[derive(Debug, Clone, PartialEq, Eq, Hash)]
239pub struct TypeAliasDef { 487pub struct TypeAliasDef {
240 pub(crate) syntax: SyntaxNode, 488 pub(crate) syntax: SyntaxNode,
@@ -252,13 +500,27 @@ impl TypeAliasDef {
252 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 500 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
253 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 501 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
254} 502}
255 503/// Inherent and trait impl definition.
504/// Includes all of its inner and outer attributes.
505///
506/// ```
507/// ❰
508/// #[attr]
509/// unsafe impl<T> const !Foo for Bar where T: Debug {
510/// #![inner_attr]
511/// // ...
512/// }
513/// ❱
514/// ```
515///
516/// [Reference](https://doc.rust-lang.org/reference/items/implementations.html)
256#[derive(Debug, Clone, PartialEq, Eq, Hash)] 517#[derive(Debug, Clone, PartialEq, Eq, Hash)]
257pub struct ImplDef { 518pub struct ImplDef {
258 pub(crate) syntax: SyntaxNode, 519 pub(crate) syntax: SyntaxNode,
259} 520}
260impl ast::TypeParamsOwner for ImplDef {} 521impl ast::TypeParamsOwner for ImplDef {}
261impl ast::AttrsOwner for ImplDef {} 522impl ast::AttrsOwner for ImplDef {}
523impl ast::DocCommentsOwner for ImplDef {}
262impl ImplDef { 524impl ImplDef {
263 pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) } 525 pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) }
264 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } 526 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
@@ -268,7 +530,16 @@ impl ImplDef {
268 pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) } 530 pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) }
269 pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } 531 pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) }
270} 532}
271 533/// Parenthesized type reference.
534/// Note: parens are only used for grouping, this is not a tuple type.
535///
536/// ```
537/// // This is effectively just `u32`.
538/// // Single-item tuple must be defined with a trailing comma: `(u32,)`
539/// type Foo = ❰ (u32) ❱;
540///
541/// let bar: &'static ❰ (dyn Debug) ❱ = "bruh";
542/// ```
272#[derive(Debug, Clone, PartialEq, Eq, Hash)] 543#[derive(Debug, Clone, PartialEq, Eq, Hash)]
273pub struct ParenType { 544pub struct ParenType {
274 pub(crate) syntax: SyntaxNode, 545 pub(crate) syntax: SyntaxNode,
@@ -278,7 +549,13 @@ impl ParenType {
278 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 549 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
279 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 550 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
280} 551}
281 552/// Unnamed tuple type.
553///
554/// ```
555/// let foo: ❰ (u32, bool) ❱ = (42, true);
556/// ```
557///
558/// [Reference](https://doc.rust-lang.org/reference/types/tuple.html)
282#[derive(Debug, Clone, PartialEq, Eq, Hash)] 559#[derive(Debug, Clone, PartialEq, Eq, Hash)]
283pub struct TupleType { 560pub struct TupleType {
284 pub(crate) syntax: SyntaxNode, 561 pub(crate) syntax: SyntaxNode,
@@ -288,7 +565,17 @@ impl TupleType {
288 pub fn fields(&self) -> AstChildren<TypeRef> { support::children(&self.syntax) } 565 pub fn fields(&self) -> AstChildren<TypeRef> { support::children(&self.syntax) }
289 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 566 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
290} 567}
291 568/// The never type (i.e. the exclamation point).
569///
570/// ```
571/// type T = ❰ ! ❱;
572///
573/// fn no_return() -> ❰ ! ❱ {
574/// loop {}
575/// }
576/// ```
577///
578/// [Reference](https://doc.rust-lang.org/reference/types/never.html)
292#[derive(Debug, Clone, PartialEq, Eq, Hash)] 579#[derive(Debug, Clone, PartialEq, Eq, Hash)]
293pub struct NeverType { 580pub struct NeverType {
294 pub(crate) syntax: SyntaxNode, 581 pub(crate) syntax: SyntaxNode,
@@ -296,7 +583,17 @@ pub struct NeverType {
296impl NeverType { 583impl NeverType {
297 pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) } 584 pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) }
298} 585}
299 586/// Path to a type.
587/// Includes single identifier type names and elaborate paths with
588/// generic parameters.
589///
590/// ```
591/// type Foo = ❰ String ❱;
592/// type Bar = ❰ std::vec::Vec<T> ❱;
593/// type Baz = ❰ ::bruh::<Bruuh as Iterator>::Item ❱;
594/// ```
595///
596/// [Reference](https://doc.rust-lang.org/reference/paths.html)
300#[derive(Debug, Clone, PartialEq, Eq, Hash)] 597#[derive(Debug, Clone, PartialEq, Eq, Hash)]
301pub struct PathType { 598pub struct PathType {
302 pub(crate) syntax: SyntaxNode, 599 pub(crate) syntax: SyntaxNode,
@@ -304,7 +601,14 @@ pub struct PathType {
304impl PathType { 601impl PathType {
305 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } 602 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
306} 603}
307 604/// Raw pointer type.
605///
606/// ```
607/// type Foo = ❰ *const u32 ❱;
608/// type Bar = ❰ *mut u32 ❱;
609/// ```
610///
611/// [Reference](https://doc.rust-lang.org/reference/types/pointer.html#raw-pointers-const-and-mut)
308#[derive(Debug, Clone, PartialEq, Eq, Hash)] 612#[derive(Debug, Clone, PartialEq, Eq, Hash)]
309pub struct PointerType { 613pub struct PointerType {
310 pub(crate) syntax: SyntaxNode, 614 pub(crate) syntax: SyntaxNode,
@@ -315,7 +619,13 @@ impl PointerType {
315 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } 619 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
316 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 620 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
317} 621}
318 622/// Array type.
623///
624/// ```
625/// type Foo = ❰ [u32; 24 - 3] ❱;
626/// ```
627///
628/// [Reference](https://doc.rust-lang.org/reference/types/array.html)
319#[derive(Debug, Clone, PartialEq, Eq, Hash)] 629#[derive(Debug, Clone, PartialEq, Eq, Hash)]
320pub struct ArrayType { 630pub struct ArrayType {
321 pub(crate) syntax: SyntaxNode, 631 pub(crate) syntax: SyntaxNode,
@@ -327,7 +637,13 @@ impl ArrayType {
327 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 637 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
328 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } 638 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
329} 639}
330 640/// Slice type.
641///
642/// ```
643/// type Foo = ❰ [u8] ❱;
644/// ```
645///
646/// [Reference](https://doc.rust-lang.org/reference/types/slice.html)
331#[derive(Debug, Clone, PartialEq, Eq, Hash)] 647#[derive(Debug, Clone, PartialEq, Eq, Hash)]
332pub struct SliceType { 648pub struct SliceType {
333 pub(crate) syntax: SyntaxNode, 649 pub(crate) syntax: SyntaxNode,
@@ -337,7 +653,13 @@ impl SliceType {
337 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 653 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
338 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } 654 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
339} 655}
340 656/// Reference type.
657///
658/// ```
659/// type Foo = ❰ &'static str ❱;
660/// ```
661///
662/// [Reference](https://doc.rust-lang.org/reference/types/pointer.html)
341#[derive(Debug, Clone, PartialEq, Eq, Hash)] 663#[derive(Debug, Clone, PartialEq, Eq, Hash)]
342pub struct ReferenceType { 664pub struct ReferenceType {
343 pub(crate) syntax: SyntaxNode, 665 pub(crate) syntax: SyntaxNode,
@@ -350,7 +672,13 @@ impl ReferenceType {
350 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } 672 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
351 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 673 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
352} 674}
353 675/// Placeholder type (i.e. the underscore).
676///
677/// ```
678/// let foo: ❰ _ ❱ = 42_u32;
679/// ```
680///
681/// [Reference](https://doc.rust-lang.org/reference/types/inferred.html)
354#[derive(Debug, Clone, PartialEq, Eq, Hash)] 682#[derive(Debug, Clone, PartialEq, Eq, Hash)]
355pub struct PlaceholderType { 683pub struct PlaceholderType {
356 pub(crate) syntax: SyntaxNode, 684 pub(crate) syntax: SyntaxNode,
@@ -358,7 +686,15 @@ pub struct PlaceholderType {
358impl PlaceholderType { 686impl PlaceholderType {
359 pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) } 687 pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) }
360} 688}
361 689/// Function pointer type (not to be confused with `Fn*` family of traits).
690///
691/// ```
692/// type Foo = ❰ async fn(#[attr] u32, named: bool) -> u32 ❱;
693///
694/// type Bar = ❰ extern "C" fn(variadic: u32, #[attr] ...) ❱;
695/// ```
696///
697/// [Reference](https://doc.rust-lang.org/reference/types/function-pointer.html)
362#[derive(Debug, Clone, PartialEq, Eq, Hash)] 698#[derive(Debug, Clone, PartialEq, Eq, Hash)]
363pub struct FnPointerType { 699pub struct FnPointerType {
364 pub(crate) syntax: SyntaxNode, 700 pub(crate) syntax: SyntaxNode,
@@ -370,7 +706,13 @@ impl FnPointerType {
370 pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) } 706 pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) }
371 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } 707 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) }
372} 708}
373 709/// Higher order type.
710///
711/// ```
712/// type Foo = ❰ for<'a> fn(&'a str) ❱;
713/// ```
714///
715/// [Reference](https://doc.rust-lang.org/nomicon/hrtb.html)
374#[derive(Debug, Clone, PartialEq, Eq, Hash)] 716#[derive(Debug, Clone, PartialEq, Eq, Hash)]
375pub struct ForType { 717pub struct ForType {
376 pub(crate) syntax: SyntaxNode, 718 pub(crate) syntax: SyntaxNode,
@@ -380,7 +722,13 @@ impl ForType {
380 pub fn type_param_list(&self) -> Option<TypeParamList> { support::child(&self.syntax) } 722 pub fn type_param_list(&self) -> Option<TypeParamList> { support::child(&self.syntax) }
381 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 723 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
382} 724}
383 725/// Opaque `impl Trait` type.
726///
727/// ```
728/// fn foo(bar: ❰ impl Debug + Eq ❱) {}
729/// ```
730///
731/// [Reference](https://doc.rust-lang.org/reference/types/impl-trait.html)
384#[derive(Debug, Clone, PartialEq, Eq, Hash)] 732#[derive(Debug, Clone, PartialEq, Eq, Hash)]
385pub struct ImplTraitType { 733pub struct ImplTraitType {
386 pub(crate) syntax: SyntaxNode, 734 pub(crate) syntax: SyntaxNode,
@@ -389,7 +737,13 @@ impl ast::TypeBoundsOwner for ImplTraitType {}
389impl ImplTraitType { 737impl ImplTraitType {
390 pub fn impl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![impl]) } 738 pub fn impl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![impl]) }
391} 739}
392 740/// Trait object type.
741///
742/// ```
743/// type Foo = ❰ dyn Debug ❱;
744/// ```
745///
746/// [Reference](https://doc.rust-lang.org/reference/types/trait-object.html)
393#[derive(Debug, Clone, PartialEq, Eq, Hash)] 747#[derive(Debug, Clone, PartialEq, Eq, Hash)]
394pub struct DynTraitType { 748pub struct DynTraitType {
395 pub(crate) syntax: SyntaxNode, 749 pub(crate) syntax: SyntaxNode,
@@ -398,7 +752,13 @@ impl ast::TypeBoundsOwner for DynTraitType {}
398impl DynTraitType { 752impl DynTraitType {
399 pub fn dyn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![dyn]) } 753 pub fn dyn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![dyn]) }
400} 754}
401 755/// Tuple literal.
756///
757/// ```
758/// ❰ (42, true) ❱;
759/// ```
760///
761/// [Reference](https://doc.rust-lang.org/reference/expressions/tuple-expr.html)
402#[derive(Debug, Clone, PartialEq, Eq, Hash)] 762#[derive(Debug, Clone, PartialEq, Eq, Hash)]
403pub struct TupleExpr { 763pub struct TupleExpr {
404 pub(crate) syntax: SyntaxNode, 764 pub(crate) syntax: SyntaxNode,
@@ -409,7 +769,15 @@ impl TupleExpr {
409 pub fn exprs(&self) -> AstChildren<Expr> { support::children(&self.syntax) } 769 pub fn exprs(&self) -> AstChildren<Expr> { support::children(&self.syntax) }
410 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 770 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
411} 771}
412 772/// Array literal.
773///
774/// ```
775/// ❰ [#![inner_attr] true, false, true] ❱;
776///
777/// ❰ ["baz"; 24] ❱;
778/// ```
779///
780/// [Reference](https://doc.rust-lang.org/reference/expressions/array-expr.html)
413#[derive(Debug, Clone, PartialEq, Eq, Hash)] 781#[derive(Debug, Clone, PartialEq, Eq, Hash)]
414pub struct ArrayExpr { 782pub struct ArrayExpr {
415 pub(crate) syntax: SyntaxNode, 783 pub(crate) syntax: SyntaxNode,
@@ -421,7 +789,14 @@ impl ArrayExpr {
421 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 789 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
422 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } 790 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
423} 791}
424 792/// Parenthesized expression.
793/// Note: parens are only used for grouping, this is not a tuple literal.
794///
795/// ```
796/// ❰ (#![inner_attr] 2 + 2) ❱ * 2;
797/// ```
798///
799/// [Reference](https://doc.rust-lang.org/reference/expressions/grouped-expr.html)
425#[derive(Debug, Clone, PartialEq, Eq, Hash)] 800#[derive(Debug, Clone, PartialEq, Eq, Hash)]
426pub struct ParenExpr { 801pub struct ParenExpr {
427 pub(crate) syntax: SyntaxNode, 802 pub(crate) syntax: SyntaxNode,
@@ -432,7 +807,19 @@ impl ParenExpr {
432 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 807 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
433 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 808 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
434} 809}
435 810/// Path to a symbol in expression context.
811/// Includes single identifier variable names and elaborate paths with
812/// generic parameters.
813///
814/// ```
815/// ❰ Some::<i32> ❱;
816/// ❰ foo ❱ + 42;
817/// ❰ Vec::<i32>::push ❱;
818/// ❰ <[i32]>::reverse ❱;
819/// ❰ <String as std::borrow::Borrow<str>>::borrow ❱;
820/// ```
821///
822/// [Reference](https://doc.rust-lang.org/reference/expressions/path-expr.html)
436#[derive(Debug, Clone, PartialEq, Eq, Hash)] 823#[derive(Debug, Clone, PartialEq, Eq, Hash)]
437pub struct PathExpr { 824pub struct PathExpr {
438 pub(crate) syntax: SyntaxNode, 825 pub(crate) syntax: SyntaxNode,
@@ -440,7 +827,17 @@ pub struct PathExpr {
440impl PathExpr { 827impl PathExpr {
441 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } 828 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
442} 829}
443 830/// Anonymous callable object literal a.k.a. closure, lambda or functor.
831///
832/// ```
833/// ❰ || 42 ❱;
834/// ❰ |a: u32| val + 1 ❱;
835/// ❰ async |#[attr] Pattern(_): Pattern| { bar } ❱;
836/// ❰ move || baz ❱;
837/// ❰ || -> u32 { closure_with_ret_type_annotation_requires_block_expr } ❱
838/// ```
839///
840/// [Reference](https://doc.rust-lang.org/reference/expressions/closure-expr.html)
444#[derive(Debug, Clone, PartialEq, Eq, Hash)] 841#[derive(Debug, Clone, PartialEq, Eq, Hash)]
445pub struct LambdaExpr { 842pub struct LambdaExpr {
446 pub(crate) syntax: SyntaxNode, 843 pub(crate) syntax: SyntaxNode,
@@ -454,7 +851,25 @@ impl LambdaExpr {
454 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } 851 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) }
455 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } 852 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) }
456} 853}
457 854/// If expression. Includes both regular `if` and `if let` forms.
855/// Beware that `else if` is a special case syntax sugar, because in general
856/// there has to be block expression after `else`.
857///
858/// ```
859/// ❰ if bool_cond { 42 } ❱
860/// ❰ if bool_cond { 42 } else { 24 } ❱
861/// ❰ if bool_cond { 42 } else if bool_cond2 { 42 } ❱
862///
863/// ❰
864/// if let Pattern(foo) = bar {
865/// foo
866/// } else {
867/// panic!();
868/// }
869/// ❱
870/// ```
871///
872/// [Reference](https://doc.rust-lang.org/reference/expressions/if-expr.html)
458#[derive(Debug, Clone, PartialEq, Eq, Hash)] 873#[derive(Debug, Clone, PartialEq, Eq, Hash)]
459pub struct IfExpr { 874pub struct IfExpr {
460 pub(crate) syntax: SyntaxNode, 875 pub(crate) syntax: SyntaxNode,
@@ -464,7 +879,17 @@ impl IfExpr {
464 pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) } 879 pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) }
465 pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } 880 pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) }
466} 881}
467 882/// Unconditional loop expression.
883///
884/// ```
885/// ❰
886/// loop {
887/// // yeah, it's that simple...
888/// }
889/// ❱
890/// ```
891///
892/// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html)
468#[derive(Debug, Clone, PartialEq, Eq, Hash)] 893#[derive(Debug, Clone, PartialEq, Eq, Hash)]
469pub struct LoopExpr { 894pub struct LoopExpr {
470 pub(crate) syntax: SyntaxNode, 895 pub(crate) syntax: SyntaxNode,
@@ -474,7 +899,45 @@ impl ast::LoopBodyOwner for LoopExpr {}
474impl LoopExpr { 899impl LoopExpr {
475 pub fn loop_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![loop]) } 900 pub fn loop_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![loop]) }
476} 901}
477 902/// Block expression with an optional prefix (label, try ketword,
903/// unsafe keyword, async keyword...).
904///
905/// ```
906/// ❰
907/// 'label: try {
908/// None?
909/// }
910/// ❱
911/// ```
912///
913/// - [try block](https://doc.rust-lang.org/unstable-book/language-features/try-blocks.html)
914/// - [unsafe block](https://doc.rust-lang.org/reference/expressions/block-expr.html#unsafe-blocks)
915/// - [async block](https://doc.rust-lang.org/reference/expressions/block-expr.html#async-blocks)
916#[derive(Debug, Clone, PartialEq, Eq, Hash)]
917pub struct EffectExpr {
918 pub(crate) syntax: SyntaxNode,
919}
920impl ast::AttrsOwner for EffectExpr {}
921impl EffectExpr {
922 pub fn label(&self) -> Option<Label> { support::child(&self.syntax) }
923 pub fn try_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![try]) }
924 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) }
925 pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) }
926 pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) }
927}
928/// For loop expression.
929/// Note: record struct literals are not valid as iterable expression
930/// due to ambiguity.
931///
932/// ```
933/// ❰
934/// for i in (0..4) {
935/// dbg!(i);
936/// }
937/// ❱
938/// ```
939///
940/// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#iterator-loops)
478#[derive(Debug, Clone, PartialEq, Eq, Hash)] 941#[derive(Debug, Clone, PartialEq, Eq, Hash)]
479pub struct ForExpr { 942pub struct ForExpr {
480 pub(crate) syntax: SyntaxNode, 943 pub(crate) syntax: SyntaxNode,
@@ -487,7 +950,22 @@ impl ForExpr {
487 pub fn in_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![in]) } 950 pub fn in_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![in]) }
488 pub fn iterable(&self) -> Option<Expr> { support::child(&self.syntax) } 951 pub fn iterable(&self) -> Option<Expr> { support::child(&self.syntax) }
489} 952}
490 953/// While loop expression. Includes both regular `while` and `while let` forms.
954///
955/// ```
956/// ❰
957/// while bool_cond {
958/// 42;
959/// }
960/// ❱
961/// ❰
962/// while let Pattern(foo) = bar {
963/// bar += 1;
964/// }
965/// ❱
966/// ```
967///
968/// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-loops)
491#[derive(Debug, Clone, PartialEq, Eq, Hash)] 969#[derive(Debug, Clone, PartialEq, Eq, Hash)]
492pub struct WhileExpr { 970pub struct WhileExpr {
493 pub(crate) syntax: SyntaxNode, 971 pub(crate) syntax: SyntaxNode,
@@ -498,7 +976,22 @@ impl WhileExpr {
498 pub fn while_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![while]) } 976 pub fn while_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![while]) }
499 pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } 977 pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) }
500} 978}
501 979/// Continue expression.
980///
981/// ```
982/// while bool_cond {
983/// ❰ continue ❱;
984/// }
985///
986/// 'outer: loop {
987/// loop {
988/// ❰ continue 'outer ❱;
989/// }
990/// }
991///
992/// ```
993///
994/// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#continue-expressions)
502#[derive(Debug, Clone, PartialEq, Eq, Hash)] 995#[derive(Debug, Clone, PartialEq, Eq, Hash)]
503pub struct ContinueExpr { 996pub struct ContinueExpr {
504 pub(crate) syntax: SyntaxNode, 997 pub(crate) syntax: SyntaxNode,
@@ -512,7 +1005,25 @@ impl ContinueExpr {
512 support::token(&self.syntax, T![lifetime]) 1005 support::token(&self.syntax, T![lifetime])
513 } 1006 }
514} 1007}
515 1008/// Break expression.
1009///
1010/// ```
1011/// while bool_cond {
1012/// ❰ break ❱;
1013/// }
1014/// 'outer: loop {
1015/// for foo in bar {
1016/// ❰ break 'outer ❱;
1017/// }
1018/// }
1019/// 'outer: loop {
1020/// loop {
1021/// ❰ break 'outer 42 ❱;
1022/// }
1023/// }
1024/// ```
1025///
1026/// [Refernce](https://doc.rust-lang.org/reference/expressions/loop-expr.html#break-expressions)
516#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1027#[derive(Debug, Clone, PartialEq, Eq, Hash)]
517pub struct BreakExpr { 1028pub struct BreakExpr {
518 pub(crate) syntax: SyntaxNode, 1029 pub(crate) syntax: SyntaxNode,
@@ -525,7 +1036,20 @@ impl BreakExpr {
525 } 1036 }
526 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 1037 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
527} 1038}
528 1039/// Label.
1040///
1041/// ```
1042/// ❰ 'outer: ❱ loop {}
1043///
1044/// let foo = ❰ 'bar: ❱ loop {}
1045///
1046/// ❰ 'baz: ❱ {
1047/// break 'baz;
1048/// }
1049/// ```
1050///
1051/// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html?highlight=label#loop-labels)
1052/// [Labels for blocks RFC](https://github.com/rust-lang/rfcs/blob/master/text/2046-label-break-value.md)
529#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1053#[derive(Debug, Clone, PartialEq, Eq, Hash)]
530pub struct Label { 1054pub struct Label {
531 pub(crate) syntax: SyntaxNode, 1055 pub(crate) syntax: SyntaxNode,
@@ -535,19 +1059,44 @@ impl Label {
535 support::token(&self.syntax, T![lifetime]) 1059 support::token(&self.syntax, T![lifetime])
536 } 1060 }
537} 1061}
538 1062/// Block expression. Includes unsafe blocks and block labels.
1063///
1064/// ```
1065/// let foo = ❰
1066/// {
1067/// #![inner_attr]
1068/// ❰ { } ❱
1069///
1070/// ❰ 'label: { break 'label } ❱
1071/// }
1072/// ❱;
1073/// ```
1074///
1075/// [Reference](https://doc.rust-lang.org/reference/expressions/block-expr.html)
1076/// [Labels for blocks RFC](https://github.com/rust-lang/rfcs/blob/master/text/2046-label-break-value.md)
539#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1077#[derive(Debug, Clone, PartialEq, Eq, Hash)]
540pub struct BlockExpr { 1078pub struct BlockExpr {
541 pub(crate) syntax: SyntaxNode, 1079 pub(crate) syntax: SyntaxNode,
542} 1080}
543impl ast::AttrsOwner for BlockExpr {} 1081impl ast::AttrsOwner for BlockExpr {}
1082impl ast::ModuleItemOwner for BlockExpr {}
544impl BlockExpr { 1083impl BlockExpr {
545 pub fn label(&self) -> Option<Label> { support::child(&self.syntax) } 1084 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
546 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) } 1085 pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) }
547 pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) } 1086 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
548 pub fn block(&self) -> Option<Block> { support::child(&self.syntax) } 1087 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
549} 1088}
550 1089/// Return expression.
1090///
1091/// ```
1092/// || ❰ return 42 ❱;
1093///
1094/// fn bar() {
1095/// ❰ return ❱;
1096/// }
1097/// ```
1098///
1099/// [Reference](https://doc.rust-lang.org/reference/expressions/return-expr.html)
551#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1100#[derive(Debug, Clone, PartialEq, Eq, Hash)]
552pub struct ReturnExpr { 1101pub struct ReturnExpr {
553 pub(crate) syntax: SyntaxNode, 1102 pub(crate) syntax: SyntaxNode,
@@ -556,7 +1105,16 @@ impl ast::AttrsOwner for ReturnExpr {}
556impl ReturnExpr { 1105impl ReturnExpr {
557 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 1106 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
558} 1107}
559 1108/// Call expression (not to be confused with method call expression, it is
1109/// a separate ast node).
1110///
1111/// ```
1112/// ❰ foo() ❱;
1113/// ❰ &str::len("bar") ❱;
1114/// ❰ <&str as PartialEq<&str>>::eq(&"", &"") ❱;
1115/// ```
1116///
1117/// [Reference](https://doc.rust-lang.org/reference/expressions/call-expr.html)
560#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1118#[derive(Debug, Clone, PartialEq, Eq, Hash)]
561pub struct CallExpr { 1119pub struct CallExpr {
562 pub(crate) syntax: SyntaxNode, 1120 pub(crate) syntax: SyntaxNode,
@@ -565,7 +1123,16 @@ impl ast::ArgListOwner for CallExpr {}
565impl CallExpr { 1123impl CallExpr {
566 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 1124 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
567} 1125}
568 1126/// Method call expression.
1127///
1128/// ```
1129/// ❰ receiver_expr.method() ❱;
1130/// ❰ receiver_expr.method::<T>(42, true) ❱;
1131///
1132/// ❰ ❰ ❰ foo.bar() ❱ .baz() ❱ .bruh() ❱;
1133/// ```
1134///
1135/// [Reference](https://doc.rust-lang.org/reference/expressions/method-call-expr.html)
569#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1136#[derive(Debug, Clone, PartialEq, Eq, Hash)]
570pub struct MethodCallExpr { 1137pub struct MethodCallExpr {
571 pub(crate) syntax: SyntaxNode, 1138 pub(crate) syntax: SyntaxNode,
@@ -578,7 +1145,13 @@ impl MethodCallExpr {
578 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } 1145 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
579 pub fn type_arg_list(&self) -> Option<TypeArgList> { support::child(&self.syntax) } 1146 pub fn type_arg_list(&self) -> Option<TypeArgList> { support::child(&self.syntax) }
580} 1147}
581 1148/// Index expression a.k.a. subscript operator call.
1149///
1150/// ```
1151/// ❰ foo[42] ❱;
1152/// ```
1153///
1154/// [Reference](https://doc.rust-lang.org/reference/expressions/array-expr.html)
582#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1155#[derive(Debug, Clone, PartialEq, Eq, Hash)]
583pub struct IndexExpr { 1156pub struct IndexExpr {
584 pub(crate) syntax: SyntaxNode, 1157 pub(crate) syntax: SyntaxNode,
@@ -588,7 +1161,15 @@ impl IndexExpr {
588 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } 1161 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
589 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } 1162 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
590} 1163}
591 1164/// Field access expression.
1165///
1166/// ```
1167/// ❰ expr.bar ❱;
1168///
1169/// ❰ ❰ ❰ foo.bar ❱ .baz ❱ .bruh ❱;
1170/// ```
1171///
1172/// [Reference](https://doc.rust-lang.org/reference/expressions/field-expr.html)
592#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1173#[derive(Debug, Clone, PartialEq, Eq, Hash)]
593pub struct FieldExpr { 1174pub struct FieldExpr {
594 pub(crate) syntax: SyntaxNode, 1175 pub(crate) syntax: SyntaxNode,
@@ -599,7 +1180,13 @@ impl FieldExpr {
599 pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) } 1180 pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) }
600 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } 1181 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
601} 1182}
602 1183/// Await operator call expression.
1184///
1185/// ```
1186/// ❰ expr.await ❱;
1187/// ```
1188///
1189/// [Reference](https://doc.rust-lang.org/reference/expressions/await-expr.html)
603#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1190#[derive(Debug, Clone, PartialEq, Eq, Hash)]
604pub struct AwaitExpr { 1191pub struct AwaitExpr {
605 pub(crate) syntax: SyntaxNode, 1192 pub(crate) syntax: SyntaxNode,
@@ -610,17 +1197,29 @@ impl AwaitExpr {
610 pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) } 1197 pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) }
611 pub fn await_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![await]) } 1198 pub fn await_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![await]) }
612} 1199}
613 1200/// The question mark operator call.
1201///
1202/// ```
1203/// ❰ expr? ❱;
1204/// ```
1205///
1206/// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#the-question-mark-operator)
614#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1207#[derive(Debug, Clone, PartialEq, Eq, Hash)]
615pub struct TryExpr { 1208pub struct TryExpr {
616 pub(crate) syntax: SyntaxNode, 1209 pub(crate) syntax: SyntaxNode,
617} 1210}
618impl ast::AttrsOwner for TryExpr {} 1211impl ast::AttrsOwner for TryExpr {}
619impl TryExpr { 1212impl TryExpr {
620 pub fn try_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![try]) }
621 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 1213 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1214 pub fn question_mark_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![?]) }
622} 1215}
623 1216/// Type cast expression.
1217///
1218/// ```
1219/// ❰ expr as T ❱;
1220/// ```
1221///
1222/// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions)
624#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1223#[derive(Debug, Clone, PartialEq, Eq, Hash)]
625pub struct CastExpr { 1224pub struct CastExpr {
626 pub(crate) syntax: SyntaxNode, 1225 pub(crate) syntax: SyntaxNode,
@@ -631,7 +1230,14 @@ impl CastExpr {
631 pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) } 1230 pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) }
632 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 1231 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
633} 1232}
634 1233/// Borrow operator call.
1234///
1235/// ```
1236/// ❰ &foo ❱;
1237/// ❰ &mut bar ❱;
1238/// ```
1239///
1240/// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#borrow-operators)
635#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1241#[derive(Debug, Clone, PartialEq, Eq, Hash)]
636pub struct RefExpr { 1242pub struct RefExpr {
637 pub(crate) syntax: SyntaxNode, 1243 pub(crate) syntax: SyntaxNode,
@@ -643,7 +1249,15 @@ impl RefExpr {
643 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } 1249 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
644 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 1250 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
645} 1251}
646 1252/// Prefix operator call. This is either `!` or `*` or `-`.
1253///
1254/// ```
1255/// ❰ !foo ❱;
1256/// ❰ *bar ❱;
1257/// ❰ -42 ❱;
1258/// ```
1259///
1260/// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html)
647#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1261#[derive(Debug, Clone, PartialEq, Eq, Hash)]
648pub struct PrefixExpr { 1262pub struct PrefixExpr {
649 pub(crate) syntax: SyntaxNode, 1263 pub(crate) syntax: SyntaxNode,
@@ -652,7 +1266,13 @@ impl ast::AttrsOwner for PrefixExpr {}
652impl PrefixExpr { 1266impl PrefixExpr {
653 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 1267 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
654} 1268}
655 1269/// Box operator call.
1270///
1271/// ```
1272/// ❰ box 42 ❱;
1273/// ```
1274///
1275/// [RFC](https://github.com/rust-lang/rfcs/blob/0806be4f282144cfcd55b1d20284b43f87cbe1c6/text/0809-box-and-in-for-stdlib.md)
656#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1276#[derive(Debug, Clone, PartialEq, Eq, Hash)]
657pub struct BoxExpr { 1277pub struct BoxExpr {
658 pub(crate) syntax: SyntaxNode, 1278 pub(crate) syntax: SyntaxNode,
@@ -662,27 +1282,69 @@ impl BoxExpr {
662 pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) } 1282 pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) }
663 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 1283 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
664} 1284}
665 1285/// Range operator call.
1286///
1287/// ```
1288/// ❰ 0..42 ❱;
1289/// ❰ ..42 ❱;
1290/// ❰ 0.. ❱;
1291/// ❰ .. ❱;
1292/// ❰ 0..=42 ❱;
1293/// ❰ ..=42 ❱;
1294/// ```
1295///
1296/// [Reference](https://doc.rust-lang.org/reference/expressions/range-expr.html)
666#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1297#[derive(Debug, Clone, PartialEq, Eq, Hash)]
667pub struct RangeExpr { 1298pub struct RangeExpr {
668 pub(crate) syntax: SyntaxNode, 1299 pub(crate) syntax: SyntaxNode,
669} 1300}
670impl ast::AttrsOwner for RangeExpr {} 1301impl ast::AttrsOwner for RangeExpr {}
671impl RangeExpr {} 1302impl RangeExpr {}
672 1303/// Binary operator call.
1304/// Includes all arithmetic, logic, bitwise and assignment operators.
1305///
1306/// ```
1307/// ❰ 2 + ❰ 2 * 2 ❱ ❱;
1308/// ❰ ❰ true && false ❱ || true ❱;
1309/// ```
1310///
1311/// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#arithmetic-and-logical-binary-operators)
673#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1312#[derive(Debug, Clone, PartialEq, Eq, Hash)]
674pub struct BinExpr { 1313pub struct BinExpr {
675 pub(crate) syntax: SyntaxNode, 1314 pub(crate) syntax: SyntaxNode,
676} 1315}
677impl ast::AttrsOwner for BinExpr {} 1316impl ast::AttrsOwner for BinExpr {}
678impl BinExpr {} 1317impl BinExpr {}
679 1318/// [Raw] string, [raw] byte string, char, byte, integer, float or bool literal.
1319///
1320/// ```
1321/// ❰ "str" ❱;
1322/// ❰ br##"raw byte str"## ❱;
1323/// ❰ 'c' ❱;
1324/// ❰ b'c' ❱;
1325/// ❰ 42 ❱;
1326/// ❰ 1e9 ❱;
1327/// ❰ true ❱;
1328/// ```
1329///
1330/// [Reference](https://doc.rust-lang.org/reference/expressions/literal-expr.html)
680#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1331#[derive(Debug, Clone, PartialEq, Eq, Hash)]
681pub struct Literal { 1332pub struct Literal {
682 pub(crate) syntax: SyntaxNode, 1333 pub(crate) syntax: SyntaxNode,
683} 1334}
684impl Literal {} 1335impl Literal {}
685 1336/// Match expression.
1337///
1338/// ```
1339/// ❰
1340/// match expr {
1341/// Pat1 => {}
1342/// Pat2(_) => 42,
1343/// }
1344/// ❱
1345/// ```
1346///
1347/// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html)
686#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1348#[derive(Debug, Clone, PartialEq, Eq, Hash)]
687pub struct MatchExpr { 1349pub struct MatchExpr {
688 pub(crate) syntax: SyntaxNode, 1350 pub(crate) syntax: SyntaxNode,
@@ -693,7 +1355,20 @@ impl MatchExpr {
693 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 1355 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
694 pub fn match_arm_list(&self) -> Option<MatchArmList> { support::child(&self.syntax) } 1356 pub fn match_arm_list(&self) -> Option<MatchArmList> { support::child(&self.syntax) }
695} 1357}
696 1358/// Match arm list part of match expression. Includes its inner attributes.
1359///
1360/// ```
1361/// match expr
1362/// ❰
1363/// {
1364/// #![inner_attr]
1365/// Pat1 => {}
1366/// Pat2(_) => 42,
1367/// }
1368/// ❱
1369/// ```
1370///
1371/// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html)
697#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1372#[derive(Debug, Clone, PartialEq, Eq, Hash)]
698pub struct MatchArmList { 1373pub struct MatchArmList {
699 pub(crate) syntax: SyntaxNode, 1374 pub(crate) syntax: SyntaxNode,
@@ -704,7 +1379,16 @@ impl MatchArmList {
704 pub fn arms(&self) -> AstChildren<MatchArm> { support::children(&self.syntax) } 1379 pub fn arms(&self) -> AstChildren<MatchArm> { support::children(&self.syntax) }
705 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } 1380 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
706} 1381}
707 1382/// Match arm.
1383/// Note: record struct literals are not valid as target match expression
1384/// due to ambiguity.
1385/// ```
1386/// match expr {
1387/// ❰ #[attr] Pattern(it) if bool_cond => it ❱,
1388/// }
1389/// ```
1390///
1391/// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html)
708#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1392#[derive(Debug, Clone, PartialEq, Eq, Hash)]
709pub struct MatchArm { 1393pub struct MatchArm {
710 pub(crate) syntax: SyntaxNode, 1394 pub(crate) syntax: SyntaxNode,
@@ -716,7 +1400,15 @@ impl MatchArm {
716 pub fn fat_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=>]) } 1400 pub fn fat_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=>]) }
717 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 1401 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
718} 1402}
719 1403/// Match guard.
1404///
1405/// ```
1406/// match expr {
1407/// Pattern(it) ❰ if bool_cond ❱ => it,
1408/// }
1409/// ```
1410///
1411/// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html#match-guards)
720#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1412#[derive(Debug, Clone, PartialEq, Eq, Hash)]
721pub struct MatchGuard { 1413pub struct MatchGuard {
722 pub(crate) syntax: SyntaxNode, 1414 pub(crate) syntax: SyntaxNode,
@@ -725,7 +1417,21 @@ impl MatchGuard {
725 pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) } 1417 pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) }
726 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 1418 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
727} 1419}
728 1420/// Record literal expression. The same syntax is used for structs,
1421/// unions and record enum variants.
1422///
1423/// ```
1424/// ❰
1425/// foo::Bar {
1426/// #![inner_attr]
1427/// baz: 42,
1428/// bruh: true,
1429/// ..spread
1430/// }
1431/// ❱
1432/// ```
1433///
1434/// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html)
729#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1435#[derive(Debug, Clone, PartialEq, Eq, Hash)]
730pub struct RecordLit { 1436pub struct RecordLit {
731 pub(crate) syntax: SyntaxNode, 1437 pub(crate) syntax: SyntaxNode,
@@ -734,7 +1440,16 @@ impl RecordLit {
734 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } 1440 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
735 pub fn record_field_list(&self) -> Option<RecordFieldList> { support::child(&self.syntax) } 1441 pub fn record_field_list(&self) -> Option<RecordFieldList> { support::child(&self.syntax) }
736} 1442}
737 1443/// Record field list including enclosing curly braces.
1444///
1445/// foo::Bar ❰
1446/// {
1447/// baz: 42,
1448/// ..spread
1449/// }
1450/// ❱
1451///
1452/// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html)
738#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1453#[derive(Debug, Clone, PartialEq, Eq, Hash)]
739pub struct RecordFieldList { 1454pub struct RecordFieldList {
740 pub(crate) syntax: SyntaxNode, 1455 pub(crate) syntax: SyntaxNode,
@@ -746,7 +1461,15 @@ impl RecordFieldList {
746 pub fn spread(&self) -> Option<Expr> { support::child(&self.syntax) } 1461 pub fn spread(&self) -> Option<Expr> { support::child(&self.syntax) }
747 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } 1462 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
748} 1463}
749 1464/// Record field.
1465///
1466/// ```
1467/// foo::Bar {
1468/// ❰ #[attr] baz: 42 ❱
1469/// }
1470/// ```
1471///
1472/// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html)
750#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1473#[derive(Debug, Clone, PartialEq, Eq, Hash)]
751pub struct RecordField { 1474pub struct RecordField {
752 pub(crate) syntax: SyntaxNode, 1475 pub(crate) syntax: SyntaxNode,
@@ -757,7 +1480,13 @@ impl RecordField {
757 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } 1480 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
758 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 1481 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
759} 1482}
760 1483/// Disjunction of patterns.
1484///
1485/// ```
1486/// let ❰ Foo(it) | Bar(it) | Baz(it) ❱ = bruh;
1487/// ```
1488///
1489/// [Reference](https://doc.rust-lang.org/reference/patterns.html)
761#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1490#[derive(Debug, Clone, PartialEq, Eq, Hash)]
762pub struct OrPat { 1491pub struct OrPat {
763 pub(crate) syntax: SyntaxNode, 1492 pub(crate) syntax: SyntaxNode,
@@ -765,7 +1494,14 @@ pub struct OrPat {
765impl OrPat { 1494impl OrPat {
766 pub fn pats(&self) -> AstChildren<Pat> { support::children(&self.syntax) } 1495 pub fn pats(&self) -> AstChildren<Pat> { support::children(&self.syntax) }
767} 1496}
768 1497/// Parenthesized pattern.
1498/// Note: parens are only used for grouping, this is not a tuple pattern.
1499///
1500/// ```
1501/// if let ❰ &(0..=42) ❱ = foo {}
1502/// ```
1503///
1504/// https://doc.rust-lang.org/reference/patterns.html#grouped-patterns
769#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1505#[derive(Debug, Clone, PartialEq, Eq, Hash)]
770pub struct ParenPat { 1506pub struct ParenPat {
771 pub(crate) syntax: SyntaxNode, 1507 pub(crate) syntax: SyntaxNode,
@@ -775,7 +1511,16 @@ impl ParenPat {
775 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 1511 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
776 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 1512 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
777} 1513}
778 1514/// Reference pattern.
1515/// Note: this has nothing to do with `ref` keyword, the latter is used in bind patterns.
1516///
1517/// ```
1518/// let ❰ &mut foo ❱ = bar;
1519///
1520/// let ❰ & ❰ &mut ❰ &_ ❱ ❱ ❱ = baz;
1521/// ```
1522///
1523/// [Reference](https://doc.rust-lang.org/reference/patterns.html#reference-patterns)
779#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1524#[derive(Debug, Clone, PartialEq, Eq, Hash)]
780pub struct RefPat { 1525pub struct RefPat {
781 pub(crate) syntax: SyntaxNode, 1526 pub(crate) syntax: SyntaxNode,
@@ -785,7 +1530,13 @@ impl RefPat {
785 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } 1530 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
786 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 1531 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
787} 1532}
788 1533/// Box pattern.
1534///
1535/// ```
1536/// let ❰ box foo ❱ = box 42;
1537/// ```
1538///
1539/// [Unstable book](https://doc.rust-lang.org/unstable-book/language-features/box-patterns.html)
789#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1540#[derive(Debug, Clone, PartialEq, Eq, Hash)]
790pub struct BoxPat { 1541pub struct BoxPat {
791 pub(crate) syntax: SyntaxNode, 1542 pub(crate) syntax: SyntaxNode,
@@ -794,7 +1545,16 @@ impl BoxPat {
794 pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) } 1545 pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) }
795 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 1546 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
796} 1547}
797 1548/// Bind pattern.
1549///
1550/// ```
1551/// match foo {
1552/// Some(❰ ref mut bar ❱) => {}
1553/// ❰ baz @ None ❱ => {}
1554/// }
1555/// ```
1556///
1557/// [Reference](https://doc.rust-lang.org/reference/patterns.html#identifier-patterns)
798#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1558#[derive(Debug, Clone, PartialEq, Eq, Hash)]
799pub struct BindPat { 1559pub struct BindPat {
800 pub(crate) syntax: SyntaxNode, 1560 pub(crate) syntax: SyntaxNode,
@@ -807,7 +1567,13 @@ impl BindPat {
807 pub fn at_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![@]) } 1567 pub fn at_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![@]) }
808 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 1568 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
809} 1569}
810 1570/// Placeholder pattern a.k.a. the wildcard pattern or the underscore.
1571///
1572/// ```
1573/// let ❰ _ ❱ = foo;
1574/// ```
1575///
1576/// [Reference](https://doc.rust-lang.org/reference/patterns.html#wildcard-pattern)
811#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1577#[derive(Debug, Clone, PartialEq, Eq, Hash)]
812pub struct PlaceholderPat { 1578pub struct PlaceholderPat {
813 pub(crate) syntax: SyntaxNode, 1579 pub(crate) syntax: SyntaxNode,
@@ -815,7 +1581,16 @@ pub struct PlaceholderPat {
815impl PlaceholderPat { 1581impl PlaceholderPat {
816 pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) } 1582 pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) }
817} 1583}
818 1584/// Rest-of-the record/tuple pattern.
1585/// Note: this is not the unbonded range pattern (even more: it doesn't exist).
1586///
1587/// ```
1588/// let Foo { bar, ❰ .. ❱ } = baz;
1589/// let (❰ .. ❱, bruh) = (42, 24, 42);
1590/// let Bruuh(❰ .. ❱) = bruuuh;
1591/// ```
1592///
1593/// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns)
819#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1594#[derive(Debug, Clone, PartialEq, Eq, Hash)]
820pub struct DotDotPat { 1595pub struct DotDotPat {
821 pub(crate) syntax: SyntaxNode, 1596 pub(crate) syntax: SyntaxNode,
@@ -823,7 +1598,15 @@ pub struct DotDotPat {
823impl DotDotPat { 1598impl DotDotPat {
824 pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } 1599 pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) }
825} 1600}
826 1601/// Path pattern.
1602/// Doesn't include the underscore pattern (it is a special case, namely `PlaceholderPat`).
1603///
1604/// ```
1605/// let ❰ foo::bar::Baz ❱ { .. } = bruh;
1606/// if let ❰ CONST ❱ = 42 {}
1607/// ```
1608///
1609/// [Reference](https://doc.rust-lang.org/reference/patterns.html#path-patterns)
827#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1610#[derive(Debug, Clone, PartialEq, Eq, Hash)]
828pub struct PathPat { 1611pub struct PathPat {
829 pub(crate) syntax: SyntaxNode, 1612 pub(crate) syntax: SyntaxNode,
@@ -831,7 +1614,13 @@ pub struct PathPat {
831impl PathPat { 1614impl PathPat {
832 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } 1615 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
833} 1616}
834 1617/// Slice pattern.
1618///
1619/// ```
1620/// let ❰ [foo, bar, baz] ❱ = [1, 2, 3];
1621/// ```
1622///
1623/// [Reference](https://doc.rust-lang.org/reference/patterns.html#slice-patterns)
835#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1624#[derive(Debug, Clone, PartialEq, Eq, Hash)]
836pub struct SlicePat { 1625pub struct SlicePat {
837 pub(crate) syntax: SyntaxNode, 1626 pub(crate) syntax: SyntaxNode,
@@ -841,13 +1630,33 @@ impl SlicePat {
841 pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } 1630 pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) }
842 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } 1631 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
843} 1632}
844 1633/// Range pattern.
1634///
1635/// ```
1636/// match foo {
1637/// ❰ 0..42 ❱ => {}
1638/// ❰ 0..=42 ❱ => {}
1639/// }
1640/// ```
1641///
1642/// [Reference](https://doc.rust-lang.org/reference/patterns.html#range-patterns)
845#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1643#[derive(Debug, Clone, PartialEq, Eq, Hash)]
846pub struct RangePat { 1644pub struct RangePat {
847 pub(crate) syntax: SyntaxNode, 1645 pub(crate) syntax: SyntaxNode,
848} 1646}
849impl RangePat {} 1647impl RangePat {}
850 1648/// Literal pattern.
1649/// Includes only bool, number, char, and string literals.
1650///
1651/// ```
1652/// match foo {
1653/// Number(❰ 42 ❱) => {}
1654/// String(❰ "42" ❱) => {}
1655/// Bool(❰ true ❱) => {}
1656/// }
1657/// ```
1658///
1659/// [Reference](https://doc.rust-lang.org/reference/patterns.html#literal-patterns)
851#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1660#[derive(Debug, Clone, PartialEq, Eq, Hash)]
852pub struct LiteralPat { 1661pub struct LiteralPat {
853 pub(crate) syntax: SyntaxNode, 1662 pub(crate) syntax: SyntaxNode,
@@ -855,7 +1664,13 @@ pub struct LiteralPat {
855impl LiteralPat { 1664impl LiteralPat {
856 pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) } 1665 pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) }
857} 1666}
858 1667/// Macro invocation in pattern position.
1668///
1669/// ```
1670/// let ❰ foo!(my custom syntax) ❱ = baz;
1671///
1672/// ```
1673/// [Reference](https://doc.rust-lang.org/reference/macros.html#macro-invocation)
859#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1674#[derive(Debug, Clone, PartialEq, Eq, Hash)]
860pub struct MacroPat { 1675pub struct MacroPat {
861 pub(crate) syntax: SyntaxNode, 1676 pub(crate) syntax: SyntaxNode,
@@ -863,7 +1678,13 @@ pub struct MacroPat {
863impl MacroPat { 1678impl MacroPat {
864 pub fn macro_call(&self) -> Option<MacroCall> { support::child(&self.syntax) } 1679 pub fn macro_call(&self) -> Option<MacroCall> { support::child(&self.syntax) }
865} 1680}
866 1681/// Record literal pattern.
1682///
1683/// ```
1684/// let ❰ foo::Bar { baz, .. } ❱ = bruh;
1685/// ```
1686///
1687/// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns)
867#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1688#[derive(Debug, Clone, PartialEq, Eq, Hash)]
868pub struct RecordPat { 1689pub struct RecordPat {
869 pub(crate) syntax: SyntaxNode, 1690 pub(crate) syntax: SyntaxNode,
@@ -874,7 +1695,13 @@ impl RecordPat {
874 } 1695 }
875 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } 1696 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
876} 1697}
877 1698/// Record literal's field patterns list including enclosing curly braces.
1699///
1700/// ```
1701/// let foo::Bar ❰ { baz, bind @ bruh, .. } ❱ = bruuh;
1702/// ``
1703///
1704/// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns)
878#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1705#[derive(Debug, Clone, PartialEq, Eq, Hash)]
879pub struct RecordFieldPatList { 1706pub struct RecordFieldPatList {
880 pub(crate) syntax: SyntaxNode, 1707 pub(crate) syntax: SyntaxNode,
@@ -889,7 +1716,15 @@ impl RecordFieldPatList {
889 pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } 1716 pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) }
890 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } 1717 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
891} 1718}
892 1719/// Record literal's field pattern.
1720/// Note: record literal can also match tuple structs.
1721///
1722/// ```
1723/// let Foo { ❰ bar: _ ❱ } = baz;
1724/// let TupleStruct { ❰ 0: _ ❱ } = bruh;
1725/// ```
1726///
1727/// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns)
893#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1728#[derive(Debug, Clone, PartialEq, Eq, Hash)]
894pub struct RecordFieldPat { 1729pub struct RecordFieldPat {
895 pub(crate) syntax: SyntaxNode, 1730 pub(crate) syntax: SyntaxNode,
@@ -900,7 +1735,13 @@ impl RecordFieldPat {
900 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } 1735 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
901 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 1736 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
902} 1737}
903 1738/// Tuple struct literal pattern.
1739///
1740/// ```
1741/// let ❰ foo::Bar(baz, bruh) ❱ = bruuh;
1742/// ```
1743///
1744/// [Reference](https://doc.rust-lang.org/reference/patterns.html#tuple-struct-patterns)
904#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1745#[derive(Debug, Clone, PartialEq, Eq, Hash)]
905pub struct TupleStructPat { 1746pub struct TupleStructPat {
906 pub(crate) syntax: SyntaxNode, 1747 pub(crate) syntax: SyntaxNode,
@@ -911,7 +1752,14 @@ impl TupleStructPat {
911 pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } 1752 pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) }
912 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 1753 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
913} 1754}
914 1755/// Tuple pattern.
1756/// Note: this doesn't include tuple structs (see `TupleStructPat`)
1757///
1758/// ```
1759/// let ❰ (foo, bar, .., baz) ❱ = bruh;
1760/// ```
1761///
1762/// [Reference](https://doc.rust-lang.org/reference/patterns.html#tuple-patterns)
915#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1763#[derive(Debug, Clone, PartialEq, Eq, Hash)]
916pub struct TuplePat { 1764pub struct TuplePat {
917 pub(crate) syntax: SyntaxNode, 1765 pub(crate) syntax: SyntaxNode,
@@ -921,7 +1769,17 @@ impl TuplePat {
921 pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } 1769 pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) }
922 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 1770 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
923} 1771}
924 1772/// Visibility.
1773///
1774/// ```
1775/// ❰ pub mod ❱ foo;
1776/// ❰ pub(crate) ❱ struct Bar;
1777/// ❰ pub(self) ❱ enum Baz {}
1778/// ❰ pub(super) ❱ fn bruh() {}
1779/// ❰ pub(in bruuh::bruuuh) ❱ type T = u64;
1780/// ```
1781///
1782/// [Reference](https://doc.rust-lang.org/reference/visibility-and-privacy.html)
925#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1783#[derive(Debug, Clone, PartialEq, Eq, Hash)]
926pub struct Visibility { 1784pub struct Visibility {
927 pub(crate) syntax: SyntaxNode, 1785 pub(crate) syntax: SyntaxNode,
@@ -932,7 +1790,29 @@ impl Visibility {
932 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) } 1790 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) }
933 pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) } 1791 pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) }
934} 1792}
935 1793/// Single identifier.
1794/// Note(@matklad): `Name` is for things that install a new name into the scope,
1795/// `NameRef` is a usage of a name. Most of the time, this definition/reference
1796/// distinction can be determined purely syntactically, ie in
1797/// ```
1798/// fn foo() { foo() }
1799/// ```
1800/// the first foo is `Name`, the second one is `NameRef`.
1801/// The notable exception are patterns, where in
1802/// ``
1803/// let x = 92
1804/// ```
1805/// `x` can be semantically either a name or a name ref, depeding on
1806/// wether there's an `x` constant in scope.
1807/// We use `Name` for patterns, and disambiguate semantically (see `NameClass` in ide_db).
1808///
1809/// ```
1810/// let ❰ foo ❱ = bar;
1811/// struct ❰ Baz ❱;
1812/// fn ❰ bruh ❱() {}
1813/// ```
1814///
1815/// [Reference](https://doc.rust-lang.org/reference/identifiers.html)
936#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1816#[derive(Debug, Clone, PartialEq, Eq, Hash)]
937pub struct Name { 1817pub struct Name {
938 pub(crate) syntax: SyntaxNode, 1818 pub(crate) syntax: SyntaxNode,
@@ -940,13 +1820,41 @@ pub struct Name {
940impl Name { 1820impl Name {
941 pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) } 1821 pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) }
942} 1822}
943 1823/// Reference to a name.
1824/// See the explanation on the difference between `Name` and `NameRef`
1825/// in `Name` ast node docs.
1826///
1827/// ```
1828/// let foo = ❰ bar ❱(❰ Baz(❰ bruh ❱) ❱;
1829/// ```
1830///
1831/// [Reference](https://doc.rust-lang.org/reference/identifiers.html)
944#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1832#[derive(Debug, Clone, PartialEq, Eq, Hash)]
945pub struct NameRef { 1833pub struct NameRef {
946 pub(crate) syntax: SyntaxNode, 1834 pub(crate) syntax: SyntaxNode,
947} 1835}
948impl NameRef {} 1836impl NameRef {}
949 1837/// Macro call.
1838/// Includes all of its attributes and doc comments.
1839///
1840/// ```
1841/// ❰
1842/// /// Docs
1843/// #[attr]
1844/// macro_rules! foo { // macro rules is also a macro call
1845/// ($bar: tt) => {}
1846/// }
1847/// ❱
1848///
1849/// // semicolon is a part of `MacroCall` when it is used in item positions
1850/// ❰ foo!(); ❱
1851///
1852/// fn main() {
1853/// ❰ foo!() ❱; // macro call in expression positions doesn't include the semi
1854/// }
1855/// ```
1856///
1857/// [Reference](https://doc.rust-lang.org/reference/macros.html)
950#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1858#[derive(Debug, Clone, PartialEq, Eq, Hash)]
951pub struct MacroCall { 1859pub struct MacroCall {
952 pub(crate) syntax: SyntaxNode, 1860 pub(crate) syntax: SyntaxNode,
@@ -960,7 +1868,18 @@ impl MacroCall {
960 pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) } 1868 pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) }
961 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 1869 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
962} 1870}
963 1871/// Attribute.
1872///
1873/// ```
1874/// ❰ #![inner_attr] ❱
1875///
1876/// ❰ #[attr] ❱
1877/// ❰ #[foo = "bar"] ❱
1878/// ❰ #[baz(bruh::bruuh = "42")] ❱
1879/// struct Foo;
1880/// ```
1881///
1882/// [Reference](https://doc.rust-lang.org/reference/attributes.html)
964#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1883#[derive(Debug, Clone, PartialEq, Eq, Hash)]
965pub struct Attr { 1884pub struct Attr {
966 pub(crate) syntax: SyntaxNode, 1885 pub(crate) syntax: SyntaxNode,
@@ -974,13 +1893,32 @@ impl Attr {
974 pub fn input(&self) -> Option<AttrInput> { support::child(&self.syntax) } 1893 pub fn input(&self) -> Option<AttrInput> { support::child(&self.syntax) }
975 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } 1894 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
976} 1895}
977 1896/// Stores a list of lexer tokens and other `TokenTree`s.
1897/// It appears in attributes, macro_rules and macro call (foo!)
1898///
1899/// ```
1900/// macro_call! ❰ { my syntax here } ❱;
1901/// ```
1902///
1903/// [Reference](https://doc.rust-lang.org/reference/macros.html)
978#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1904#[derive(Debug, Clone, PartialEq, Eq, Hash)]
979pub struct TokenTree { 1905pub struct TokenTree {
980 pub(crate) syntax: SyntaxNode, 1906 pub(crate) syntax: SyntaxNode,
981} 1907}
982impl TokenTree {} 1908impl TokenTree {}
983 1909/// Generic lifetime, type and constants parameters list **declaration**.
1910///
1911/// ```
1912/// fn foo❰ <'a, 'b, T, U, const BAR: u64> ❱() {}
1913///
1914/// struct Baz❰ <T> ❱(T);
1915///
1916/// impl❰ <T> ❱ Bruh<T> {}
1917///
1918/// type Bruuh = for❰ <'a> ❱ fn(&'a str) -> &'a str;
1919/// ```
1920///
1921/// [Reference](https://doc.rust-lang.org/reference/items/generics.html)
984#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1922#[derive(Debug, Clone, PartialEq, Eq, Hash)]
985pub struct TypeParamList { 1923pub struct TypeParamList {
986 pub(crate) syntax: SyntaxNode, 1924 pub(crate) syntax: SyntaxNode,
@@ -993,7 +1931,13 @@ impl TypeParamList {
993 pub fn const_params(&self) -> AstChildren<ConstParam> { support::children(&self.syntax) } 1931 pub fn const_params(&self) -> AstChildren<ConstParam> { support::children(&self.syntax) }
994 pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) } 1932 pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) }
995} 1933}
996 1934/// Single type parameter **declaration**.
1935///
1936/// ```
1937/// fn foo<❰ K ❱, ❰ I ❱, ❰ E: Debug ❱, ❰ V = DefaultType ❱>() {}
1938/// ```
1939///
1940/// [Reference](https://doc.rust-lang.org/reference/items/generics.html)
997#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1941#[derive(Debug, Clone, PartialEq, Eq, Hash)]
998pub struct TypeParam { 1942pub struct TypeParam {
999 pub(crate) syntax: SyntaxNode, 1943 pub(crate) syntax: SyntaxNode,
@@ -1005,7 +1949,12 @@ impl TypeParam {
1005 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } 1949 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
1006 pub fn default_type(&self) -> Option<TypeRef> { support::child(&self.syntax) } 1950 pub fn default_type(&self) -> Option<TypeRef> { support::child(&self.syntax) }
1007} 1951}
1008 1952/// Const generic parameter **declaration**.
1953/// ```
1954/// fn foo<T, U, ❰ const BAR: usize ❱, ❰ const BAZ: bool ❱>() {}
1955/// ```
1956///
1957/// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/2000-const-generics.md#declaring-a-const-parameter)
1009#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1958#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1010pub struct ConstParam { 1959pub struct ConstParam {
1011 pub(crate) syntax: SyntaxNode, 1960 pub(crate) syntax: SyntaxNode,
@@ -1017,7 +1966,13 @@ impl ConstParam {
1017 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } 1966 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
1018 pub fn default_val(&self) -> Option<Expr> { support::child(&self.syntax) } 1967 pub fn default_val(&self) -> Option<Expr> { support::child(&self.syntax) }
1019} 1968}
1020 1969/// Lifetime parameter **declaration**.
1970///
1971/// ```
1972/// fn foo<❰ 'a ❱, ❰ 'b ❱, V, G, D>(bar: &'a str, baz: &'b mut str) {}
1973/// ```
1974///
1975/// [Reference](https://doc.rust-lang.org/reference/items/generics.html)
1021#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1976#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1022pub struct LifetimeParam { 1977pub struct LifetimeParam {
1023 pub(crate) syntax: SyntaxNode, 1978 pub(crate) syntax: SyntaxNode,
@@ -1028,7 +1983,20 @@ impl LifetimeParam {
1028 support::token(&self.syntax, T![lifetime]) 1983 support::token(&self.syntax, T![lifetime])
1029 } 1984 }
1030} 1985}
1031 1986/// Type bound declaration clause.
1987///
1988/// ```
1989/// fn foo<T: ❰ ?Sized ❱ + ❰ Debug ❱>() {}
1990///
1991/// trait Bar<T>
1992/// where
1993/// T: ❰ Send ❱ + ❰ Sync ❱
1994/// {
1995/// type Baz: ❰ !Sync ❱ + ❰ Debug ❱ + ❰ ?const Add ❱;
1996/// }
1997/// ```
1998///
1999/// [Reference](https://doc.rust-lang.org/reference/trait-bounds.html)
1032#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2000#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1033pub struct TypeBound { 2001pub struct TypeBound {
1034 pub(crate) syntax: SyntaxNode, 2002 pub(crate) syntax: SyntaxNode,
@@ -1040,7 +2008,21 @@ impl TypeBound {
1040 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } 2008 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
1041 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 2009 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
1042} 2010}
1043 2011/// Type bounds list.
2012///
2013/// ```
2014///
2015/// fn foo<T: ❰ ?Sized + Debug ❱>() {}
2016///
2017/// trait Bar<T>
2018/// where
2019/// T: ❰ Send + Sync ❱
2020/// {
2021/// type Baz: ❰ !Sync + Debug ❱;
2022/// }
2023/// ```
2024///
2025/// [Reference](https://doc.rust-lang.org/reference/trait-bounds.html)
1044#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2026#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1045pub struct TypeBoundList { 2027pub struct TypeBoundList {
1046 pub(crate) syntax: SyntaxNode, 2028 pub(crate) syntax: SyntaxNode,
@@ -1048,7 +2030,18 @@ pub struct TypeBoundList {
1048impl TypeBoundList { 2030impl TypeBoundList {
1049 pub fn bounds(&self) -> AstChildren<TypeBound> { support::children(&self.syntax) } 2031 pub fn bounds(&self) -> AstChildren<TypeBound> { support::children(&self.syntax) }
1050} 2032}
1051 2033/// Single where predicate.
2034///
2035/// ```
2036/// trait Foo<'a, 'b, T>
2037/// where
2038/// ❰ 'a: 'b ❱,
2039/// ❰ T: IntoIterator ❱,
2040/// ❰ for<'c> <T as IntoIterator>::Item: Bar<'c> ❱
2041/// {}
2042/// ```
2043///
2044/// [Reference](https://doc.rust-lang.org/reference/items/generics.html#where-clauses)
1052#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2045#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1053pub struct WherePred { 2046pub struct WherePred {
1054 pub(crate) syntax: SyntaxNode, 2047 pub(crate) syntax: SyntaxNode,
@@ -1060,7 +2053,14 @@ impl WherePred {
1060 } 2053 }
1061 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 2054 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
1062} 2055}
1063 2056/// Where clause.
2057///
2058/// ```
2059/// trait Foo<'a, T> ❰ where 'a: 'static, T: Debug ❱ {}
2060///
2061/// ```
2062///
2063/// [Reference](https://doc.rust-lang.org/reference/items/generics.html#where-clauses)
1064#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2064#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1065pub struct WhereClause { 2065pub struct WhereClause {
1066 pub(crate) syntax: SyntaxNode, 2066 pub(crate) syntax: SyntaxNode,
@@ -1069,13 +2069,42 @@ impl WhereClause {
1069 pub fn where_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![where]) } 2069 pub fn where_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![where]) }
1070 pub fn predicates(&self) -> AstChildren<WherePred> { support::children(&self.syntax) } 2070 pub fn predicates(&self) -> AstChildren<WherePred> { support::children(&self.syntax) }
1071} 2071}
1072 2072/// Abi declaration.
2073/// Note: the abi string is optional.
2074///
2075/// ```
2076/// ❰ extern "C" ❱ {
2077/// fn foo() {}
2078/// }
2079///
2080/// type Bar = ❰ extern ❱ fn() -> u32;
2081///
2082/// type Baz = ❰ extern r#"stdcall"# ❱ fn() -> bool;
2083/// ```
2084///
2085/// - [Extern blocks reference](https://doc.rust-lang.org/reference/items/external-blocks.html)
2086/// - [FFI function pointers reference](https://doc.rust-lang.org/reference/items/functions.html#functions)
1073#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2087#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1074pub struct Abi { 2088pub struct Abi {
1075 pub(crate) syntax: SyntaxNode, 2089 pub(crate) syntax: SyntaxNode,
1076} 2090}
1077impl Abi {} 2091impl Abi {}
1078 2092/// Expression statement.
2093///
2094/// ```
2095/// ❰ 42; ❱
2096/// ❰ foo(); ❱
2097/// ❰ (); ❱
2098/// ❰ {}; ❱
2099///
2100/// // constructions with trailing curly brace can omit the semicolon
2101/// // but only when there are satements immediately after them (this is important!)
2102/// ❰ if bool_cond { } ❱
2103/// ❰ loop {} ❱
2104/// ❰ somestatment; ❱
2105/// ```
2106///
2107/// [Reference](https://doc.rust-lang.org/reference/statements.html)
1079#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2108#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1080pub struct ExprStmt { 2109pub struct ExprStmt {
1081 pub(crate) syntax: SyntaxNode, 2110 pub(crate) syntax: SyntaxNode,
@@ -1085,7 +2114,16 @@ impl ExprStmt {
1085 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 2114 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1086 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 2115 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
1087} 2116}
1088 2117/// Let statement.
2118///
2119/// ```
2120/// ❰ #[attr] let foo; ❱
2121/// ❰ let bar: u64; ❱
2122/// ❰ let baz = 42; ❱
2123/// ❰ let bruh: bool = true; ❱
2124/// ```
2125///
2126/// [Reference](https://doc.rust-lang.org/reference/statements.html#let-statements)
1089#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2127#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1090pub struct LetStmt { 2128pub struct LetStmt {
1091 pub(crate) syntax: SyntaxNode, 2129 pub(crate) syntax: SyntaxNode,
@@ -1099,7 +2137,18 @@ impl LetStmt {
1099 pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) } 2137 pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) }
1100 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 2138 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
1101} 2139}
1102 2140/// Condition of `if` or `while` expression.
2141///
2142/// ```
2143/// if ❰ true ❱ {}
2144/// if ❰ let Pat(foo) = bar ❱ {}
2145///
2146/// while ❰ true ❱ {}
2147/// while ❰ let Pat(baz) = bruh ❱ {}
2148/// ```
2149///
2150/// [If expression reference](https://doc.rust-lang.org/reference/expressions/if-expr.html)
2151/// [While expression reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-loops)
1103#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2152#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1104pub struct Condition { 2153pub struct Condition {
1105 pub(crate) syntax: SyntaxNode, 2154 pub(crate) syntax: SyntaxNode,
@@ -1110,20 +2159,18 @@ impl Condition {
1110 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } 2159 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
1111 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 2160 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1112} 2161}
1113 2162/// Parameter list **declaration**.
1114#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2163///
1115pub struct Block { 2164/// ```
1116 pub(crate) syntax: SyntaxNode, 2165/// fn foo❰ (a: u32, b: bool) ❱ -> u32 {}
1117} 2166/// let bar = ❰ |a, b| ❱ {};
1118impl ast::AttrsOwner for Block {} 2167///
1119impl ast::ModuleItemOwner for Block {} 2168/// impl Baz {
1120impl Block { 2169/// fn bruh❰ (&self, a: u32) ❱ {}
1121 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } 2170/// }
1122 pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) } 2171/// ```
1123 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 2172///
1124 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } 2173/// [Reference](https://doc.rust-lang.org/reference/items/functions.html)ocs to codegen script
1125}
1126
1127#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2174#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1128pub struct ParamList { 2175pub struct ParamList {
1129 pub(crate) syntax: SyntaxNode, 2176 pub(crate) syntax: SyntaxNode,
@@ -1134,7 +2181,19 @@ impl ParamList {
1134 pub fn params(&self) -> AstChildren<Param> { support::children(&self.syntax) } 2181 pub fn params(&self) -> AstChildren<Param> { support::children(&self.syntax) }
1135 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 2182 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
1136} 2183}
1137 2184/// Self parameter **declaration**.
2185///
2186/// ```
2187/// impl Bruh {
2188/// fn foo(❰ self ❱) {}
2189/// fn bar(❰ &self ❱) {}
2190/// fn baz(❰ &mut self ❱) {}
2191/// fn blah<'a>(❰ &'a self ❱) {}
2192/// fn blin(❰ self: Box<Self> ❱) {}
2193/// }
2194/// ```
2195///
2196/// [Reference](https://doc.rust-lang.org/reference/items/functions.html)
1138#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2197#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1139pub struct SelfParam { 2198pub struct SelfParam {
1140 pub(crate) syntax: SyntaxNode, 2199 pub(crate) syntax: SyntaxNode,
@@ -1149,7 +2208,17 @@ impl SelfParam {
1149 } 2208 }
1150 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) } 2209 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) }
1151} 2210}
1152 2211/// Parameter **declaration**.
2212///
2213/// ```
2214/// fn foo(❰ #[attr] Pat(bar): Pat(u32) ❱, ❰ #[attr] _: bool ❱) {}
2215///
2216/// extern "C" {
2217/// fn bar(❰ baz: u32 ❱, ❰ ... ❱) -> u32;
2218/// }
2219/// ```
2220///
2221/// [Reference](https://doc.rust-lang.org/reference/items/functions.html)
1153#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2222#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1154pub struct Param { 2223pub struct Param {
1155 pub(crate) syntax: SyntaxNode, 2224 pub(crate) syntax: SyntaxNode,
@@ -1160,7 +2229,16 @@ impl Param {
1160 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 2229 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
1161 pub fn dotdotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![...]) } 2230 pub fn dotdotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![...]) }
1162} 2231}
1163 2232/// Use declaration.
2233///
2234/// ```
2235/// ❰ #[attr] pub use foo; ❱
2236/// ❰ use bar as baz; ❱
2237/// ❰ use bruh::{self, bruuh}; ❱
2238/// ❰ use { blin::blen, blah::* };
2239/// ```
2240///
2241/// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html)
1164#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2242#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1165pub struct UseItem { 2243pub struct UseItem {
1166 pub(crate) syntax: SyntaxNode, 2244 pub(crate) syntax: SyntaxNode,
@@ -1171,7 +2249,16 @@ impl UseItem {
1171 pub fn use_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![use]) } 2249 pub fn use_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![use]) }
1172 pub fn use_tree(&self) -> Option<UseTree> { support::child(&self.syntax) } 2250 pub fn use_tree(&self) -> Option<UseTree> { support::child(&self.syntax) }
1173} 2251}
1174 2252/// Use tree.
2253///
2254/// ```
2255/// pub use ❰ foo::❰ * ❱ ❱;
2256/// use ❰ bar as baz ❱;
2257/// use ❰ bruh::bruuh::{ ❰ self ❱, ❰ blin ❱ } ❱;
2258/// use ❰ { ❰ blin::blen ❱ } ❱
2259/// ```
2260///
2261/// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html)
1175#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2262#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1176pub struct UseTree { 2263pub struct UseTree {
1177 pub(crate) syntax: SyntaxNode, 2264 pub(crate) syntax: SyntaxNode,
@@ -1182,7 +2269,16 @@ impl UseTree {
1182 pub fn use_tree_list(&self) -> Option<UseTreeList> { support::child(&self.syntax) } 2269 pub fn use_tree_list(&self) -> Option<UseTreeList> { support::child(&self.syntax) }
1183 pub fn alias(&self) -> Option<Alias> { support::child(&self.syntax) } 2270 pub fn alias(&self) -> Option<Alias> { support::child(&self.syntax) }
1184} 2271}
1185 2272/// Item alias.
2273/// Note: this is not the type alias.
2274///
2275/// ```
2276/// use foo ❰ as bar ❱;
2277/// use baz::{bruh ❰ as _ ❱};
2278/// extern crate bruuh ❰ as blin ❱;
2279/// ```
2280///
2281/// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html)
1186#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2282#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1187pub struct Alias { 2283pub struct Alias {
1188 pub(crate) syntax: SyntaxNode, 2284 pub(crate) syntax: SyntaxNode,
@@ -1191,7 +2287,14 @@ impl ast::NameOwner for Alias {}
1191impl Alias { 2287impl Alias {
1192 pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) } 2288 pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) }
1193} 2289}
1194 2290/// Sublist of use trees.
2291///
2292/// ```
2293/// use bruh::bruuh::❰ { ❰ self ❱, ❰ blin ❱ } ❱;
2294/// use ❰ { blin::blen::❰ {} ❱ } ❱
2295/// ```
2296///
2297/// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html)
1195#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2298#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1196pub struct UseTreeList { 2299pub struct UseTreeList {
1197 pub(crate) syntax: SyntaxNode, 2300 pub(crate) syntax: SyntaxNode,
@@ -1201,7 +2304,14 @@ impl UseTreeList {
1201 pub fn use_trees(&self) -> AstChildren<UseTree> { support::children(&self.syntax) } 2304 pub fn use_trees(&self) -> AstChildren<UseTree> { support::children(&self.syntax) }
1202 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } 2305 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
1203} 2306}
1204 2307/// Extern crate item.
2308///
2309/// ```
2310/// ❰ #[attr] pub extern crate foo; ❱
2311/// ❰ extern crate self as bar; ❱
2312/// ```
2313///
2314/// [Reference](https://doc.rust-lang.org/reference/items/extern-crates.html)
1205#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2315#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1206pub struct ExternCrateItem { 2316pub struct ExternCrateItem {
1207 pub(crate) syntax: SyntaxNode, 2317 pub(crate) syntax: SyntaxNode,
@@ -1214,7 +2324,13 @@ impl ExternCrateItem {
1214 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } 2324 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
1215 pub fn alias(&self) -> Option<Alias> { support::child(&self.syntax) } 2325 pub fn alias(&self) -> Option<Alias> { support::child(&self.syntax) }
1216} 2326}
1217 2327/// Call site arguments list.
2328///
2329/// ```
2330/// foo::<T, U>❰ (42, true) ❱;
2331/// ```
2332///
2333/// [Reference](https://doc.rust-lang.org/reference/expressions/call-expr.html)
1218#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2334#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1219pub struct ArgList { 2335pub struct ArgList {
1220 pub(crate) syntax: SyntaxNode, 2336 pub(crate) syntax: SyntaxNode,
@@ -1224,16 +2340,41 @@ impl ArgList {
1224 pub fn args(&self) -> AstChildren<Expr> { support::children(&self.syntax) } 2340 pub fn args(&self) -> AstChildren<Expr> { support::children(&self.syntax) }
1225 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 2341 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
1226} 2342}
1227 2343/// Path to a symbol. Includes single identifier names and elaborate paths with
2344/// generic parameters.
2345///
2346/// ```
2347/// (0..10).❰ ❰ collect ❱ ::<Vec<_>> ❱();
2348/// ❰ ❰ ❰ Vec ❱ ::<u8> ❱ ::with_capacity ❱(1024);
2349/// ❰ ❰ <❰ Foo ❱ as ❰ ❰ bar ❱ ::Bar ❱> ❱ ::baz ❱();
2350/// ❰ ❰ <❰ bruh ❱> ❱ ::bruuh ❱();
2351/// ```
2352///
2353/// [Reference](https://doc.rust-lang.org/reference/paths.html)
1228#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2354#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1229pub struct Path { 2355pub struct Path {
1230 pub(crate) syntax: SyntaxNode, 2356 pub(crate) syntax: SyntaxNode,
1231} 2357}
1232impl Path { 2358impl Path {
1233 pub fn segment(&self) -> Option<PathSegment> { support::child(&self.syntax) } 2359 pub fn segment(&self) -> Option<PathSegment> { support::child(&self.syntax) }
2360 pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) }
1234 pub fn qualifier(&self) -> Option<Path> { support::child(&self.syntax) } 2361 pub fn qualifier(&self) -> Option<Path> { support::child(&self.syntax) }
1235} 2362}
1236 2363/// Segment of the path to a symbol.
2364/// Only path segment of an absolute path holds the `::` token,
2365/// all other `::` tokens that connect path segments reside under `Path` itself.`
2366///
2367/// ```
2368/// (0..10).❰ collect ❱ :: ❰ <Vec<_>> ❱();
2369/// ❰ Vec ❱ :: ❰ <u8> ❱ :: ❰ with_capacity ❱(1024);
2370/// ❰ <❰ Foo ❱ as ❰ bar ❱ :: ❰ Bar ❱> ❱ :: ❰ baz ❱();
2371/// ❰ <❰ bruh ❱> ❱ :: ❰ bruuh ❱();
2372///
2373/// // Note that only in this case `::` token is inlcuded:
2374/// ❰ ::foo ❱;
2375/// ```
2376///
2377/// [Reference](https://doc.rust-lang.org/reference/paths.html)
1237#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2378#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1238pub struct PathSegment { 2379pub struct PathSegment {
1239 pub(crate) syntax: SyntaxNode, 2380 pub(crate) syntax: SyntaxNode,
@@ -1251,7 +2392,15 @@ impl PathSegment {
1251 pub fn path_type(&self) -> Option<PathType> { support::child(&self.syntax) } 2392 pub fn path_type(&self) -> Option<PathType> { support::child(&self.syntax) }
1252 pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) } 2393 pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) }
1253} 2394}
1254 2395/// List of type arguments that are passed at generic instantiation site.
2396///
2397/// ```
2398/// type _ = Foo ❰ ::<'a, u64, Item = Bar, 42, {true}> ❱::Bar;
2399///
2400/// Vec❰ ::<bool> ❱::();
2401/// ```
2402///
2403/// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions)
1255#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2404#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1256pub struct TypeArgList { 2405pub struct TypeArgList {
1257 pub(crate) syntax: SyntaxNode, 2406 pub(crate) syntax: SyntaxNode,
@@ -1266,7 +2415,13 @@ impl TypeArgList {
1266 pub fn const_args(&self) -> AstChildren<ConstArg> { support::children(&self.syntax) } 2415 pub fn const_args(&self) -> AstChildren<ConstArg> { support::children(&self.syntax) }
1267 pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) } 2416 pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) }
1268} 2417}
1269 2418/// Type argument that is passed at generic instantiation site.
2419///
2420/// ```
2421/// type _ = Foo::<'a, ❰ u64 ❱, ❰ bool ❱, Item = Bar, 42>::Baz;
2422/// ```
2423///
2424/// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions)
1270#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2425#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1271pub struct TypeArg { 2426pub struct TypeArg {
1272 pub(crate) syntax: SyntaxNode, 2427 pub(crate) syntax: SyntaxNode,
@@ -1274,7 +2429,13 @@ pub struct TypeArg {
1274impl TypeArg { 2429impl TypeArg {
1275 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 2430 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
1276} 2431}
1277 2432/// Associated type argument that is passed at generic instantiation site.
2433/// ```
2434/// type Foo = Bar::<'a, u64, bool, ❰ Item = Baz ❱, 42>::Bruh;
2435///
2436/// trait Bruh<T>: Iterator<❰ Item: Debug ❱> {}
2437/// ```
2438///
1278#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2439#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1279pub struct AssocTypeArg { 2440pub struct AssocTypeArg {
1280 pub(crate) syntax: SyntaxNode, 2441 pub(crate) syntax: SyntaxNode,
@@ -1285,7 +2446,15 @@ impl AssocTypeArg {
1285 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } 2446 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
1286 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 2447 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
1287} 2448}
1288 2449/// Lifetime argument that is passed at generic instantiation site.
2450///
2451/// ```
2452/// fn foo<'a>(s: &'a str) {
2453/// bar::<❰ 'a ❱>(s);
2454/// }
2455/// ```
2456///
2457/// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions)
1289#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2458#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1290pub struct LifetimeArg { 2459pub struct LifetimeArg {
1291 pub(crate) syntax: SyntaxNode, 2460 pub(crate) syntax: SyntaxNode,
@@ -1295,24 +2464,41 @@ impl LifetimeArg {
1295 support::token(&self.syntax, T![lifetime]) 2464 support::token(&self.syntax, T![lifetime])
1296 } 2465 }
1297} 2466}
1298 2467/// Constant value argument that is passed at generic instantiation site.
2468///
2469/// ```
2470/// foo::<u32, ❰ { true } ❱>();
2471///
2472/// bar::<❰ { 2 + 2} ❱>();
2473/// ```
2474///
2475/// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/2000-const-generics.md#declaring-a-const-parameter)
1299#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2476#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1300pub struct ConstArg { 2477pub struct ConstArg {
1301 pub(crate) syntax: SyntaxNode, 2478 pub(crate) syntax: SyntaxNode,
1302} 2479}
1303impl ConstArg { 2480impl ConstArg {
1304 pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) } 2481 pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) }
1305 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
1306 pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) } 2482 pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) }
1307} 2483}
1308 2484/// FIXME: (@edwin0cheng) Remove it to use ItemList instead
2485/// https://github.com/rust-analyzer/rust-analyzer/pull/4083#discussion_r422666243
2486///
2487/// [Reference](https://doc.rust-lang.org/reference/macros.html)
1309#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2488#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1310pub struct MacroItems { 2489pub struct MacroItems {
1311 pub(crate) syntax: SyntaxNode, 2490 pub(crate) syntax: SyntaxNode,
1312} 2491}
1313impl ast::ModuleItemOwner for MacroItems {} 2492impl ast::ModuleItemOwner for MacroItems {}
1314impl MacroItems {} 2493impl MacroItems {}
1315 2494/// FIXME: (@edwin0cheng) add some documentation here. As per the writing
2495/// of this comment this ast node is not used.
2496///
2497/// ```
2498/// // FIXME: example here
2499/// ```
2500///
2501/// [Reference](https://doc.rust-lang.org/reference/macros.html)
1316#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2502#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1317pub struct MacroStmts { 2503pub struct MacroStmts {
1318 pub(crate) syntax: SyntaxNode, 2504 pub(crate) syntax: SyntaxNode,
@@ -1321,7 +2507,18 @@ impl MacroStmts {
1321 pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) } 2507 pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) }
1322 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 2508 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1323} 2509}
1324 2510/// List of items in an extern block.
2511///
2512/// ```
2513/// extern "C" ❰
2514/// {
2515/// fn foo();
2516/// static var: u32;
2517/// }
2518/// ❱
2519/// ```
2520///
2521/// [Reference](https://doc.rust-lang.org/reference/items/external-blocks.html)
1325#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2522#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1326pub struct ExternItemList { 2523pub struct ExternItemList {
1327 pub(crate) syntax: SyntaxNode, 2524 pub(crate) syntax: SyntaxNode,
@@ -1332,7 +2529,18 @@ impl ExternItemList {
1332 pub fn extern_items(&self) -> AstChildren<ExternItem> { support::children(&self.syntax) } 2529 pub fn extern_items(&self) -> AstChildren<ExternItem> { support::children(&self.syntax) }
1333 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } 2530 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
1334} 2531}
1335 2532/// Extern block.
2533///
2534/// ```
2535/// ❰
2536/// extern "C" {
2537/// fn foo();
2538/// }
2539/// ❱
2540///
2541/// ```
2542///
2543/// [Reference](https://doc.rust-lang.org/reference/items/external-blocks.html)
1336#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2544#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1337pub struct ExternBlock { 2545pub struct ExternBlock {
1338 pub(crate) syntax: SyntaxNode, 2546 pub(crate) syntax: SyntaxNode,
@@ -1341,7 +2549,15 @@ impl ExternBlock {
1341 pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) } 2549 pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) }
1342 pub fn extern_item_list(&self) -> Option<ExternItemList> { support::child(&self.syntax) } 2550 pub fn extern_item_list(&self) -> Option<ExternItemList> { support::child(&self.syntax) }
1343} 2551}
1344 2552/// Meta item in an attribute.
2553///
2554/// ```
2555/// #[❰ bar::baz = "42" ❱]
2556/// #[❰ bruh(bruuh("true")) ❱]
2557/// struct Foo;
2558/// ```
2559///
2560/// [Reference](https://doc.rust-lang.org/reference/attributes.html?highlight=meta,item#meta-item-attribute-syntax)
1345#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2561#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1346pub struct MetaItem { 2562pub struct MetaItem {
1347 pub(crate) syntax: SyntaxNode, 2563 pub(crate) syntax: SyntaxNode,
@@ -1352,7 +2568,15 @@ impl MetaItem {
1352 pub fn attr_input(&self) -> Option<AttrInput> { support::child(&self.syntax) } 2568 pub fn attr_input(&self) -> Option<AttrInput> { support::child(&self.syntax) }
1353 pub fn nested_meta_items(&self) -> AstChildren<MetaItem> { support::children(&self.syntax) } 2569 pub fn nested_meta_items(&self) -> AstChildren<MetaItem> { support::children(&self.syntax) }
1354} 2570}
1355 2571/// Macro 2.0 definition.
2572/// Their syntax is still WIP by rustc team...
2573/// ```
2574/// ❰
2575/// macro foo { }
2576/// ❱
2577/// ```
2578///
2579/// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/1584-macros.md)
1356#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2580#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1357pub struct MacroDef { 2581pub struct MacroDef {
1358 pub(crate) syntax: SyntaxNode, 2582 pub(crate) syntax: SyntaxNode,
@@ -1361,7 +2585,7 @@ impl MacroDef {
1361 pub fn name(&self) -> Option<Name> { support::child(&self.syntax) } 2585 pub fn name(&self) -> Option<Name> { support::child(&self.syntax) }
1362 pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) } 2586 pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) }
1363} 2587}
1364 2588/// Any kind of nominal type definition.
1365#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2589#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1366pub enum NominalDef { 2590pub enum NominalDef {
1367 StructDef(StructDef), 2591 StructDef(StructDef),
@@ -1371,14 +2595,14 @@ pub enum NominalDef {
1371impl ast::NameOwner for NominalDef {} 2595impl ast::NameOwner for NominalDef {}
1372impl ast::TypeParamsOwner for NominalDef {} 2596impl ast::TypeParamsOwner for NominalDef {}
1373impl ast::AttrsOwner for NominalDef {} 2597impl ast::AttrsOwner for NominalDef {}
1374 2598/// Any kind of **declared** generic parameter
1375#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2599#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1376pub enum GenericParam { 2600pub enum GenericParam {
1377 LifetimeParam(LifetimeParam), 2601 LifetimeParam(LifetimeParam),
1378 TypeParam(TypeParam), 2602 TypeParam(TypeParam),
1379 ConstParam(ConstParam), 2603 ConstParam(ConstParam),
1380} 2604}
1381 2605/// Any kind of generic argument passed at instantiation site
1382#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2606#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1383pub enum GenericArg { 2607pub enum GenericArg {
1384 LifetimeArg(LifetimeArg), 2608 LifetimeArg(LifetimeArg),
@@ -1386,7 +2610,7 @@ pub enum GenericArg {
1386 ConstArg(ConstArg), 2610 ConstArg(ConstArg),
1387 AssocTypeArg(AssocTypeArg), 2611 AssocTypeArg(AssocTypeArg),
1388} 2612}
1389 2613/// Any kind of construct valid in type context
1390#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2614#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1391pub enum TypeRef { 2615pub enum TypeRef {
1392 ParenType(ParenType), 2616 ParenType(ParenType),
@@ -1403,7 +2627,7 @@ pub enum TypeRef {
1403 ImplTraitType(ImplTraitType), 2627 ImplTraitType(ImplTraitType),
1404 DynTraitType(DynTraitType), 2628 DynTraitType(DynTraitType),
1405} 2629}
1406 2630/// Any kind of top-level item that may appear in a module
1407#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2631#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1408pub enum ModuleItem { 2632pub enum ModuleItem {
1409 StructDef(StructDef), 2633 StructDef(StructDef),
@@ -1424,16 +2648,20 @@ pub enum ModuleItem {
1424impl ast::NameOwner for ModuleItem {} 2648impl ast::NameOwner for ModuleItem {}
1425impl ast::AttrsOwner for ModuleItem {} 2649impl ast::AttrsOwner for ModuleItem {}
1426impl ast::VisibilityOwner for ModuleItem {} 2650impl ast::VisibilityOwner for ModuleItem {}
1427 2651/// Any kind of item that may appear in an impl block
2652///
2653/// // FIXME: impl blocks can also contain MacroCall
1428#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2654#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1429pub enum ImplItem { 2655pub enum AssocItem {
1430 FnDef(FnDef), 2656 FnDef(FnDef),
1431 TypeAliasDef(TypeAliasDef), 2657 TypeAliasDef(TypeAliasDef),
1432 ConstDef(ConstDef), 2658 ConstDef(ConstDef),
1433} 2659}
1434impl ast::NameOwner for ImplItem {} 2660impl ast::NameOwner for AssocItem {}
1435impl ast::AttrsOwner for ImplItem {} 2661impl ast::AttrsOwner for AssocItem {}
1436 2662/// Any kind of item that may appear in an extern block
2663///
2664/// // FIXME: extern blocks can also contain MacroCall
1437#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2665#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1438pub enum ExternItem { 2666pub enum ExternItem {
1439 FnDef(FnDef), 2667 FnDef(FnDef),
@@ -1442,7 +2670,7 @@ pub enum ExternItem {
1442impl ast::NameOwner for ExternItem {} 2670impl ast::NameOwner for ExternItem {}
1443impl ast::AttrsOwner for ExternItem {} 2671impl ast::AttrsOwner for ExternItem {}
1444impl ast::VisibilityOwner for ExternItem {} 2672impl ast::VisibilityOwner for ExternItem {}
1445 2673/// Any kind of expression
1446#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2674#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1447pub enum Expr { 2675pub enum Expr {
1448 TupleExpr(TupleExpr), 2676 TupleExpr(TupleExpr),
@@ -1467,6 +2695,7 @@ pub enum Expr {
1467 FieldExpr(FieldExpr), 2695 FieldExpr(FieldExpr),
1468 AwaitExpr(AwaitExpr), 2696 AwaitExpr(AwaitExpr),
1469 TryExpr(TryExpr), 2697 TryExpr(TryExpr),
2698 EffectExpr(EffectExpr),
1470 CastExpr(CastExpr), 2699 CastExpr(CastExpr),
1471 RefExpr(RefExpr), 2700 RefExpr(RefExpr),
1472 PrefixExpr(PrefixExpr), 2701 PrefixExpr(PrefixExpr),
@@ -1477,7 +2706,7 @@ pub enum Expr {
1477 BoxExpr(BoxExpr), 2706 BoxExpr(BoxExpr),
1478} 2707}
1479impl ast::AttrsOwner for Expr {} 2708impl ast::AttrsOwner for Expr {}
1480 2709/// Any kind of pattern
1481#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2710#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1482pub enum Pat { 2711pub enum Pat {
1483 OrPat(OrPat), 2712 OrPat(OrPat),
@@ -1496,25 +2725,28 @@ pub enum Pat {
1496 LiteralPat(LiteralPat), 2725 LiteralPat(LiteralPat),
1497 MacroPat(MacroPat), 2726 MacroPat(MacroPat),
1498} 2727}
1499 2728/// Any kind of pattern that appears directly inside of the curly
2729/// braces of a record pattern
1500#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2730#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1501pub enum RecordInnerPat { 2731pub enum RecordInnerPat {
1502 RecordFieldPat(RecordFieldPat), 2732 RecordFieldPat(RecordFieldPat),
1503 BindPat(BindPat), 2733 BindPat(BindPat),
1504} 2734}
1505 2735/// Any kind of input to an attribute
1506#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2736#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1507pub enum AttrInput { 2737pub enum AttrInput {
1508 Literal(Literal), 2738 Literal(Literal),
1509 TokenTree(TokenTree), 2739 TokenTree(TokenTree),
1510} 2740}
1511 2741/// Any kind of statement
2742/// Note: there are no empty statements, these are just represented as
2743/// bare semicolons without a dedicated statement ast node.
1512#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2744#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1513pub enum Stmt { 2745pub enum Stmt {
1514 LetStmt(LetStmt), 2746 LetStmt(LetStmt),
1515 ExprStmt(ExprStmt), 2747 ExprStmt(ExprStmt),
1516} 2748}
1517 2749/// Any kind of fields list (record or tuple field lists)
1518#[derive(Debug, Clone, PartialEq, Eq, Hash)] 2750#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1519pub enum FieldDefList { 2751pub enum FieldDefList {
1520 RecordFieldDefList(RecordFieldDefList), 2752 RecordFieldDefList(RecordFieldDefList),
@@ -1949,6 +3181,17 @@ impl AstNode for LoopExpr {
1949 } 3181 }
1950 fn syntax(&self) -> &SyntaxNode { &self.syntax } 3182 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1951} 3183}
3184impl AstNode for EffectExpr {
3185 fn can_cast(kind: SyntaxKind) -> bool { kind == EFFECT_EXPR }
3186 fn cast(syntax: SyntaxNode) -> Option<Self> {
3187 if Self::can_cast(syntax.kind()) {
3188 Some(Self { syntax })
3189 } else {
3190 None
3191 }
3192 }
3193 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3194}
1952impl AstNode for ForExpr { 3195impl AstNode for ForExpr {
1953 fn can_cast(kind: SyntaxKind) -> bool { kind == FOR_EXPR } 3196 fn can_cast(kind: SyntaxKind) -> bool { kind == FOR_EXPR }
1954 fn cast(syntax: SyntaxNode) -> Option<Self> { 3197 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -2631,17 +3874,6 @@ impl AstNode for Condition {
2631 } 3874 }
2632 fn syntax(&self) -> &SyntaxNode { &self.syntax } 3875 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2633} 3876}
2634impl AstNode for Block {
2635 fn can_cast(kind: SyntaxKind) -> bool { kind == BLOCK }
2636 fn cast(syntax: SyntaxNode) -> Option<Self> {
2637 if Self::can_cast(syntax.kind()) {
2638 Some(Self { syntax })
2639 } else {
2640 None
2641 }
2642 }
2643 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2644}
2645impl AstNode for ParamList { 3877impl AstNode for ParamList {
2646 fn can_cast(kind: SyntaxKind) -> bool { kind == PARAM_LIST } 3878 fn can_cast(kind: SyntaxKind) -> bool { kind == PARAM_LIST }
2647 fn cast(syntax: SyntaxNode) -> Option<Self> { 3879 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -3163,16 +4395,16 @@ impl AstNode for ModuleItem {
3163 } 4395 }
3164 } 4396 }
3165} 4397}
3166impl From<FnDef> for ImplItem { 4398impl From<FnDef> for AssocItem {
3167 fn from(node: FnDef) -> ImplItem { ImplItem::FnDef(node) } 4399 fn from(node: FnDef) -> AssocItem { AssocItem::FnDef(node) }
3168} 4400}
3169impl From<TypeAliasDef> for ImplItem { 4401impl From<TypeAliasDef> for AssocItem {
3170 fn from(node: TypeAliasDef) -> ImplItem { ImplItem::TypeAliasDef(node) } 4402 fn from(node: TypeAliasDef) -> AssocItem { AssocItem::TypeAliasDef(node) }
3171} 4403}
3172impl From<ConstDef> for ImplItem { 4404impl From<ConstDef> for AssocItem {
3173 fn from(node: ConstDef) -> ImplItem { ImplItem::ConstDef(node) } 4405 fn from(node: ConstDef) -> AssocItem { AssocItem::ConstDef(node) }
3174} 4406}
3175impl AstNode for ImplItem { 4407impl AstNode for AssocItem {
3176 fn can_cast(kind: SyntaxKind) -> bool { 4408 fn can_cast(kind: SyntaxKind) -> bool {
3177 match kind { 4409 match kind {
3178 FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true, 4410 FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true,
@@ -3181,18 +4413,18 @@ impl AstNode for ImplItem {
3181 } 4413 }
3182 fn cast(syntax: SyntaxNode) -> Option<Self> { 4414 fn cast(syntax: SyntaxNode) -> Option<Self> {
3183 let res = match syntax.kind() { 4415 let res = match syntax.kind() {
3184 FN_DEF => ImplItem::FnDef(FnDef { syntax }), 4416 FN_DEF => AssocItem::FnDef(FnDef { syntax }),
3185 TYPE_ALIAS_DEF => ImplItem::TypeAliasDef(TypeAliasDef { syntax }), 4417 TYPE_ALIAS_DEF => AssocItem::TypeAliasDef(TypeAliasDef { syntax }),
3186 CONST_DEF => ImplItem::ConstDef(ConstDef { syntax }), 4418 CONST_DEF => AssocItem::ConstDef(ConstDef { syntax }),
3187 _ => return None, 4419 _ => return None,
3188 }; 4420 };
3189 Some(res) 4421 Some(res)
3190 } 4422 }
3191 fn syntax(&self) -> &SyntaxNode { 4423 fn syntax(&self) -> &SyntaxNode {
3192 match self { 4424 match self {
3193 ImplItem::FnDef(it) => &it.syntax, 4425 AssocItem::FnDef(it) => &it.syntax,
3194 ImplItem::TypeAliasDef(it) => &it.syntax, 4426 AssocItem::TypeAliasDef(it) => &it.syntax,
3195 ImplItem::ConstDef(it) => &it.syntax, 4427 AssocItem::ConstDef(it) => &it.syntax,
3196 } 4428 }
3197 } 4429 }
3198} 4430}
@@ -3290,6 +4522,9 @@ impl From<AwaitExpr> for Expr {
3290impl From<TryExpr> for Expr { 4522impl From<TryExpr> for Expr {
3291 fn from(node: TryExpr) -> Expr { Expr::TryExpr(node) } 4523 fn from(node: TryExpr) -> Expr { Expr::TryExpr(node) }
3292} 4524}
4525impl From<EffectExpr> for Expr {
4526 fn from(node: EffectExpr) -> Expr { Expr::EffectExpr(node) }
4527}
3293impl From<CastExpr> for Expr { 4528impl From<CastExpr> for Expr {
3294 fn from(node: CastExpr) -> Expr { Expr::CastExpr(node) } 4529 fn from(node: CastExpr) -> Expr { Expr::CastExpr(node) }
3295} 4530}
@@ -3320,8 +4555,10 @@ impl AstNode for Expr {
3320 TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR 4555 TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR
3321 | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL 4556 | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL
3322 | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | RECORD_LIT | CALL_EXPR | INDEX_EXPR 4557 | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | RECORD_LIT | CALL_EXPR | INDEX_EXPR
3323 | METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | CAST_EXPR | REF_EXPR 4558 | METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | EFFECT_EXPR | CAST_EXPR
3324 | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL | BOX_EXPR => true, 4559 | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL | BOX_EXPR => {
4560 true
4561 }
3325 _ => false, 4562 _ => false,
3326 } 4563 }
3327 } 4564 }
@@ -3349,6 +4586,7 @@ impl AstNode for Expr {
3349 FIELD_EXPR => Expr::FieldExpr(FieldExpr { syntax }), 4586 FIELD_EXPR => Expr::FieldExpr(FieldExpr { syntax }),
3350 AWAIT_EXPR => Expr::AwaitExpr(AwaitExpr { syntax }), 4587 AWAIT_EXPR => Expr::AwaitExpr(AwaitExpr { syntax }),
3351 TRY_EXPR => Expr::TryExpr(TryExpr { syntax }), 4588 TRY_EXPR => Expr::TryExpr(TryExpr { syntax }),
4589 EFFECT_EXPR => Expr::EffectExpr(EffectExpr { syntax }),
3352 CAST_EXPR => Expr::CastExpr(CastExpr { syntax }), 4590 CAST_EXPR => Expr::CastExpr(CastExpr { syntax }),
3353 REF_EXPR => Expr::RefExpr(RefExpr { syntax }), 4591 REF_EXPR => Expr::RefExpr(RefExpr { syntax }),
3354 PREFIX_EXPR => Expr::PrefixExpr(PrefixExpr { syntax }), 4592 PREFIX_EXPR => Expr::PrefixExpr(PrefixExpr { syntax }),
@@ -3385,6 +4623,7 @@ impl AstNode for Expr {
3385 Expr::FieldExpr(it) => &it.syntax, 4623 Expr::FieldExpr(it) => &it.syntax,
3386 Expr::AwaitExpr(it) => &it.syntax, 4624 Expr::AwaitExpr(it) => &it.syntax,
3387 Expr::TryExpr(it) => &it.syntax, 4625 Expr::TryExpr(it) => &it.syntax,
4626 Expr::EffectExpr(it) => &it.syntax,
3388 Expr::CastExpr(it) => &it.syntax, 4627 Expr::CastExpr(it) => &it.syntax,
3389 Expr::RefExpr(it) => &it.syntax, 4628 Expr::RefExpr(it) => &it.syntax,
3390 Expr::PrefixExpr(it) => &it.syntax, 4629 Expr::PrefixExpr(it) => &it.syntax,
@@ -3630,7 +4869,7 @@ impl std::fmt::Display for ModuleItem {
3630 std::fmt::Display::fmt(self.syntax(), f) 4869 std::fmt::Display::fmt(self.syntax(), f)
3631 } 4870 }
3632} 4871}
3633impl std::fmt::Display for ImplItem { 4872impl std::fmt::Display for AssocItem {
3634 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { 4873 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
3635 std::fmt::Display::fmt(self.syntax(), f) 4874 std::fmt::Display::fmt(self.syntax(), f)
3636 } 4875 }
@@ -3865,6 +5104,11 @@ impl std::fmt::Display for LoopExpr {
3865 std::fmt::Display::fmt(self.syntax(), f) 5104 std::fmt::Display::fmt(self.syntax(), f)
3866 } 5105 }
3867} 5106}
5107impl std::fmt::Display for EffectExpr {
5108 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
5109 std::fmt::Display::fmt(self.syntax(), f)
5110 }
5111}
3868impl std::fmt::Display for ForExpr { 5112impl std::fmt::Display for ForExpr {
3869 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { 5113 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
3870 std::fmt::Display::fmt(self.syntax(), f) 5114 std::fmt::Display::fmt(self.syntax(), f)
@@ -4175,11 +5419,6 @@ impl std::fmt::Display for Condition {
4175 std::fmt::Display::fmt(self.syntax(), f) 5419 std::fmt::Display::fmt(self.syntax(), f)
4176 } 5420 }
4177} 5421}
4178impl std::fmt::Display for Block {
4179 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
4180 std::fmt::Display::fmt(self.syntax(), f)
4181 }
4182}
4183impl std::fmt::Display for ParamList { 5422impl std::fmt::Display for ParamList {
4184 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { 5423 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
4185 std::fmt::Display::fmt(self.syntax(), f) 5424 std::fmt::Display::fmt(self.syntax(), f)