aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-07-29 18:18:53 +0100
committerGitHub <[email protected]>2020-07-29 18:18:53 +0100
commit2dfda0b984c45946b9a4148bd848350deac544f2 (patch)
tree1942eeab995b0bd191c6a998b47cb20a426e5dd3
parent525ae706b3e4c0f5f8b80d197e5fede0a9974442 (diff)
parent3d28292157e1b6c9675ef64eddf53786c3e7dc5f (diff)
Merge #5572
5572: Switch to ungrammar from ast_src r=matklad a=matklad The primary advantage of ungrammar is that it (eventually) allows one to describe concrete syntax tree structure -- with alternatives and specific sequence of tokens & nodes. That should be re-usable for: * generate `make` calls * Rust reference * Hypothetical parser's evented API We loose doc comments for the time being unfortunately. I don't think we should add support for doc comments to ungrammar -- they'll make grammar file hard to read. We might supply docs as out-of band info, or maybe just via a reference, but we'll think about that once things are no longer in flux bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r--Cargo.lock7
-rw-r--r--crates/ra_hir_def/src/type_ref.rs2
-rw-r--r--crates/ra_syntax/src/ast/expr_ext.rs2
-rw-r--r--crates/ra_syntax/src/ast/generated/nodes.rs3010
-rw-r--r--crates/ra_syntax/src/ast/node_ext.rs16
-rw-r--r--xtask/Cargo.toml9
-rw-r--r--xtask/src/ast_src.rs1984
-rw-r--r--xtask/src/codegen/gen_syntax.rs224
-rw-r--r--xtask/src/codegen/rust.ungram529
9 files changed, 1591 insertions, 4192 deletions
diff --git a/Cargo.lock b/Cargo.lock
index ff225399e..b7a9516e3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1750,6 +1750,12 @@ dependencies = [
1750] 1750]
1751 1751
1752[[package]] 1752[[package]]
1753name = "ungrammar"
1754version = "0.1.0"
1755source = "registry+https://github.com/rust-lang/crates.io-index"
1756checksum = "0ee12e4891ab3acc2d95d5023022ace22020247bb8a8d1ece875a443f7dab37d"
1757
1758[[package]]
1753name = "unicode-bidi" 1759name = "unicode-bidi"
1754version = "0.3.4" 1760version = "0.3.4"
1755source = "registry+https://github.com/rust-lang/crates.io-index" 1761source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1893,5 +1899,6 @@ dependencies = [
1893 "pico-args", 1899 "pico-args",
1894 "proc-macro2", 1900 "proc-macro2",
1895 "quote", 1901 "quote",
1902 "ungrammar",
1896 "walkdir", 1903 "walkdir",
1897] 1904]
diff --git a/crates/ra_hir_def/src/type_ref.rs b/crates/ra_hir_def/src/type_ref.rs
index e90b2a0b9..970fc9af5 100644
--- a/crates/ra_hir_def/src/type_ref.rs
+++ b/crates/ra_hir_def/src/type_ref.rs
@@ -1,7 +1,7 @@
1//! HIR for references to types. Paths in these are not yet resolved. They can 1//! HIR for references to types. Paths in these are not yet resolved. They can
2//! be directly created from an ast::TypeRef, without further queries. 2//! be directly created from an ast::TypeRef, without further queries.
3 3
4use ra_syntax::ast::{self, TypeAscriptionOwner, TypeBoundsOwner}; 4use ra_syntax::ast::{self, TypeAscriptionOwner};
5 5
6use crate::{body::LowerCtx, path::Path}; 6use crate::{body::LowerCtx, path::Path};
7 7
diff --git a/crates/ra_syntax/src/ast/expr_ext.rs b/crates/ra_syntax/src/ast/expr_ext.rs
index db5438d68..69c85c809 100644
--- a/crates/ra_syntax/src/ast/expr_ext.rs
+++ b/crates/ra_syntax/src/ast/expr_ext.rs
@@ -7,6 +7,8 @@ use crate::{
7 SyntaxToken, T, 7 SyntaxToken, T,
8}; 8};
9 9
10impl ast::AttrsOwner for ast::Expr {}
11
10impl ast::Expr { 12impl ast::Expr {
11 pub fn is_block_like(&self) -> bool { 13 pub fn is_block_like(&self) -> bool {
12 match self { 14 match self {
diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs
index 1fe5f450a..b2d108a7c 100644
--- a/crates/ra_syntax/src/ast/generated/nodes.rs
+++ b/crates/ra_syntax/src/ast/generated/nodes.rs
@@ -5,48 +5,34 @@ use crate::{
5 SyntaxKind::{self, *}, 5 SyntaxKind::{self, *},
6 SyntaxNode, SyntaxToken, T, 6 SyntaxNode, SyntaxToken, T,
7}; 7};
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)
11#[derive(Debug, Clone, PartialEq, Eq, Hash)] 8#[derive(Debug, Clone, PartialEq, Eq, Hash)]
12pub struct SourceFile { 9pub struct SourceFile {
13 pub(crate) syntax: SyntaxNode, 10 pub(crate) syntax: SyntaxNode,
14} 11}
15impl ast::ModuleItemOwner for SourceFile {}
16impl ast::AttrsOwner for SourceFile {} 12impl ast::AttrsOwner for SourceFile {}
17impl ast::DocCommentsOwner for SourceFile {} 13impl ast::ModuleItemOwner for SourceFile {}
18impl SourceFile {} 14impl SourceFile {}
19/// Function definition either with body or not. 15#[derive(Debug, Clone, PartialEq, Eq, Hash)]
20/// Includes all of its attributes and doc comments. 16pub struct Attr {
21/// 17 pub(crate) syntax: SyntaxNode,
22/// ``` 18}
23/// ❰ 19impl Attr {
24/// /// Docs 20 pub fn pound_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![#]) }
25/// #[attr] 21 pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) }
26/// pub extern "C" fn foo<T>(#[attr] Patern {p}: Pattern) -> u32 22 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
27/// where 23 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
28/// T: Debug 24 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
29/// { 25 pub fn input(&self) -> Option<AttrInput> { support::child(&self.syntax) }
30/// 42 26 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
31/// } 27}
32/// ❱
33///
34/// extern "C" {
35/// ❰ fn fn_decl(also_variadic_ffi: u32, ...) -> u32; ❱
36/// }
37/// ```
38///
39/// - [Reference](https://doc.rust-lang.org/reference/items/functions.html)
40/// - [Nomicon](https://doc.rust-lang.org/nomicon/ffi.html#variadic-functions)
41#[derive(Debug, Clone, PartialEq, Eq, Hash)] 28#[derive(Debug, Clone, PartialEq, Eq, Hash)]
42pub struct FnDef { 29pub struct FnDef {
43 pub(crate) syntax: SyntaxNode, 30 pub(crate) syntax: SyntaxNode,
44} 31}
45impl ast::VisibilityOwner for FnDef {} 32impl ast::AttrsOwner for FnDef {}
46impl ast::NameOwner for FnDef {} 33impl ast::NameOwner for FnDef {}
34impl ast::VisibilityOwner for FnDef {}
47impl ast::TypeParamsOwner for FnDef {} 35impl ast::TypeParamsOwner for FnDef {}
48impl ast::DocCommentsOwner for FnDef {}
49impl ast::AttrsOwner for FnDef {}
50impl FnDef { 36impl FnDef {
51 pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) } 37 pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) }
52 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } 38 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
@@ -59,13 +45,53 @@ impl FnDef {
59 pub fn body(&self) -> Option<BlockExpr> { support::child(&self.syntax) } 45 pub fn body(&self) -> Option<BlockExpr> { support::child(&self.syntax) }
60 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 46 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
61} 47}
62/// Return type annotation. 48#[derive(Debug, Clone, PartialEq, Eq, Hash)]
63/// 49pub struct Visibility {
64/// ``` 50 pub(crate) syntax: SyntaxNode,
65/// fn foo(a: u32) ❰ -> Option<u32> ❱ { Some(a) } 51}
66/// ``` 52impl Visibility {
67/// 53 pub fn pub_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![pub]) }
68/// [Reference](https://doc.rust-lang.org/reference/items/functions.html) 54 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
55 pub fn super_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![super]) }
56 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) }
57 pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) }
58 pub fn in_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![in]) }
59 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
60 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
61}
62#[derive(Debug, Clone, PartialEq, Eq, Hash)]
63pub struct Abi {
64 pub(crate) syntax: SyntaxNode,
65}
66impl Abi {}
67#[derive(Debug, Clone, PartialEq, Eq, Hash)]
68pub struct Name {
69 pub(crate) syntax: SyntaxNode,
70}
71impl Name {
72 pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) }
73}
74#[derive(Debug, Clone, PartialEq, Eq, Hash)]
75pub struct TypeParamList {
76 pub(crate) syntax: SyntaxNode,
77}
78impl TypeParamList {
79 pub fn l_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![<]) }
80 pub fn type_params(&self) -> AstChildren<TypeParam> { support::children(&self.syntax) }
81 pub fn lifetime_params(&self) -> AstChildren<LifetimeParam> { support::children(&self.syntax) }
82 pub fn const_params(&self) -> AstChildren<ConstParam> { support::children(&self.syntax) }
83 pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) }
84}
85#[derive(Debug, Clone, PartialEq, Eq, Hash)]
86pub struct ParamList {
87 pub(crate) syntax: SyntaxNode,
88}
89impl ParamList {
90 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
91 pub fn self_param(&self) -> Option<SelfParam> { support::child(&self.syntax) }
92 pub fn params(&self) -> AstChildren<Param> { support::children(&self.syntax) }
93 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
94}
69#[derive(Debug, Clone, PartialEq, Eq, Hash)] 95#[derive(Debug, Clone, PartialEq, Eq, Hash)]
70pub struct RetType { 96pub struct RetType {
71 pub(crate) syntax: SyntaxNode, 97 pub(crate) syntax: SyntaxNode,
@@ -74,204 +100,105 @@ impl RetType {
74 pub fn thin_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![->]) } 100 pub fn thin_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![->]) }
75 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 101 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
76} 102}
77/// Struct definition. 103#[derive(Debug, Clone, PartialEq, Eq, Hash)]
78/// Includes all of its attributes and doc comments. 104pub struct WhereClause {
79/// 105 pub(crate) syntax: SyntaxNode,
80/// ``` 106}
81/// ❰ 107impl WhereClause {
82/// /// Docs 108 pub fn where_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![where]) }
83/// #[attr] 109 pub fn predicates(&self) -> AstChildren<WherePred> { support::children(&self.syntax) }
84/// struct Foo<T> where T: Debug { 110}
85/// /// Docs 111#[derive(Debug, Clone, PartialEq, Eq, Hash)]
86/// #[attr] 112pub struct BlockExpr {
87/// pub a: u32, 113 pub(crate) syntax: SyntaxNode,
88/// b: T, 114}
89/// } 115impl ast::AttrsOwner for BlockExpr {}
90/// ❱ 116impl ast::ModuleItemOwner for BlockExpr {}
91/// 117impl BlockExpr {
92/// ❰ struct Foo; ❱ 118 pub fn label(&self) -> Option<Label> { support::child(&self.syntax) }
93/// ❰ struct Foo<T>(#[attr] T) where T: Debug; ❱ 119 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
94/// ``` 120 pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) }
95/// 121 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
96/// [Reference](https://doc.rust-lang.org/reference/items/structs.html) 122 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
123}
97#[derive(Debug, Clone, PartialEq, Eq, Hash)] 124#[derive(Debug, Clone, PartialEq, Eq, Hash)]
98pub struct StructDef { 125pub struct StructDef {
99 pub(crate) syntax: SyntaxNode, 126 pub(crate) syntax: SyntaxNode,
100} 127}
101impl ast::VisibilityOwner for StructDef {} 128impl ast::AttrsOwner for StructDef {}
102impl ast::NameOwner for StructDef {} 129impl ast::NameOwner for StructDef {}
130impl ast::VisibilityOwner for StructDef {}
103impl ast::TypeParamsOwner for StructDef {} 131impl ast::TypeParamsOwner for StructDef {}
104impl ast::AttrsOwner for StructDef {}
105impl ast::DocCommentsOwner for StructDef {}
106impl StructDef { 132impl StructDef {
107 pub fn struct_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![struct]) } 133 pub fn struct_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![struct]) }
108 pub fn field_def_list(&self) -> Option<FieldDefList> { support::child(&self.syntax) }
109 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 134 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
135 pub fn field_def_list(&self) -> Option<FieldDefList> { support::child(&self.syntax) }
136}
137#[derive(Debug, Clone, PartialEq, Eq, Hash)]
138pub struct RecordFieldDefList {
139 pub(crate) syntax: SyntaxNode,
140}
141impl RecordFieldDefList {
142 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
143 pub fn fields(&self) -> AstChildren<RecordFieldDef> { support::children(&self.syntax) }
144 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
145}
146#[derive(Debug, Clone, PartialEq, Eq, Hash)]
147pub struct TupleFieldDefList {
148 pub(crate) syntax: SyntaxNode,
149}
150impl TupleFieldDefList {
151 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
152 pub fn fields(&self) -> AstChildren<TupleFieldDef> { support::children(&self.syntax) }
153 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
110} 154}
111/// Union definition.
112/// Includes all of its attributes and doc comments.
113///
114/// ```
115/// ❰
116/// /// Docs
117/// #[attr]
118/// pub union Foo<T> where T: Debug {
119/// /// Docs
120/// #[attr]
121/// a: T,
122/// b: u32,
123/// }
124/// ❱
125/// ```
126///
127/// [Reference](https://doc.rust-lang.org/reference/items/unions.html)
128#[derive(Debug, Clone, PartialEq, Eq, Hash)] 155#[derive(Debug, Clone, PartialEq, Eq, Hash)]
129pub struct UnionDef { 156pub struct UnionDef {
130 pub(crate) syntax: SyntaxNode, 157 pub(crate) syntax: SyntaxNode,
131} 158}
132impl ast::VisibilityOwner for UnionDef {} 159impl ast::AttrsOwner for UnionDef {}
133impl ast::NameOwner for UnionDef {} 160impl ast::NameOwner for UnionDef {}
161impl ast::VisibilityOwner for UnionDef {}
134impl ast::TypeParamsOwner for UnionDef {} 162impl ast::TypeParamsOwner for UnionDef {}
135impl ast::AttrsOwner for UnionDef {}
136impl ast::DocCommentsOwner for UnionDef {}
137impl UnionDef { 163impl UnionDef {
138 pub fn union_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![union]) } 164 pub fn union_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![union]) }
139 pub fn record_field_def_list(&self) -> Option<RecordFieldDefList> { 165 pub fn record_field_def_list(&self) -> Option<RecordFieldDefList> {
140 support::child(&self.syntax) 166 support::child(&self.syntax)
141 } 167 }
142} 168}
143/// Record field definition list including enclosing curly braces.
144///
145/// ```
146/// struct Foo // same for union
147/// ❰
148/// {
149/// a: u32,
150/// b: bool,
151/// }
152/// ❱
153/// ```
154///
155/// [Reference](https://doc.rust-lang.org/reference/items/structs.html)
156#[derive(Debug, Clone, PartialEq, Eq, Hash)]
157pub struct RecordFieldDefList {
158 pub(crate) syntax: SyntaxNode,
159}
160impl RecordFieldDefList {
161 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
162 pub fn fields(&self) -> AstChildren<RecordFieldDef> { support::children(&self.syntax) }
163 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
164}
165/// Record field definition including its attributes and doc comments.
166///
167/// ` ``
168/// same for union
169/// struct Foo {
170/// ❰
171/// /// Docs
172/// #[attr]
173/// pub a: u32
174/// ❱
175///
176/// ❰ b: bool ❱
177/// }
178/// ```
179///
180/// [Reference](https://doc.rust-lang.org/reference/items/structs.html)
181#[derive(Debug, Clone, PartialEq, Eq, Hash)] 169#[derive(Debug, Clone, PartialEq, Eq, Hash)]
182pub struct RecordFieldDef { 170pub struct RecordFieldDef {
183 pub(crate) syntax: SyntaxNode, 171 pub(crate) syntax: SyntaxNode,
184} 172}
185impl ast::VisibilityOwner for RecordFieldDef {}
186impl ast::NameOwner for RecordFieldDef {}
187impl ast::AttrsOwner for RecordFieldDef {} 173impl ast::AttrsOwner for RecordFieldDef {}
188impl ast::DocCommentsOwner for RecordFieldDef {} 174impl ast::NameOwner for RecordFieldDef {}
175impl ast::VisibilityOwner for RecordFieldDef {}
189impl ast::TypeAscriptionOwner for RecordFieldDef {} 176impl ast::TypeAscriptionOwner for RecordFieldDef {}
190impl RecordFieldDef {} 177impl RecordFieldDef {
191/// Tuple field definition list including enclosing parens. 178 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
192///
193/// ```
194/// struct Foo ❰ (u32, String, Vec<u32>) ❱;
195/// ```
196///
197/// [Reference](https://doc.rust-lang.org/reference/items/structs.html)
198#[derive(Debug, Clone, PartialEq, Eq, Hash)]
199pub struct TupleFieldDefList {
200 pub(crate) syntax: SyntaxNode,
201}
202impl TupleFieldDefList {
203 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
204 pub fn fields(&self) -> AstChildren<TupleFieldDef> { support::children(&self.syntax) }
205 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
206} 179}
207/// Tuple field definition including its attributes.
208///
209/// ```
210/// struct Foo(❰ #[attr] u32 ❱);
211/// ```
212///
213/// [Reference](https://doc.rust-lang.org/reference/items/structs.html)
214#[derive(Debug, Clone, PartialEq, Eq, Hash)] 180#[derive(Debug, Clone, PartialEq, Eq, Hash)]
215pub struct TupleFieldDef { 181pub struct TupleFieldDef {
216 pub(crate) syntax: SyntaxNode, 182 pub(crate) syntax: SyntaxNode,
217} 183}
218impl ast::VisibilityOwner for TupleFieldDef {}
219impl ast::AttrsOwner for TupleFieldDef {} 184impl ast::AttrsOwner for TupleFieldDef {}
185impl ast::NameOwner for TupleFieldDef {}
186impl ast::VisibilityOwner for TupleFieldDef {}
220impl TupleFieldDef { 187impl TupleFieldDef {
221 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 188 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
222} 189}
223/// Enum definition.
224/// Includes all of its attributes and doc comments.
225///
226/// ```
227/// ❰
228/// /// Docs
229/// #[attr]
230/// pub enum Foo<T> where T: Debug {
231/// /// Docs
232/// #[attr]
233/// Bar,
234/// Baz(#[attr] u32),
235/// Bruh {
236/// a: u32,
237/// /// Docs
238/// #[attr]
239/// b: T,
240/// }
241/// }
242/// ❱
243/// ```
244///
245/// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html)
246#[derive(Debug, Clone, PartialEq, Eq, Hash)] 190#[derive(Debug, Clone, PartialEq, Eq, Hash)]
247pub struct EnumDef { 191pub struct EnumDef {
248 pub(crate) syntax: SyntaxNode, 192 pub(crate) syntax: SyntaxNode,
249} 193}
250impl ast::VisibilityOwner for EnumDef {} 194impl ast::AttrsOwner for EnumDef {}
251impl ast::NameOwner for EnumDef {} 195impl ast::NameOwner for EnumDef {}
196impl ast::VisibilityOwner for EnumDef {}
252impl ast::TypeParamsOwner for EnumDef {} 197impl ast::TypeParamsOwner for EnumDef {}
253impl ast::AttrsOwner for EnumDef {}
254impl ast::DocCommentsOwner for EnumDef {}
255impl EnumDef { 198impl EnumDef {
256 pub fn enum_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![enum]) } 199 pub fn enum_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![enum]) }
257 pub fn variant_list(&self) -> Option<EnumVariantList> { support::child(&self.syntax) } 200 pub fn variant_list(&self) -> Option<EnumVariantList> { support::child(&self.syntax) }
258} 201}
259/// Enum variant definition list including enclosing curly braces.
260///
261/// ```
262/// enum Foo
263/// ❰
264/// {
265/// Bar,
266/// Baz(u32),
267/// Bruh {
268/// a: u32
269/// }
270/// }
271/// ❱
272/// ```
273///
274/// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html)
275#[derive(Debug, Clone, PartialEq, Eq, Hash)] 202#[derive(Debug, Clone, PartialEq, Eq, Hash)]
276pub struct EnumVariantList { 203pub struct EnumVariantList {
277 pub(crate) syntax: SyntaxNode, 204 pub(crate) syntax: SyntaxNode,
@@ -281,56 +208,25 @@ impl EnumVariantList {
281 pub fn variants(&self) -> AstChildren<EnumVariant> { support::children(&self.syntax) } 208 pub fn variants(&self) -> AstChildren<EnumVariant> { support::children(&self.syntax) }
282 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } 209 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
283} 210}
284/// Enum variant definition including its attributes and discriminant value definition.
285///
286/// ```
287/// enum Foo {
288/// ❰
289/// /// Docs
290/// #[attr]
291/// Bar
292/// ❱
293///
294/// // same for tuple and record variants
295/// }
296/// ```
297///
298/// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html)
299#[derive(Debug, Clone, PartialEq, Eq, Hash)] 211#[derive(Debug, Clone, PartialEq, Eq, Hash)]
300pub struct EnumVariant { 212pub struct EnumVariant {
301 pub(crate) syntax: SyntaxNode, 213 pub(crate) syntax: SyntaxNode,
302} 214}
303impl ast::VisibilityOwner for EnumVariant {}
304impl ast::NameOwner for EnumVariant {}
305impl ast::DocCommentsOwner for EnumVariant {}
306impl ast::AttrsOwner for EnumVariant {} 215impl ast::AttrsOwner for EnumVariant {}
216impl ast::NameOwner for EnumVariant {}
217impl ast::VisibilityOwner for EnumVariant {}
307impl EnumVariant { 218impl EnumVariant {
308 pub fn field_def_list(&self) -> Option<FieldDefList> { support::child(&self.syntax) } 219 pub fn field_def_list(&self) -> Option<FieldDefList> { support::child(&self.syntax) }
309 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } 220 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
310 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 221 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
311} 222}
312/// Trait definition.
313/// Includes all of its attributes and doc comments.
314///
315/// ```
316/// ❰
317/// /// Docs
318/// #[attr]
319/// pub unsafe trait Foo<T>: Debug where T: Debug {
320/// // ...
321/// }
322/// ❱
323/// ```
324///
325/// [Reference](https://doc.rust-lang.org/reference/items/traits.html)
326#[derive(Debug, Clone, PartialEq, Eq, Hash)] 223#[derive(Debug, Clone, PartialEq, Eq, Hash)]
327pub struct TraitDef { 224pub struct TraitDef {
328 pub(crate) syntax: SyntaxNode, 225 pub(crate) syntax: SyntaxNode,
329} 226}
330impl ast::VisibilityOwner for TraitDef {}
331impl ast::NameOwner for TraitDef {}
332impl ast::AttrsOwner for TraitDef {} 227impl ast::AttrsOwner for TraitDef {}
333impl ast::DocCommentsOwner for TraitDef {} 228impl ast::NameOwner for TraitDef {}
229impl ast::VisibilityOwner for TraitDef {}
334impl ast::TypeParamsOwner for TraitDef {} 230impl ast::TypeParamsOwner for TraitDef {}
335impl ast::TypeBoundsOwner for TraitDef {} 231impl ast::TypeBoundsOwner for TraitDef {}
336impl TraitDef { 232impl TraitDef {
@@ -339,62 +235,13 @@ impl TraitDef {
339 pub fn trait_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![trait]) } 235 pub fn trait_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![trait]) }
340 pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } 236 pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) }
341} 237}
342/// Module definition either with body or not.
343/// Includes all of its inner and outer attributes, module items, doc comments.
344///
345/// ```
346/// ❰
347/// /// Docs
348/// #[attr]
349/// pub mod foo;
350/// ❱
351///
352/// ❰
353/// /// Docs
354/// #[attr]
355/// pub mod bar {
356/// //! Inner docs
357/// #![inner_attr]
358/// }
359/// ❱
360/// ```
361///
362/// [Reference](https://doc.rust-lang.org/reference/items/modules.html)
363#[derive(Debug, Clone, PartialEq, Eq, Hash)] 238#[derive(Debug, Clone, PartialEq, Eq, Hash)]
364pub struct Module { 239pub struct TypeBoundList {
365 pub(crate) syntax: SyntaxNode, 240 pub(crate) syntax: SyntaxNode,
366} 241}
367impl ast::VisibilityOwner for Module {} 242impl TypeBoundList {
368impl ast::NameOwner for Module {} 243 pub fn bounds(&self) -> AstChildren<TypeBound> { support::children(&self.syntax) }
369impl ast::AttrsOwner for Module {}
370impl ast::DocCommentsOwner for Module {}
371impl Module {
372 pub fn mod_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mod]) }
373 pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) }
374 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
375} 244}
376/// Item defintion list.
377/// This is used for both top-level items and impl block items.
378///
379/// ```
380/// ❰
381/// fn foo {}
382/// struct Bar;
383/// enum Baz;
384/// trait Bruh;
385/// const BRUUH: u32 = 42;
386/// ❱
387///
388/// impl Foo
389/// ❰
390/// {
391/// fn bar() {}
392/// const BAZ: u32 = 42;
393/// }
394/// ❱
395/// ```
396///
397/// [Reference](https://doc.rust-lang.org/reference/items.html)
398#[derive(Debug, Clone, PartialEq, Eq, Hash)] 245#[derive(Debug, Clone, PartialEq, Eq, Hash)]
399pub struct ItemList { 246pub struct ItemList {
400 pub(crate) syntax: SyntaxNode, 247 pub(crate) syntax: SyntaxNode,
@@ -405,91 +252,58 @@ impl ItemList {
405 pub fn assoc_items(&self) -> AstChildren<AssocItem> { support::children(&self.syntax) } 252 pub fn assoc_items(&self) -> AstChildren<AssocItem> { support::children(&self.syntax) }
406 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } 253 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
407} 254}
408/// Constant variable definition. 255#[derive(Debug, Clone, PartialEq, Eq, Hash)]
409/// Includes all of its attributes and doc comments. 256pub struct Module {
410/// 257 pub(crate) syntax: SyntaxNode,
411/// ``` 258}
412/// 259impl ast::AttrsOwner for Module {}
413/// /// Docs 260impl ast::NameOwner for Module {}
414/// #[attr] 261impl ast::VisibilityOwner for Module {}
415/// pub const FOO: u32 = 42; 262impl Module {
416/// 263 pub fn mod_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mod]) }
417/// ``` 264 pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) }
418/// 265 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
419/// [Reference](https://doc.rust-lang.org/reference/items/constant-items.html) 266}
420#[derive(Debug, Clone, PartialEq, Eq, Hash)] 267#[derive(Debug, Clone, PartialEq, Eq, Hash)]
421pub struct ConstDef { 268pub struct ConstDef {
422 pub(crate) syntax: SyntaxNode, 269 pub(crate) syntax: SyntaxNode,
423} 270}
424impl ast::VisibilityOwner for ConstDef {}
425impl ast::NameOwner for ConstDef {}
426impl ast::TypeParamsOwner for ConstDef {}
427impl ast::AttrsOwner for ConstDef {} 271impl ast::AttrsOwner for ConstDef {}
428impl ast::DocCommentsOwner for ConstDef {} 272impl ast::NameOwner for ConstDef {}
273impl ast::VisibilityOwner for ConstDef {}
429impl ast::TypeAscriptionOwner for ConstDef {} 274impl ast::TypeAscriptionOwner for ConstDef {}
430impl ConstDef { 275impl ConstDef {
431 pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) } 276 pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) }
432 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } 277 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
278 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
433 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } 279 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
434 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } 280 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) }
435 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 281 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
436} 282}
437/// Static variable definition.
438/// Includes all of its attributes and doc comments.
439///
440/// ```
441/// ❰
442/// /// Docs
443/// #[attr]
444/// pub static mut FOO: u32 = 42;
445/// ❱
446/// ```
447///
448/// [Reference](https://doc.rust-lang.org/reference/items/static-items.html)
449#[derive(Debug, Clone, PartialEq, Eq, Hash)] 283#[derive(Debug, Clone, PartialEq, Eq, Hash)]
450pub struct StaticDef { 284pub struct StaticDef {
451 pub(crate) syntax: SyntaxNode, 285 pub(crate) syntax: SyntaxNode,
452} 286}
453impl ast::VisibilityOwner for StaticDef {}
454impl ast::NameOwner for StaticDef {}
455impl ast::TypeParamsOwner for StaticDef {}
456impl ast::AttrsOwner for StaticDef {} 287impl ast::AttrsOwner for StaticDef {}
457impl ast::DocCommentsOwner for StaticDef {} 288impl ast::NameOwner for StaticDef {}
289impl ast::VisibilityOwner for StaticDef {}
458impl ast::TypeAscriptionOwner for StaticDef {} 290impl ast::TypeAscriptionOwner for StaticDef {}
459impl StaticDef { 291impl StaticDef {
460 pub fn static_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![static]) } 292 pub fn static_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![static]) }
461 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } 293 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
294 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
462 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } 295 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
463 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } 296 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) }
464 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 297 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
465} 298}
466/// Type alias definition.
467/// Includes associated type clauses with type bounds.
468///
469/// ```
470/// ❰
471/// /// Docs
472/// #[attr]
473/// pub type Foo<T> where T: Debug = T;
474/// ❱
475///
476/// trait Bar {
477/// ❰ type Baz: Debug; ❱
478/// ❰ type Bruh = String; ❱
479/// ❰ type Bruuh: Debug = u32; ❱
480/// }
481/// ```
482///
483/// [Reference](https://doc.rust-lang.org/reference/items/type-aliases.html)
484#[derive(Debug, Clone, PartialEq, Eq, Hash)] 299#[derive(Debug, Clone, PartialEq, Eq, Hash)]
485pub struct TypeAliasDef { 300pub struct TypeAliasDef {
486 pub(crate) syntax: SyntaxNode, 301 pub(crate) syntax: SyntaxNode,
487} 302}
488impl ast::VisibilityOwner for TypeAliasDef {} 303impl ast::AttrsOwner for TypeAliasDef {}
489impl ast::NameOwner for TypeAliasDef {} 304impl ast::NameOwner for TypeAliasDef {}
305impl ast::VisibilityOwner for TypeAliasDef {}
490impl ast::TypeParamsOwner for TypeAliasDef {} 306impl ast::TypeParamsOwner for TypeAliasDef {}
491impl ast::AttrsOwner for TypeAliasDef {}
492impl ast::DocCommentsOwner for TypeAliasDef {}
493impl ast::TypeBoundsOwner for TypeAliasDef {} 307impl ast::TypeBoundsOwner for TypeAliasDef {}
494impl TypeAliasDef { 308impl TypeAliasDef {
495 pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) } 309 pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) }
@@ -498,46 +312,22 @@ impl TypeAliasDef {
498 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 312 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
499 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 313 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
500} 314}
501/// Inherent and trait impl definition.
502/// Includes all of its inner and outer attributes.
503///
504/// ```
505/// ❰
506/// #[attr]
507/// unsafe impl<T> const !Foo for Bar where T: Debug {
508/// #![inner_attr]
509/// // ...
510/// }
511/// ❱
512/// ```
513///
514/// [Reference](https://doc.rust-lang.org/reference/items/implementations.html)
515#[derive(Debug, Clone, PartialEq, Eq, Hash)] 315#[derive(Debug, Clone, PartialEq, Eq, Hash)]
516pub struct ImplDef { 316pub struct ImplDef {
517 pub(crate) syntax: SyntaxNode, 317 pub(crate) syntax: SyntaxNode,
518} 318}
519impl ast::TypeParamsOwner for ImplDef {}
520impl ast::AttrsOwner for ImplDef {} 319impl ast::AttrsOwner for ImplDef {}
521impl ast::DocCommentsOwner for ImplDef {} 320impl ast::VisibilityOwner for ImplDef {}
321impl ast::TypeParamsOwner for ImplDef {}
522impl ImplDef { 322impl ImplDef {
523 pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) }
524 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } 323 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
324 pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) }
525 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) } 325 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) }
526 pub fn impl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![impl]) } 326 pub fn impl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![impl]) }
527 pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) } 327 pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) }
528 pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) } 328 pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) }
529 pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } 329 pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) }
530} 330}
531/// Parenthesized type reference.
532/// Note: parens are only used for grouping, this is not a tuple type.
533///
534/// ```
535/// // This is effectively just `u32`.
536/// // Single-item tuple must be defined with a trailing comma: `(u32,)`
537/// type Foo = ❰ (u32) ❱;
538///
539/// let bar: &'static ❰ (dyn Debug) ❱ = "bruh";
540/// ```
541#[derive(Debug, Clone, PartialEq, Eq, Hash)] 331#[derive(Debug, Clone, PartialEq, Eq, Hash)]
542pub struct ParenType { 332pub struct ParenType {
543 pub(crate) syntax: SyntaxNode, 333 pub(crate) syntax: SyntaxNode,
@@ -547,13 +337,6 @@ impl ParenType {
547 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 337 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
548 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 338 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
549} 339}
550/// Unnamed tuple type.
551///
552/// ```
553/// let foo: ❰ (u32, bool) ❱ = (42, true);
554/// ```
555///
556/// [Reference](https://doc.rust-lang.org/reference/types/tuple.html)
557#[derive(Debug, Clone, PartialEq, Eq, Hash)] 340#[derive(Debug, Clone, PartialEq, Eq, Hash)]
558pub struct TupleType { 341pub struct TupleType {
559 pub(crate) syntax: SyntaxNode, 342 pub(crate) syntax: SyntaxNode,
@@ -563,17 +346,6 @@ impl TupleType {
563 pub fn fields(&self) -> AstChildren<TypeRef> { support::children(&self.syntax) } 346 pub fn fields(&self) -> AstChildren<TypeRef> { support::children(&self.syntax) }
564 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 347 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
565} 348}
566/// The never type (i.e. the exclamation point).
567///
568/// ```
569/// type T = ❰ ! ❱;
570///
571/// fn no_return() -> ❰ ! ❱ {
572/// loop {}
573/// }
574/// ```
575///
576/// [Reference](https://doc.rust-lang.org/reference/types/never.html)
577#[derive(Debug, Clone, PartialEq, Eq, Hash)] 349#[derive(Debug, Clone, PartialEq, Eq, Hash)]
578pub struct NeverType { 350pub struct NeverType {
579 pub(crate) syntax: SyntaxNode, 351 pub(crate) syntax: SyntaxNode,
@@ -581,17 +353,6 @@ pub struct NeverType {
581impl NeverType { 353impl NeverType {
582 pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) } 354 pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) }
583} 355}
584/// Path to a type.
585/// Includes single identifier type names and elaborate paths with
586/// generic parameters.
587///
588/// ```
589/// type Foo = ❰ String ❱;
590/// type Bar = ❰ std::vec::Vec<T> ❱;
591/// type Baz = ❰ ::bruh::<Bruuh as Iterator>::Item ❱;
592/// ```
593///
594/// [Reference](https://doc.rust-lang.org/reference/paths.html)
595#[derive(Debug, Clone, PartialEq, Eq, Hash)] 356#[derive(Debug, Clone, PartialEq, Eq, Hash)]
596pub struct PathType { 357pub struct PathType {
597 pub(crate) syntax: SyntaxNode, 358 pub(crate) syntax: SyntaxNode,
@@ -599,14 +360,15 @@ pub struct PathType {
599impl PathType { 360impl PathType {
600 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } 361 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
601} 362}
602/// Raw pointer type. 363#[derive(Debug, Clone, PartialEq, Eq, Hash)]
603/// 364pub struct Path {
604/// ``` 365 pub(crate) syntax: SyntaxNode,
605/// type Foo = ❰ *const u32 ❱; 366}
606/// type Bar = ❰ *mut u32 ❱; 367impl Path {
607/// ``` 368 pub fn qualifier(&self) -> Option<Path> { support::child(&self.syntax) }
608/// 369 pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) }
609/// [Reference](https://doc.rust-lang.org/reference/types/pointer.html#raw-pointers-const-and-mut) 370 pub fn segment(&self) -> Option<PathSegment> { support::child(&self.syntax) }
371}
610#[derive(Debug, Clone, PartialEq, Eq, Hash)] 372#[derive(Debug, Clone, PartialEq, Eq, Hash)]
611pub struct PointerType { 373pub struct PointerType {
612 pub(crate) syntax: SyntaxNode, 374 pub(crate) syntax: SyntaxNode,
@@ -617,13 +379,6 @@ impl PointerType {
617 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } 379 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
618 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 380 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
619} 381}
620/// Array type.
621///
622/// ```
623/// type Foo = ❰ [u32; 24 - 3] ❱;
624/// ```
625///
626/// [Reference](https://doc.rust-lang.org/reference/types/array.html)
627#[derive(Debug, Clone, PartialEq, Eq, Hash)] 382#[derive(Debug, Clone, PartialEq, Eq, Hash)]
628pub struct ArrayType { 383pub struct ArrayType {
629 pub(crate) syntax: SyntaxNode, 384 pub(crate) syntax: SyntaxNode,
@@ -635,13 +390,6 @@ impl ArrayType {
635 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 390 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
636 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } 391 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
637} 392}
638/// Slice type.
639///
640/// ```
641/// type Foo = ❰ [u8] ❱;
642/// ```
643///
644/// [Reference](https://doc.rust-lang.org/reference/types/slice.html)
645#[derive(Debug, Clone, PartialEq, Eq, Hash)] 393#[derive(Debug, Clone, PartialEq, Eq, Hash)]
646pub struct SliceType { 394pub struct SliceType {
647 pub(crate) syntax: SyntaxNode, 395 pub(crate) syntax: SyntaxNode,
@@ -651,13 +399,6 @@ impl SliceType {
651 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 399 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
652 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } 400 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
653} 401}
654/// Reference type.
655///
656/// ```
657/// type Foo = ❰ &'static str ❱;
658/// ```
659///
660/// [Reference](https://doc.rust-lang.org/reference/types/pointer.html)
661#[derive(Debug, Clone, PartialEq, Eq, Hash)] 402#[derive(Debug, Clone, PartialEq, Eq, Hash)]
662pub struct ReferenceType { 403pub struct ReferenceType {
663 pub(crate) syntax: SyntaxNode, 404 pub(crate) syntax: SyntaxNode,
@@ -670,13 +411,6 @@ impl ReferenceType {
670 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } 411 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
671 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 412 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
672} 413}
673/// Placeholder type (i.e. the underscore).
674///
675/// ```
676/// let foo: ❰ _ ❱ = 42_u32;
677/// ```
678///
679/// [Reference](https://doc.rust-lang.org/reference/types/inferred.html)
680#[derive(Debug, Clone, PartialEq, Eq, Hash)] 414#[derive(Debug, Clone, PartialEq, Eq, Hash)]
681pub struct PlaceholderType { 415pub struct PlaceholderType {
682 pub(crate) syntax: SyntaxNode, 416 pub(crate) syntax: SyntaxNode,
@@ -684,15 +418,6 @@ pub struct PlaceholderType {
684impl PlaceholderType { 418impl PlaceholderType {
685 pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) } 419 pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) }
686} 420}
687/// Function pointer type (not to be confused with `Fn*` family of traits).
688///
689/// ```
690/// type Foo = ❰ async fn(#[attr] u32, named: bool) -> u32 ❱;
691///
692/// type Bar = ❰ extern "C" fn(variadic: u32, #[attr] ...) ❱;
693/// ```
694///
695/// [Reference](https://doc.rust-lang.org/reference/types/function-pointer.html)
696#[derive(Debug, Clone, PartialEq, Eq, Hash)] 421#[derive(Debug, Clone, PartialEq, Eq, Hash)]
697pub struct FnPointerType { 422pub struct FnPointerType {
698 pub(crate) syntax: SyntaxNode, 423 pub(crate) syntax: SyntaxNode,
@@ -704,13 +429,6 @@ impl FnPointerType {
704 pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) } 429 pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) }
705 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } 430 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) }
706} 431}
707/// Higher order type.
708///
709/// ```
710/// type Foo = ❰ for<'a> fn(&'a str) ❱;
711/// ```
712///
713/// [Reference](https://doc.rust-lang.org/nomicon/hrtb.html)
714#[derive(Debug, Clone, PartialEq, Eq, Hash)] 432#[derive(Debug, Clone, PartialEq, Eq, Hash)]
715pub struct ForType { 433pub struct ForType {
716 pub(crate) syntax: SyntaxNode, 434 pub(crate) syntax: SyntaxNode,
@@ -720,43 +438,22 @@ impl ForType {
720 pub fn type_param_list(&self) -> Option<TypeParamList> { support::child(&self.syntax) } 438 pub fn type_param_list(&self) -> Option<TypeParamList> { support::child(&self.syntax) }
721 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 439 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
722} 440}
723/// Opaque `impl Trait` type.
724///
725/// ```
726/// fn foo(bar: ❰ impl Debug + Eq ❱) {}
727/// ```
728///
729/// [Reference](https://doc.rust-lang.org/reference/types/impl-trait.html)
730#[derive(Debug, Clone, PartialEq, Eq, Hash)] 441#[derive(Debug, Clone, PartialEq, Eq, Hash)]
731pub struct ImplTraitType { 442pub struct ImplTraitType {
732 pub(crate) syntax: SyntaxNode, 443 pub(crate) syntax: SyntaxNode,
733} 444}
734impl ast::TypeBoundsOwner for ImplTraitType {}
735impl ImplTraitType { 445impl ImplTraitType {
736 pub fn impl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![impl]) } 446 pub fn impl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![impl]) }
447 pub fn type_bound_list(&self) -> Option<TypeBoundList> { support::child(&self.syntax) }
737} 448}
738/// Trait object type.
739///
740/// ```
741/// type Foo = ❰ dyn Debug ❱;
742/// ```
743///
744/// [Reference](https://doc.rust-lang.org/reference/types/trait-object.html)
745#[derive(Debug, Clone, PartialEq, Eq, Hash)] 449#[derive(Debug, Clone, PartialEq, Eq, Hash)]
746pub struct DynTraitType { 450pub struct DynTraitType {
747 pub(crate) syntax: SyntaxNode, 451 pub(crate) syntax: SyntaxNode,
748} 452}
749impl ast::TypeBoundsOwner for DynTraitType {}
750impl DynTraitType { 453impl DynTraitType {
751 pub fn dyn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![dyn]) } 454 pub fn dyn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![dyn]) }
455 pub fn type_bound_list(&self) -> Option<TypeBoundList> { support::child(&self.syntax) }
752} 456}
753/// Tuple literal.
754///
755/// ```
756/// ❰ (42, true) ❱;
757/// ```
758///
759/// [Reference](https://doc.rust-lang.org/reference/expressions/tuple-expr.html)
760#[derive(Debug, Clone, PartialEq, Eq, Hash)] 457#[derive(Debug, Clone, PartialEq, Eq, Hash)]
761pub struct TupleExpr { 458pub struct TupleExpr {
762 pub(crate) syntax: SyntaxNode, 459 pub(crate) syntax: SyntaxNode,
@@ -767,15 +464,6 @@ impl TupleExpr {
767 pub fn exprs(&self) -> AstChildren<Expr> { support::children(&self.syntax) } 464 pub fn exprs(&self) -> AstChildren<Expr> { support::children(&self.syntax) }
768 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 465 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
769} 466}
770/// Array literal.
771///
772/// ```
773/// ❰ [#![inner_attr] true, false, true] ❱;
774///
775/// ❰ ["baz"; 24] ❱;
776/// ```
777///
778/// [Reference](https://doc.rust-lang.org/reference/expressions/array-expr.html)
779#[derive(Debug, Clone, PartialEq, Eq, Hash)] 467#[derive(Debug, Clone, PartialEq, Eq, Hash)]
780pub struct ArrayExpr { 468pub struct ArrayExpr {
781 pub(crate) syntax: SyntaxNode, 469 pub(crate) syntax: SyntaxNode,
@@ -784,17 +472,10 @@ impl ast::AttrsOwner for ArrayExpr {}
784impl ArrayExpr { 472impl ArrayExpr {
785 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } 473 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
786 pub fn exprs(&self) -> AstChildren<Expr> { support::children(&self.syntax) } 474 pub fn exprs(&self) -> AstChildren<Expr> { support::children(&self.syntax) }
475 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
787 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 476 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
788 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } 477 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
789} 478}
790/// Parenthesized expression.
791/// Note: parens are only used for grouping, this is not a tuple literal.
792///
793/// ```
794/// ❰ (#![inner_attr] 2 + 2) ❱ * 2;
795/// ```
796///
797/// [Reference](https://doc.rust-lang.org/reference/expressions/grouped-expr.html)
798#[derive(Debug, Clone, PartialEq, Eq, Hash)] 479#[derive(Debug, Clone, PartialEq, Eq, Hash)]
799pub struct ParenExpr { 480pub struct ParenExpr {
800 pub(crate) syntax: SyntaxNode, 481 pub(crate) syntax: SyntaxNode,
@@ -805,19 +486,6 @@ impl ParenExpr {
805 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 486 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
806 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 487 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
807} 488}
808/// Path to a symbol in expression context.
809/// Includes single identifier variable names and elaborate paths with
810/// generic parameters.
811///
812/// ```
813/// ❰ Some::<i32> ❱;
814/// ❰ foo ❱ + 42;
815/// ❰ Vec::<i32>::push ❱;
816/// ❰ <[i32]>::reverse ❱;
817/// ❰ <String as std::borrow::Borrow<str>>::borrow ❱;
818/// ```
819///
820/// [Reference](https://doc.rust-lang.org/reference/expressions/path-expr.html)
821#[derive(Debug, Clone, PartialEq, Eq, Hash)] 489#[derive(Debug, Clone, PartialEq, Eq, Hash)]
822pub struct PathExpr { 490pub struct PathExpr {
823 pub(crate) syntax: SyntaxNode, 491 pub(crate) syntax: SyntaxNode,
@@ -825,17 +493,6 @@ pub struct PathExpr {
825impl PathExpr { 493impl PathExpr {
826 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } 494 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
827} 495}
828/// Anonymous callable object literal a.k.a. closure, lambda or functor.
829///
830/// ```
831/// ❰ || 42 ❱;
832/// ❰ |a: u32| val + 1 ❱;
833/// ❰ async |#[attr] Pattern(_): Pattern| { bar } ❱;
834/// ❰ move || baz ❱;
835/// ❰ || -> u32 { closure_with_ret_type_annotation_requires_block_expr } ❱
836/// ```
837///
838/// [Reference](https://doc.rust-lang.org/reference/expressions/closure-expr.html)
839#[derive(Debug, Clone, PartialEq, Eq, Hash)] 496#[derive(Debug, Clone, PartialEq, Eq, Hash)]
840pub struct LambdaExpr { 497pub struct LambdaExpr {
841 pub(crate) syntax: SyntaxNode, 498 pub(crate) syntax: SyntaxNode,
@@ -849,25 +506,6 @@ impl LambdaExpr {
849 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } 506 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) }
850 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } 507 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) }
851} 508}
852/// If expression. Includes both regular `if` and `if let` forms.
853/// Beware that `else if` is a special case syntax sugar, because in general
854/// there has to be block expression after `else`.
855///
856/// ```
857/// ❰ if bool_cond { 42 } ❱
858/// ❰ if bool_cond { 42 } else { 24 } ❱
859/// ❰ if bool_cond { 42 } else if bool_cond2 { 42 } ❱
860///
861/// ❰
862/// if let Pattern(foo) = bar {
863/// foo
864/// } else {
865/// panic!();
866/// }
867/// ❱
868/// ```
869///
870/// [Reference](https://doc.rust-lang.org/reference/expressions/if-expr.html)
871#[derive(Debug, Clone, PartialEq, Eq, Hash)] 509#[derive(Debug, Clone, PartialEq, Eq, Hash)]
872pub struct IfExpr { 510pub struct IfExpr {
873 pub(crate) syntax: SyntaxNode, 511 pub(crate) syntax: SyntaxNode,
@@ -877,40 +515,16 @@ impl IfExpr {
877 pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) } 515 pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) }
878 pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } 516 pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) }
879} 517}
880/// Unconditional loop expression.
881///
882/// ```
883/// ❰
884/// loop {
885/// // yeah, it's that simple...
886/// }
887/// ❱
888/// ```
889///
890/// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html)
891#[derive(Debug, Clone, PartialEq, Eq, Hash)] 518#[derive(Debug, Clone, PartialEq, Eq, Hash)]
892pub struct LoopExpr { 519pub struct Condition {
893 pub(crate) syntax: SyntaxNode, 520 pub(crate) syntax: SyntaxNode,
894} 521}
895impl ast::AttrsOwner for LoopExpr {} 522impl Condition {
896impl ast::LoopBodyOwner for LoopExpr {} 523 pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) }
897impl LoopExpr { 524 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
898 pub fn loop_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![loop]) } 525 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
526 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
899} 527}
900/// Block expression with an optional prefix (label, try ketword,
901/// unsafe keyword, async keyword...).
902///
903/// ```
904/// ❰
905/// 'label: try {
906/// None?
907/// }
908/// ❱
909/// ```
910///
911/// - [try block](https://doc.rust-lang.org/unstable-book/language-features/try-blocks.html)
912/// - [unsafe block](https://doc.rust-lang.org/reference/expressions/block-expr.html#unsafe-blocks)
913/// - [async block](https://doc.rust-lang.org/reference/expressions/block-expr.html#async-blocks)
914#[derive(Debug, Clone, PartialEq, Eq, Hash)] 528#[derive(Debug, Clone, PartialEq, Eq, Hash)]
915pub struct EffectExpr { 529pub struct EffectExpr {
916 pub(crate) syntax: SyntaxNode, 530 pub(crate) syntax: SyntaxNode,
@@ -923,19 +537,24 @@ impl EffectExpr {
923 pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) } 537 pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) }
924 pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) } 538 pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) }
925} 539}
926/// For loop expression. 540#[derive(Debug, Clone, PartialEq, Eq, Hash)]
927/// Note: record struct literals are not valid as iterable expression 541pub struct Label {
928/// due to ambiguity. 542 pub(crate) syntax: SyntaxNode,
929/// 543}
930/// ``` 544impl Label {
931/// ❰ 545 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
932/// for i in (0..4) { 546 support::token(&self.syntax, T![lifetime])
933/// dbg!(i); 547 }
934/// } 548}
935/// ❱ 549#[derive(Debug, Clone, PartialEq, Eq, Hash)]
936/// ``` 550pub struct LoopExpr {
937/// 551 pub(crate) syntax: SyntaxNode,
938/// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#iterator-loops) 552}
553impl ast::AttrsOwner for LoopExpr {}
554impl ast::LoopBodyOwner for LoopExpr {}
555impl LoopExpr {
556 pub fn loop_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![loop]) }
557}
939#[derive(Debug, Clone, PartialEq, Eq, Hash)] 558#[derive(Debug, Clone, PartialEq, Eq, Hash)]
940pub struct ForExpr { 559pub struct ForExpr {
941 pub(crate) syntax: SyntaxNode, 560 pub(crate) syntax: SyntaxNode,
@@ -948,22 +567,6 @@ impl ForExpr {
948 pub fn in_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![in]) } 567 pub fn in_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![in]) }
949 pub fn iterable(&self) -> Option<Expr> { support::child(&self.syntax) } 568 pub fn iterable(&self) -> Option<Expr> { support::child(&self.syntax) }
950} 569}
951/// While loop expression. Includes both regular `while` and `while let` forms.
952///
953/// ```
954/// ❰
955/// while bool_cond {
956/// 42;
957/// }
958/// ❱
959/// ❰
960/// while let Pattern(foo) = bar {
961/// bar += 1;
962/// }
963/// ❱
964/// ```
965///
966/// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-loops)
967#[derive(Debug, Clone, PartialEq, Eq, Hash)] 570#[derive(Debug, Clone, PartialEq, Eq, Hash)]
968pub struct WhileExpr { 571pub struct WhileExpr {
969 pub(crate) syntax: SyntaxNode, 572 pub(crate) syntax: SyntaxNode,
@@ -974,22 +577,6 @@ impl WhileExpr {
974 pub fn while_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![while]) } 577 pub fn while_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![while]) }
975 pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } 578 pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) }
976} 579}
977/// Continue expression.
978///
979/// ```
980/// while bool_cond {
981/// ❰ continue ❱;
982/// }
983///
984/// 'outer: loop {
985/// loop {
986/// ❰ continue 'outer ❱;
987/// }
988/// }
989///
990/// ```
991///
992/// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#continue-expressions)
993#[derive(Debug, Clone, PartialEq, Eq, Hash)] 580#[derive(Debug, Clone, PartialEq, Eq, Hash)]
994pub struct ContinueExpr { 581pub struct ContinueExpr {
995 pub(crate) syntax: SyntaxNode, 582 pub(crate) syntax: SyntaxNode,
@@ -1003,25 +590,6 @@ impl ContinueExpr {
1003 support::token(&self.syntax, T![lifetime]) 590 support::token(&self.syntax, T![lifetime])
1004 } 591 }
1005} 592}
1006/// Break expression.
1007///
1008/// ```
1009/// while bool_cond {
1010/// ❰ break ❱;
1011/// }
1012/// 'outer: loop {
1013/// for foo in bar {
1014/// ❰ break 'outer ❱;
1015/// }
1016/// }
1017/// 'outer: loop {
1018/// loop {
1019/// ❰ break 'outer 42 ❱;
1020/// }
1021/// }
1022/// ```
1023///
1024/// [Refernce](https://doc.rust-lang.org/reference/expressions/loop-expr.html#break-expressions)
1025#[derive(Debug, Clone, PartialEq, Eq, Hash)] 593#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1026pub struct BreakExpr { 594pub struct BreakExpr {
1027 pub(crate) syntax: SyntaxNode, 595 pub(crate) syntax: SyntaxNode,
@@ -1034,104 +602,33 @@ impl BreakExpr {
1034 } 602 }
1035 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 603 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1036} 604}
1037/// Label.
1038///
1039/// ```
1040/// ❰ 'outer: ❱ loop {}
1041///
1042/// let foo = ❰ 'bar: ❱ loop {}
1043///
1044/// ❰ 'baz: ❱ {
1045/// break 'baz;
1046/// }
1047/// ```
1048///
1049/// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html?highlight=label#loop-labels)
1050/// [Labels for blocks RFC](https://github.com/rust-lang/rfcs/blob/master/text/2046-label-break-value.md)
1051#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1052pub struct Label {
1053 pub(crate) syntax: SyntaxNode,
1054}
1055impl Label {
1056 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
1057 support::token(&self.syntax, T![lifetime])
1058 }
1059}
1060/// Block expression. Includes unsafe blocks and block labels.
1061///
1062/// ```
1063/// let foo = ❰
1064/// {
1065/// #![inner_attr]
1066/// ❰ { } ❱
1067///
1068/// ❰ 'label: { break 'label } ❱
1069/// }
1070/// ❱;
1071/// ```
1072///
1073/// [Reference](https://doc.rust-lang.org/reference/expressions/block-expr.html)
1074/// [Labels for blocks RFC](https://github.com/rust-lang/rfcs/blob/master/text/2046-label-break-value.md)
1075#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1076pub struct BlockExpr {
1077 pub(crate) syntax: SyntaxNode,
1078}
1079impl ast::AttrsOwner for BlockExpr {}
1080impl ast::ModuleItemOwner for BlockExpr {}
1081impl BlockExpr {
1082 pub fn label(&self) -> Option<Label> { support::child(&self.syntax) }
1083 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
1084 pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) }
1085 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1086 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
1087}
1088/// Return expression.
1089///
1090/// ```
1091/// || ❰ return 42 ❱;
1092///
1093/// fn bar() {
1094/// ❰ return ❱;
1095/// }
1096/// ```
1097///
1098/// [Reference](https://doc.rust-lang.org/reference/expressions/return-expr.html)
1099#[derive(Debug, Clone, PartialEq, Eq, Hash)] 605#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1100pub struct ReturnExpr { 606pub struct ReturnExpr {
1101 pub(crate) syntax: SyntaxNode, 607 pub(crate) syntax: SyntaxNode,
1102} 608}
1103impl ast::AttrsOwner for ReturnExpr {} 609impl ast::AttrsOwner for ReturnExpr {}
1104impl ReturnExpr { 610impl ReturnExpr {
611 pub fn return_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![return]) }
1105 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 612 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1106} 613}
1107/// Call expression (not to be confused with method call expression, it is
1108/// a separate ast node).
1109///
1110/// ```
1111/// ❰ foo() ❱;
1112/// ❰ &str::len("bar") ❱;
1113/// ❰ <&str as PartialEq<&str>>::eq(&"", &"") ❱;
1114/// ```
1115///
1116/// [Reference](https://doc.rust-lang.org/reference/expressions/call-expr.html)
1117#[derive(Debug, Clone, PartialEq, Eq, Hash)] 614#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1118pub struct CallExpr { 615pub struct CallExpr {
1119 pub(crate) syntax: SyntaxNode, 616 pub(crate) syntax: SyntaxNode,
1120} 617}
618impl ast::AttrsOwner for CallExpr {}
1121impl ast::ArgListOwner for CallExpr {} 619impl ast::ArgListOwner for CallExpr {}
1122impl CallExpr { 620impl CallExpr {
1123 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 621 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1124} 622}
1125/// Method call expression. 623#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1126/// 624pub struct ArgList {
1127/// ``` 625 pub(crate) syntax: SyntaxNode,
1128/// ❰ receiver_expr.method() ❱; 626}
1129/// ❰ receiver_expr.method::<T>(42, true) ❱; 627impl ArgList {
1130/// 628 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
1131/// ❰ ❰ ❰ foo.bar() ❱ .baz() ❱ .bruh() ❱; 629 pub fn args(&self) -> AstChildren<Expr> { support::children(&self.syntax) }
1132/// ``` 630 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
1133/// 631}
1134/// [Reference](https://doc.rust-lang.org/reference/expressions/method-call-expr.html)
1135#[derive(Debug, Clone, PartialEq, Eq, Hash)] 632#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1136pub struct MethodCallExpr { 633pub struct MethodCallExpr {
1137 pub(crate) syntax: SyntaxNode, 634 pub(crate) syntax: SyntaxNode,
@@ -1144,31 +641,26 @@ impl MethodCallExpr {
1144 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } 641 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
1145 pub fn type_arg_list(&self) -> Option<TypeArgList> { support::child(&self.syntax) } 642 pub fn type_arg_list(&self) -> Option<TypeArgList> { support::child(&self.syntax) }
1146} 643}
1147/// Index expression a.k.a. subscript operator call.
1148///
1149/// ```
1150/// ❰ foo[42] ❱;
1151/// ```
1152///
1153/// [Reference](https://doc.rust-lang.org/reference/expressions/array-expr.html)
1154#[derive(Debug, Clone, PartialEq, Eq, Hash)] 644#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1155pub struct IndexExpr { 645pub struct NameRef {
1156 pub(crate) syntax: SyntaxNode, 646 pub(crate) syntax: SyntaxNode,
1157} 647}
1158impl ast::AttrsOwner for IndexExpr {} 648impl NameRef {
1159impl IndexExpr { 649 pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) }
1160 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } 650}
1161 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } 651#[derive(Debug, Clone, PartialEq, Eq, Hash)]
652pub struct TypeArgList {
653 pub(crate) syntax: SyntaxNode,
654}
655impl TypeArgList {
656 pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) }
657 pub fn l_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![<]) }
658 pub fn type_args(&self) -> AstChildren<TypeArg> { support::children(&self.syntax) }
659 pub fn lifetime_args(&self) -> AstChildren<LifetimeArg> { support::children(&self.syntax) }
660 pub fn assoc_type_args(&self) -> AstChildren<AssocTypeArg> { support::children(&self.syntax) }
661 pub fn const_args(&self) -> AstChildren<ConstArg> { support::children(&self.syntax) }
662 pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) }
1162} 663}
1163/// Field access expression.
1164///
1165/// ```
1166/// ❰ expr.bar ❱;
1167///
1168/// ❰ ❰ ❰ foo.bar ❱ .baz ❱ .bruh ❱;
1169/// ```
1170///
1171/// [Reference](https://doc.rust-lang.org/reference/expressions/field-expr.html)
1172#[derive(Debug, Clone, PartialEq, Eq, Hash)] 664#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1173pub struct FieldExpr { 665pub struct FieldExpr {
1174 pub(crate) syntax: SyntaxNode, 666 pub(crate) syntax: SyntaxNode,
@@ -1179,13 +671,15 @@ impl FieldExpr {
1179 pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) } 671 pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) }
1180 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } 672 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
1181} 673}
1182/// Await operator call expression. 674#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1183/// 675pub struct IndexExpr {
1184/// ``` 676 pub(crate) syntax: SyntaxNode,
1185/// ❰ expr.await ❱; 677}
1186/// ``` 678impl ast::AttrsOwner for IndexExpr {}
1187/// 679impl IndexExpr {
1188/// [Reference](https://doc.rust-lang.org/reference/expressions/await-expr.html) 680 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
681 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
682}
1189#[derive(Debug, Clone, PartialEq, Eq, Hash)] 683#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1190pub struct AwaitExpr { 684pub struct AwaitExpr {
1191 pub(crate) syntax: SyntaxNode, 685 pub(crate) syntax: SyntaxNode,
@@ -1196,13 +690,6 @@ impl AwaitExpr {
1196 pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) } 690 pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) }
1197 pub fn await_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![await]) } 691 pub fn await_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![await]) }
1198} 692}
1199/// The question mark operator call.
1200///
1201/// ```
1202/// ❰ expr? ❱;
1203/// ```
1204///
1205/// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#the-question-mark-operator)
1206#[derive(Debug, Clone, PartialEq, Eq, Hash)] 693#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1207pub struct TryExpr { 694pub struct TryExpr {
1208 pub(crate) syntax: SyntaxNode, 695 pub(crate) syntax: SyntaxNode,
@@ -1212,13 +699,6 @@ impl TryExpr {
1212 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 699 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1213 pub fn question_mark_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![?]) } 700 pub fn question_mark_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![?]) }
1214} 701}
1215/// Type cast expression.
1216///
1217/// ```
1218/// ❰ expr as T ❱;
1219/// ```
1220///
1221/// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions)
1222#[derive(Debug, Clone, PartialEq, Eq, Hash)] 702#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1223pub struct CastExpr { 703pub struct CastExpr {
1224 pub(crate) syntax: SyntaxNode, 704 pub(crate) syntax: SyntaxNode,
@@ -1229,16 +709,6 @@ impl CastExpr {
1229 pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) } 709 pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) }
1230 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 710 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
1231} 711}
1232/// Borrow operator call.
1233///
1234/// ```
1235/// ❰ &foo ❱;
1236/// ❰ &mut bar ❱;
1237/// ❰ &raw const bar ❱;
1238/// ❰ &raw mut bar ❱;
1239/// ```
1240///
1241/// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#borrow-operators)
1242#[derive(Debug, Clone, PartialEq, Eq, Hash)] 712#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1243pub struct RefExpr { 713pub struct RefExpr {
1244 pub(crate) syntax: SyntaxNode, 714 pub(crate) syntax: SyntaxNode,
@@ -1251,15 +721,6 @@ impl RefExpr {
1251 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } 721 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
1252 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 722 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1253} 723}
1254/// Prefix operator call. This is either `!` or `*` or `-`.
1255///
1256/// ```
1257/// ❰ !foo ❱;
1258/// ❰ *bar ❱;
1259/// ❰ -42 ❱;
1260/// ```
1261///
1262/// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html)
1263#[derive(Debug, Clone, PartialEq, Eq, Hash)] 724#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1264pub struct PrefixExpr { 725pub struct PrefixExpr {
1265 pub(crate) syntax: SyntaxNode, 726 pub(crate) syntax: SyntaxNode,
@@ -1268,13 +729,6 @@ impl ast::AttrsOwner for PrefixExpr {}
1268impl PrefixExpr { 729impl PrefixExpr {
1269 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 730 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1270} 731}
1271/// Box operator call.
1272///
1273/// ```
1274/// ❰ box 42 ❱;
1275/// ```
1276///
1277/// [RFC](https://github.com/rust-lang/rfcs/blob/0806be4f282144cfcd55b1d20284b43f87cbe1c6/text/0809-box-and-in-for-stdlib.md)
1278#[derive(Debug, Clone, PartialEq, Eq, Hash)] 732#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1279pub struct BoxExpr { 733pub struct BoxExpr {
1280 pub(crate) syntax: SyntaxNode, 734 pub(crate) syntax: SyntaxNode,
@@ -1284,69 +738,23 @@ impl BoxExpr {
1284 pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) } 738 pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) }
1285 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 739 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1286} 740}
1287/// Range operator call.
1288///
1289/// ```
1290/// ❰ 0..42 ❱;
1291/// ❰ ..42 ❱;
1292/// ❰ 0.. ❱;
1293/// ❰ .. ❱;
1294/// ❰ 0..=42 ❱;
1295/// ❰ ..=42 ❱;
1296/// ```
1297///
1298/// [Reference](https://doc.rust-lang.org/reference/expressions/range-expr.html)
1299#[derive(Debug, Clone, PartialEq, Eq, Hash)] 741#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1300pub struct RangeExpr { 742pub struct RangeExpr {
1301 pub(crate) syntax: SyntaxNode, 743 pub(crate) syntax: SyntaxNode,
1302} 744}
1303impl ast::AttrsOwner for RangeExpr {} 745impl ast::AttrsOwner for RangeExpr {}
1304impl RangeExpr {} 746impl RangeExpr {}
1305/// Binary operator call.
1306/// Includes all arithmetic, logic, bitwise and assignment operators.
1307///
1308/// ```
1309/// ❰ 2 + ❰ 2 * 2 ❱ ❱;
1310/// ❰ ❰ true && false ❱ || true ❱;
1311/// ```
1312///
1313/// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#arithmetic-and-logical-binary-operators)
1314#[derive(Debug, Clone, PartialEq, Eq, Hash)] 747#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1315pub struct BinExpr { 748pub struct BinExpr {
1316 pub(crate) syntax: SyntaxNode, 749 pub(crate) syntax: SyntaxNode,
1317} 750}
1318impl ast::AttrsOwner for BinExpr {} 751impl ast::AttrsOwner for BinExpr {}
1319impl BinExpr {} 752impl BinExpr {}
1320/// [Raw] string, [raw] byte string, char, byte, integer, float or bool literal.
1321///
1322/// ```
1323/// ❰ "str" ❱;
1324/// ❰ br##"raw byte str"## ❱;
1325/// ❰ 'c' ❱;
1326/// ❰ b'c' ❱;
1327/// ❰ 42 ❱;
1328/// ❰ 1e9 ❱;
1329/// ❰ true ❱;
1330/// ```
1331///
1332/// [Reference](https://doc.rust-lang.org/reference/expressions/literal-expr.html)
1333#[derive(Debug, Clone, PartialEq, Eq, Hash)] 753#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1334pub struct Literal { 754pub struct Literal {
1335 pub(crate) syntax: SyntaxNode, 755 pub(crate) syntax: SyntaxNode,
1336} 756}
1337impl Literal {} 757impl Literal {}
1338/// Match expression.
1339///
1340/// ```
1341/// ❰
1342/// match expr {
1343/// Pat1 => {}
1344/// Pat2(_) => 42,
1345/// }
1346/// ❱
1347/// ```
1348///
1349/// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html)
1350#[derive(Debug, Clone, PartialEq, Eq, Hash)] 758#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1351pub struct MatchExpr { 759pub struct MatchExpr {
1352 pub(crate) syntax: SyntaxNode, 760 pub(crate) syntax: SyntaxNode,
@@ -1357,40 +765,15 @@ impl MatchExpr {
1357 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 765 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1358 pub fn match_arm_list(&self) -> Option<MatchArmList> { support::child(&self.syntax) } 766 pub fn match_arm_list(&self) -> Option<MatchArmList> { support::child(&self.syntax) }
1359} 767}
1360/// Match arm list part of match expression. Includes its inner attributes.
1361///
1362/// ```
1363/// match expr
1364/// ❰
1365/// {
1366/// #![inner_attr]
1367/// Pat1 => {}
1368/// Pat2(_) => 42,
1369/// }
1370/// ❱
1371/// ```
1372///
1373/// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html)
1374#[derive(Debug, Clone, PartialEq, Eq, Hash)] 768#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1375pub struct MatchArmList { 769pub struct MatchArmList {
1376 pub(crate) syntax: SyntaxNode, 770 pub(crate) syntax: SyntaxNode,
1377} 771}
1378impl ast::AttrsOwner for MatchArmList {}
1379impl MatchArmList { 772impl MatchArmList {
1380 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } 773 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
1381 pub fn arms(&self) -> AstChildren<MatchArm> { support::children(&self.syntax) } 774 pub fn arms(&self) -> AstChildren<MatchArm> { support::children(&self.syntax) }
1382 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } 775 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
1383} 776}
1384/// Match arm.
1385/// Note: record struct literals are not valid as target match expression
1386/// due to ambiguity.
1387/// ```
1388/// match expr {
1389/// ❰ #[attr] Pattern(it) if bool_cond => it ❱,
1390/// }
1391/// ```
1392///
1393/// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html)
1394#[derive(Debug, Clone, PartialEq, Eq, Hash)] 777#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1395pub struct MatchArm { 778pub struct MatchArm {
1396 pub(crate) syntax: SyntaxNode, 779 pub(crate) syntax: SyntaxNode,
@@ -1402,15 +785,6 @@ impl MatchArm {
1402 pub fn fat_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=>]) } 785 pub fn fat_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=>]) }
1403 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 786 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1404} 787}
1405/// Match guard.
1406///
1407/// ```
1408/// match expr {
1409/// Pattern(it) ❰ if bool_cond ❱ => it,
1410/// }
1411/// ```
1412///
1413/// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html#match-guards)
1414#[derive(Debug, Clone, PartialEq, Eq, Hash)] 788#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1415pub struct MatchGuard { 789pub struct MatchGuard {
1416 pub(crate) syntax: SyntaxNode, 790 pub(crate) syntax: SyntaxNode,
@@ -1419,21 +793,6 @@ impl MatchGuard {
1419 pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) } 793 pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) }
1420 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 794 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1421} 795}
1422/// Record literal expression. The same syntax is used for structs,
1423/// unions and record enum variants.
1424///
1425/// ```
1426/// ❰
1427/// foo::Bar {
1428/// #![inner_attr]
1429/// baz: 42,
1430/// bruh: true,
1431/// ..spread
1432/// }
1433/// ❱
1434/// ```
1435///
1436/// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html)
1437#[derive(Debug, Clone, PartialEq, Eq, Hash)] 796#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1438pub struct RecordLit { 797pub struct RecordLit {
1439 pub(crate) syntax: SyntaxNode, 798 pub(crate) syntax: SyntaxNode,
@@ -1442,16 +801,6 @@ impl RecordLit {
1442 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } 801 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
1443 pub fn record_field_list(&self) -> Option<RecordFieldList> { support::child(&self.syntax) } 802 pub fn record_field_list(&self) -> Option<RecordFieldList> { support::child(&self.syntax) }
1444} 803}
1445/// Record field list including enclosing curly braces.
1446///
1447/// foo::Bar ❰
1448/// {
1449/// baz: 42,
1450/// ..spread
1451/// }
1452/// ❱
1453///
1454/// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html)
1455#[derive(Debug, Clone, PartialEq, Eq, Hash)] 804#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1456pub struct RecordFieldList { 805pub struct RecordFieldList {
1457 pub(crate) syntax: SyntaxNode, 806 pub(crate) syntax: SyntaxNode,
@@ -1463,15 +812,6 @@ impl RecordFieldList {
1463 pub fn spread(&self) -> Option<Expr> { support::child(&self.syntax) } 812 pub fn spread(&self) -> Option<Expr> { support::child(&self.syntax) }
1464 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } 813 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
1465} 814}
1466/// Record field.
1467///
1468/// ```
1469/// foo::Bar {
1470/// ❰ #[attr] baz: 42 ❱
1471/// }
1472/// ```
1473///
1474/// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html)
1475#[derive(Debug, Clone, PartialEq, Eq, Hash)] 815#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1476pub struct RecordField { 816pub struct RecordField {
1477 pub(crate) syntax: SyntaxNode, 817 pub(crate) syntax: SyntaxNode,
@@ -1482,13 +822,6 @@ impl RecordField {
1482 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } 822 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
1483 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 823 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1484} 824}
1485/// Disjunction of patterns.
1486///
1487/// ```
1488/// let ❰ Foo(it) | Bar(it) | Baz(it) ❱ = bruh;
1489/// ```
1490///
1491/// [Reference](https://doc.rust-lang.org/reference/patterns.html)
1492#[derive(Debug, Clone, PartialEq, Eq, Hash)] 825#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1493pub struct OrPat { 826pub struct OrPat {
1494 pub(crate) syntax: SyntaxNode, 827 pub(crate) syntax: SyntaxNode,
@@ -1496,14 +829,6 @@ pub struct OrPat {
1496impl OrPat { 829impl OrPat {
1497 pub fn pats(&self) -> AstChildren<Pat> { support::children(&self.syntax) } 830 pub fn pats(&self) -> AstChildren<Pat> { support::children(&self.syntax) }
1498} 831}
1499/// Parenthesized pattern.
1500/// Note: parens are only used for grouping, this is not a tuple pattern.
1501///
1502/// ```
1503/// if let ❰ &(0..=42) ❱ = foo {}
1504/// ```
1505///
1506/// https://doc.rust-lang.org/reference/patterns.html#grouped-patterns
1507#[derive(Debug, Clone, PartialEq, Eq, Hash)] 832#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1508pub struct ParenPat { 833pub struct ParenPat {
1509 pub(crate) syntax: SyntaxNode, 834 pub(crate) syntax: SyntaxNode,
@@ -1513,16 +838,6 @@ impl ParenPat {
1513 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 838 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
1514 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 839 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
1515} 840}
1516/// Reference pattern.
1517/// Note: this has nothing to do with `ref` keyword, the latter is used in bind patterns.
1518///
1519/// ```
1520/// let ❰ &mut foo ❱ = bar;
1521///
1522/// let ❰ & ❰ &mut ❰ &_ ❱ ❱ ❱ = baz;
1523/// ```
1524///
1525/// [Reference](https://doc.rust-lang.org/reference/patterns.html#reference-patterns)
1526#[derive(Debug, Clone, PartialEq, Eq, Hash)] 841#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1527pub struct RefPat { 842pub struct RefPat {
1528 pub(crate) syntax: SyntaxNode, 843 pub(crate) syntax: SyntaxNode,
@@ -1532,31 +847,14 @@ impl RefPat {
1532 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } 847 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
1533 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 848 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
1534} 849}
1535/// Box pattern.
1536///
1537/// ```
1538/// let ❰ box foo ❱ = box 42;
1539/// ```
1540///
1541/// [Unstable book](https://doc.rust-lang.org/unstable-book/language-features/box-patterns.html)
1542#[derive(Debug, Clone, PartialEq, Eq, Hash)] 850#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1543pub struct BoxPat { 851pub struct BoxPat {
1544 pub(crate) syntax: SyntaxNode, 852 pub(crate) syntax: SyntaxNode,
1545} 853}
1546impl BoxPat { 854impl BoxPat {
1547 pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) } 855 pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) }
1548 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 856 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
1549} 857}
1550/// Bind pattern.
1551///
1552/// ```
1553/// match foo {
1554/// Some(❰ ref mut bar ❱) => {}
1555/// ❰ baz @ None ❱ => {}
1556/// }
1557/// ```
1558///
1559/// [Reference](https://doc.rust-lang.org/reference/patterns.html#identifier-patterns)
1560#[derive(Debug, Clone, PartialEq, Eq, Hash)] 858#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1561pub struct BindPat { 859pub struct BindPat {
1562 pub(crate) syntax: SyntaxNode, 860 pub(crate) syntax: SyntaxNode,
@@ -1569,13 +867,6 @@ impl BindPat {
1569 pub fn at_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![@]) } 867 pub fn at_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![@]) }
1570 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 868 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
1571} 869}
1572/// Placeholder pattern a.k.a. the wildcard pattern or the underscore.
1573///
1574/// ```
1575/// let ❰ _ ❱ = foo;
1576/// ```
1577///
1578/// [Reference](https://doc.rust-lang.org/reference/patterns.html#wildcard-pattern)
1579#[derive(Debug, Clone, PartialEq, Eq, Hash)] 870#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1580pub struct PlaceholderPat { 871pub struct PlaceholderPat {
1581 pub(crate) syntax: SyntaxNode, 872 pub(crate) syntax: SyntaxNode,
@@ -1583,16 +874,6 @@ pub struct PlaceholderPat {
1583impl PlaceholderPat { 874impl PlaceholderPat {
1584 pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) } 875 pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) }
1585} 876}
1586/// Rest-of-the record/tuple pattern.
1587/// Note: this is not the unbonded range pattern (even more: it doesn't exist).
1588///
1589/// ```
1590/// let Foo { bar, ❰ .. ❱ } = baz;
1591/// let (❰ .. ❱, bruh) = (42, 24, 42);
1592/// let Bruuh(❰ .. ❱) = bruuuh;
1593/// ```
1594///
1595/// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns)
1596#[derive(Debug, Clone, PartialEq, Eq, Hash)] 877#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1597pub struct DotDotPat { 878pub struct DotDotPat {
1598 pub(crate) syntax: SyntaxNode, 879 pub(crate) syntax: SyntaxNode,
@@ -1600,15 +881,6 @@ pub struct DotDotPat {
1600impl DotDotPat { 881impl DotDotPat {
1601 pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } 882 pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) }
1602} 883}
1603/// Path pattern.
1604/// Doesn't include the underscore pattern (it is a special case, namely `PlaceholderPat`).
1605///
1606/// ```
1607/// let ❰ foo::bar::Baz ❱ { .. } = bruh;
1608/// if let ❰ CONST ❱ = 42 {}
1609/// ```
1610///
1611/// [Reference](https://doc.rust-lang.org/reference/patterns.html#path-patterns)
1612#[derive(Debug, Clone, PartialEq, Eq, Hash)] 884#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1613pub struct PathPat { 885pub struct PathPat {
1614 pub(crate) syntax: SyntaxNode, 886 pub(crate) syntax: SyntaxNode,
@@ -1616,13 +888,6 @@ pub struct PathPat {
1616impl PathPat { 888impl PathPat {
1617 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } 889 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
1618} 890}
1619/// Slice pattern.
1620///
1621/// ```
1622/// let ❰ [foo, bar, baz] ❱ = [1, 2, 3];
1623/// ```
1624///
1625/// [Reference](https://doc.rust-lang.org/reference/patterns.html#slice-patterns)
1626#[derive(Debug, Clone, PartialEq, Eq, Hash)] 891#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1627pub struct SlicePat { 892pub struct SlicePat {
1628 pub(crate) syntax: SyntaxNode, 893 pub(crate) syntax: SyntaxNode,
@@ -1632,33 +897,14 @@ impl SlicePat {
1632 pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } 897 pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) }
1633 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } 898 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
1634} 899}
1635/// Range pattern.
1636///
1637/// ```
1638/// match foo {
1639/// ❰ 0..42 ❱ => {}
1640/// ❰ 0..=42 ❱ => {}
1641/// }
1642/// ```
1643///
1644/// [Reference](https://doc.rust-lang.org/reference/patterns.html#range-patterns)
1645#[derive(Debug, Clone, PartialEq, Eq, Hash)] 900#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1646pub struct RangePat { 901pub struct RangePat {
1647 pub(crate) syntax: SyntaxNode, 902 pub(crate) syntax: SyntaxNode,
1648} 903}
1649impl RangePat {} 904impl RangePat {
1650/// Literal pattern. 905 pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) }
1651/// Includes only bool, number, char, and string literals. 906 pub fn dotdoteq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..=]) }
1652/// 907}
1653/// ```
1654/// match foo {
1655/// Number(❰ 42 ❱) => {}
1656/// String(❰ "42" ❱) => {}
1657/// Bool(❰ true ❱) => {}
1658/// }
1659/// ```
1660///
1661/// [Reference](https://doc.rust-lang.org/reference/patterns.html#literal-patterns)
1662#[derive(Debug, Clone, PartialEq, Eq, Hash)] 908#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1663pub struct LiteralPat { 909pub struct LiteralPat {
1664 pub(crate) syntax: SyntaxNode, 910 pub(crate) syntax: SyntaxNode,
@@ -1666,13 +912,6 @@ pub struct LiteralPat {
1666impl LiteralPat { 912impl LiteralPat {
1667 pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) } 913 pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) }
1668} 914}
1669/// Macro invocation in pattern position.
1670///
1671/// ```
1672/// let ❰ foo!(my custom syntax) ❱ = baz;
1673///
1674/// ```
1675/// [Reference](https://doc.rust-lang.org/reference/macros.html#macro-invocation)
1676#[derive(Debug, Clone, PartialEq, Eq, Hash)] 915#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1677pub struct MacroPat { 916pub struct MacroPat {
1678 pub(crate) syntax: SyntaxNode, 917 pub(crate) syntax: SyntaxNode,
@@ -1680,30 +919,28 @@ pub struct MacroPat {
1680impl MacroPat { 919impl MacroPat {
1681 pub fn macro_call(&self) -> Option<MacroCall> { support::child(&self.syntax) } 920 pub fn macro_call(&self) -> Option<MacroCall> { support::child(&self.syntax) }
1682} 921}
1683/// Record literal pattern. 922#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1684/// 923pub struct MacroCall {
1685/// ``` 924 pub(crate) syntax: SyntaxNode,
1686/// let ❰ foo::Bar { baz, .. } ❱ = bruh; 925}
1687/// ``` 926impl ast::AttrsOwner for MacroCall {}
1688/// 927impl ast::NameOwner for MacroCall {}
1689/// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns) 928impl MacroCall {
929 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
930 pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) }
931 pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) }
932 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
933}
1690#[derive(Debug, Clone, PartialEq, Eq, Hash)] 934#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1691pub struct RecordPat { 935pub struct RecordPat {
1692 pub(crate) syntax: SyntaxNode, 936 pub(crate) syntax: SyntaxNode,
1693} 937}
1694impl RecordPat { 938impl RecordPat {
939 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
1695 pub fn record_field_pat_list(&self) -> Option<RecordFieldPatList> { 940 pub fn record_field_pat_list(&self) -> Option<RecordFieldPatList> {
1696 support::child(&self.syntax) 941 support::child(&self.syntax)
1697 } 942 }
1698 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
1699} 943}
1700/// Record literal's field patterns list including enclosing curly braces.
1701///
1702/// ```
1703/// let foo::Bar ❰ { baz, bind @ bruh, .. } ❱ = bruuh;
1704/// ``
1705///
1706/// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns)
1707#[derive(Debug, Clone, PartialEq, Eq, Hash)] 944#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1708pub struct RecordFieldPatList { 945pub struct RecordFieldPatList {
1709 pub(crate) syntax: SyntaxNode, 946 pub(crate) syntax: SyntaxNode,
@@ -1717,15 +954,6 @@ impl RecordFieldPatList {
1717 pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } 954 pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) }
1718 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } 955 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
1719} 956}
1720/// Record literal's field pattern.
1721/// Note: record literal can also match tuple structs.
1722///
1723/// ```
1724/// let Foo { ❰ bar: _ ❱ } = baz;
1725/// let TupleStruct { ❰ 0: _ ❱ } = bruh;
1726/// ```
1727///
1728/// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns)
1729#[derive(Debug, Clone, PartialEq, Eq, Hash)] 957#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1730pub struct RecordFieldPat { 958pub struct RecordFieldPat {
1731 pub(crate) syntax: SyntaxNode, 959 pub(crate) syntax: SyntaxNode,
@@ -1736,13 +964,6 @@ impl RecordFieldPat {
1736 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } 964 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
1737 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 965 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
1738} 966}
1739/// Tuple struct literal pattern.
1740///
1741/// ```
1742/// let ❰ foo::Bar(baz, bruh) ❱ = bruuh;
1743/// ```
1744///
1745/// [Reference](https://doc.rust-lang.org/reference/patterns.html#tuple-struct-patterns)
1746#[derive(Debug, Clone, PartialEq, Eq, Hash)] 967#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1747pub struct TupleStructPat { 968pub struct TupleStructPat {
1748 pub(crate) syntax: SyntaxNode, 969 pub(crate) syntax: SyntaxNode,
@@ -1753,14 +974,6 @@ impl TupleStructPat {
1753 pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } 974 pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) }
1754 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 975 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
1755} 976}
1756/// Tuple pattern.
1757/// Note: this doesn't include tuple structs (see `TupleStructPat`)
1758///
1759/// ```
1760/// let ❰ (foo, bar, .., baz) ❱ = bruh;
1761/// ```
1762///
1763/// [Reference](https://doc.rust-lang.org/reference/patterns.html#tuple-patterns)
1764#[derive(Debug, Clone, PartialEq, Eq, Hash)] 977#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1765pub struct TuplePat { 978pub struct TuplePat {
1766 pub(crate) syntax: SyntaxNode, 979 pub(crate) syntax: SyntaxNode,
@@ -1770,209 +983,51 @@ impl TuplePat {
1770 pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } 983 pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) }
1771 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 984 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
1772} 985}
1773/// Visibility.
1774///
1775/// ```
1776/// ❰ pub mod ❱ foo;
1777/// ❰ pub(crate) ❱ struct Bar;
1778/// ❰ pub(self) ❱ enum Baz {}
1779/// ❰ pub(super) ❱ fn bruh() {}
1780/// ❰ pub(in bruuh::bruuuh) ❱ type T = u64;
1781/// ```
1782///
1783/// [Reference](https://doc.rust-lang.org/reference/visibility-and-privacy.html)
1784#[derive(Debug, Clone, PartialEq, Eq, Hash)] 986#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1785pub struct Visibility { 987pub struct TokenTree {
1786 pub(crate) syntax: SyntaxNode,
1787}
1788impl Visibility {
1789 pub fn pub_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![pub]) }
1790 pub fn super_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![super]) }
1791 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) }
1792 pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) }
1793}
1794/// Single identifier.
1795/// Note(@matklad): `Name` is for things that install a new name into the scope,
1796/// `NameRef` is a usage of a name. Most of the time, this definition/reference
1797/// distinction can be determined purely syntactically, ie in
1798/// ```
1799/// fn foo() { foo() }
1800/// ```
1801/// the first foo is `Name`, the second one is `NameRef`.
1802/// The notable exception are patterns, where in
1803/// ``
1804/// let x = 92
1805/// ```
1806/// `x` can be semantically either a name or a name ref, depeding on
1807/// wether there's an `x` constant in scope.
1808/// We use `Name` for patterns, and disambiguate semantically (see `NameClass` in ide_db).
1809///
1810/// ```
1811/// let ❰ foo ❱ = bar;
1812/// struct ❰ Baz ❱;
1813/// fn ❰ bruh ❱() {}
1814/// ```
1815///
1816/// [Reference](https://doc.rust-lang.org/reference/identifiers.html)
1817#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1818pub struct Name {
1819 pub(crate) syntax: SyntaxNode, 988 pub(crate) syntax: SyntaxNode,
1820} 989}
1821impl Name { 990impl TokenTree {
1822 pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) } 991 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
1823} 992 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
1824/// Reference to a name. 993 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
1825/// See the explanation on the difference between `Name` and `NameRef` 994 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
1826/// in `Name` ast node docs. 995 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
1827/// 996 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
1828/// ```
1829/// let foo = ❰ bar ❱(❰ Baz(❰ bruh ❱) ❱;
1830/// ```
1831///
1832/// [Reference](https://doc.rust-lang.org/reference/identifiers.html)
1833#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1834pub struct NameRef {
1835 pub(crate) syntax: SyntaxNode,
1836} 997}
1837impl NameRef {}
1838/// Macro call.
1839/// Includes all of its attributes and doc comments.
1840///
1841/// ```
1842/// ❰
1843/// /// Docs
1844/// #[attr]
1845/// macro_rules! foo { // macro rules is also a macro call
1846/// ($bar: tt) => {}
1847/// }
1848/// ❱
1849///
1850/// // semicolon is a part of `MacroCall` when it is used in item positions
1851/// ❰ foo!(); ❱
1852///
1853/// fn main() {
1854/// ❰ foo!() ❱; // macro call in expression positions doesn't include the semi
1855/// }
1856/// ```
1857///
1858/// [Reference](https://doc.rust-lang.org/reference/macros.html)
1859#[derive(Debug, Clone, PartialEq, Eq, Hash)] 998#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1860pub struct MacroCall { 999pub struct MacroDef {
1861 pub(crate) syntax: SyntaxNode, 1000 pub(crate) syntax: SyntaxNode,
1862} 1001}
1863impl ast::NameOwner for MacroCall {} 1002impl ast::NameOwner for MacroDef {}
1864impl ast::AttrsOwner for MacroCall {} 1003impl MacroDef {
1865impl ast::DocCommentsOwner for MacroCall {}
1866impl MacroCall {
1867 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
1868 pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) }
1869 pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) } 1004 pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) }
1870 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
1871}
1872/// Attribute.
1873///
1874/// ```
1875/// ❰ #![inner_attr] ❱
1876///
1877/// ❰ #[attr] ❱
1878/// ❰ #[foo = "bar"] ❱
1879/// ❰ #[baz(bruh::bruuh = "42")] ❱
1880/// struct Foo;
1881/// ```
1882///
1883/// [Reference](https://doc.rust-lang.org/reference/attributes.html)
1884#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1885pub struct Attr {
1886 pub(crate) syntax: SyntaxNode,
1887} 1005}
1888impl Attr {
1889 pub fn pound_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![#]) }
1890 pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) }
1891 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
1892 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
1893 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
1894 pub fn input(&self) -> Option<AttrInput> { support::child(&self.syntax) }
1895 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
1896}
1897/// Stores a list of lexer tokens and other `TokenTree`s.
1898/// It appears in attributes, macro_rules and macro call (foo!)
1899///
1900/// ```
1901/// macro_call! ❰ { my syntax here } ❱;
1902/// ```
1903///
1904/// [Reference](https://doc.rust-lang.org/reference/macros.html)
1905#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1006#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1906pub struct TokenTree { 1007pub struct MacroItems {
1907 pub(crate) syntax: SyntaxNode, 1008 pub(crate) syntax: SyntaxNode,
1908} 1009}
1909impl TokenTree {} 1010impl ast::ModuleItemOwner for MacroItems {}
1910/// Generic lifetime, type and constants parameters list **declaration**. 1011impl MacroItems {}
1911///
1912/// ```
1913/// fn foo❰ <'a, 'b, T, U, const BAR: u64> ❱() {}
1914///
1915/// struct Baz❰ <T> ❱(T);
1916///
1917/// impl❰ <T> ❱ Bruh<T> {}
1918///
1919/// type Bruuh = for❰ <'a> ❱ fn(&'a str) -> &'a str;
1920/// ```
1921///
1922/// [Reference](https://doc.rust-lang.org/reference/items/generics.html)
1923#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1012#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1924pub struct TypeParamList { 1013pub struct MacroStmts {
1925 pub(crate) syntax: SyntaxNode, 1014 pub(crate) syntax: SyntaxNode,
1926} 1015}
1927impl TypeParamList { 1016impl MacroStmts {
1928 pub fn l_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![<]) } 1017 pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) }
1929 pub fn type_params(&self) -> AstChildren<TypeParam> { support::children(&self.syntax) } 1018 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1930 pub fn lifetime_params(&self) -> AstChildren<LifetimeParam> { support::children(&self.syntax) }
1931 pub fn const_params(&self) -> AstChildren<ConstParam> { support::children(&self.syntax) }
1932 pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) }
1933} 1019}
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)
1941#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1020#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1942pub struct TypeParam { 1021pub struct TypeParam {
1943 pub(crate) syntax: SyntaxNode, 1022 pub(crate) syntax: SyntaxNode,
1944} 1023}
1945impl ast::NameOwner for TypeParam {}
1946impl ast::AttrsOwner for TypeParam {} 1024impl ast::AttrsOwner for TypeParam {}
1025impl ast::NameOwner for TypeParam {}
1947impl ast::TypeBoundsOwner for TypeParam {} 1026impl ast::TypeBoundsOwner for TypeParam {}
1948impl TypeParam { 1027impl TypeParam {
1949 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } 1028 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
1950 pub fn default_type(&self) -> Option<TypeRef> { support::child(&self.syntax) } 1029 pub fn default_type(&self) -> Option<TypeRef> { support::child(&self.syntax) }
1951} 1030}
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)
1958#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1959pub struct ConstParam {
1960 pub(crate) syntax: SyntaxNode,
1961}
1962impl ast::NameOwner for ConstParam {}
1963impl ast::AttrsOwner for ConstParam {}
1964impl ast::TypeAscriptionOwner for ConstParam {}
1965impl ConstParam {
1966 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
1967 pub fn default_val(&self) -> Option<Expr> { support::child(&self.syntax) }
1968}
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)
1976#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1031#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1977pub struct LifetimeParam { 1032pub struct LifetimeParam {
1978 pub(crate) syntax: SyntaxNode, 1033 pub(crate) syntax: SyntaxNode,
@@ -1983,20 +1038,19 @@ impl LifetimeParam {
1983 support::token(&self.syntax, T![lifetime]) 1038 support::token(&self.syntax, T![lifetime])
1984 } 1039 }
1985} 1040}
1986/// Type bound declaration clause. 1041#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1987/// 1042pub struct ConstParam {
1988/// ``` 1043 pub(crate) syntax: SyntaxNode,
1989/// fn foo<T: ❰ ?Sized ❱ + ❰ Debug ❱>() {} 1044}
1990/// 1045impl ast::AttrsOwner for ConstParam {}
1991/// trait Bar<T> 1046impl ast::NameOwner for ConstParam {}
1992/// where 1047impl ast::TypeAscriptionOwner for ConstParam {}
1993/// T: ❰ Send ❱ + ❰ Sync ❱ 1048impl ConstParam {
1994/// { 1049 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
1995/// type Baz: ❰ !Sync ❱ + ❰ Debug ❱ + ❰ ?const Add ❱; 1050 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
1996/// } 1051 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
1997/// ``` 1052 pub fn default_val(&self) -> Option<Expr> { support::child(&self.syntax) }
1998/// 1053}
1999/// [Reference](https://doc.rust-lang.org/reference/trait-bounds.html)
2000#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1054#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2001pub struct TypeBound { 1055pub struct TypeBound {
2002 pub(crate) syntax: SyntaxNode, 1056 pub(crate) syntax: SyntaxNode,
@@ -2008,40 +1062,6 @@ impl TypeBound {
2008 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } 1062 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
2009 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 1063 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
2010} 1064}
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)
2026#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2027pub struct TypeBoundList {
2028 pub(crate) syntax: SyntaxNode,
2029}
2030impl TypeBoundList {
2031 pub fn bounds(&self) -> AstChildren<TypeBound> { support::children(&self.syntax) }
2032}
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)
2045#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1065#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2046pub struct WherePred { 1066pub struct WherePred {
2047 pub(crate) syntax: SyntaxNode, 1067 pub(crate) syntax: SyntaxNode,
@@ -2055,58 +1075,6 @@ impl WherePred {
2055 } 1075 }
2056 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 1076 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
2057} 1077}
2058/// Where clause.
2059///
2060/// ```
2061/// trait Foo<'a, T> ❰ where 'a: 'static, T: Debug ❱ {}
2062///
2063/// ```
2064///
2065/// [Reference](https://doc.rust-lang.org/reference/items/generics.html#where-clauses)
2066#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2067pub struct WhereClause {
2068 pub(crate) syntax: SyntaxNode,
2069}
2070impl WhereClause {
2071 pub fn where_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![where]) }
2072 pub fn predicates(&self) -> AstChildren<WherePred> { support::children(&self.syntax) }
2073}
2074/// Abi declaration.
2075/// Note: the abi string is optional.
2076///
2077/// ```
2078/// ❰ extern "C" ❱ {
2079/// fn foo() {}
2080/// }
2081///
2082/// type Bar = ❰ extern ❱ fn() -> u32;
2083///
2084/// type Baz = ❰ extern r#"stdcall"# ❱ fn() -> bool;
2085/// ```
2086///
2087/// - [Extern blocks reference](https://doc.rust-lang.org/reference/items/external-blocks.html)
2088/// - [FFI function pointers reference](https://doc.rust-lang.org/reference/items/functions.html#functions)
2089#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2090pub struct Abi {
2091 pub(crate) syntax: SyntaxNode,
2092}
2093impl Abi {}
2094/// Expression statement.
2095///
2096/// ```
2097/// ❰ 42; ❱
2098/// ❰ foo(); ❱
2099/// ❰ (); ❱
2100/// ❰ {}; ❱
2101///
2102/// // constructions with trailing curly brace can omit the semicolon
2103/// // but only when there are satements immediately after them (this is important!)
2104/// ❰ if bool_cond { } ❱
2105/// ❰ loop {} ❱
2106/// ❰ somestatment; ❱
2107/// ```
2108///
2109/// [Reference](https://doc.rust-lang.org/reference/statements.html)
2110#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1078#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2111pub struct ExprStmt { 1079pub struct ExprStmt {
2112 pub(crate) syntax: SyntaxNode, 1080 pub(crate) syntax: SyntaxNode,
@@ -2116,16 +1084,6 @@ impl ExprStmt {
2116 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 1084 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
2117 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 1085 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
2118} 1086}
2119/// Let statement.
2120///
2121/// ```
2122/// ❰ #[attr] let foo; ❱
2123/// ❰ let bar: u64; ❱
2124/// ❰ let baz = 42; ❱
2125/// ❰ let bruh: bool = true; ❱
2126/// ```
2127///
2128/// [Reference](https://doc.rust-lang.org/reference/statements.html#let-statements)
2129#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1087#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2130pub struct LetStmt { 1088pub struct LetStmt {
2131 pub(crate) syntax: SyntaxNode, 1089 pub(crate) syntax: SyntaxNode,
@@ -2135,112 +1093,37 @@ impl ast::TypeAscriptionOwner for LetStmt {}
2135impl LetStmt { 1093impl LetStmt {
2136 pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) } 1094 pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) }
2137 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 1095 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
1096 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
2138 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } 1097 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
2139 pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) } 1098 pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) }
2140 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 1099 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
2141} 1100}
2142/// Condition of `if` or `while` expression.
2143///
2144/// ```
2145/// if ❰ true ❱ {}
2146/// if ❰ let Pat(foo) = bar ❱ {}
2147///
2148/// while ❰ true ❱ {}
2149/// while ❰ let Pat(baz) = bruh ❱ {}
2150/// ```
2151///
2152/// [If expression reference](https://doc.rust-lang.org/reference/expressions/if-expr.html)
2153/// [While expression reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-loops)
2154#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2155pub struct Condition {
2156 pub(crate) syntax: SyntaxNode,
2157}
2158impl Condition {
2159 pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) }
2160 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
2161 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
2162 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
2163}
2164/// Parameter list **declaration**.
2165///
2166/// ```
2167/// fn foo❰ (a: u32, b: bool) ❱ -> u32 {}
2168/// let bar = ❰ |a, b| ❱ {};
2169///
2170/// impl Baz {
2171/// fn bruh❰ (&self, a: u32) ❱ {}
2172/// }
2173/// ```
2174///
2175/// [Reference](https://doc.rust-lang.org/reference/items/functions.html)ocs to codegen script
2176#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2177pub struct ParamList {
2178 pub(crate) syntax: SyntaxNode,
2179}
2180impl ParamList {
2181 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
2182 pub fn self_param(&self) -> Option<SelfParam> { support::child(&self.syntax) }
2183 pub fn params(&self) -> AstChildren<Param> { support::children(&self.syntax) }
2184 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
2185}
2186/// Self parameter **declaration**.
2187///
2188/// ```
2189/// impl Bruh {
2190/// fn foo(❰ self ❱) {}
2191/// fn bar(❰ &self ❱) {}
2192/// fn baz(❰ &mut self ❱) {}
2193/// fn blah<'a>(❰ &'a self ❱) {}
2194/// fn blin(❰ self: Box<Self> ❱) {}
2195/// }
2196/// ```
2197///
2198/// [Reference](https://doc.rust-lang.org/reference/items/functions.html)
2199#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1101#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2200pub struct SelfParam { 1102pub struct SelfParam {
2201 pub(crate) syntax: SyntaxNode, 1103 pub(crate) syntax: SyntaxNode,
2202} 1104}
2203impl ast::TypeAscriptionOwner for SelfParam {}
2204impl ast::AttrsOwner for SelfParam {} 1105impl ast::AttrsOwner for SelfParam {}
1106impl ast::TypeAscriptionOwner for SelfParam {}
2205impl SelfParam { 1107impl SelfParam {
2206 pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) } 1108 pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) }
2207 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
2208 pub fn lifetime_token(&self) -> Option<SyntaxToken> { 1109 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
2209 support::token(&self.syntax, T![lifetime]) 1110 support::token(&self.syntax, T![lifetime])
2210 } 1111 }
1112 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
2211 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) } 1113 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) }
1114 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
2212} 1115}
2213/// Parameter **declaration**.
2214///
2215/// ```
2216/// fn foo(❰ #[attr] Pat(bar): Pat(u32) ❱, ❰ #[attr] _: bool ❱) {}
2217///
2218/// extern "C" {
2219/// fn bar(❰ baz: u32 ❱, ❰ ... ❱) -> u32;
2220/// }
2221/// ```
2222///
2223/// [Reference](https://doc.rust-lang.org/reference/items/functions.html)
2224#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1116#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2225pub struct Param { 1117pub struct Param {
2226 pub(crate) syntax: SyntaxNode, 1118 pub(crate) syntax: SyntaxNode,
2227} 1119}
2228impl ast::TypeAscriptionOwner for Param {}
2229impl ast::AttrsOwner for Param {} 1120impl ast::AttrsOwner for Param {}
1121impl ast::TypeAscriptionOwner for Param {}
2230impl Param { 1122impl Param {
2231 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 1123 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
1124 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
2232 pub fn dotdotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![...]) } 1125 pub fn dotdotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![...]) }
2233} 1126}
2234/// Use declaration.
2235///
2236/// ```
2237/// ❰ #[attr] pub use foo; ❱
2238/// ❰ use bar as baz; ❱
2239/// ❰ use bruh::{self, bruuh}; ❱
2240/// ❰ use { blin::blen, blah::* };
2241/// ```
2242///
2243/// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html)
2244#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1127#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2245pub struct UseItem { 1128pub struct UseItem {
2246 pub(crate) syntax: SyntaxNode, 1129 pub(crate) syntax: SyntaxNode,
@@ -2250,53 +1133,19 @@ impl ast::VisibilityOwner for UseItem {}
2250impl UseItem { 1133impl UseItem {
2251 pub fn use_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![use]) } 1134 pub fn use_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![use]) }
2252 pub fn use_tree(&self) -> Option<UseTree> { support::child(&self.syntax) } 1135 pub fn use_tree(&self) -> Option<UseTree> { support::child(&self.syntax) }
1136 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
2253} 1137}
2254/// Use tree.
2255///
2256/// ```
2257/// pub use ❰ foo::❰ * ❱ ❱;
2258/// use ❰ bar as baz ❱;
2259/// use ❰ bruh::bruuh::{ ❰ self ❱, ❰ blin ❱ } ❱;
2260/// use ❰ { ❰ blin::blen ❱ } ❱
2261/// ```
2262///
2263/// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html)
2264#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1138#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2265pub struct UseTree { 1139pub struct UseTree {
2266 pub(crate) syntax: SyntaxNode, 1140 pub(crate) syntax: SyntaxNode,
2267} 1141}
2268impl UseTree { 1142impl UseTree {
2269 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } 1143 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
1144 pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) }
2270 pub fn star_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![*]) } 1145 pub fn star_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![*]) }
2271 pub fn use_tree_list(&self) -> Option<UseTreeList> { support::child(&self.syntax) } 1146 pub fn use_tree_list(&self) -> Option<UseTreeList> { support::child(&self.syntax) }
2272 pub fn alias(&self) -> Option<Alias> { support::child(&self.syntax) } 1147 pub fn alias(&self) -> Option<Alias> { support::child(&self.syntax) }
2273} 1148}
2274/// Item alias.
2275/// Note: this is not the type alias.
2276///
2277/// ```
2278/// use foo ❰ as bar ❱;
2279/// use baz::{bruh ❰ as _ ❱};
2280/// extern crate bruuh ❰ as blin ❱;
2281/// ```
2282///
2283/// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html)
2284#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2285pub struct Alias {
2286 pub(crate) syntax: SyntaxNode,
2287}
2288impl ast::NameOwner for Alias {}
2289impl Alias {
2290 pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) }
2291}
2292/// Sublist of use trees.
2293///
2294/// ```
2295/// use bruh::bruuh::❰ { ❰ self ❱, ❰ blin ❱ } ❱;
2296/// use ❰ { blin::blen::❰ {} ❱ } ❱
2297/// ```
2298///
2299/// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html)
2300#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1149#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2301pub struct UseTreeList { 1150pub struct UseTreeList {
2302 pub(crate) syntax: SyntaxNode, 1151 pub(crate) syntax: SyntaxNode,
@@ -2306,14 +1155,14 @@ impl UseTreeList {
2306 pub fn use_trees(&self) -> AstChildren<UseTree> { support::children(&self.syntax) } 1155 pub fn use_trees(&self) -> AstChildren<UseTree> { support::children(&self.syntax) }
2307 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } 1156 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
2308} 1157}
2309/// Extern crate item. 1158#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2310/// 1159pub struct Alias {
2311/// ``` 1160 pub(crate) syntax: SyntaxNode,
2312/// ❰ #[attr] pub extern crate foo; ❱ 1161}
2313/// ❰ extern crate self as bar; ❱ 1162impl ast::NameOwner for Alias {}
2314/// ``` 1163impl Alias {
2315/// 1164 pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) }
2316/// [Reference](https://doc.rust-lang.org/reference/items/extern-crates.html) 1165}
2317#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1166#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2318pub struct ExternCrateItem { 1167pub struct ExternCrateItem {
2319 pub(crate) syntax: SyntaxNode, 1168 pub(crate) syntax: SyntaxNode,
@@ -2324,59 +1173,10 @@ impl ExternCrateItem {
2324 pub fn extern_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![extern]) } 1173 pub fn extern_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![extern]) }
2325 pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) } 1174 pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) }
2326 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } 1175 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
1176 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) }
2327 pub fn alias(&self) -> Option<Alias> { support::child(&self.syntax) } 1177 pub fn alias(&self) -> Option<Alias> { support::child(&self.syntax) }
1178 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
2328} 1179}
2329/// Call site arguments list.
2330///
2331/// ```
2332/// foo::<T, U>❰ (42, true) ❱;
2333/// ```
2334///
2335/// [Reference](https://doc.rust-lang.org/reference/expressions/call-expr.html)
2336#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2337pub struct ArgList {
2338 pub(crate) syntax: SyntaxNode,
2339}
2340impl ArgList {
2341 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
2342 pub fn args(&self) -> AstChildren<Expr> { support::children(&self.syntax) }
2343 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
2344}
2345/// Path to a symbol. Includes single identifier names and elaborate paths with
2346/// generic parameters.
2347///
2348/// ```
2349/// (0..10).❰ ❰ collect ❱ ::<Vec<_>> ❱();
2350/// ❰ ❰ ❰ Vec ❱ ::<u8> ❱ ::with_capacity ❱(1024);
2351/// ❰ ❰ <❰ Foo ❱ as ❰ ❰ bar ❱ ::Bar ❱> ❱ ::baz ❱();
2352/// ❰ ❰ <❰ bruh ❱> ❱ ::bruuh ❱();
2353/// ```
2354///
2355/// [Reference](https://doc.rust-lang.org/reference/paths.html)
2356#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2357pub struct Path {
2358 pub(crate) syntax: SyntaxNode,
2359}
2360impl Path {
2361 pub fn segment(&self) -> Option<PathSegment> { support::child(&self.syntax) }
2362 pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) }
2363 pub fn qualifier(&self) -> Option<Path> { support::child(&self.syntax) }
2364}
2365/// Segment of the path to a symbol.
2366/// Only path segment of an absolute path holds the `::` token,
2367/// all other `::` tokens that connect path segments reside under `Path` itself.`
2368///
2369/// ```
2370/// (0..10).❰ collect ❱ :: ❰ <Vec<_>> ❱();
2371/// ❰ Vec ❱ :: ❰ <u8> ❱ :: ❰ with_capacity ❱(1024);
2372/// ❰ <❰ Foo ❱ as ❰ bar ❱ :: ❰ Bar ❱> ❱ :: ❰ baz ❱();
2373/// ❰ <❰ bruh ❱> ❱ :: ❰ bruuh ❱();
2374///
2375/// // Note that only in this case `::` token is inlcuded:
2376/// ❰ ::foo ❱;
2377/// ```
2378///
2379/// [Reference](https://doc.rust-lang.org/reference/paths.html)
2380#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1180#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2381pub struct PathSegment { 1181pub struct PathSegment {
2382 pub(crate) syntax: SyntaxNode, 1182 pub(crate) syntax: SyntaxNode,
@@ -2394,50 +1194,22 @@ impl PathSegment {
2394 pub fn path_type(&self) -> Option<PathType> { support::child(&self.syntax) } 1194 pub fn path_type(&self) -> Option<PathType> { support::child(&self.syntax) }
2395 pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) } 1195 pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) }
2396} 1196}
2397/// List of type arguments that are passed at generic instantiation site.
2398///
2399/// ```
2400/// type _ = Foo ❰ ::<'a, u64, Item = Bar, 42, {true}> ❱::Bar;
2401///
2402/// Vec❰ ::<bool> ❱::();
2403/// ```
2404///
2405/// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions)
2406#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1197#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2407pub struct TypeArgList { 1198pub struct TypeArg {
2408 pub(crate) syntax: SyntaxNode, 1199 pub(crate) syntax: SyntaxNode,
2409} 1200}
2410impl TypeArgList { 1201impl TypeArg {
2411 pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) } 1202 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
2412 pub fn l_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![<]) }
2413 pub fn generic_args(&self) -> AstChildren<GenericArg> { support::children(&self.syntax) }
2414 pub fn type_args(&self) -> AstChildren<TypeArg> { support::children(&self.syntax) }
2415 pub fn lifetime_args(&self) -> AstChildren<LifetimeArg> { support::children(&self.syntax) }
2416 pub fn assoc_type_args(&self) -> AstChildren<AssocTypeArg> { support::children(&self.syntax) }
2417 pub fn const_args(&self) -> AstChildren<ConstArg> { support::children(&self.syntax) }
2418 pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) }
2419} 1203}
2420/// Type argument that is passed at generic instantiation site.
2421///
2422/// ```
2423/// type _ = Foo::<'a, ❰ u64 ❱, ❰ bool ❱, Item = Bar, 42>::Baz;
2424/// ```
2425///
2426/// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions)
2427#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1204#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2428pub struct TypeArg { 1205pub struct LifetimeArg {
2429 pub(crate) syntax: SyntaxNode, 1206 pub(crate) syntax: SyntaxNode,
2430} 1207}
2431impl TypeArg { 1208impl LifetimeArg {
2432 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 1209 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
1210 support::token(&self.syntax, T![lifetime])
1211 }
2433} 1212}
2434/// Associated type argument that is passed at generic instantiation site.
2435/// ```
2436/// type Foo = Bar::<'a, u64, bool, ❰ Item = Baz ❱, 42>::Bruh;
2437///
2438/// trait Bruh<T>: Iterator<❰ Item: Debug ❱> {}
2439/// ```
2440///
2441#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1213#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2442pub struct AssocTypeArg { 1214pub struct AssocTypeArg {
2443 pub(crate) syntax: SyntaxNode, 1215 pub(crate) syntax: SyntaxNode,
@@ -2448,33 +1220,6 @@ impl AssocTypeArg {
2448 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } 1220 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
2449 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 1221 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
2450} 1222}
2451/// Lifetime argument that is passed at generic instantiation site.
2452///
2453/// ```
2454/// fn foo<'a>(s: &'a str) {
2455/// bar::<❰ 'a ❱>(s);
2456/// }
2457/// ```
2458///
2459/// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions)
2460#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2461pub struct LifetimeArg {
2462 pub(crate) syntax: SyntaxNode,
2463}
2464impl LifetimeArg {
2465 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
2466 support::token(&self.syntax, T![lifetime])
2467 }
2468}
2469/// Constant value argument that is passed at generic instantiation site.
2470///
2471/// ```
2472/// foo::<u32, ❰ { true } ❱>();
2473///
2474/// bar::<❰ { 2 + 2} ❱>();
2475/// ```
2476///
2477/// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/2000-const-generics.md#declaring-a-const-parameter)
2478#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1223#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2479pub struct ConstArg { 1224pub struct ConstArg {
2480 pub(crate) syntax: SyntaxNode, 1225 pub(crate) syntax: SyntaxNode,
@@ -2483,83 +1228,24 @@ impl ConstArg {
2483 pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) } 1228 pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) }
2484 pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) } 1229 pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) }
2485} 1230}
2486/// FIXME: (@edwin0cheng) Remove it to use ItemList instead
2487/// https://github.com/rust-analyzer/rust-analyzer/pull/4083#discussion_r422666243
2488///
2489/// [Reference](https://doc.rust-lang.org/reference/macros.html)
2490#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2491pub struct MacroItems {
2492 pub(crate) syntax: SyntaxNode,
2493}
2494impl ast::ModuleItemOwner for MacroItems {}
2495impl MacroItems {}
2496/// FIXME: (@edwin0cheng) add some documentation here. As per the writing
2497/// of this comment this ast node is not used.
2498///
2499/// ```
2500/// // FIXME: example here
2501/// ```
2502///
2503/// [Reference](https://doc.rust-lang.org/reference/macros.html)
2504#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1231#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2505pub struct MacroStmts { 1232pub struct ExternBlock {
2506 pub(crate) syntax: SyntaxNode, 1233 pub(crate) syntax: SyntaxNode,
2507} 1234}
2508impl MacroStmts { 1235impl ast::AttrsOwner for ExternBlock {}
2509 pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) } 1236impl ExternBlock {
2510 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 1237 pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) }
1238 pub fn extern_item_list(&self) -> Option<ExternItemList> { support::child(&self.syntax) }
2511} 1239}
2512/// List of items in an extern block.
2513///
2514/// ```
2515/// extern "C" ❰
2516/// {
2517/// fn foo();
2518/// static var: u32;
2519/// }
2520/// ❱
2521/// ```
2522///
2523/// [Reference](https://doc.rust-lang.org/reference/items/external-blocks.html)
2524#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1240#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2525pub struct ExternItemList { 1241pub struct ExternItemList {
2526 pub(crate) syntax: SyntaxNode, 1242 pub(crate) syntax: SyntaxNode,
2527} 1243}
2528impl ast::ModuleItemOwner for ExternItemList {}
2529impl ExternItemList { 1244impl ExternItemList {
2530 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } 1245 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
2531 pub fn extern_items(&self) -> AstChildren<ExternItem> { support::children(&self.syntax) } 1246 pub fn extern_items(&self) -> AstChildren<ExternItem> { support::children(&self.syntax) }
2532 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } 1247 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
2533} 1248}
2534/// Extern block.
2535///
2536/// ```
2537/// ❰
2538/// extern "C" {
2539/// fn foo();
2540/// }
2541/// ❱
2542///
2543/// ```
2544///
2545/// [Reference](https://doc.rust-lang.org/reference/items/external-blocks.html)
2546#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2547pub struct ExternBlock {
2548 pub(crate) syntax: SyntaxNode,
2549}
2550impl ExternBlock {
2551 pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) }
2552 pub fn extern_item_list(&self) -> Option<ExternItemList> { support::child(&self.syntax) }
2553}
2554/// Meta item in an attribute.
2555///
2556/// ```
2557/// #[❰ bar::baz = "42" ❱]
2558/// #[❰ bruh(bruuh("true")) ❱]
2559/// struct Foo;
2560/// ```
2561///
2562/// [Reference](https://doc.rust-lang.org/reference/attributes.html?highlight=meta,item#meta-item-attribute-syntax)
2563#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1249#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2564pub struct MetaItem { 1250pub struct MetaItem {
2565 pub(crate) syntax: SyntaxNode, 1251 pub(crate) syntax: SyntaxNode,
@@ -2570,59 +1256,6 @@ impl MetaItem {
2570 pub fn attr_input(&self) -> Option<AttrInput> { support::child(&self.syntax) } 1256 pub fn attr_input(&self) -> Option<AttrInput> { support::child(&self.syntax) }
2571 pub fn nested_meta_items(&self) -> AstChildren<MetaItem> { support::children(&self.syntax) } 1257 pub fn nested_meta_items(&self) -> AstChildren<MetaItem> { support::children(&self.syntax) }
2572} 1258}
2573/// Macro 2.0 definition.
2574/// Their syntax is still WIP by rustc team...
2575/// ```
2576/// ❰
2577/// macro foo { }
2578/// ❱
2579/// ```
2580///
2581/// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/1584-macros.md)
2582#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2583pub struct MacroDef {
2584 pub(crate) syntax: SyntaxNode,
2585}
2586impl MacroDef {
2587 pub fn name(&self) -> Option<Name> { support::child(&self.syntax) }
2588 pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) }
2589}
2590/// Any kind of nominal type definition.
2591#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2592pub enum NominalDef {
2593 StructDef(StructDef),
2594 EnumDef(EnumDef),
2595 UnionDef(UnionDef),
2596}
2597impl ast::NameOwner for NominalDef {}
2598impl ast::TypeParamsOwner for NominalDef {}
2599impl ast::AttrsOwner for NominalDef {}
2600/// Any kind of generic argument passed at instantiation site
2601#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2602pub enum GenericArg {
2603 LifetimeArg(LifetimeArg),
2604 TypeArg(TypeArg),
2605 ConstArg(ConstArg),
2606 AssocTypeArg(AssocTypeArg),
2607}
2608/// Any kind of construct valid in type context
2609#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2610pub enum TypeRef {
2611 ParenType(ParenType),
2612 TupleType(TupleType),
2613 NeverType(NeverType),
2614 PathType(PathType),
2615 PointerType(PointerType),
2616 ArrayType(ArrayType),
2617 SliceType(SliceType),
2618 ReferenceType(ReferenceType),
2619 PlaceholderType(PlaceholderType),
2620 FnPointerType(FnPointerType),
2621 ForType(ForType),
2622 ImplTraitType(ImplTraitType),
2623 DynTraitType(DynTraitType),
2624}
2625/// Any kind of top-level item that may appear in a module
2626#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1259#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2627pub enum ModuleItem { 1260pub enum ModuleItem {
2628 StructDef(StructDef), 1261 StructDef(StructDef),
@@ -2640,32 +1273,28 @@ pub enum ModuleItem {
2640 MacroCall(MacroCall), 1273 MacroCall(MacroCall),
2641 ExternBlock(ExternBlock), 1274 ExternBlock(ExternBlock),
2642} 1275}
2643impl ast::NameOwner for ModuleItem {}
2644impl ast::AttrsOwner for ModuleItem {} 1276impl ast::AttrsOwner for ModuleItem {}
2645impl ast::VisibilityOwner for ModuleItem {}
2646/// Any kind of item that may appear in an impl block
2647///
2648/// // FIXME: impl blocks can also contain MacroCall
2649#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1277#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2650pub enum AssocItem { 1278pub enum TypeRef {
2651 FnDef(FnDef), 1279 ParenType(ParenType),
2652 TypeAliasDef(TypeAliasDef), 1280 TupleType(TupleType),
2653 ConstDef(ConstDef), 1281 NeverType(NeverType),
1282 PathType(PathType),
1283 PointerType(PointerType),
1284 ArrayType(ArrayType),
1285 SliceType(SliceType),
1286 ReferenceType(ReferenceType),
1287 PlaceholderType(PlaceholderType),
1288 FnPointerType(FnPointerType),
1289 ForType(ForType),
1290 ImplTraitType(ImplTraitType),
1291 DynTraitType(DynTraitType),
2654} 1292}
2655impl ast::NameOwner for AssocItem {}
2656impl ast::AttrsOwner for AssocItem {}
2657/// Any kind of item that may appear in an extern block
2658///
2659/// // FIXME: extern blocks can also contain MacroCall
2660#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1293#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2661pub enum ExternItem { 1294pub enum FieldDefList {
2662 FnDef(FnDef), 1295 RecordFieldDefList(RecordFieldDefList),
2663 StaticDef(StaticDef), 1296 TupleFieldDefList(TupleFieldDefList),
2664} 1297}
2665impl ast::NameOwner for ExternItem {}
2666impl ast::AttrsOwner for ExternItem {}
2667impl ast::VisibilityOwner for ExternItem {}
2668/// Any kind of expression
2669#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1298#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2670pub enum Expr { 1299pub enum Expr {
2671 TupleExpr(TupleExpr), 1300 TupleExpr(TupleExpr),
@@ -2700,8 +1329,15 @@ pub enum Expr {
2700 MacroCall(MacroCall), 1329 MacroCall(MacroCall),
2701 BoxExpr(BoxExpr), 1330 BoxExpr(BoxExpr),
2702} 1331}
2703impl ast::AttrsOwner for Expr {} 1332#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2704/// Any kind of pattern 1333pub enum AssocItem {
1334 FnDef(FnDef),
1335 TypeAliasDef(TypeAliasDef),
1336 ConstDef(ConstDef),
1337}
1338impl ast::AttrsOwner for AssocItem {}
1339impl ast::NameOwner for AssocItem {}
1340impl ast::VisibilityOwner for AssocItem {}
2705#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1341#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2706pub enum Pat { 1342pub enum Pat {
2707 OrPat(OrPat), 1343 OrPat(OrPat),
@@ -2720,26 +1356,35 @@ pub enum Pat {
2720 LiteralPat(LiteralPat), 1356 LiteralPat(LiteralPat),
2721 MacroPat(MacroPat), 1357 MacroPat(MacroPat),
2722} 1358}
2723/// Any kind of input to an attribute 1359#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1360pub enum Stmt {
1361 LetStmt(LetStmt),
1362 ExprStmt(ExprStmt),
1363}
1364impl ast::AttrsOwner for Stmt {}
2724#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1365#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2725pub enum AttrInput { 1366pub enum AttrInput {
2726 Literal(Literal), 1367 Literal(Literal),
2727 TokenTree(TokenTree), 1368 TokenTree(TokenTree),
2728} 1369}
2729/// Any kind of statement
2730/// Note: there are no empty statements, these are just represented as
2731/// bare semicolons without a dedicated statement ast node.
2732#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1370#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2733pub enum Stmt { 1371pub enum ExternItem {
2734 LetStmt(LetStmt), 1372 FnDef(FnDef),
2735 ExprStmt(ExprStmt), 1373 StaticDef(StaticDef),
2736} 1374}
2737/// Any kind of fields list (record or tuple field lists) 1375impl ast::AttrsOwner for ExternItem {}
1376impl ast::NameOwner for ExternItem {}
1377impl ast::VisibilityOwner for ExternItem {}
2738#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1378#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2739pub enum FieldDefList { 1379pub enum NominalDef {
2740 RecordFieldDefList(RecordFieldDefList), 1380 StructDef(StructDef),
2741 TupleFieldDefList(TupleFieldDefList), 1381 EnumDef(EnumDef),
1382 UnionDef(UnionDef),
2742} 1383}
1384impl ast::AttrsOwner for NominalDef {}
1385impl ast::NameOwner for NominalDef {}
1386impl ast::TypeParamsOwner for NominalDef {}
1387impl ast::VisibilityOwner for NominalDef {}
2743impl AstNode for SourceFile { 1388impl AstNode for SourceFile {
2744 fn can_cast(kind: SyntaxKind) -> bool { kind == SOURCE_FILE } 1389 fn can_cast(kind: SyntaxKind) -> bool { kind == SOURCE_FILE }
2745 fn cast(syntax: SyntaxNode) -> Option<Self> { 1390 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -2751,6 +1396,17 @@ impl AstNode for SourceFile {
2751 } 1396 }
2752 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1397 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2753} 1398}
1399impl AstNode for Attr {
1400 fn can_cast(kind: SyntaxKind) -> bool { kind == ATTR }
1401 fn cast(syntax: SyntaxNode) -> Option<Self> {
1402 if Self::can_cast(syntax.kind()) {
1403 Some(Self { syntax })
1404 } else {
1405 None
1406 }
1407 }
1408 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1409}
2754impl AstNode for FnDef { 1410impl AstNode for FnDef {
2755 fn can_cast(kind: SyntaxKind) -> bool { kind == FN_DEF } 1411 fn can_cast(kind: SyntaxKind) -> bool { kind == FN_DEF }
2756 fn cast(syntax: SyntaxNode) -> Option<Self> { 1412 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -2762,6 +1418,61 @@ impl AstNode for FnDef {
2762 } 1418 }
2763 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1419 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2764} 1420}
1421impl AstNode for Visibility {
1422 fn can_cast(kind: SyntaxKind) -> bool { kind == VISIBILITY }
1423 fn cast(syntax: SyntaxNode) -> Option<Self> {
1424 if Self::can_cast(syntax.kind()) {
1425 Some(Self { syntax })
1426 } else {
1427 None
1428 }
1429 }
1430 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1431}
1432impl AstNode for Abi {
1433 fn can_cast(kind: SyntaxKind) -> bool { kind == ABI }
1434 fn cast(syntax: SyntaxNode) -> Option<Self> {
1435 if Self::can_cast(syntax.kind()) {
1436 Some(Self { syntax })
1437 } else {
1438 None
1439 }
1440 }
1441 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1442}
1443impl AstNode for Name {
1444 fn can_cast(kind: SyntaxKind) -> bool { kind == NAME }
1445 fn cast(syntax: SyntaxNode) -> Option<Self> {
1446 if Self::can_cast(syntax.kind()) {
1447 Some(Self { syntax })
1448 } else {
1449 None
1450 }
1451 }
1452 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1453}
1454impl AstNode for TypeParamList {
1455 fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_PARAM_LIST }
1456 fn cast(syntax: SyntaxNode) -> Option<Self> {
1457 if Self::can_cast(syntax.kind()) {
1458 Some(Self { syntax })
1459 } else {
1460 None
1461 }
1462 }
1463 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1464}
1465impl AstNode for ParamList {
1466 fn can_cast(kind: SyntaxKind) -> bool { kind == PARAM_LIST }
1467 fn cast(syntax: SyntaxNode) -> Option<Self> {
1468 if Self::can_cast(syntax.kind()) {
1469 Some(Self { syntax })
1470 } else {
1471 None
1472 }
1473 }
1474 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1475}
2765impl AstNode for RetType { 1476impl AstNode for RetType {
2766 fn can_cast(kind: SyntaxKind) -> bool { kind == RET_TYPE } 1477 fn can_cast(kind: SyntaxKind) -> bool { kind == RET_TYPE }
2767 fn cast(syntax: SyntaxNode) -> Option<Self> { 1478 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -2773,8 +1484,8 @@ impl AstNode for RetType {
2773 } 1484 }
2774 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1485 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2775} 1486}
2776impl AstNode for StructDef { 1487impl AstNode for WhereClause {
2777 fn can_cast(kind: SyntaxKind) -> bool { kind == STRUCT_DEF } 1488 fn can_cast(kind: SyntaxKind) -> bool { kind == WHERE_CLAUSE }
2778 fn cast(syntax: SyntaxNode) -> Option<Self> { 1489 fn cast(syntax: SyntaxNode) -> Option<Self> {
2779 if Self::can_cast(syntax.kind()) { 1490 if Self::can_cast(syntax.kind()) {
2780 Some(Self { syntax }) 1491 Some(Self { syntax })
@@ -2784,8 +1495,8 @@ impl AstNode for StructDef {
2784 } 1495 }
2785 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1496 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2786} 1497}
2787impl AstNode for UnionDef { 1498impl AstNode for BlockExpr {
2788 fn can_cast(kind: SyntaxKind) -> bool { kind == UNION_DEF } 1499 fn can_cast(kind: SyntaxKind) -> bool { kind == BLOCK_EXPR }
2789 fn cast(syntax: SyntaxNode) -> Option<Self> { 1500 fn cast(syntax: SyntaxNode) -> Option<Self> {
2790 if Self::can_cast(syntax.kind()) { 1501 if Self::can_cast(syntax.kind()) {
2791 Some(Self { syntax }) 1502 Some(Self { syntax })
@@ -2795,8 +1506,8 @@ impl AstNode for UnionDef {
2795 } 1506 }
2796 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1507 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2797} 1508}
2798impl AstNode for RecordFieldDefList { 1509impl AstNode for StructDef {
2799 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_DEF_LIST } 1510 fn can_cast(kind: SyntaxKind) -> bool { kind == STRUCT_DEF }
2800 fn cast(syntax: SyntaxNode) -> Option<Self> { 1511 fn cast(syntax: SyntaxNode) -> Option<Self> {
2801 if Self::can_cast(syntax.kind()) { 1512 if Self::can_cast(syntax.kind()) {
2802 Some(Self { syntax }) 1513 Some(Self { syntax })
@@ -2806,8 +1517,8 @@ impl AstNode for RecordFieldDefList {
2806 } 1517 }
2807 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1518 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2808} 1519}
2809impl AstNode for RecordFieldDef { 1520impl AstNode for RecordFieldDefList {
2810 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_DEF } 1521 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_DEF_LIST }
2811 fn cast(syntax: SyntaxNode) -> Option<Self> { 1522 fn cast(syntax: SyntaxNode) -> Option<Self> {
2812 if Self::can_cast(syntax.kind()) { 1523 if Self::can_cast(syntax.kind()) {
2813 Some(Self { syntax }) 1524 Some(Self { syntax })
@@ -2828,6 +1539,28 @@ impl AstNode for TupleFieldDefList {
2828 } 1539 }
2829 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1540 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2830} 1541}
1542impl AstNode for UnionDef {
1543 fn can_cast(kind: SyntaxKind) -> bool { kind == UNION_DEF }
1544 fn cast(syntax: SyntaxNode) -> Option<Self> {
1545 if Self::can_cast(syntax.kind()) {
1546 Some(Self { syntax })
1547 } else {
1548 None
1549 }
1550 }
1551 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1552}
1553impl AstNode for RecordFieldDef {
1554 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_DEF }
1555 fn cast(syntax: SyntaxNode) -> Option<Self> {
1556 if Self::can_cast(syntax.kind()) {
1557 Some(Self { syntax })
1558 } else {
1559 None
1560 }
1561 }
1562 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1563}
2831impl AstNode for TupleFieldDef { 1564impl AstNode for TupleFieldDef {
2832 fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_FIELD_DEF } 1565 fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_FIELD_DEF }
2833 fn cast(syntax: SyntaxNode) -> Option<Self> { 1566 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -2883,8 +1616,8 @@ impl AstNode for TraitDef {
2883 } 1616 }
2884 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1617 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2885} 1618}
2886impl AstNode for Module { 1619impl AstNode for TypeBoundList {
2887 fn can_cast(kind: SyntaxKind) -> bool { kind == MODULE } 1620 fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_BOUND_LIST }
2888 fn cast(syntax: SyntaxNode) -> Option<Self> { 1621 fn cast(syntax: SyntaxNode) -> Option<Self> {
2889 if Self::can_cast(syntax.kind()) { 1622 if Self::can_cast(syntax.kind()) {
2890 Some(Self { syntax }) 1623 Some(Self { syntax })
@@ -2905,6 +1638,17 @@ impl AstNode for ItemList {
2905 } 1638 }
2906 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1639 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2907} 1640}
1641impl AstNode for Module {
1642 fn can_cast(kind: SyntaxKind) -> bool { kind == MODULE }
1643 fn cast(syntax: SyntaxNode) -> Option<Self> {
1644 if Self::can_cast(syntax.kind()) {
1645 Some(Self { syntax })
1646 } else {
1647 None
1648 }
1649 }
1650 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1651}
2908impl AstNode for ConstDef { 1652impl AstNode for ConstDef {
2909 fn can_cast(kind: SyntaxKind) -> bool { kind == CONST_DEF } 1653 fn can_cast(kind: SyntaxKind) -> bool { kind == CONST_DEF }
2910 fn cast(syntax: SyntaxNode) -> Option<Self> { 1654 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -2993,6 +1737,17 @@ impl AstNode for PathType {
2993 } 1737 }
2994 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1738 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2995} 1739}
1740impl AstNode for Path {
1741 fn can_cast(kind: SyntaxKind) -> bool { kind == PATH }
1742 fn cast(syntax: SyntaxNode) -> Option<Self> {
1743 if Self::can_cast(syntax.kind()) {
1744 Some(Self { syntax })
1745 } else {
1746 None
1747 }
1748 }
1749 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1750}
2996impl AstNode for PointerType { 1751impl AstNode for PointerType {
2997 fn can_cast(kind: SyntaxKind) -> bool { kind == POINTER_TYPE } 1752 fn can_cast(kind: SyntaxKind) -> bool { kind == POINTER_TYPE }
2998 fn cast(syntax: SyntaxNode) -> Option<Self> { 1753 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -3158,8 +1913,8 @@ impl AstNode for IfExpr {
3158 } 1913 }
3159 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1914 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3160} 1915}
3161impl AstNode for LoopExpr { 1916impl AstNode for Condition {
3162 fn can_cast(kind: SyntaxKind) -> bool { kind == LOOP_EXPR } 1917 fn can_cast(kind: SyntaxKind) -> bool { kind == CONDITION }
3163 fn cast(syntax: SyntaxNode) -> Option<Self> { 1918 fn cast(syntax: SyntaxNode) -> Option<Self> {
3164 if Self::can_cast(syntax.kind()) { 1919 if Self::can_cast(syntax.kind()) {
3165 Some(Self { syntax }) 1920 Some(Self { syntax })
@@ -3180,6 +1935,28 @@ impl AstNode for EffectExpr {
3180 } 1935 }
3181 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1936 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3182} 1937}
1938impl AstNode for Label {
1939 fn can_cast(kind: SyntaxKind) -> bool { kind == LABEL }
1940 fn cast(syntax: SyntaxNode) -> Option<Self> {
1941 if Self::can_cast(syntax.kind()) {
1942 Some(Self { syntax })
1943 } else {
1944 None
1945 }
1946 }
1947 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1948}
1949impl AstNode for LoopExpr {
1950 fn can_cast(kind: SyntaxKind) -> bool { kind == LOOP_EXPR }
1951 fn cast(syntax: SyntaxNode) -> Option<Self> {
1952 if Self::can_cast(syntax.kind()) {
1953 Some(Self { syntax })
1954 } else {
1955 None
1956 }
1957 }
1958 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1959}
3183impl AstNode for ForExpr { 1960impl AstNode for ForExpr {
3184 fn can_cast(kind: SyntaxKind) -> bool { kind == FOR_EXPR } 1961 fn can_cast(kind: SyntaxKind) -> bool { kind == FOR_EXPR }
3185 fn cast(syntax: SyntaxNode) -> Option<Self> { 1962 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -3224,8 +2001,8 @@ impl AstNode for BreakExpr {
3224 } 2001 }
3225 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2002 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3226} 2003}
3227impl AstNode for Label { 2004impl AstNode for ReturnExpr {
3228 fn can_cast(kind: SyntaxKind) -> bool { kind == LABEL } 2005 fn can_cast(kind: SyntaxKind) -> bool { kind == RETURN_EXPR }
3229 fn cast(syntax: SyntaxNode) -> Option<Self> { 2006 fn cast(syntax: SyntaxNode) -> Option<Self> {
3230 if Self::can_cast(syntax.kind()) { 2007 if Self::can_cast(syntax.kind()) {
3231 Some(Self { syntax }) 2008 Some(Self { syntax })
@@ -3235,8 +2012,8 @@ impl AstNode for Label {
3235 } 2012 }
3236 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2013 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3237} 2014}
3238impl AstNode for BlockExpr { 2015impl AstNode for CallExpr {
3239 fn can_cast(kind: SyntaxKind) -> bool { kind == BLOCK_EXPR } 2016 fn can_cast(kind: SyntaxKind) -> bool { kind == CALL_EXPR }
3240 fn cast(syntax: SyntaxNode) -> Option<Self> { 2017 fn cast(syntax: SyntaxNode) -> Option<Self> {
3241 if Self::can_cast(syntax.kind()) { 2018 if Self::can_cast(syntax.kind()) {
3242 Some(Self { syntax }) 2019 Some(Self { syntax })
@@ -3246,8 +2023,8 @@ impl AstNode for BlockExpr {
3246 } 2023 }
3247 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2024 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3248} 2025}
3249impl AstNode for ReturnExpr { 2026impl AstNode for ArgList {
3250 fn can_cast(kind: SyntaxKind) -> bool { kind == RETURN_EXPR } 2027 fn can_cast(kind: SyntaxKind) -> bool { kind == ARG_LIST }
3251 fn cast(syntax: SyntaxNode) -> Option<Self> { 2028 fn cast(syntax: SyntaxNode) -> Option<Self> {
3252 if Self::can_cast(syntax.kind()) { 2029 if Self::can_cast(syntax.kind()) {
3253 Some(Self { syntax }) 2030 Some(Self { syntax })
@@ -3257,8 +2034,8 @@ impl AstNode for ReturnExpr {
3257 } 2034 }
3258 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2035 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3259} 2036}
3260impl AstNode for CallExpr { 2037impl AstNode for MethodCallExpr {
3261 fn can_cast(kind: SyntaxKind) -> bool { kind == CALL_EXPR } 2038 fn can_cast(kind: SyntaxKind) -> bool { kind == METHOD_CALL_EXPR }
3262 fn cast(syntax: SyntaxNode) -> Option<Self> { 2039 fn cast(syntax: SyntaxNode) -> Option<Self> {
3263 if Self::can_cast(syntax.kind()) { 2040 if Self::can_cast(syntax.kind()) {
3264 Some(Self { syntax }) 2041 Some(Self { syntax })
@@ -3268,8 +2045,8 @@ impl AstNode for CallExpr {
3268 } 2045 }
3269 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2046 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3270} 2047}
3271impl AstNode for MethodCallExpr { 2048impl AstNode for NameRef {
3272 fn can_cast(kind: SyntaxKind) -> bool { kind == METHOD_CALL_EXPR } 2049 fn can_cast(kind: SyntaxKind) -> bool { kind == NAME_REF }
3273 fn cast(syntax: SyntaxNode) -> Option<Self> { 2050 fn cast(syntax: SyntaxNode) -> Option<Self> {
3274 if Self::can_cast(syntax.kind()) { 2051 if Self::can_cast(syntax.kind()) {
3275 Some(Self { syntax }) 2052 Some(Self { syntax })
@@ -3279,8 +2056,8 @@ impl AstNode for MethodCallExpr {
3279 } 2056 }
3280 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2057 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3281} 2058}
3282impl AstNode for IndexExpr { 2059impl AstNode for TypeArgList {
3283 fn can_cast(kind: SyntaxKind) -> bool { kind == INDEX_EXPR } 2060 fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_ARG_LIST }
3284 fn cast(syntax: SyntaxNode) -> Option<Self> { 2061 fn cast(syntax: SyntaxNode) -> Option<Self> {
3285 if Self::can_cast(syntax.kind()) { 2062 if Self::can_cast(syntax.kind()) {
3286 Some(Self { syntax }) 2063 Some(Self { syntax })
@@ -3301,6 +2078,17 @@ impl AstNode for FieldExpr {
3301 } 2078 }
3302 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2079 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3303} 2080}
2081impl AstNode for IndexExpr {
2082 fn can_cast(kind: SyntaxKind) -> bool { kind == INDEX_EXPR }
2083 fn cast(syntax: SyntaxNode) -> Option<Self> {
2084 if Self::can_cast(syntax.kind()) {
2085 Some(Self { syntax })
2086 } else {
2087 None
2088 }
2089 }
2090 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2091}
3304impl AstNode for AwaitExpr { 2092impl AstNode for AwaitExpr {
3305 fn can_cast(kind: SyntaxKind) -> bool { kind == AWAIT_EXPR } 2093 fn can_cast(kind: SyntaxKind) -> bool { kind == AWAIT_EXPR }
3306 fn cast(syntax: SyntaxNode) -> Option<Self> { 2094 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -3609,6 +2397,17 @@ impl AstNode for MacroPat {
3609 } 2397 }
3610 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2398 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3611} 2399}
2400impl AstNode for MacroCall {
2401 fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_CALL }
2402 fn cast(syntax: SyntaxNode) -> Option<Self> {
2403 if Self::can_cast(syntax.kind()) {
2404 Some(Self { syntax })
2405 } else {
2406 None
2407 }
2408 }
2409 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2410}
3612impl AstNode for RecordPat { 2411impl AstNode for RecordPat {
3613 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_PAT } 2412 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_PAT }
3614 fn cast(syntax: SyntaxNode) -> Option<Self> { 2413 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -3664,41 +2463,8 @@ impl AstNode for TuplePat {
3664 } 2463 }
3665 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2464 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3666} 2465}
3667impl AstNode for Visibility { 2466impl AstNode for TokenTree {
3668 fn can_cast(kind: SyntaxKind) -> bool { kind == VISIBILITY } 2467 fn can_cast(kind: SyntaxKind) -> bool { kind == TOKEN_TREE }
3669 fn cast(syntax: SyntaxNode) -> Option<Self> {
3670 if Self::can_cast(syntax.kind()) {
3671 Some(Self { syntax })
3672 } else {
3673 None
3674 }
3675 }
3676 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3677}
3678impl AstNode for Name {
3679 fn can_cast(kind: SyntaxKind) -> bool { kind == NAME }
3680 fn cast(syntax: SyntaxNode) -> Option<Self> {
3681 if Self::can_cast(syntax.kind()) {
3682 Some(Self { syntax })
3683 } else {
3684 None
3685 }
3686 }
3687 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3688}
3689impl AstNode for NameRef {
3690 fn can_cast(kind: SyntaxKind) -> bool { kind == NAME_REF }
3691 fn cast(syntax: SyntaxNode) -> Option<Self> {
3692 if Self::can_cast(syntax.kind()) {
3693 Some(Self { syntax })
3694 } else {
3695 None
3696 }
3697 }
3698 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3699}
3700impl AstNode for MacroCall {
3701 fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_CALL }
3702 fn cast(syntax: SyntaxNode) -> Option<Self> { 2468 fn cast(syntax: SyntaxNode) -> Option<Self> {
3703 if Self::can_cast(syntax.kind()) { 2469 if Self::can_cast(syntax.kind()) {
3704 Some(Self { syntax }) 2470 Some(Self { syntax })
@@ -3708,8 +2474,8 @@ impl AstNode for MacroCall {
3708 } 2474 }
3709 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2475 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3710} 2476}
3711impl AstNode for Attr { 2477impl AstNode for MacroDef {
3712 fn can_cast(kind: SyntaxKind) -> bool { kind == ATTR } 2478 fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_DEF }
3713 fn cast(syntax: SyntaxNode) -> Option<Self> { 2479 fn cast(syntax: SyntaxNode) -> Option<Self> {
3714 if Self::can_cast(syntax.kind()) { 2480 if Self::can_cast(syntax.kind()) {
3715 Some(Self { syntax }) 2481 Some(Self { syntax })
@@ -3719,8 +2485,8 @@ impl AstNode for Attr {
3719 } 2485 }
3720 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2486 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3721} 2487}
3722impl AstNode for TokenTree { 2488impl AstNode for MacroItems {
3723 fn can_cast(kind: SyntaxKind) -> bool { kind == TOKEN_TREE } 2489 fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_ITEMS }
3724 fn cast(syntax: SyntaxNode) -> Option<Self> { 2490 fn cast(syntax: SyntaxNode) -> Option<Self> {
3725 if Self::can_cast(syntax.kind()) { 2491 if Self::can_cast(syntax.kind()) {
3726 Some(Self { syntax }) 2492 Some(Self { syntax })
@@ -3730,8 +2496,8 @@ impl AstNode for TokenTree {
3730 } 2496 }
3731 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2497 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3732} 2498}
3733impl AstNode for TypeParamList { 2499impl AstNode for MacroStmts {
3734 fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_PARAM_LIST } 2500 fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_STMTS }
3735 fn cast(syntax: SyntaxNode) -> Option<Self> { 2501 fn cast(syntax: SyntaxNode) -> Option<Self> {
3736 if Self::can_cast(syntax.kind()) { 2502 if Self::can_cast(syntax.kind()) {
3737 Some(Self { syntax }) 2503 Some(Self { syntax })
@@ -3752,17 +2518,6 @@ impl AstNode for TypeParam {
3752 } 2518 }
3753 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2519 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3754} 2520}
3755impl AstNode for ConstParam {
3756 fn can_cast(kind: SyntaxKind) -> bool { kind == CONST_PARAM }
3757 fn cast(syntax: SyntaxNode) -> Option<Self> {
3758 if Self::can_cast(syntax.kind()) {
3759 Some(Self { syntax })
3760 } else {
3761 None
3762 }
3763 }
3764 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3765}
3766impl AstNode for LifetimeParam { 2521impl AstNode for LifetimeParam {
3767 fn can_cast(kind: SyntaxKind) -> bool { kind == LIFETIME_PARAM } 2522 fn can_cast(kind: SyntaxKind) -> bool { kind == LIFETIME_PARAM }
3768 fn cast(syntax: SyntaxNode) -> Option<Self> { 2523 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -3774,8 +2529,8 @@ impl AstNode for LifetimeParam {
3774 } 2529 }
3775 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2530 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3776} 2531}
3777impl AstNode for TypeBound { 2532impl AstNode for ConstParam {
3778 fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_BOUND } 2533 fn can_cast(kind: SyntaxKind) -> bool { kind == CONST_PARAM }
3779 fn cast(syntax: SyntaxNode) -> Option<Self> { 2534 fn cast(syntax: SyntaxNode) -> Option<Self> {
3780 if Self::can_cast(syntax.kind()) { 2535 if Self::can_cast(syntax.kind()) {
3781 Some(Self { syntax }) 2536 Some(Self { syntax })
@@ -3785,8 +2540,8 @@ impl AstNode for TypeBound {
3785 } 2540 }
3786 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2541 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3787} 2542}
3788impl AstNode for TypeBoundList { 2543impl AstNode for TypeBound {
3789 fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_BOUND_LIST } 2544 fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_BOUND }
3790 fn cast(syntax: SyntaxNode) -> Option<Self> { 2545 fn cast(syntax: SyntaxNode) -> Option<Self> {
3791 if Self::can_cast(syntax.kind()) { 2546 if Self::can_cast(syntax.kind()) {
3792 Some(Self { syntax }) 2547 Some(Self { syntax })
@@ -3807,28 +2562,6 @@ impl AstNode for WherePred {
3807 } 2562 }
3808 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2563 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3809} 2564}
3810impl AstNode for WhereClause {
3811 fn can_cast(kind: SyntaxKind) -> bool { kind == WHERE_CLAUSE }
3812 fn cast(syntax: SyntaxNode) -> Option<Self> {
3813 if Self::can_cast(syntax.kind()) {
3814 Some(Self { syntax })
3815 } else {
3816 None
3817 }
3818 }
3819 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3820}
3821impl AstNode for Abi {
3822 fn can_cast(kind: SyntaxKind) -> bool { kind == ABI }
3823 fn cast(syntax: SyntaxNode) -> Option<Self> {
3824 if Self::can_cast(syntax.kind()) {
3825 Some(Self { syntax })
3826 } else {
3827 None
3828 }
3829 }
3830 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3831}
3832impl AstNode for ExprStmt { 2565impl AstNode for ExprStmt {
3833 fn can_cast(kind: SyntaxKind) -> bool { kind == EXPR_STMT } 2566 fn can_cast(kind: SyntaxKind) -> bool { kind == EXPR_STMT }
3834 fn cast(syntax: SyntaxNode) -> Option<Self> { 2567 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -3851,28 +2584,6 @@ impl AstNode for LetStmt {
3851 } 2584 }
3852 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2585 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3853} 2586}
3854impl AstNode for Condition {
3855 fn can_cast(kind: SyntaxKind) -> bool { kind == CONDITION }
3856 fn cast(syntax: SyntaxNode) -> Option<Self> {
3857 if Self::can_cast(syntax.kind()) {
3858 Some(Self { syntax })
3859 } else {
3860 None
3861 }
3862 }
3863 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3864}
3865impl AstNode for ParamList {
3866 fn can_cast(kind: SyntaxKind) -> bool { kind == PARAM_LIST }
3867 fn cast(syntax: SyntaxNode) -> Option<Self> {
3868 if Self::can_cast(syntax.kind()) {
3869 Some(Self { syntax })
3870 } else {
3871 None
3872 }
3873 }
3874 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3875}
3876impl AstNode for SelfParam { 2587impl AstNode for SelfParam {
3877 fn can_cast(kind: SyntaxKind) -> bool { kind == SELF_PARAM } 2588 fn can_cast(kind: SyntaxKind) -> bool { kind == SELF_PARAM }
3878 fn cast(syntax: SyntaxNode) -> Option<Self> { 2589 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -3917,17 +2628,6 @@ impl AstNode for UseTree {
3917 } 2628 }
3918 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2629 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3919} 2630}
3920impl AstNode for Alias {
3921 fn can_cast(kind: SyntaxKind) -> bool { kind == ALIAS }
3922 fn cast(syntax: SyntaxNode) -> Option<Self> {
3923 if Self::can_cast(syntax.kind()) {
3924 Some(Self { syntax })
3925 } else {
3926 None
3927 }
3928 }
3929 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3930}
3931impl AstNode for UseTreeList { 2631impl AstNode for UseTreeList {
3932 fn can_cast(kind: SyntaxKind) -> bool { kind == USE_TREE_LIST } 2632 fn can_cast(kind: SyntaxKind) -> bool { kind == USE_TREE_LIST }
3933 fn cast(syntax: SyntaxNode) -> Option<Self> { 2633 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -3939,19 +2639,8 @@ impl AstNode for UseTreeList {
3939 } 2639 }
3940 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2640 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3941} 2641}
3942impl AstNode for ExternCrateItem { 2642impl AstNode for Alias {
3943 fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_CRATE_ITEM } 2643 fn can_cast(kind: SyntaxKind) -> bool { kind == ALIAS }
3944 fn cast(syntax: SyntaxNode) -> Option<Self> {
3945 if Self::can_cast(syntax.kind()) {
3946 Some(Self { syntax })
3947 } else {
3948 None
3949 }
3950 }
3951 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3952}
3953impl AstNode for ArgList {
3954 fn can_cast(kind: SyntaxKind) -> bool { kind == ARG_LIST }
3955 fn cast(syntax: SyntaxNode) -> Option<Self> { 2644 fn cast(syntax: SyntaxNode) -> Option<Self> {
3956 if Self::can_cast(syntax.kind()) { 2645 if Self::can_cast(syntax.kind()) {
3957 Some(Self { syntax }) 2646 Some(Self { syntax })
@@ -3961,8 +2650,8 @@ impl AstNode for ArgList {
3961 } 2650 }
3962 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2651 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3963} 2652}
3964impl AstNode for Path { 2653impl AstNode for ExternCrateItem {
3965 fn can_cast(kind: SyntaxKind) -> bool { kind == PATH } 2654 fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_CRATE_ITEM }
3966 fn cast(syntax: SyntaxNode) -> Option<Self> { 2655 fn cast(syntax: SyntaxNode) -> Option<Self> {
3967 if Self::can_cast(syntax.kind()) { 2656 if Self::can_cast(syntax.kind()) {
3968 Some(Self { syntax }) 2657 Some(Self { syntax })
@@ -3983,17 +2672,6 @@ impl AstNode for PathSegment {
3983 } 2672 }
3984 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2673 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3985} 2674}
3986impl AstNode for TypeArgList {
3987 fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_ARG_LIST }
3988 fn cast(syntax: SyntaxNode) -> Option<Self> {
3989 if Self::can_cast(syntax.kind()) {
3990 Some(Self { syntax })
3991 } else {
3992 None
3993 }
3994 }
3995 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3996}
3997impl AstNode for TypeArg { 2675impl AstNode for TypeArg {
3998 fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_ARG } 2676 fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_ARG }
3999 fn cast(syntax: SyntaxNode) -> Option<Self> { 2677 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -4005,17 +2683,6 @@ impl AstNode for TypeArg {
4005 } 2683 }
4006 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2684 fn syntax(&self) -> &SyntaxNode { &self.syntax }
4007} 2685}
4008impl AstNode for AssocTypeArg {
4009 fn can_cast(kind: SyntaxKind) -> bool { kind == ASSOC_TYPE_ARG }
4010 fn cast(syntax: SyntaxNode) -> Option<Self> {
4011 if Self::can_cast(syntax.kind()) {
4012 Some(Self { syntax })
4013 } else {
4014 None
4015 }
4016 }
4017 fn syntax(&self) -> &SyntaxNode { &self.syntax }
4018}
4019impl AstNode for LifetimeArg { 2686impl AstNode for LifetimeArg {
4020 fn can_cast(kind: SyntaxKind) -> bool { kind == LIFETIME_ARG } 2687 fn can_cast(kind: SyntaxKind) -> bool { kind == LIFETIME_ARG }
4021 fn cast(syntax: SyntaxNode) -> Option<Self> { 2688 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -4027,8 +2694,8 @@ impl AstNode for LifetimeArg {
4027 } 2694 }
4028 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2695 fn syntax(&self) -> &SyntaxNode { &self.syntax }
4029} 2696}
4030impl AstNode for ConstArg { 2697impl AstNode for AssocTypeArg {
4031 fn can_cast(kind: SyntaxKind) -> bool { kind == CONST_ARG } 2698 fn can_cast(kind: SyntaxKind) -> bool { kind == ASSOC_TYPE_ARG }
4032 fn cast(syntax: SyntaxNode) -> Option<Self> { 2699 fn cast(syntax: SyntaxNode) -> Option<Self> {
4033 if Self::can_cast(syntax.kind()) { 2700 if Self::can_cast(syntax.kind()) {
4034 Some(Self { syntax }) 2701 Some(Self { syntax })
@@ -4038,8 +2705,8 @@ impl AstNode for ConstArg {
4038 } 2705 }
4039 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2706 fn syntax(&self) -> &SyntaxNode { &self.syntax }
4040} 2707}
4041impl AstNode for MacroItems { 2708impl AstNode for ConstArg {
4042 fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_ITEMS } 2709 fn can_cast(kind: SyntaxKind) -> bool { kind == CONST_ARG }
4043 fn cast(syntax: SyntaxNode) -> Option<Self> { 2710 fn cast(syntax: SyntaxNode) -> Option<Self> {
4044 if Self::can_cast(syntax.kind()) { 2711 if Self::can_cast(syntax.kind()) {
4045 Some(Self { syntax }) 2712 Some(Self { syntax })
@@ -4049,8 +2716,8 @@ impl AstNode for MacroItems {
4049 } 2716 }
4050 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2717 fn syntax(&self) -> &SyntaxNode { &self.syntax }
4051} 2718}
4052impl AstNode for MacroStmts { 2719impl AstNode for ExternBlock {
4053 fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_STMTS } 2720 fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_BLOCK }
4054 fn cast(syntax: SyntaxNode) -> Option<Self> { 2721 fn cast(syntax: SyntaxNode) -> Option<Self> {
4055 if Self::can_cast(syntax.kind()) { 2722 if Self::can_cast(syntax.kind()) {
4056 Some(Self { syntax }) 2723 Some(Self { syntax })
@@ -4071,17 +2738,6 @@ impl AstNode for ExternItemList {
4071 } 2738 }
4072 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2739 fn syntax(&self) -> &SyntaxNode { &self.syntax }
4073} 2740}
4074impl AstNode for ExternBlock {
4075 fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_BLOCK }
4076 fn cast(syntax: SyntaxNode) -> Option<Self> {
4077 if Self::can_cast(syntax.kind()) {
4078 Some(Self { syntax })
4079 } else {
4080 None
4081 }
4082 }
4083 fn syntax(&self) -> &SyntaxNode { &self.syntax }
4084}
4085impl AstNode for MetaItem { 2741impl AstNode for MetaItem {
4086 fn can_cast(kind: SyntaxKind) -> bool { kind == META_ITEM } 2742 fn can_cast(kind: SyntaxKind) -> bool { kind == META_ITEM }
4087 fn cast(syntax: SyntaxNode) -> Option<Self> { 2743 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -4093,85 +2749,93 @@ impl AstNode for MetaItem {
4093 } 2749 }
4094 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2750 fn syntax(&self) -> &SyntaxNode { &self.syntax }
4095} 2751}
4096impl AstNode for MacroDef { 2752impl From<StructDef> for ModuleItem {
4097 fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_DEF } 2753 fn from(node: StructDef) -> ModuleItem { ModuleItem::StructDef(node) }
4098 fn cast(syntax: SyntaxNode) -> Option<Self> {
4099 if Self::can_cast(syntax.kind()) {
4100 Some(Self { syntax })
4101 } else {
4102 None
4103 }
4104 }
4105 fn syntax(&self) -> &SyntaxNode { &self.syntax }
4106} 2754}
4107impl From<StructDef> for NominalDef { 2755impl From<UnionDef> for ModuleItem {
4108 fn from(node: StructDef) -> NominalDef { NominalDef::StructDef(node) } 2756 fn from(node: UnionDef) -> ModuleItem { ModuleItem::UnionDef(node) }
4109} 2757}
4110impl From<EnumDef> for NominalDef { 2758impl From<EnumDef> for ModuleItem {
4111 fn from(node: EnumDef) -> NominalDef { NominalDef::EnumDef(node) } 2759 fn from(node: EnumDef) -> ModuleItem { ModuleItem::EnumDef(node) }
4112} 2760}
4113impl From<UnionDef> for NominalDef { 2761impl From<FnDef> for ModuleItem {
4114 fn from(node: UnionDef) -> NominalDef { NominalDef::UnionDef(node) } 2762 fn from(node: FnDef) -> ModuleItem { ModuleItem::FnDef(node) }
4115} 2763}
4116impl AstNode for NominalDef { 2764impl From<TraitDef> for ModuleItem {
4117 fn can_cast(kind: SyntaxKind) -> bool { 2765 fn from(node: TraitDef) -> ModuleItem { ModuleItem::TraitDef(node) }
4118 match kind { 2766}
4119 STRUCT_DEF | ENUM_DEF | UNION_DEF => true, 2767impl From<TypeAliasDef> for ModuleItem {
4120 _ => false, 2768 fn from(node: TypeAliasDef) -> ModuleItem { ModuleItem::TypeAliasDef(node) }
4121 } 2769}
4122 } 2770impl From<ImplDef> for ModuleItem {
4123 fn cast(syntax: SyntaxNode) -> Option<Self> { 2771 fn from(node: ImplDef) -> ModuleItem { ModuleItem::ImplDef(node) }
4124 let res = match syntax.kind() {
4125 STRUCT_DEF => NominalDef::StructDef(StructDef { syntax }),
4126 ENUM_DEF => NominalDef::EnumDef(EnumDef { syntax }),
4127 UNION_DEF => NominalDef::UnionDef(UnionDef { syntax }),
4128 _ => return None,
4129 };
4130 Some(res)
4131 }
4132 fn syntax(&self) -> &SyntaxNode {
4133 match self {
4134 NominalDef::StructDef(it) => &it.syntax,
4135 NominalDef::EnumDef(it) => &it.syntax,
4136 NominalDef::UnionDef(it) => &it.syntax,
4137 }
4138 }
4139} 2772}
4140impl From<LifetimeArg> for GenericArg { 2773impl From<UseItem> for ModuleItem {
4141 fn from(node: LifetimeArg) -> GenericArg { GenericArg::LifetimeArg(node) } 2774 fn from(node: UseItem) -> ModuleItem { ModuleItem::UseItem(node) }
2775}
2776impl From<ExternCrateItem> for ModuleItem {
2777 fn from(node: ExternCrateItem) -> ModuleItem { ModuleItem::ExternCrateItem(node) }
4142} 2778}
4143impl From<TypeArg> for GenericArg { 2779impl From<ConstDef> for ModuleItem {
4144 fn from(node: TypeArg) -> GenericArg { GenericArg::TypeArg(node) } 2780 fn from(node: ConstDef) -> ModuleItem { ModuleItem::ConstDef(node) }
4145} 2781}
4146impl From<ConstArg> for GenericArg { 2782impl From<StaticDef> for ModuleItem {
4147 fn from(node: ConstArg) -> GenericArg { GenericArg::ConstArg(node) } 2783 fn from(node: StaticDef) -> ModuleItem { ModuleItem::StaticDef(node) }
4148} 2784}
4149impl From<AssocTypeArg> for GenericArg { 2785impl From<Module> for ModuleItem {
4150 fn from(node: AssocTypeArg) -> GenericArg { GenericArg::AssocTypeArg(node) } 2786 fn from(node: Module) -> ModuleItem { ModuleItem::Module(node) }
4151} 2787}
4152impl AstNode for GenericArg { 2788impl From<MacroCall> for ModuleItem {
2789 fn from(node: MacroCall) -> ModuleItem { ModuleItem::MacroCall(node) }
2790}
2791impl From<ExternBlock> for ModuleItem {
2792 fn from(node: ExternBlock) -> ModuleItem { ModuleItem::ExternBlock(node) }
2793}
2794impl AstNode for ModuleItem {
4153 fn can_cast(kind: SyntaxKind) -> bool { 2795 fn can_cast(kind: SyntaxKind) -> bool {
4154 match kind { 2796 match kind {
4155 LIFETIME_ARG | TYPE_ARG | CONST_ARG | ASSOC_TYPE_ARG => true, 2797 STRUCT_DEF | UNION_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_DEF
2798 | USE_ITEM | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE | MACRO_CALL
2799 | EXTERN_BLOCK => true,
4156 _ => false, 2800 _ => false,
4157 } 2801 }
4158 } 2802 }
4159 fn cast(syntax: SyntaxNode) -> Option<Self> { 2803 fn cast(syntax: SyntaxNode) -> Option<Self> {
4160 let res = match syntax.kind() { 2804 let res = match syntax.kind() {
4161 LIFETIME_ARG => GenericArg::LifetimeArg(LifetimeArg { syntax }), 2805 STRUCT_DEF => ModuleItem::StructDef(StructDef { syntax }),
4162 TYPE_ARG => GenericArg::TypeArg(TypeArg { syntax }), 2806 UNION_DEF => ModuleItem::UnionDef(UnionDef { syntax }),
4163 CONST_ARG => GenericArg::ConstArg(ConstArg { syntax }), 2807 ENUM_DEF => ModuleItem::EnumDef(EnumDef { syntax }),
4164 ASSOC_TYPE_ARG => GenericArg::AssocTypeArg(AssocTypeArg { syntax }), 2808 FN_DEF => ModuleItem::FnDef(FnDef { syntax }),
2809 TRAIT_DEF => ModuleItem::TraitDef(TraitDef { syntax }),
2810 TYPE_ALIAS_DEF => ModuleItem::TypeAliasDef(TypeAliasDef { syntax }),
2811 IMPL_DEF => ModuleItem::ImplDef(ImplDef { syntax }),
2812 USE_ITEM => ModuleItem::UseItem(UseItem { syntax }),
2813 EXTERN_CRATE_ITEM => ModuleItem::ExternCrateItem(ExternCrateItem { syntax }),
2814 CONST_DEF => ModuleItem::ConstDef(ConstDef { syntax }),
2815 STATIC_DEF => ModuleItem::StaticDef(StaticDef { syntax }),
2816 MODULE => ModuleItem::Module(Module { syntax }),
2817 MACRO_CALL => ModuleItem::MacroCall(MacroCall { syntax }),
2818 EXTERN_BLOCK => ModuleItem::ExternBlock(ExternBlock { syntax }),
4165 _ => return None, 2819 _ => return None,
4166 }; 2820 };
4167 Some(res) 2821 Some(res)
4168 } 2822 }
4169 fn syntax(&self) -> &SyntaxNode { 2823 fn syntax(&self) -> &SyntaxNode {
4170 match self { 2824 match self {
4171 GenericArg::LifetimeArg(it) => &it.syntax, 2825 ModuleItem::StructDef(it) => &it.syntax,
4172 GenericArg::TypeArg(it) => &it.syntax, 2826 ModuleItem::UnionDef(it) => &it.syntax,
4173 GenericArg::ConstArg(it) => &it.syntax, 2827 ModuleItem::EnumDef(it) => &it.syntax,
4174 GenericArg::AssocTypeArg(it) => &it.syntax, 2828 ModuleItem::FnDef(it) => &it.syntax,
2829 ModuleItem::TraitDef(it) => &it.syntax,
2830 ModuleItem::TypeAliasDef(it) => &it.syntax,
2831 ModuleItem::ImplDef(it) => &it.syntax,
2832 ModuleItem::UseItem(it) => &it.syntax,
2833 ModuleItem::ExternCrateItem(it) => &it.syntax,
2834 ModuleItem::ConstDef(it) => &it.syntax,
2835 ModuleItem::StaticDef(it) => &it.syntax,
2836 ModuleItem::Module(it) => &it.syntax,
2837 ModuleItem::MacroCall(it) => &it.syntax,
2838 ModuleItem::ExternBlock(it) => &it.syntax,
4175 } 2839 }
4176 } 2840 }
4177} 2841}
@@ -4260,154 +2924,33 @@ impl AstNode for TypeRef {
4260 } 2924 }
4261 } 2925 }
4262} 2926}
4263impl From<StructDef> for ModuleItem { 2927impl From<RecordFieldDefList> for FieldDefList {
4264 fn from(node: StructDef) -> ModuleItem { ModuleItem::StructDef(node) } 2928 fn from(node: RecordFieldDefList) -> FieldDefList { FieldDefList::RecordFieldDefList(node) }
4265}
4266impl From<UnionDef> for ModuleItem {
4267 fn from(node: UnionDef) -> ModuleItem { ModuleItem::UnionDef(node) }
4268}
4269impl From<EnumDef> for ModuleItem {
4270 fn from(node: EnumDef) -> ModuleItem { ModuleItem::EnumDef(node) }
4271}
4272impl From<FnDef> for ModuleItem {
4273 fn from(node: FnDef) -> ModuleItem { ModuleItem::FnDef(node) }
4274}
4275impl From<TraitDef> for ModuleItem {
4276 fn from(node: TraitDef) -> ModuleItem { ModuleItem::TraitDef(node) }
4277}
4278impl From<TypeAliasDef> for ModuleItem {
4279 fn from(node: TypeAliasDef) -> ModuleItem { ModuleItem::TypeAliasDef(node) }
4280}
4281impl From<ImplDef> for ModuleItem {
4282 fn from(node: ImplDef) -> ModuleItem { ModuleItem::ImplDef(node) }
4283}
4284impl From<UseItem> for ModuleItem {
4285 fn from(node: UseItem) -> ModuleItem { ModuleItem::UseItem(node) }
4286}
4287impl From<ExternCrateItem> for ModuleItem {
4288 fn from(node: ExternCrateItem) -> ModuleItem { ModuleItem::ExternCrateItem(node) }
4289}
4290impl From<ConstDef> for ModuleItem {
4291 fn from(node: ConstDef) -> ModuleItem { ModuleItem::ConstDef(node) }
4292}
4293impl From<StaticDef> for ModuleItem {
4294 fn from(node: StaticDef) -> ModuleItem { ModuleItem::StaticDef(node) }
4295}
4296impl From<Module> for ModuleItem {
4297 fn from(node: Module) -> ModuleItem { ModuleItem::Module(node) }
4298}
4299impl From<MacroCall> for ModuleItem {
4300 fn from(node: MacroCall) -> ModuleItem { ModuleItem::MacroCall(node) }
4301}
4302impl From<ExternBlock> for ModuleItem {
4303 fn from(node: ExternBlock) -> ModuleItem { ModuleItem::ExternBlock(node) }
4304}
4305impl AstNode for ModuleItem {
4306 fn can_cast(kind: SyntaxKind) -> bool {
4307 match kind {
4308 STRUCT_DEF | UNION_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_DEF
4309 | USE_ITEM | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE | MACRO_CALL
4310 | EXTERN_BLOCK => true,
4311 _ => false,
4312 }
4313 }
4314 fn cast(syntax: SyntaxNode) -> Option<Self> {
4315 let res = match syntax.kind() {
4316 STRUCT_DEF => ModuleItem::StructDef(StructDef { syntax }),
4317 UNION_DEF => ModuleItem::UnionDef(UnionDef { syntax }),
4318 ENUM_DEF => ModuleItem::EnumDef(EnumDef { syntax }),
4319 FN_DEF => ModuleItem::FnDef(FnDef { syntax }),
4320 TRAIT_DEF => ModuleItem::TraitDef(TraitDef { syntax }),
4321 TYPE_ALIAS_DEF => ModuleItem::TypeAliasDef(TypeAliasDef { syntax }),
4322 IMPL_DEF => ModuleItem::ImplDef(ImplDef { syntax }),
4323 USE_ITEM => ModuleItem::UseItem(UseItem { syntax }),
4324 EXTERN_CRATE_ITEM => ModuleItem::ExternCrateItem(ExternCrateItem { syntax }),
4325 CONST_DEF => ModuleItem::ConstDef(ConstDef { syntax }),
4326 STATIC_DEF => ModuleItem::StaticDef(StaticDef { syntax }),
4327 MODULE => ModuleItem::Module(Module { syntax }),
4328 MACRO_CALL => ModuleItem::MacroCall(MacroCall { syntax }),
4329 EXTERN_BLOCK => ModuleItem::ExternBlock(ExternBlock { syntax }),
4330 _ => return None,
4331 };
4332 Some(res)
4333 }
4334 fn syntax(&self) -> &SyntaxNode {
4335 match self {
4336 ModuleItem::StructDef(it) => &it.syntax,
4337 ModuleItem::UnionDef(it) => &it.syntax,
4338 ModuleItem::EnumDef(it) => &it.syntax,
4339 ModuleItem::FnDef(it) => &it.syntax,
4340 ModuleItem::TraitDef(it) => &it.syntax,
4341 ModuleItem::TypeAliasDef(it) => &it.syntax,
4342 ModuleItem::ImplDef(it) => &it.syntax,
4343 ModuleItem::UseItem(it) => &it.syntax,
4344 ModuleItem::ExternCrateItem(it) => &it.syntax,
4345 ModuleItem::ConstDef(it) => &it.syntax,
4346 ModuleItem::StaticDef(it) => &it.syntax,
4347 ModuleItem::Module(it) => &it.syntax,
4348 ModuleItem::MacroCall(it) => &it.syntax,
4349 ModuleItem::ExternBlock(it) => &it.syntax,
4350 }
4351 }
4352}
4353impl From<FnDef> for AssocItem {
4354 fn from(node: FnDef) -> AssocItem { AssocItem::FnDef(node) }
4355}
4356impl From<TypeAliasDef> for AssocItem {
4357 fn from(node: TypeAliasDef) -> AssocItem { AssocItem::TypeAliasDef(node) }
4358}
4359impl From<ConstDef> for AssocItem {
4360 fn from(node: ConstDef) -> AssocItem { AssocItem::ConstDef(node) }
4361}
4362impl AstNode for AssocItem {
4363 fn can_cast(kind: SyntaxKind) -> bool {
4364 match kind {
4365 FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true,
4366 _ => false,
4367 }
4368 }
4369 fn cast(syntax: SyntaxNode) -> Option<Self> {
4370 let res = match syntax.kind() {
4371 FN_DEF => AssocItem::FnDef(FnDef { syntax }),
4372 TYPE_ALIAS_DEF => AssocItem::TypeAliasDef(TypeAliasDef { syntax }),
4373 CONST_DEF => AssocItem::ConstDef(ConstDef { syntax }),
4374 _ => return None,
4375 };
4376 Some(res)
4377 }
4378 fn syntax(&self) -> &SyntaxNode {
4379 match self {
4380 AssocItem::FnDef(it) => &it.syntax,
4381 AssocItem::TypeAliasDef(it) => &it.syntax,
4382 AssocItem::ConstDef(it) => &it.syntax,
4383 }
4384 }
4385}
4386impl From<FnDef> for ExternItem {
4387 fn from(node: FnDef) -> ExternItem { ExternItem::FnDef(node) }
4388} 2929}
4389impl From<StaticDef> for ExternItem { 2930impl From<TupleFieldDefList> for FieldDefList {
4390 fn from(node: StaticDef) -> ExternItem { ExternItem::StaticDef(node) } 2931 fn from(node: TupleFieldDefList) -> FieldDefList { FieldDefList::TupleFieldDefList(node) }
4391} 2932}
4392impl AstNode for ExternItem { 2933impl AstNode for FieldDefList {
4393 fn can_cast(kind: SyntaxKind) -> bool { 2934 fn can_cast(kind: SyntaxKind) -> bool {
4394 match kind { 2935 match kind {
4395 FN_DEF | STATIC_DEF => true, 2936 RECORD_FIELD_DEF_LIST | TUPLE_FIELD_DEF_LIST => true,
4396 _ => false, 2937 _ => false,
4397 } 2938 }
4398 } 2939 }
4399 fn cast(syntax: SyntaxNode) -> Option<Self> { 2940 fn cast(syntax: SyntaxNode) -> Option<Self> {
4400 let res = match syntax.kind() { 2941 let res = match syntax.kind() {
4401 FN_DEF => ExternItem::FnDef(FnDef { syntax }), 2942 RECORD_FIELD_DEF_LIST => {
4402 STATIC_DEF => ExternItem::StaticDef(StaticDef { syntax }), 2943 FieldDefList::RecordFieldDefList(RecordFieldDefList { syntax })
2944 }
2945 TUPLE_FIELD_DEF_LIST => FieldDefList::TupleFieldDefList(TupleFieldDefList { syntax }),
4403 _ => return None, 2946 _ => return None,
4404 }; 2947 };
4405 Some(res) 2948 Some(res)
4406 } 2949 }
4407 fn syntax(&self) -> &SyntaxNode { 2950 fn syntax(&self) -> &SyntaxNode {
4408 match self { 2951 match self {
4409 ExternItem::FnDef(it) => &it.syntax, 2952 FieldDefList::RecordFieldDefList(it) => &it.syntax,
4410 ExternItem::StaticDef(it) => &it.syntax, 2953 FieldDefList::TupleFieldDefList(it) => &it.syntax,
4411 } 2954 }
4412 } 2955 }
4413} 2956}
@@ -4590,6 +3133,39 @@ impl AstNode for Expr {
4590 } 3133 }
4591 } 3134 }
4592} 3135}
3136impl From<FnDef> for AssocItem {
3137 fn from(node: FnDef) -> AssocItem { AssocItem::FnDef(node) }
3138}
3139impl From<TypeAliasDef> for AssocItem {
3140 fn from(node: TypeAliasDef) -> AssocItem { AssocItem::TypeAliasDef(node) }
3141}
3142impl From<ConstDef> for AssocItem {
3143 fn from(node: ConstDef) -> AssocItem { AssocItem::ConstDef(node) }
3144}
3145impl AstNode for AssocItem {
3146 fn can_cast(kind: SyntaxKind) -> bool {
3147 match kind {
3148 FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true,
3149 _ => false,
3150 }
3151 }
3152 fn cast(syntax: SyntaxNode) -> Option<Self> {
3153 let res = match syntax.kind() {
3154 FN_DEF => AssocItem::FnDef(FnDef { syntax }),
3155 TYPE_ALIAS_DEF => AssocItem::TypeAliasDef(TypeAliasDef { syntax }),
3156 CONST_DEF => AssocItem::ConstDef(ConstDef { syntax }),
3157 _ => return None,
3158 };
3159 Some(res)
3160 }
3161 fn syntax(&self) -> &SyntaxNode {
3162 match self {
3163 AssocItem::FnDef(it) => &it.syntax,
3164 AssocItem::TypeAliasDef(it) => &it.syntax,
3165 AssocItem::ConstDef(it) => &it.syntax,
3166 }
3167 }
3168}
4593impl From<OrPat> for Pat { 3169impl From<OrPat> for Pat {
4594 fn from(node: OrPat) -> Pat { Pat::OrPat(node) } 3170 fn from(node: OrPat) -> Pat { Pat::OrPat(node) }
4595} 3171}
@@ -4685,6 +3261,34 @@ impl AstNode for Pat {
4685 } 3261 }
4686 } 3262 }
4687} 3263}
3264impl From<LetStmt> for Stmt {
3265 fn from(node: LetStmt) -> Stmt { Stmt::LetStmt(node) }
3266}
3267impl From<ExprStmt> for Stmt {
3268 fn from(node: ExprStmt) -> Stmt { Stmt::ExprStmt(node) }
3269}
3270impl AstNode for Stmt {
3271 fn can_cast(kind: SyntaxKind) -> bool {
3272 match kind {
3273 LET_STMT | EXPR_STMT => true,
3274 _ => false,
3275 }
3276 }
3277 fn cast(syntax: SyntaxNode) -> Option<Self> {
3278 let res = match syntax.kind() {
3279 LET_STMT => Stmt::LetStmt(LetStmt { syntax }),
3280 EXPR_STMT => Stmt::ExprStmt(ExprStmt { syntax }),
3281 _ => return None,
3282 };
3283 Some(res)
3284 }
3285 fn syntax(&self) -> &SyntaxNode {
3286 match self {
3287 Stmt::LetStmt(it) => &it.syntax,
3288 Stmt::ExprStmt(it) => &it.syntax,
3289 }
3290 }
3291}
4688impl From<Literal> for AttrInput { 3292impl From<Literal> for AttrInput {
4689 fn from(node: Literal) -> AttrInput { AttrInput::Literal(node) } 3293 fn from(node: Literal) -> AttrInput { AttrInput::Literal(node) }
4690} 3294}
@@ -4713,80 +3317,83 @@ impl AstNode for AttrInput {
4713 } 3317 }
4714 } 3318 }
4715} 3319}
4716impl From<LetStmt> for Stmt { 3320impl From<FnDef> for ExternItem {
4717 fn from(node: LetStmt) -> Stmt { Stmt::LetStmt(node) } 3321 fn from(node: FnDef) -> ExternItem { ExternItem::FnDef(node) }
4718} 3322}
4719impl From<ExprStmt> for Stmt { 3323impl From<StaticDef> for ExternItem {
4720 fn from(node: ExprStmt) -> Stmt { Stmt::ExprStmt(node) } 3324 fn from(node: StaticDef) -> ExternItem { ExternItem::StaticDef(node) }
4721} 3325}
4722impl AstNode for Stmt { 3326impl AstNode for ExternItem {
4723 fn can_cast(kind: SyntaxKind) -> bool { 3327 fn can_cast(kind: SyntaxKind) -> bool {
4724 match kind { 3328 match kind {
4725 LET_STMT | EXPR_STMT => true, 3329 FN_DEF | STATIC_DEF => true,
4726 _ => false, 3330 _ => false,
4727 } 3331 }
4728 } 3332 }
4729 fn cast(syntax: SyntaxNode) -> Option<Self> { 3333 fn cast(syntax: SyntaxNode) -> Option<Self> {
4730 let res = match syntax.kind() { 3334 let res = match syntax.kind() {
4731 LET_STMT => Stmt::LetStmt(LetStmt { syntax }), 3335 FN_DEF => ExternItem::FnDef(FnDef { syntax }),
4732 EXPR_STMT => Stmt::ExprStmt(ExprStmt { syntax }), 3336 STATIC_DEF => ExternItem::StaticDef(StaticDef { syntax }),
4733 _ => return None, 3337 _ => return None,
4734 }; 3338 };
4735 Some(res) 3339 Some(res)
4736 } 3340 }
4737 fn syntax(&self) -> &SyntaxNode { 3341 fn syntax(&self) -> &SyntaxNode {
4738 match self { 3342 match self {
4739 Stmt::LetStmt(it) => &it.syntax, 3343 ExternItem::FnDef(it) => &it.syntax,
4740 Stmt::ExprStmt(it) => &it.syntax, 3344 ExternItem::StaticDef(it) => &it.syntax,
4741 } 3345 }
4742 } 3346 }
4743} 3347}
4744impl From<RecordFieldDefList> for FieldDefList { 3348impl From<StructDef> for NominalDef {
4745 fn from(node: RecordFieldDefList) -> FieldDefList { FieldDefList::RecordFieldDefList(node) } 3349 fn from(node: StructDef) -> NominalDef { NominalDef::StructDef(node) }
4746} 3350}
4747impl From<TupleFieldDefList> for FieldDefList { 3351impl From<EnumDef> for NominalDef {
4748 fn from(node: TupleFieldDefList) -> FieldDefList { FieldDefList::TupleFieldDefList(node) } 3352 fn from(node: EnumDef) -> NominalDef { NominalDef::EnumDef(node) }
4749} 3353}
4750impl AstNode for FieldDefList { 3354impl From<UnionDef> for NominalDef {
3355 fn from(node: UnionDef) -> NominalDef { NominalDef::UnionDef(node) }
3356}
3357impl AstNode for NominalDef {
4751 fn can_cast(kind: SyntaxKind) -> bool { 3358 fn can_cast(kind: SyntaxKind) -> bool {
4752 match kind { 3359 match kind {
4753 RECORD_FIELD_DEF_LIST | TUPLE_FIELD_DEF_LIST => true, 3360 STRUCT_DEF | ENUM_DEF | UNION_DEF => true,
4754 _ => false, 3361 _ => false,
4755 } 3362 }
4756 } 3363 }
4757 fn cast(syntax: SyntaxNode) -> Option<Self> { 3364 fn cast(syntax: SyntaxNode) -> Option<Self> {
4758 let res = match syntax.kind() { 3365 let res = match syntax.kind() {
4759 RECORD_FIELD_DEF_LIST => { 3366 STRUCT_DEF => NominalDef::StructDef(StructDef { syntax }),
4760 FieldDefList::RecordFieldDefList(RecordFieldDefList { syntax }) 3367 ENUM_DEF => NominalDef::EnumDef(EnumDef { syntax }),
4761 } 3368 UNION_DEF => NominalDef::UnionDef(UnionDef { syntax }),
4762 TUPLE_FIELD_DEF_LIST => FieldDefList::TupleFieldDefList(TupleFieldDefList { syntax }),
4763 _ => return None, 3369 _ => return None,
4764 }; 3370 };
4765 Some(res) 3371 Some(res)
4766 } 3372 }
4767 fn syntax(&self) -> &SyntaxNode { 3373 fn syntax(&self) -> &SyntaxNode {
4768 match self { 3374 match self {
4769 FieldDefList::RecordFieldDefList(it) => &it.syntax, 3375 NominalDef::StructDef(it) => &it.syntax,
4770 FieldDefList::TupleFieldDefList(it) => &it.syntax, 3376 NominalDef::EnumDef(it) => &it.syntax,
3377 NominalDef::UnionDef(it) => &it.syntax,
4771 } 3378 }
4772 } 3379 }
4773} 3380}
4774impl std::fmt::Display for NominalDef { 3381impl std::fmt::Display for ModuleItem {
4775 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3382 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4776 std::fmt::Display::fmt(self.syntax(), f) 3383 std::fmt::Display::fmt(self.syntax(), f)
4777 } 3384 }
4778} 3385}
4779impl std::fmt::Display for GenericArg { 3386impl std::fmt::Display for TypeRef {
4780 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3387 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4781 std::fmt::Display::fmt(self.syntax(), f) 3388 std::fmt::Display::fmt(self.syntax(), f)
4782 } 3389 }
4783} 3390}
4784impl std::fmt::Display for TypeRef { 3391impl std::fmt::Display for FieldDefList {
4785 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3392 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4786 std::fmt::Display::fmt(self.syntax(), f) 3393 std::fmt::Display::fmt(self.syntax(), f)
4787 } 3394 }
4788} 3395}
4789impl std::fmt::Display for ModuleItem { 3396impl std::fmt::Display for Expr {
4790 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3397 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4791 std::fmt::Display::fmt(self.syntax(), f) 3398 std::fmt::Display::fmt(self.syntax(), f)
4792 } 3399 }
@@ -4796,37 +3403,37 @@ impl std::fmt::Display for AssocItem {
4796 std::fmt::Display::fmt(self.syntax(), f) 3403 std::fmt::Display::fmt(self.syntax(), f)
4797 } 3404 }
4798} 3405}
4799impl std::fmt::Display for ExternItem { 3406impl std::fmt::Display for Pat {
4800 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3407 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4801 std::fmt::Display::fmt(self.syntax(), f) 3408 std::fmt::Display::fmt(self.syntax(), f)
4802 } 3409 }
4803} 3410}
4804impl std::fmt::Display for Expr { 3411impl std::fmt::Display for Stmt {
4805 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3412 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4806 std::fmt::Display::fmt(self.syntax(), f) 3413 std::fmt::Display::fmt(self.syntax(), f)
4807 } 3414 }
4808} 3415}
4809impl std::fmt::Display for Pat { 3416impl std::fmt::Display for AttrInput {
4810 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3417 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4811 std::fmt::Display::fmt(self.syntax(), f) 3418 std::fmt::Display::fmt(self.syntax(), f)
4812 } 3419 }
4813} 3420}
4814impl std::fmt::Display for AttrInput { 3421impl std::fmt::Display for ExternItem {
4815 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3422 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4816 std::fmt::Display::fmt(self.syntax(), f) 3423 std::fmt::Display::fmt(self.syntax(), f)
4817 } 3424 }
4818} 3425}
4819impl std::fmt::Display for Stmt { 3426impl std::fmt::Display for NominalDef {
4820 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3427 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4821 std::fmt::Display::fmt(self.syntax(), f) 3428 std::fmt::Display::fmt(self.syntax(), f)
4822 } 3429 }
4823} 3430}
4824impl std::fmt::Display for FieldDefList { 3431impl std::fmt::Display for SourceFile {
4825 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3432 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4826 std::fmt::Display::fmt(self.syntax(), f) 3433 std::fmt::Display::fmt(self.syntax(), f)
4827 } 3434 }
4828} 3435}
4829impl std::fmt::Display for SourceFile { 3436impl std::fmt::Display for Attr {
4830 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3437 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4831 std::fmt::Display::fmt(self.syntax(), f) 3438 std::fmt::Display::fmt(self.syntax(), f)
4832 } 3439 }
@@ -4836,27 +3443,52 @@ impl std::fmt::Display for FnDef {
4836 std::fmt::Display::fmt(self.syntax(), f) 3443 std::fmt::Display::fmt(self.syntax(), f)
4837 } 3444 }
4838} 3445}
3446impl std::fmt::Display for Visibility {
3447 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3448 std::fmt::Display::fmt(self.syntax(), f)
3449 }
3450}
3451impl std::fmt::Display for Abi {
3452 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3453 std::fmt::Display::fmt(self.syntax(), f)
3454 }
3455}
3456impl std::fmt::Display for Name {
3457 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3458 std::fmt::Display::fmt(self.syntax(), f)
3459 }
3460}
3461impl std::fmt::Display for TypeParamList {
3462 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3463 std::fmt::Display::fmt(self.syntax(), f)
3464 }
3465}
3466impl std::fmt::Display for ParamList {
3467 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3468 std::fmt::Display::fmt(self.syntax(), f)
3469 }
3470}
4839impl std::fmt::Display for RetType { 3471impl std::fmt::Display for RetType {
4840 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3472 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4841 std::fmt::Display::fmt(self.syntax(), f) 3473 std::fmt::Display::fmt(self.syntax(), f)
4842 } 3474 }
4843} 3475}
4844impl std::fmt::Display for StructDef { 3476impl std::fmt::Display for WhereClause {
4845 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3477 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4846 std::fmt::Display::fmt(self.syntax(), f) 3478 std::fmt::Display::fmt(self.syntax(), f)
4847 } 3479 }
4848} 3480}
4849impl std::fmt::Display for UnionDef { 3481impl std::fmt::Display for BlockExpr {
4850 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3482 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4851 std::fmt::Display::fmt(self.syntax(), f) 3483 std::fmt::Display::fmt(self.syntax(), f)
4852 } 3484 }
4853} 3485}
4854impl std::fmt::Display for RecordFieldDefList { 3486impl std::fmt::Display for StructDef {
4855 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3487 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4856 std::fmt::Display::fmt(self.syntax(), f) 3488 std::fmt::Display::fmt(self.syntax(), f)
4857 } 3489 }
4858} 3490}
4859impl std::fmt::Display for RecordFieldDef { 3491impl std::fmt::Display for RecordFieldDefList {
4860 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3492 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4861 std::fmt::Display::fmt(self.syntax(), f) 3493 std::fmt::Display::fmt(self.syntax(), f)
4862 } 3494 }
@@ -4866,6 +3498,16 @@ impl std::fmt::Display for TupleFieldDefList {
4866 std::fmt::Display::fmt(self.syntax(), f) 3498 std::fmt::Display::fmt(self.syntax(), f)
4867 } 3499 }
4868} 3500}
3501impl std::fmt::Display for UnionDef {
3502 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3503 std::fmt::Display::fmt(self.syntax(), f)
3504 }
3505}
3506impl std::fmt::Display for RecordFieldDef {
3507 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3508 std::fmt::Display::fmt(self.syntax(), f)
3509 }
3510}
4869impl std::fmt::Display for TupleFieldDef { 3511impl std::fmt::Display for TupleFieldDef {
4870 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3512 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4871 std::fmt::Display::fmt(self.syntax(), f) 3513 std::fmt::Display::fmt(self.syntax(), f)
@@ -4891,7 +3533,7 @@ impl std::fmt::Display for TraitDef {
4891 std::fmt::Display::fmt(self.syntax(), f) 3533 std::fmt::Display::fmt(self.syntax(), f)
4892 } 3534 }
4893} 3535}
4894impl std::fmt::Display for Module { 3536impl std::fmt::Display for TypeBoundList {
4895 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3537 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4896 std::fmt::Display::fmt(self.syntax(), f) 3538 std::fmt::Display::fmt(self.syntax(), f)
4897 } 3539 }
@@ -4901,6 +3543,11 @@ impl std::fmt::Display for ItemList {
4901 std::fmt::Display::fmt(self.syntax(), f) 3543 std::fmt::Display::fmt(self.syntax(), f)
4902 } 3544 }
4903} 3545}
3546impl std::fmt::Display for Module {
3547 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3548 std::fmt::Display::fmt(self.syntax(), f)
3549 }
3550}
4904impl std::fmt::Display for ConstDef { 3551impl std::fmt::Display for ConstDef {
4905 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3552 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4906 std::fmt::Display::fmt(self.syntax(), f) 3553 std::fmt::Display::fmt(self.syntax(), f)
@@ -4941,6 +3588,11 @@ impl std::fmt::Display for PathType {
4941 std::fmt::Display::fmt(self.syntax(), f) 3588 std::fmt::Display::fmt(self.syntax(), f)
4942 } 3589 }
4943} 3590}
3591impl std::fmt::Display for Path {
3592 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3593 std::fmt::Display::fmt(self.syntax(), f)
3594 }
3595}
4944impl std::fmt::Display for PointerType { 3596impl std::fmt::Display for PointerType {
4945 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3597 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4946 std::fmt::Display::fmt(self.syntax(), f) 3598 std::fmt::Display::fmt(self.syntax(), f)
@@ -5016,7 +3668,7 @@ impl std::fmt::Display for IfExpr {
5016 std::fmt::Display::fmt(self.syntax(), f) 3668 std::fmt::Display::fmt(self.syntax(), f)
5017 } 3669 }
5018} 3670}
5019impl std::fmt::Display for LoopExpr { 3671impl std::fmt::Display for Condition {
5020 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3672 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5021 std::fmt::Display::fmt(self.syntax(), f) 3673 std::fmt::Display::fmt(self.syntax(), f)
5022 } 3674 }
@@ -5026,6 +3678,16 @@ impl std::fmt::Display for EffectExpr {
5026 std::fmt::Display::fmt(self.syntax(), f) 3678 std::fmt::Display::fmt(self.syntax(), f)
5027 } 3679 }
5028} 3680}
3681impl std::fmt::Display for Label {
3682 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3683 std::fmt::Display::fmt(self.syntax(), f)
3684 }
3685}
3686impl std::fmt::Display for LoopExpr {
3687 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3688 std::fmt::Display::fmt(self.syntax(), f)
3689 }
3690}
5029impl std::fmt::Display for ForExpr { 3691impl std::fmt::Display for ForExpr {
5030 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3692 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5031 std::fmt::Display::fmt(self.syntax(), f) 3693 std::fmt::Display::fmt(self.syntax(), f)
@@ -5046,32 +3708,32 @@ impl std::fmt::Display for BreakExpr {
5046 std::fmt::Display::fmt(self.syntax(), f) 3708 std::fmt::Display::fmt(self.syntax(), f)
5047 } 3709 }
5048} 3710}
5049impl std::fmt::Display for Label { 3711impl std::fmt::Display for ReturnExpr {
5050 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3712 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5051 std::fmt::Display::fmt(self.syntax(), f) 3713 std::fmt::Display::fmt(self.syntax(), f)
5052 } 3714 }
5053} 3715}
5054impl std::fmt::Display for BlockExpr { 3716impl std::fmt::Display for CallExpr {
5055 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3717 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5056 std::fmt::Display::fmt(self.syntax(), f) 3718 std::fmt::Display::fmt(self.syntax(), f)
5057 } 3719 }
5058} 3720}
5059impl std::fmt::Display for ReturnExpr { 3721impl std::fmt::Display for ArgList {
5060 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3722 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5061 std::fmt::Display::fmt(self.syntax(), f) 3723 std::fmt::Display::fmt(self.syntax(), f)
5062 } 3724 }
5063} 3725}
5064impl std::fmt::Display for CallExpr { 3726impl std::fmt::Display for MethodCallExpr {
5065 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3727 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5066 std::fmt::Display::fmt(self.syntax(), f) 3728 std::fmt::Display::fmt(self.syntax(), f)
5067 } 3729 }
5068} 3730}
5069impl std::fmt::Display for MethodCallExpr { 3731impl std::fmt::Display for NameRef {
5070 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3732 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5071 std::fmt::Display::fmt(self.syntax(), f) 3733 std::fmt::Display::fmt(self.syntax(), f)
5072 } 3734 }
5073} 3735}
5074impl std::fmt::Display for IndexExpr { 3736impl std::fmt::Display for TypeArgList {
5075 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3737 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5076 std::fmt::Display::fmt(self.syntax(), f) 3738 std::fmt::Display::fmt(self.syntax(), f)
5077 } 3739 }
@@ -5081,6 +3743,11 @@ impl std::fmt::Display for FieldExpr {
5081 std::fmt::Display::fmt(self.syntax(), f) 3743 std::fmt::Display::fmt(self.syntax(), f)
5082 } 3744 }
5083} 3745}
3746impl std::fmt::Display for IndexExpr {
3747 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3748 std::fmt::Display::fmt(self.syntax(), f)
3749 }
3750}
5084impl std::fmt::Display for AwaitExpr { 3751impl std::fmt::Display for AwaitExpr {
5085 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3752 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5086 std::fmt::Display::fmt(self.syntax(), f) 3753 std::fmt::Display::fmt(self.syntax(), f)
@@ -5221,6 +3888,11 @@ impl std::fmt::Display for MacroPat {
5221 std::fmt::Display::fmt(self.syntax(), f) 3888 std::fmt::Display::fmt(self.syntax(), f)
5222 } 3889 }
5223} 3890}
3891impl std::fmt::Display for MacroCall {
3892 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3893 std::fmt::Display::fmt(self.syntax(), f)
3894 }
3895}
5224impl std::fmt::Display for RecordPat { 3896impl std::fmt::Display for RecordPat {
5225 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3897 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5226 std::fmt::Display::fmt(self.syntax(), f) 3898 std::fmt::Display::fmt(self.syntax(), f)
@@ -5246,37 +3918,22 @@ impl std::fmt::Display for TuplePat {
5246 std::fmt::Display::fmt(self.syntax(), f) 3918 std::fmt::Display::fmt(self.syntax(), f)
5247 } 3919 }
5248} 3920}
5249impl std::fmt::Display for Visibility { 3921impl std::fmt::Display for TokenTree {
5250 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5251 std::fmt::Display::fmt(self.syntax(), f)
5252 }
5253}
5254impl std::fmt::Display for Name {
5255 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5256 std::fmt::Display::fmt(self.syntax(), f)
5257 }
5258}
5259impl std::fmt::Display for NameRef {
5260 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5261 std::fmt::Display::fmt(self.syntax(), f)
5262 }
5263}
5264impl std::fmt::Display for MacroCall {
5265 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3922 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5266 std::fmt::Display::fmt(self.syntax(), f) 3923 std::fmt::Display::fmt(self.syntax(), f)
5267 } 3924 }
5268} 3925}
5269impl std::fmt::Display for Attr { 3926impl std::fmt::Display for MacroDef {
5270 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3927 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5271 std::fmt::Display::fmt(self.syntax(), f) 3928 std::fmt::Display::fmt(self.syntax(), f)
5272 } 3929 }
5273} 3930}
5274impl std::fmt::Display for TokenTree { 3931impl std::fmt::Display for MacroItems {
5275 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3932 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5276 std::fmt::Display::fmt(self.syntax(), f) 3933 std::fmt::Display::fmt(self.syntax(), f)
5277 } 3934 }
5278} 3935}
5279impl std::fmt::Display for TypeParamList { 3936impl std::fmt::Display for MacroStmts {
5280 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3937 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5281 std::fmt::Display::fmt(self.syntax(), f) 3938 std::fmt::Display::fmt(self.syntax(), f)
5282 } 3939 }
@@ -5286,22 +3943,17 @@ impl std::fmt::Display for TypeParam {
5286 std::fmt::Display::fmt(self.syntax(), f) 3943 std::fmt::Display::fmt(self.syntax(), f)
5287 } 3944 }
5288} 3945}
5289impl std::fmt::Display for ConstParam {
5290 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5291 std::fmt::Display::fmt(self.syntax(), f)
5292 }
5293}
5294impl std::fmt::Display for LifetimeParam { 3946impl std::fmt::Display for LifetimeParam {
5295 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3947 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5296 std::fmt::Display::fmt(self.syntax(), f) 3948 std::fmt::Display::fmt(self.syntax(), f)
5297 } 3949 }
5298} 3950}
5299impl std::fmt::Display for TypeBound { 3951impl std::fmt::Display for ConstParam {
5300 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3952 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5301 std::fmt::Display::fmt(self.syntax(), f) 3953 std::fmt::Display::fmt(self.syntax(), f)
5302 } 3954 }
5303} 3955}
5304impl std::fmt::Display for TypeBoundList { 3956impl std::fmt::Display for TypeBound {
5305 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3957 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5306 std::fmt::Display::fmt(self.syntax(), f) 3958 std::fmt::Display::fmt(self.syntax(), f)
5307 } 3959 }
@@ -5311,16 +3963,6 @@ impl std::fmt::Display for WherePred {
5311 std::fmt::Display::fmt(self.syntax(), f) 3963 std::fmt::Display::fmt(self.syntax(), f)
5312 } 3964 }
5313} 3965}
5314impl std::fmt::Display for WhereClause {
5315 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5316 std::fmt::Display::fmt(self.syntax(), f)
5317 }
5318}
5319impl std::fmt::Display for Abi {
5320 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5321 std::fmt::Display::fmt(self.syntax(), f)
5322 }
5323}
5324impl std::fmt::Display for ExprStmt { 3966impl std::fmt::Display for ExprStmt {
5325 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3967 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5326 std::fmt::Display::fmt(self.syntax(), f) 3968 std::fmt::Display::fmt(self.syntax(), f)
@@ -5331,16 +3973,6 @@ impl std::fmt::Display for LetStmt {
5331 std::fmt::Display::fmt(self.syntax(), f) 3973 std::fmt::Display::fmt(self.syntax(), f)
5332 } 3974 }
5333} 3975}
5334impl std::fmt::Display for Condition {
5335 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5336 std::fmt::Display::fmt(self.syntax(), f)
5337 }
5338}
5339impl std::fmt::Display for ParamList {
5340 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5341 std::fmt::Display::fmt(self.syntax(), f)
5342 }
5343}
5344impl std::fmt::Display for SelfParam { 3976impl std::fmt::Display for SelfParam {
5345 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3977 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5346 std::fmt::Display::fmt(self.syntax(), f) 3978 std::fmt::Display::fmt(self.syntax(), f)
@@ -5361,27 +3993,17 @@ impl std::fmt::Display for UseTree {
5361 std::fmt::Display::fmt(self.syntax(), f) 3993 std::fmt::Display::fmt(self.syntax(), f)
5362 } 3994 }
5363} 3995}
5364impl std::fmt::Display for Alias {
5365 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5366 std::fmt::Display::fmt(self.syntax(), f)
5367 }
5368}
5369impl std::fmt::Display for UseTreeList { 3996impl std::fmt::Display for UseTreeList {
5370 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3997 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5371 std::fmt::Display::fmt(self.syntax(), f) 3998 std::fmt::Display::fmt(self.syntax(), f)
5372 } 3999 }
5373} 4000}
5374impl std::fmt::Display for ExternCrateItem { 4001impl std::fmt::Display for Alias {
5375 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5376 std::fmt::Display::fmt(self.syntax(), f)
5377 }
5378}
5379impl std::fmt::Display for ArgList {
5380 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 4002 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5381 std::fmt::Display::fmt(self.syntax(), f) 4003 std::fmt::Display::fmt(self.syntax(), f)
5382 } 4004 }
5383} 4005}
5384impl std::fmt::Display for Path { 4006impl std::fmt::Display for ExternCrateItem {
5385 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 4007 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5386 std::fmt::Display::fmt(self.syntax(), f) 4008 std::fmt::Display::fmt(self.syntax(), f)
5387 } 4009 }
@@ -5391,37 +4013,27 @@ impl std::fmt::Display for PathSegment {
5391 std::fmt::Display::fmt(self.syntax(), f) 4013 std::fmt::Display::fmt(self.syntax(), f)
5392 } 4014 }
5393} 4015}
5394impl std::fmt::Display for TypeArgList {
5395 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5396 std::fmt::Display::fmt(self.syntax(), f)
5397 }
5398}
5399impl std::fmt::Display for TypeArg { 4016impl std::fmt::Display for TypeArg {
5400 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 4017 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5401 std::fmt::Display::fmt(self.syntax(), f) 4018 std::fmt::Display::fmt(self.syntax(), f)
5402 } 4019 }
5403} 4020}
5404impl std::fmt::Display for AssocTypeArg {
5405 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5406 std::fmt::Display::fmt(self.syntax(), f)
5407 }
5408}
5409impl std::fmt::Display for LifetimeArg { 4021impl std::fmt::Display for LifetimeArg {
5410 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 4022 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5411 std::fmt::Display::fmt(self.syntax(), f) 4023 std::fmt::Display::fmt(self.syntax(), f)
5412 } 4024 }
5413} 4025}
5414impl std::fmt::Display for ConstArg { 4026impl std::fmt::Display for AssocTypeArg {
5415 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 4027 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5416 std::fmt::Display::fmt(self.syntax(), f) 4028 std::fmt::Display::fmt(self.syntax(), f)
5417 } 4029 }
5418} 4030}
5419impl std::fmt::Display for MacroItems { 4031impl std::fmt::Display for ConstArg {
5420 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 4032 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5421 std::fmt::Display::fmt(self.syntax(), f) 4033 std::fmt::Display::fmt(self.syntax(), f)
5422 } 4034 }
5423} 4035}
5424impl std::fmt::Display for MacroStmts { 4036impl std::fmt::Display for ExternBlock {
5425 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 4037 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5426 std::fmt::Display::fmt(self.syntax(), f) 4038 std::fmt::Display::fmt(self.syntax(), f)
5427 } 4039 }
@@ -5431,18 +4043,8 @@ impl std::fmt::Display for ExternItemList {
5431 std::fmt::Display::fmt(self.syntax(), f) 4043 std::fmt::Display::fmt(self.syntax(), f)
5432 } 4044 }
5433} 4045}
5434impl std::fmt::Display for ExternBlock {
5435 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5436 std::fmt::Display::fmt(self.syntax(), f)
5437 }
5438}
5439impl std::fmt::Display for MetaItem { 4046impl std::fmt::Display for MetaItem {
5440 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 4047 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5441 std::fmt::Display::fmt(self.syntax(), f) 4048 std::fmt::Display::fmt(self.syntax(), f)
5442 } 4049 }
5443} 4050}
5444impl std::fmt::Display for MacroDef {
5445 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5446 std::fmt::Display::fmt(self.syntax(), f)
5447 }
5448}
diff --git a/crates/ra_syntax/src/ast/node_ext.rs b/crates/ra_syntax/src/ast/node_ext.rs
index 662c6f73e..242900643 100644
--- a/crates/ra_syntax/src/ast/node_ext.rs
+++ b/crates/ra_syntax/src/ast/node_ext.rs
@@ -472,3 +472,19 @@ impl ast::TokenTree {
472 .filter(|it| matches!(it.kind(), T!['}'] | T![')'] | T![']'])) 472 .filter(|it| matches!(it.kind(), T!['}'] | T![')'] | T![']']))
473 } 473 }
474} 474}
475
476impl ast::DocCommentsOwner for ast::SourceFile {}
477impl ast::DocCommentsOwner for ast::FnDef {}
478impl ast::DocCommentsOwner for ast::StructDef {}
479impl ast::DocCommentsOwner for ast::UnionDef {}
480impl ast::DocCommentsOwner for ast::RecordFieldDef {}
481impl ast::DocCommentsOwner for ast::TupleFieldDef {}
482impl ast::DocCommentsOwner for ast::EnumDef {}
483impl ast::DocCommentsOwner for ast::EnumVariant {}
484impl ast::DocCommentsOwner for ast::TraitDef {}
485impl ast::DocCommentsOwner for ast::Module {}
486impl ast::DocCommentsOwner for ast::StaticDef {}
487impl ast::DocCommentsOwner for ast::ConstDef {}
488impl ast::DocCommentsOwner for ast::TypeAliasDef {}
489impl ast::DocCommentsOwner for ast::ImplDef {}
490impl ast::DocCommentsOwner for ast::MacroCall {}
diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml
index d1cfb5909..8140da87f 100644
--- a/xtask/Cargo.toml
+++ b/xtask/Cargo.toml
@@ -10,9 +10,10 @@ license = "MIT OR Apache-2.0"
10doctest = false 10doctest = false
11 11
12[dependencies] 12[dependencies]
13walkdir = "2.3.1"
14pico-args = "0.3.1"
15quote = "1.0.2"
16proc-macro2 = "1.0.8"
17anyhow = "1.0.26" 13anyhow = "1.0.26"
18flate2 = "1.0" 14flate2 = "1.0"
15pico-args = "0.3.1"
16proc-macro2 = "1.0.8"
17quote = "1.0.2"
18ungrammar = "0.1.0"
19walkdir = "2.3.1"
diff --git a/xtask/src/ast_src.rs b/xtask/src/ast_src.rs
index a6a4d7c35..83449437b 100644
--- a/xtask/src/ast_src.rs
+++ b/xtask/src/ast_src.rs
@@ -223,12 +223,14 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc {
223 ], 223 ],
224}; 224};
225 225
226#[derive(Default, Debug)]
226pub(crate) struct AstSrc { 227pub(crate) struct AstSrc {
227 pub(crate) tokens: Vec<String>, 228 pub(crate) tokens: Vec<String>,
228 pub(crate) nodes: Vec<AstNodeSrc>, 229 pub(crate) nodes: Vec<AstNodeSrc>,
229 pub(crate) enums: Vec<AstEnumSrc>, 230 pub(crate) enums: Vec<AstEnumSrc>,
230} 231}
231 232
233#[derive(Debug)]
232pub(crate) struct AstNodeSrc { 234pub(crate) struct AstNodeSrc {
233 pub(crate) doc: Vec<String>, 235 pub(crate) doc: Vec<String>,
234 pub(crate) name: String, 236 pub(crate) name: String,
@@ -236,1999 +238,23 @@ pub(crate) struct AstNodeSrc {
236 pub(crate) fields: Vec<Field>, 238 pub(crate) fields: Vec<Field>,
237} 239}
238 240
241#[derive(Debug, Eq, PartialEq)]
239pub(crate) enum Field { 242pub(crate) enum Field {
240 Token(String), 243 Token(String),
241 Node { name: String, src: FieldSrc }, 244 Node { name: String, src: FieldSrc },
242} 245}
243 246
247#[derive(Debug, Eq, PartialEq)]
244pub(crate) enum FieldSrc { 248pub(crate) enum FieldSrc {
245 Shorthand, 249 Shorthand,
246 Optional(String), 250 Optional(String),
247 Many(String), 251 Many(String),
248} 252}
249 253
254#[derive(Debug)]
250pub(crate) struct AstEnumSrc { 255pub(crate) struct AstEnumSrc {
251 pub(crate) doc: Vec<String>, 256 pub(crate) doc: Vec<String>,
252 pub(crate) name: String, 257 pub(crate) name: String,
253 pub(crate) traits: Vec<String>, 258 pub(crate) traits: Vec<String>,
254 pub(crate) variants: Vec<String>, 259 pub(crate) variants: Vec<String>,
255} 260}
256
257macro_rules! ast_nodes {
258 ($(
259 $(#[doc = $doc:expr])+
260 struct $name:ident$(: $($trait:ident),*)? {
261 $($field_name:ident $(![$token:tt])? $(: $ty:tt)?),*$(,)?
262 }
263 )*) => {
264 vec![$(
265 AstNodeSrc {
266 doc: vec![$($doc.to_string()),*],
267 name: stringify!($name).to_string(),
268 traits: vec![$($(stringify!($trait).to_string()),*)?],
269 fields: vec![
270 $(field!($(T![$token])? $field_name $($ty)?)),*
271 ],
272
273 }
274 ),*]
275 };
276}
277
278macro_rules! field {
279 (T![$token:tt] T) => {
280 Field::Token(stringify!($token).to_string())
281 };
282 ($field_name:ident) => {
283 Field::Node { name: stringify!($field_name).to_string(), src: FieldSrc::Shorthand }
284 };
285 ($field_name:ident [$ty:ident]) => {
286 Field::Node {
287 name: stringify!($field_name).to_string(),
288 src: FieldSrc::Many(stringify!($ty).to_string()),
289 }
290 };
291 ($field_name:ident $ty:ident) => {
292 Field::Node {
293 name: stringify!($field_name).to_string(),
294 src: FieldSrc::Optional(stringify!($ty).to_string()),
295 }
296 };
297}
298
299macro_rules! ast_enums {
300 ($(
301 $(#[doc = $doc:expr])+
302 enum $name:ident $(: $($trait:ident),*)? {
303 $($variant:ident),*$(,)?
304 }
305 )*) => {
306 vec![$(
307 AstEnumSrc {
308 doc: vec![$($doc.to_string()),*],
309 name: stringify!($name).to_string(),
310 traits: vec![$($(stringify!($trait).to_string()),*)?],
311 variants: vec![$(stringify!($variant).to_string()),*],
312 }
313 ),*]
314 };
315}
316
317pub(crate) fn rust_ast() -> AstSrc {
318 AstSrc {
319 tokens: vec!["Whitespace".into(), "Comment".into(), "String".into(), "RawString".into()],
320 nodes: ast_nodes! {
321 /// The entire Rust source file. Includes all top-level inner attributes and module items.
322 ///
323 /// [Reference](https://doc.rust-lang.org/reference/crates-and-source-files.html)
324 struct SourceFile: ModuleItemOwner, AttrsOwner, DocCommentsOwner {
325 }
326
327 /// Function definition either with body or not.
328 /// Includes all of its attributes and doc comments.
329 ///
330 /// ```
331 /// ❰
332 /// /// Docs
333 /// #[attr]
334 /// pub extern "C" fn foo<T>(#[attr] Patern {p}: Pattern) -> u32
335 /// where
336 /// T: Debug
337 /// {
338 /// 42
339 /// }
340 /// ❱
341 ///
342 /// extern "C" {
343 /// ❰ fn fn_decl(also_variadic_ffi: u32, ...) -> u32; ❱
344 /// }
345 /// ```
346 ///
347 /// - [Reference](https://doc.rust-lang.org/reference/items/functions.html)
348 /// - [Nomicon](https://doc.rust-lang.org/nomicon/ffi.html#variadic-functions)
349 struct FnDef: VisibilityOwner, NameOwner, TypeParamsOwner, DocCommentsOwner, AttrsOwner {
350 Abi,
351 T![const],
352 T![default],
353 T![async],
354 T![unsafe],
355 T![fn],
356 ParamList,
357 RetType,
358 body: BlockExpr,
359 T![;]
360 }
361
362 /// Return type annotation.
363 ///
364 /// ```
365 /// fn foo(a: u32) ❰ -> Option<u32> ❱ { Some(a) }
366 /// ```
367 ///
368 /// [Reference](https://doc.rust-lang.org/reference/items/functions.html)
369 struct RetType { T![->], TypeRef }
370
371 /// Struct definition.
372 /// Includes all of its attributes and doc comments.
373 ///
374 /// ```
375 /// ❰
376 /// /// Docs
377 /// #[attr]
378 /// struct Foo<T> where T: Debug {
379 /// /// Docs
380 /// #[attr]
381 /// pub a: u32,
382 /// b: T,
383 /// }
384 /// ❱
385 ///
386 /// ❰ struct Foo; ❱
387 /// ❰ struct Foo<T>(#[attr] T) where T: Debug; ❱
388 /// ```
389 ///
390 /// [Reference](https://doc.rust-lang.org/reference/items/structs.html)
391 struct StructDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner {
392 T![struct],
393 FieldDefList,
394 T![;]
395 }
396
397 /// Union definition.
398 /// Includes all of its attributes and doc comments.
399 ///
400 /// ```
401 /// ❰
402 /// /// Docs
403 /// #[attr]
404 /// pub union Foo<T> where T: Debug {
405 /// /// Docs
406 /// #[attr]
407 /// a: T,
408 /// b: u32,
409 /// }
410 /// ❱
411 /// ```
412 ///
413 /// [Reference](https://doc.rust-lang.org/reference/items/unions.html)
414 struct UnionDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner {
415 T![union],
416 RecordFieldDefList,
417 }
418
419 /// Record field definition list including enclosing curly braces.
420 ///
421 /// ```
422 /// struct Foo // same for union
423 /// ❰
424 /// {
425 /// a: u32,
426 /// b: bool,
427 /// }
428 /// ❱
429 /// ```
430 ///
431 /// [Reference](https://doc.rust-lang.org/reference/items/structs.html)
432 struct RecordFieldDefList { T!['{'], fields: [RecordFieldDef], T!['}'] }
433
434 /// Record field definition including its attributes and doc comments.
435 ///
436 /// ` ``
437 /// same for union
438 /// struct Foo {
439 /// ❰
440 /// /// Docs
441 /// #[attr]
442 /// pub a: u32
443 /// ❱
444 ///
445 /// ❰ b: bool ❱
446 /// }
447 /// ```
448 ///
449 /// [Reference](https://doc.rust-lang.org/reference/items/structs.html)
450 struct RecordFieldDef: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner { }
451
452 /// Tuple field definition list including enclosing parens.
453 ///
454 /// ```
455 /// struct Foo ❰ (u32, String, Vec<u32>) ❱;
456 /// ```
457 ///
458 /// [Reference](https://doc.rust-lang.org/reference/items/structs.html)
459 struct TupleFieldDefList { T!['('], fields: [TupleFieldDef], T![')'] }
460
461 /// Tuple field definition including its attributes.
462 ///
463 /// ```
464 /// struct Foo(❰ #[attr] u32 ❱);
465 /// ```
466 ///
467 /// [Reference](https://doc.rust-lang.org/reference/items/structs.html)
468 struct TupleFieldDef: VisibilityOwner, AttrsOwner {
469 TypeRef,
470 }
471
472 /// Enum definition.
473 /// Includes all of its attributes and doc comments.
474 ///
475 /// ```
476 /// ❰
477 /// /// Docs
478 /// #[attr]
479 /// pub enum Foo<T> where T: Debug {
480 /// /// Docs
481 /// #[attr]
482 /// Bar,
483 /// Baz(#[attr] u32),
484 /// Bruh {
485 /// a: u32,
486 /// /// Docs
487 /// #[attr]
488 /// b: T,
489 /// }
490 /// }
491 /// ❱
492 /// ```
493 ///
494 /// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html)
495 struct EnumDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner {
496 T![enum],
497 variant_list: EnumVariantList,
498 }
499
500 /// Enum variant definition list including enclosing curly braces.
501 ///
502 /// ```
503 /// enum Foo
504 /// ❰
505 /// {
506 /// Bar,
507 /// Baz(u32),
508 /// Bruh {
509 /// a: u32
510 /// }
511 /// }
512 /// ❱
513 /// ```
514 ///
515 /// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html)
516 struct EnumVariantList {
517 T!['{'],
518 variants: [EnumVariant],
519 T!['}']
520 }
521
522 /// Enum variant definition including its attributes and discriminant value definition.
523 ///
524 /// ```
525 /// enum Foo {
526 /// ❰
527 /// /// Docs
528 /// #[attr]
529 /// Bar
530 /// ❱
531 ///
532 /// // same for tuple and record variants
533 /// }
534 /// ```
535 ///
536 /// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html)
537 struct EnumVariant: VisibilityOwner, NameOwner, DocCommentsOwner, AttrsOwner {
538 FieldDefList,
539 T![=],
540 Expr
541 }
542
543 /// Trait definition.
544 /// Includes all of its attributes and doc comments.
545 ///
546 /// ```
547 /// ❰
548 /// /// Docs
549 /// #[attr]
550 /// pub unsafe trait Foo<T>: Debug where T: Debug {
551 /// // ...
552 /// }
553 /// ❱
554 /// ```
555 ///
556 /// [Reference](https://doc.rust-lang.org/reference/items/traits.html)
557 struct TraitDef: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner, TypeParamsOwner, TypeBoundsOwner {
558 T![unsafe],
559 T![auto],
560 T![trait],
561 ItemList,
562 }
563
564 /// Module definition either with body or not.
565 /// Includes all of its inner and outer attributes, module items, doc comments.
566 ///
567 /// ```
568 /// ❰
569 /// /// Docs
570 /// #[attr]
571 /// pub mod foo;
572 /// ❱
573 ///
574 /// ❰
575 /// /// Docs
576 /// #[attr]
577 /// pub mod bar {
578 /// //! Inner docs
579 /// #![inner_attr]
580 /// }
581 /// ❱
582 /// ```
583 ///
584 /// [Reference](https://doc.rust-lang.org/reference/items/modules.html)
585 struct Module: VisibilityOwner, NameOwner, AttrsOwner, DocCommentsOwner {
586 T![mod],
587 ItemList,
588 T![;]
589 }
590
591 /// Item defintion list.
592 /// This is used for both top-level items and impl block items.
593 ///
594 /// ```
595 /// ❰
596 /// fn foo {}
597 /// struct Bar;
598 /// enum Baz;
599 /// trait Bruh;
600 /// const BRUUH: u32 = 42;
601 /// ❱
602 ///
603 /// impl Foo
604 /// ❰
605 /// {
606 /// fn bar() {}
607 /// const BAZ: u32 = 42;
608 /// }
609 /// ❱
610 /// ```
611 ///
612 /// [Reference](https://doc.rust-lang.org/reference/items.html)
613 struct ItemList: ModuleItemOwner {
614 T!['{'],
615 assoc_items: [AssocItem],
616 T!['}']
617 }
618
619 /// Constant variable definition.
620 /// Includes all of its attributes and doc comments.
621 ///
622 /// ```
623 /// ❰
624 /// /// Docs
625 /// #[attr]
626 /// pub const FOO: u32 = 42;
627 /// ❱
628 /// ```
629 ///
630 /// [Reference](https://doc.rust-lang.org/reference/items/constant-items.html)
631 struct ConstDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner {
632 T![default],
633 T![const],
634 T![=],
635 body: Expr,
636 T![;]
637 }
638
639
640 /// Static variable definition.
641 /// Includes all of its attributes and doc comments.
642 ///
643 /// ```
644 /// ❰
645 /// /// Docs
646 /// #[attr]
647 /// pub static mut FOO: u32 = 42;
648 /// ❱
649 /// ```
650 ///
651 /// [Reference](https://doc.rust-lang.org/reference/items/static-items.html)
652 struct StaticDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeAscriptionOwner {
653 T![static],
654 T![mut],
655 T![=],
656 body: Expr,
657 T![;]
658 }
659
660 /// Type alias definition.
661 /// Includes associated type clauses with type bounds.
662 ///
663 /// ```
664 /// ❰
665 /// /// Docs
666 /// #[attr]
667 /// pub type Foo<T> where T: Debug = T;
668 /// ❱
669 ///
670 /// trait Bar {
671 /// ❰ type Baz: Debug; ❱
672 /// ❰ type Bruh = String; ❱
673 /// ❰ type Bruuh: Debug = u32; ❱
674 /// }
675 /// ```
676 ///
677 /// [Reference](https://doc.rust-lang.org/reference/items/type-aliases.html)
678 struct TypeAliasDef: VisibilityOwner, NameOwner, TypeParamsOwner, AttrsOwner, DocCommentsOwner, TypeBoundsOwner {
679 T![default],
680 T![type],
681 T![=],
682 TypeRef,
683 T![;]
684 }
685
686 /// Inherent and trait impl definition.
687 /// Includes all of its inner and outer attributes.
688 ///
689 /// ```
690 /// ❰
691 /// #[attr]
692 /// unsafe impl<T> const !Foo for Bar where T: Debug {
693 /// #![inner_attr]
694 /// // ...
695 /// }
696 /// ❱
697 /// ```
698 ///
699 /// [Reference](https://doc.rust-lang.org/reference/items/implementations.html)
700 struct ImplDef: TypeParamsOwner, AttrsOwner, DocCommentsOwner {
701 T![default],
702 T![const],
703 T![unsafe],
704 T![impl],
705 T![!],
706 T![for],
707 ItemList,
708 }
709
710
711 /// Parenthesized type reference.
712 /// Note: parens are only used for grouping, this is not a tuple type.
713 ///
714 /// ```
715 /// // This is effectively just `u32`.
716 /// // Single-item tuple must be defined with a trailing comma: `(u32,)`
717 /// type Foo = ❰ (u32) ❱;
718 ///
719 /// let bar: &'static ❰ (dyn Debug) ❱ = "bruh";
720 /// ```
721 struct ParenType { T!['('], TypeRef, T![')'] }
722
723 /// Unnamed tuple type.
724 ///
725 /// ```
726 /// let foo: ❰ (u32, bool) ❱ = (42, true);
727 /// ```
728 ///
729 /// [Reference](https://doc.rust-lang.org/reference/types/tuple.html)
730 struct TupleType { T!['('], fields: [TypeRef], T![')'] }
731
732 /// The never type (i.e. the exclamation point).
733 ///
734 /// ```
735 /// type T = ❰ ! ❱;
736 ///
737 /// fn no_return() -> ❰ ! ❱ {
738 /// loop {}
739 /// }
740 /// ```
741 ///
742 /// [Reference](https://doc.rust-lang.org/reference/types/never.html)
743 struct NeverType { T![!] }
744
745 /// Path to a type.
746 /// Includes single identifier type names and elaborate paths with
747 /// generic parameters.
748 ///
749 /// ```
750 /// type Foo = ❰ String ❱;
751 /// type Bar = ❰ std::vec::Vec<T> ❱;
752 /// type Baz = ❰ ::bruh::<Bruuh as Iterator>::Item ❱;
753 /// ```
754 ///
755 /// [Reference](https://doc.rust-lang.org/reference/paths.html)
756 struct PathType { Path }
757
758 /// Raw pointer type.
759 ///
760 /// ```
761 /// type Foo = ❰ *const u32 ❱;
762 /// type Bar = ❰ *mut u32 ❱;
763 /// ```
764 ///
765 /// [Reference](https://doc.rust-lang.org/reference/types/pointer.html#raw-pointers-const-and-mut)
766 struct PointerType { T![*], T![const], T![mut], TypeRef }
767
768 /// Array type.
769 ///
770 /// ```
771 /// type Foo = ❰ [u32; 24 - 3] ❱;
772 /// ```
773 ///
774 /// [Reference](https://doc.rust-lang.org/reference/types/array.html)
775 struct ArrayType { T!['['], TypeRef, T![;], Expr, T![']'] }
776
777 /// Slice type.
778 ///
779 /// ```
780 /// type Foo = ❰ [u8] ❱;
781 /// ```
782 ///
783 /// [Reference](https://doc.rust-lang.org/reference/types/slice.html)
784 struct SliceType { T!['['], TypeRef, T![']'] }
785
786 /// Reference type.
787 ///
788 /// ```
789 /// type Foo = ❰ &'static str ❱;
790 /// ```
791 ///
792 /// [Reference](https://doc.rust-lang.org/reference/types/pointer.html)
793 struct ReferenceType { T![&], T![lifetime], T![mut], TypeRef }
794
795 /// Placeholder type (i.e. the underscore).
796 ///
797 /// ```
798 /// let foo: ❰ _ ❱ = 42_u32;
799 /// ```
800 ///
801 /// [Reference](https://doc.rust-lang.org/reference/types/inferred.html)
802 struct PlaceholderType { T![_] }
803
804 /// Function pointer type (not to be confused with `Fn*` family of traits).
805 ///
806 /// ```
807 /// type Foo = ❰ async fn(#[attr] u32, named: bool) -> u32 ❱;
808 ///
809 /// type Bar = ❰ extern "C" fn(variadic: u32, #[attr] ...) ❱;
810 /// ```
811 ///
812 /// [Reference](https://doc.rust-lang.org/reference/types/function-pointer.html)
813 struct FnPointerType { Abi, T![unsafe], T![fn], ParamList, RetType }
814
815 /// Higher order type.
816 ///
817 /// ```
818 /// type Foo = ❰ for<'a> fn(&'a str) ❱;
819 /// ```
820 ///
821 /// [Reference](https://doc.rust-lang.org/nomicon/hrtb.html)
822 struct ForType { T![for], TypeParamList, TypeRef }
823
824 /// Opaque `impl Trait` type.
825 ///
826 /// ```
827 /// fn foo(bar: ❰ impl Debug + Eq ❱) {}
828 /// ```
829 ///
830 /// [Reference](https://doc.rust-lang.org/reference/types/impl-trait.html)
831 struct ImplTraitType: TypeBoundsOwner { T![impl] }
832
833 /// Trait object type.
834 ///
835 /// ```
836 /// type Foo = ❰ dyn Debug ❱;
837 /// ```
838 ///
839 /// [Reference](https://doc.rust-lang.org/reference/types/trait-object.html)
840 struct DynTraitType: TypeBoundsOwner { T![dyn] }
841
842 /// Tuple literal.
843 ///
844 /// ```
845 /// ❰ (42, true) ❱;
846 /// ```
847 ///
848 /// [Reference](https://doc.rust-lang.org/reference/expressions/tuple-expr.html)
849 struct TupleExpr: AttrsOwner { T!['('], exprs: [Expr], T![')'] }
850
851 /// Array literal.
852 ///
853 /// ```
854 /// ❰ [#![inner_attr] true, false, true] ❱;
855 ///
856 /// ❰ ["baz"; 24] ❱;
857 /// ```
858 ///
859 /// [Reference](https://doc.rust-lang.org/reference/expressions/array-expr.html)
860 struct ArrayExpr: AttrsOwner { T!['['], exprs: [Expr], T![;], T![']'] }
861
862 /// Parenthesized expression.
863 /// Note: parens are only used for grouping, this is not a tuple literal.
864 ///
865 /// ```
866 /// ❰ (#![inner_attr] 2 + 2) ❱ * 2;
867 /// ```
868 ///
869 /// [Reference](https://doc.rust-lang.org/reference/expressions/grouped-expr.html)
870 struct ParenExpr: AttrsOwner { T!['('], Expr, T![')'] }
871
872 /// Path to a symbol in expression context.
873 /// Includes single identifier variable names and elaborate paths with
874 /// generic parameters.
875 ///
876 /// ```
877 /// ❰ Some::<i32> ❱;
878 /// ❰ foo ❱ + 42;
879 /// ❰ Vec::<i32>::push ❱;
880 /// ❰ <[i32]>::reverse ❱;
881 /// ❰ <String as std::borrow::Borrow<str>>::borrow ❱;
882 /// ```
883 ///
884 /// [Reference](https://doc.rust-lang.org/reference/expressions/path-expr.html)
885 struct PathExpr { Path }
886
887 /// Anonymous callable object literal a.k.a. closure, lambda or functor.
888 ///
889 /// ```
890 /// ❰ || 42 ❱;
891 /// ❰ |a: u32| val + 1 ❱;
892 /// ❰ async |#[attr] Pattern(_): Pattern| { bar } ❱;
893 /// ❰ move || baz ❱;
894 /// ❰ || -> u32 { closure_with_ret_type_annotation_requires_block_expr } ❱
895 /// ```
896 ///
897 /// [Reference](https://doc.rust-lang.org/reference/expressions/closure-expr.html)
898 struct LambdaExpr: AttrsOwner {
899 T![static], // Note(@matklad): I belive this is (used to be?) syntax for generators
900 T![async],
901 T![move],
902 ParamList,
903 RetType,
904 body: Expr,
905 }
906
907 /// If expression. Includes both regular `if` and `if let` forms.
908 /// Beware that `else if` is a special case syntax sugar, because in general
909 /// there has to be block expression after `else`.
910 ///
911 /// ```
912 /// ❰ if bool_cond { 42 } ❱
913 /// ❰ if bool_cond { 42 } else { 24 } ❱
914 /// ❰ if bool_cond { 42 } else if bool_cond2 { 42 } ❱
915 ///
916 /// ❰
917 /// if let Pattern(foo) = bar {
918 /// foo
919 /// } else {
920 /// panic!();
921 /// }
922 /// ❱
923 /// ```
924 ///
925 /// [Reference](https://doc.rust-lang.org/reference/expressions/if-expr.html)
926 struct IfExpr: AttrsOwner { T![if], Condition }
927
928 /// Unconditional loop expression.
929 ///
930 /// ```
931 /// ❰
932 /// loop {
933 /// // yeah, it's that simple...
934 /// }
935 /// ❱
936 /// ```
937 ///
938 /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html)
939 struct LoopExpr: AttrsOwner, LoopBodyOwner { T![loop] }
940
941 /// Block expression with an optional prefix (label, try ketword,
942 /// unsafe keyword, async keyword...).
943 ///
944 /// ```
945 /// ❰
946 /// 'label: try {
947 /// None?
948 /// }
949 /// ❱
950 /// ```
951 ///
952 /// - [try block](https://doc.rust-lang.org/unstable-book/language-features/try-blocks.html)
953 /// - [unsafe block](https://doc.rust-lang.org/reference/expressions/block-expr.html#unsafe-blocks)
954 /// - [async block](https://doc.rust-lang.org/reference/expressions/block-expr.html#async-blocks)
955 struct EffectExpr: AttrsOwner { Label, T![try], T![unsafe], T![async], BlockExpr }
956
957
958 /// For loop expression.
959 /// Note: record struct literals are not valid as iterable expression
960 /// due to ambiguity.
961 ///
962 /// ```
963 /// ❰
964 /// for i in (0..4) {
965 /// dbg!(i);
966 /// }
967 /// ❱
968 /// ```
969 ///
970 /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#iterator-loops)
971 struct ForExpr: AttrsOwner, LoopBodyOwner {
972 T![for],
973 Pat,
974 T![in],
975 iterable: Expr,
976 }
977
978 /// While loop expression. Includes both regular `while` and `while let` forms.
979 ///
980 /// ```
981 /// ❰
982 /// while bool_cond {
983 /// 42;
984 /// }
985 /// ❱
986 /// ❰
987 /// while let Pattern(foo) = bar {
988 /// bar += 1;
989 /// }
990 /// ❱
991 /// ```
992 ///
993 /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-loops)
994 struct WhileExpr: AttrsOwner, LoopBodyOwner { T![while], Condition }
995
996 /// Continue expression.
997 ///
998 /// ```
999 /// while bool_cond {
1000 /// ❰ continue ❱;
1001 /// }
1002 ///
1003 /// 'outer: loop {
1004 /// loop {
1005 /// ❰ continue 'outer ❱;
1006 /// }
1007 /// }
1008 ///
1009 /// ```
1010 ///
1011 /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#continue-expressions)
1012 struct ContinueExpr: AttrsOwner { T![continue], T![lifetime] }
1013
1014 /// Break expression.
1015 ///
1016 /// ```
1017 /// while bool_cond {
1018 /// ❰ break ❱;
1019 /// }
1020 /// 'outer: loop {
1021 /// for foo in bar {
1022 /// ❰ break 'outer ❱;
1023 /// }
1024 /// }
1025 /// 'outer: loop {
1026 /// loop {
1027 /// ❰ break 'outer 42 ❱;
1028 /// }
1029 /// }
1030 /// ```
1031 ///
1032 /// [Refernce](https://doc.rust-lang.org/reference/expressions/loop-expr.html#break-expressions)
1033 struct BreakExpr: AttrsOwner { T![break], T![lifetime], Expr }
1034
1035 /// Label.
1036 ///
1037 /// ```
1038 /// ❰ 'outer: ❱ loop {}
1039 ///
1040 /// let foo = ❰ 'bar: ❱ loop {}
1041 ///
1042 /// ❰ 'baz: ❱ {
1043 /// break 'baz;
1044 /// }
1045 /// ```
1046 ///
1047 /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html?highlight=label#loop-labels)
1048 /// [Labels for blocks RFC](https://github.com/rust-lang/rfcs/blob/master/text/2046-label-break-value.md)
1049 struct Label { T![lifetime] }
1050
1051 /// Block expression. Includes unsafe blocks and block labels.
1052 ///
1053 /// ```
1054 /// let foo = ❰
1055 /// {
1056 /// #![inner_attr]
1057 /// ❰ { } ❱
1058 ///
1059 /// ❰ 'label: { break 'label } ❱
1060 /// }
1061 /// ❱;
1062 /// ```
1063 ///
1064 /// [Reference](https://doc.rust-lang.org/reference/expressions/block-expr.html)
1065 /// [Labels for blocks RFC](https://github.com/rust-lang/rfcs/blob/master/text/2046-label-break-value.md)
1066 struct BlockExpr: AttrsOwner, ModuleItemOwner {
1067 Label, T!['{'], statements: [Stmt], Expr, T!['}'],
1068 }
1069
1070 /// Return expression.
1071 ///
1072 /// ```
1073 /// || ❰ return 42 ❱;
1074 ///
1075 /// fn bar() {
1076 /// ❰ return ❱;
1077 /// }
1078 /// ```
1079 ///
1080 /// [Reference](https://doc.rust-lang.org/reference/expressions/return-expr.html)
1081 struct ReturnExpr: AttrsOwner { Expr }
1082
1083 /// Call expression (not to be confused with method call expression, it is
1084 /// a separate ast node).
1085 ///
1086 /// ```
1087 /// ❰ foo() ❱;
1088 /// ❰ &str::len("bar") ❱;
1089 /// ❰ <&str as PartialEq<&str>>::eq(&"", &"") ❱;
1090 /// ```
1091 ///
1092 /// [Reference](https://doc.rust-lang.org/reference/expressions/call-expr.html)
1093 struct CallExpr: ArgListOwner { Expr }
1094
1095 /// Method call expression.
1096 ///
1097 /// ```
1098 /// ❰ receiver_expr.method() ❱;
1099 /// ❰ receiver_expr.method::<T>(42, true) ❱;
1100 ///
1101 /// ❰ ❰ ❰ foo.bar() ❱ .baz() ❱ .bruh() ❱;
1102 /// ```
1103 ///
1104 /// [Reference](https://doc.rust-lang.org/reference/expressions/method-call-expr.html)
1105 struct MethodCallExpr: AttrsOwner, ArgListOwner {
1106 Expr, T![.], NameRef, TypeArgList,
1107 }
1108
1109 /// Index expression a.k.a. subscript operator call.
1110 ///
1111 /// ```
1112 /// ❰ foo[42] ❱;
1113 /// ```
1114 ///
1115 /// [Reference](https://doc.rust-lang.org/reference/expressions/array-expr.html)
1116 struct IndexExpr: AttrsOwner { T!['['], T![']'] }
1117
1118 /// Field access expression.
1119 ///
1120 /// ```
1121 /// ❰ expr.bar ❱;
1122 ///
1123 /// ❰ ❰ ❰ foo.bar ❱ .baz ❱ .bruh ❱;
1124 /// ```
1125 ///
1126 /// [Reference](https://doc.rust-lang.org/reference/expressions/field-expr.html)
1127 struct FieldExpr: AttrsOwner { Expr, T![.], NameRef }
1128
1129 /// Await operator call expression.
1130 ///
1131 /// ```
1132 /// ❰ expr.await ❱;
1133 /// ```
1134 ///
1135 /// [Reference](https://doc.rust-lang.org/reference/expressions/await-expr.html)
1136 struct AwaitExpr: AttrsOwner { Expr, T![.], T![await] }
1137
1138 /// The question mark operator call.
1139 ///
1140 /// ```
1141 /// ❰ expr? ❱;
1142 /// ```
1143 ///
1144 /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#the-question-mark-operator)
1145 struct TryExpr: AttrsOwner { Expr, T![?] }
1146
1147 /// Type cast expression.
1148 ///
1149 /// ```
1150 /// ❰ expr as T ❱;
1151 /// ```
1152 ///
1153 /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions)
1154 struct CastExpr: AttrsOwner { Expr, T![as], TypeRef }
1155
1156
1157 /// Borrow operator call.
1158 ///
1159 /// ```
1160 /// ❰ &foo ❱;
1161 /// ❰ &mut bar ❱;
1162 /// ❰ &raw const bar ❱;
1163 /// ❰ &raw mut bar ❱;
1164 /// ```
1165 ///
1166 /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#borrow-operators)
1167 struct RefExpr: AttrsOwner { T![&], T![raw], T![mut], T![const], Expr }
1168
1169 /// Prefix operator call. This is either `!` or `*` or `-`.
1170 ///
1171 /// ```
1172 /// ❰ !foo ❱;
1173 /// ❰ *bar ❱;
1174 /// ❰ -42 ❱;
1175 /// ```
1176 ///
1177 /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html)
1178 struct PrefixExpr: AttrsOwner { /*PrefixOp,*/ Expr }
1179
1180 /// Box operator call.
1181 ///
1182 /// ```
1183 /// ❰ box 42 ❱;
1184 /// ```
1185 ///
1186 /// [RFC](https://github.com/rust-lang/rfcs/blob/0806be4f282144cfcd55b1d20284b43f87cbe1c6/text/0809-box-and-in-for-stdlib.md)
1187 struct BoxExpr: AttrsOwner { T![box], Expr }
1188
1189 /// Range operator call.
1190 ///
1191 /// ```
1192 /// ❰ 0..42 ❱;
1193 /// ❰ ..42 ❱;
1194 /// ❰ 0.. ❱;
1195 /// ❰ .. ❱;
1196 /// ❰ 0..=42 ❱;
1197 /// ❰ ..=42 ❱;
1198 /// ```
1199 ///
1200 /// [Reference](https://doc.rust-lang.org/reference/expressions/range-expr.html)
1201 struct RangeExpr: AttrsOwner { /*RangeOp*/ }
1202
1203
1204 /// Binary operator call.
1205 /// Includes all arithmetic, logic, bitwise and assignment operators.
1206 ///
1207 /// ```
1208 /// ❰ 2 + ❰ 2 * 2 ❱ ❱;
1209 /// ❰ ❰ true && false ❱ || true ❱;
1210 /// ```
1211 ///
1212 /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#arithmetic-and-logical-binary-operators)
1213 struct BinExpr: AttrsOwner { /*BinOp*/ }
1214
1215
1216 /// [Raw] string, [raw] byte string, char, byte, integer, float or bool literal.
1217 ///
1218 /// ```
1219 /// ❰ "str" ❱;
1220 /// ❰ br##"raw byte str"## ❱;
1221 /// ❰ 'c' ❱;
1222 /// ❰ b'c' ❱;
1223 /// ❰ 42 ❱;
1224 /// ❰ 1e9 ❱;
1225 /// ❰ true ❱;
1226 /// ```
1227 ///
1228 /// [Reference](https://doc.rust-lang.org/reference/expressions/literal-expr.html)
1229 struct Literal { /*LiteralToken*/ }
1230
1231 /// Match expression.
1232 ///
1233 /// ```
1234 /// ❰
1235 /// match expr {
1236 /// Pat1 => {}
1237 /// Pat2(_) => 42,
1238 /// }
1239 /// ❱
1240 /// ```
1241 ///
1242 /// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html)
1243 struct MatchExpr: AttrsOwner { T![match], Expr, MatchArmList }
1244
1245 /// Match arm list part of match expression. Includes its inner attributes.
1246 ///
1247 /// ```
1248 /// match expr
1249 /// ❰
1250 /// {
1251 /// #![inner_attr]
1252 /// Pat1 => {}
1253 /// Pat2(_) => 42,
1254 /// }
1255 /// ❱
1256 /// ```
1257 ///
1258 /// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html)
1259 struct MatchArmList: AttrsOwner { T!['{'], arms: [MatchArm], T!['}'] }
1260
1261
1262 /// Match arm.
1263 /// Note: record struct literals are not valid as target match expression
1264 /// due to ambiguity.
1265 /// ```
1266 /// match expr {
1267 /// ❰ #[attr] Pattern(it) if bool_cond => it ❱,
1268 /// }
1269 /// ```
1270 ///
1271 /// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html)
1272 struct MatchArm: AttrsOwner {
1273 pat: Pat,
1274 guard: MatchGuard,
1275 T![=>],
1276 Expr,
1277 }
1278
1279 /// Match guard.
1280 ///
1281 /// ```
1282 /// match expr {
1283 /// Pattern(it) ❰ if bool_cond ❱ => it,
1284 /// }
1285 /// ```
1286 ///
1287 /// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html#match-guards)
1288 struct MatchGuard { T![if], Expr }
1289
1290 /// Record literal expression. The same syntax is used for structs,
1291 /// unions and record enum variants.
1292 ///
1293 /// ```
1294 /// ❰
1295 /// foo::Bar {
1296 /// #![inner_attr]
1297 /// baz: 42,
1298 /// bruh: true,
1299 /// ..spread
1300 /// }
1301 /// ❱
1302 /// ```
1303 ///
1304 /// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html)
1305 struct RecordLit { Path, RecordFieldList}
1306
1307 /// Record field list including enclosing curly braces.
1308 ///
1309 /// foo::Bar ❰
1310 /// {
1311 /// baz: 42,
1312 /// ..spread
1313 /// }
1314 /// ❱
1315 ///
1316 /// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html)
1317 struct RecordFieldList {
1318 T!['{'],
1319 fields: [RecordField],
1320 T![..],
1321 spread: Expr,
1322 T!['}']
1323 }
1324
1325 /// Record field.
1326 ///
1327 /// ```
1328 /// foo::Bar {
1329 /// ❰ #[attr] baz: 42 ❱
1330 /// }
1331 /// ```
1332 ///
1333 /// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html)
1334 struct RecordField: AttrsOwner { NameRef, T![:], Expr }
1335
1336 /// Disjunction of patterns.
1337 ///
1338 /// ```
1339 /// let ❰ Foo(it) | Bar(it) | Baz(it) ❱ = bruh;
1340 /// ```
1341 ///
1342 /// [Reference](https://doc.rust-lang.org/reference/patterns.html)
1343 struct OrPat { pats: [Pat] }
1344
1345 /// Parenthesized pattern.
1346 /// Note: parens are only used for grouping, this is not a tuple pattern.
1347 ///
1348 /// ```
1349 /// if let ❰ &(0..=42) ❱ = foo {}
1350 /// ```
1351 ///
1352 /// https://doc.rust-lang.org/reference/patterns.html#grouped-patterns
1353 struct ParenPat { T!['('], Pat, T![')'] }
1354
1355 /// Reference pattern.
1356 /// Note: this has nothing to do with `ref` keyword, the latter is used in bind patterns.
1357 ///
1358 /// ```
1359 /// let ❰ &mut foo ❱ = bar;
1360 ///
1361 /// let ❰ & ❰ &mut ❰ &_ ❱ ❱ ❱ = baz;
1362 /// ```
1363 ///
1364 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#reference-patterns)
1365 struct RefPat { T![&], T![mut], Pat }
1366
1367 /// Box pattern.
1368 ///
1369 /// ```
1370 /// let ❰ box foo ❱ = box 42;
1371 /// ```
1372 ///
1373 /// [Unstable book](https://doc.rust-lang.org/unstable-book/language-features/box-patterns.html)
1374 struct BoxPat { T![box], Pat }
1375
1376 /// Bind pattern.
1377 ///
1378 /// ```
1379 /// match foo {
1380 /// Some(❰ ref mut bar ❱) => {}
1381 /// ❰ baz @ None ❱ => {}
1382 /// }
1383 /// ```
1384 ///
1385 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#identifier-patterns)
1386 struct BindPat: AttrsOwner, NameOwner { T![ref], T![mut], T![@], Pat }
1387
1388 /// Placeholder pattern a.k.a. the wildcard pattern or the underscore.
1389 ///
1390 /// ```
1391 /// let ❰ _ ❱ = foo;
1392 /// ```
1393 ///
1394 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#wildcard-pattern)
1395 struct PlaceholderPat { T![_] }
1396
1397 /// Rest-of-the record/tuple pattern.
1398 /// Note: this is not the unbonded range pattern (even more: it doesn't exist).
1399 ///
1400 /// ```
1401 /// let Foo { bar, ❰ .. ❱ } = baz;
1402 /// let (❰ .. ❱, bruh) = (42, 24, 42);
1403 /// let Bruuh(❰ .. ❱) = bruuuh;
1404 /// ```
1405 ///
1406 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns)
1407 struct DotDotPat { T![..] }
1408
1409 /// Path pattern.
1410 /// Doesn't include the underscore pattern (it is a special case, namely `PlaceholderPat`).
1411 ///
1412 /// ```
1413 /// let ❰ foo::bar::Baz ❱ { .. } = bruh;
1414 /// if let ❰ CONST ❱ = 42 {}
1415 /// ```
1416 ///
1417 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#path-patterns)
1418 struct PathPat { Path }
1419
1420 /// Slice pattern.
1421 ///
1422 /// ```
1423 /// let ❰ [foo, bar, baz] ❱ = [1, 2, 3];
1424 /// ```
1425 ///
1426 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#slice-patterns)
1427 struct SlicePat { T!['['], args: [Pat], T![']'] }
1428
1429 /// Range pattern.
1430 ///
1431 /// ```
1432 /// match foo {
1433 /// ❰ 0..42 ❱ => {}
1434 /// ❰ 0..=42 ❱ => {}
1435 /// }
1436 /// ```
1437 ///
1438 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#range-patterns)
1439 struct RangePat { } // FIXME(@matklad): here should be T![..], T![..=] I think, if we don't already have an accessor in expresions_ext
1440
1441 /// Literal pattern.
1442 /// Includes only bool, number, char, and string literals.
1443 ///
1444 /// ```
1445 /// match foo {
1446 /// Number(❰ 42 ❱) => {}
1447 /// String(❰ "42" ❱) => {}
1448 /// Bool(❰ true ❱) => {}
1449 /// }
1450 /// ```
1451 ///
1452 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#literal-patterns)
1453 struct LiteralPat { Literal }
1454
1455 /// Macro invocation in pattern position.
1456 ///
1457 /// ```
1458 /// let ❰ foo!(my custom syntax) ❱ = baz;
1459 ///
1460 /// ```
1461 /// [Reference](https://doc.rust-lang.org/reference/macros.html#macro-invocation)
1462 struct MacroPat { MacroCall }
1463
1464 /// Record literal pattern.
1465 ///
1466 /// ```
1467 /// let ❰ foo::Bar { baz, .. } ❱ = bruh;
1468 /// ```
1469 ///
1470 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns)
1471 struct RecordPat { RecordFieldPatList, Path }
1472
1473 /// Record literal's field patterns list including enclosing curly braces.
1474 ///
1475 /// ```
1476 /// let foo::Bar ❰ { baz, bind @ bruh, .. } ❱ = bruuh;
1477 /// ``
1478 ///
1479 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns)
1480 struct RecordFieldPatList {
1481 T!['{'],
1482 record_field_pats: [RecordFieldPat],
1483 bind_pats: [BindPat],
1484 T![..],
1485 T!['}']
1486 }
1487
1488 /// Record literal's field pattern.
1489 /// Note: record literal can also match tuple structs.
1490 ///
1491 /// ```
1492 /// let Foo { ❰ bar: _ ❱ } = baz;
1493 /// let TupleStruct { ❰ 0: _ ❱ } = bruh;
1494 /// ```
1495 ///
1496 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns)
1497 struct RecordFieldPat: AttrsOwner { NameRef, T![:], Pat }
1498
1499 /// Tuple struct literal pattern.
1500 ///
1501 /// ```
1502 /// let ❰ foo::Bar(baz, bruh) ❱ = bruuh;
1503 /// ```
1504 ///
1505 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#tuple-struct-patterns)
1506 struct TupleStructPat { Path, T!['('], args: [Pat], T![')'] }
1507
1508 /// Tuple pattern.
1509 /// Note: this doesn't include tuple structs (see `TupleStructPat`)
1510 ///
1511 /// ```
1512 /// let ❰ (foo, bar, .., baz) ❱ = bruh;
1513 /// ```
1514 ///
1515 /// [Reference](https://doc.rust-lang.org/reference/patterns.html#tuple-patterns)
1516 struct TuplePat { T!['('], args: [Pat], T![')'] }
1517
1518 /// Visibility.
1519 ///
1520 /// ```
1521 /// ❰ pub mod ❱ foo;
1522 /// ❰ pub(crate) ❱ struct Bar;
1523 /// ❰ pub(self) ❱ enum Baz {}
1524 /// ❰ pub(super) ❱ fn bruh() {}
1525 /// ❰ pub(in bruuh::bruuuh) ❱ type T = u64;
1526 /// ```
1527 ///
1528 /// [Reference](https://doc.rust-lang.org/reference/visibility-and-privacy.html)
1529 struct Visibility { T![pub], T![super], T![self], T![crate] }
1530
1531 /// Single identifier.
1532 /// Note(@matklad): `Name` is for things that install a new name into the scope,
1533 /// `NameRef` is a usage of a name. Most of the time, this definition/reference
1534 /// distinction can be determined purely syntactically, ie in
1535 /// ```
1536 /// fn foo() { foo() }
1537 /// ```
1538 /// the first foo is `Name`, the second one is `NameRef`.
1539 /// The notable exception are patterns, where in
1540 /// ``
1541 /// let x = 92
1542 /// ```
1543 /// `x` can be semantically either a name or a name ref, depeding on
1544 /// wether there's an `x` constant in scope.
1545 /// We use `Name` for patterns, and disambiguate semantically (see `NameClass` in ide_db).
1546 ///
1547 /// ```
1548 /// let ❰ foo ❱ = bar;
1549 /// struct ❰ Baz ❱;
1550 /// fn ❰ bruh ❱() {}
1551 /// ```
1552 ///
1553 /// [Reference](https://doc.rust-lang.org/reference/identifiers.html)
1554 struct Name { T![ident] }
1555
1556 /// Reference to a name.
1557 /// See the explanation on the difference between `Name` and `NameRef`
1558 /// in `Name` ast node docs.
1559 ///
1560 /// ```
1561 /// let foo = ❰ bar ❱(❰ Baz(❰ bruh ❱) ❱;
1562 /// ```
1563 ///
1564 /// [Reference](https://doc.rust-lang.org/reference/identifiers.html)
1565 struct NameRef { }
1566
1567 /// Macro call.
1568 /// Includes all of its attributes and doc comments.
1569 ///
1570 /// ```
1571 /// ❰
1572 /// /// Docs
1573 /// #[attr]
1574 /// macro_rules! foo { // macro rules is also a macro call
1575 /// ($bar: tt) => {}
1576 /// }
1577 /// ❱
1578 ///
1579 /// // semicolon is a part of `MacroCall` when it is used in item positions
1580 /// ❰ foo!(); ❱
1581 ///
1582 /// fn main() {
1583 /// ❰ foo!() ❱; // macro call in expression positions doesn't include the semi
1584 /// }
1585 /// ```
1586 ///
1587 /// [Reference](https://doc.rust-lang.org/reference/macros.html)
1588 struct MacroCall: NameOwner, AttrsOwner, DocCommentsOwner {
1589 Path, T![!], TokenTree, T![;]
1590 }
1591
1592 /// Attribute.
1593 ///
1594 /// ```
1595 /// ❰ #![inner_attr] ❱
1596 ///
1597 /// ❰ #[attr] ❱
1598 /// ❰ #[foo = "bar"] ❱
1599 /// ❰ #[baz(bruh::bruuh = "42")] ❱
1600 /// struct Foo;
1601 /// ```
1602 ///
1603 /// [Reference](https://doc.rust-lang.org/reference/attributes.html)
1604 struct Attr { T![#], T![!], T!['['], Path, T![=], input: AttrInput, T![']'] }
1605
1606 /// Stores a list of lexer tokens and other `TokenTree`s.
1607 /// It appears in attributes, macro_rules and macro call (foo!)
1608 ///
1609 /// ```
1610 /// macro_call! ❰ { my syntax here } ❱;
1611 /// ```
1612 ///
1613 /// [Reference](https://doc.rust-lang.org/reference/macros.html)
1614 struct TokenTree {}
1615
1616 /// Generic lifetime, type and constants parameters list **declaration**.
1617 ///
1618 /// ```
1619 /// fn foo❰ <'a, 'b, T, U, const BAR: u64> ❱() {}
1620 ///
1621 /// struct Baz❰ <T> ❱(T);
1622 ///
1623 /// impl❰ <T> ❱ Bruh<T> {}
1624 ///
1625 /// type Bruuh = for❰ <'a> ❱ fn(&'a str) -> &'a str;
1626 /// ```
1627 ///
1628 /// [Reference](https://doc.rust-lang.org/reference/items/generics.html)
1629 struct TypeParamList {
1630 T![<],
1631 type_params: [TypeParam],
1632 lifetime_params: [LifetimeParam],
1633 const_params: [ConstParam],
1634 T![>]
1635 }
1636
1637 /// Single type parameter **declaration**.
1638 ///
1639 /// ```
1640 /// fn foo<❰ K ❱, ❰ I ❱, ❰ E: Debug ❱, ❰ V = DefaultType ❱>() {}
1641 /// ```
1642 ///
1643 /// [Reference](https://doc.rust-lang.org/reference/items/generics.html)
1644 struct TypeParam: NameOwner, AttrsOwner, TypeBoundsOwner {
1645 T![=],
1646 default_type: TypeRef,
1647 }
1648
1649 /// Const generic parameter **declaration**.
1650 /// ```
1651 /// fn foo<T, U, ❰ const BAR: usize ❱, ❰ const BAZ: bool ❱>() {}
1652 /// ```
1653 ///
1654 /// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/2000-const-generics.md#declaring-a-const-parameter)
1655 struct ConstParam: NameOwner, AttrsOwner, TypeAscriptionOwner {
1656 T![=],
1657 default_val: Expr,
1658 }
1659
1660 /// Lifetime parameter **declaration**.
1661 ///
1662 /// ```
1663 /// fn foo<❰ 'a ❱, ❰ 'b ❱, V, G, D>(bar: &'a str, baz: &'b mut str) {}
1664 /// ```
1665 ///
1666 /// [Reference](https://doc.rust-lang.org/reference/items/generics.html)
1667 struct LifetimeParam: AttrsOwner { T![lifetime] }
1668
1669 /// Type bound declaration clause.
1670 ///
1671 /// ```
1672 /// fn foo<T: ❰ ?Sized ❱ + ❰ Debug ❱>() {}
1673 ///
1674 /// trait Bar<T>
1675 /// where
1676 /// T: ❰ Send ❱ + ❰ Sync ❱
1677 /// {
1678 /// type Baz: ❰ !Sync ❱ + ❰ Debug ❱ + ❰ ?const Add ❱;
1679 /// }
1680 /// ```
1681 ///
1682 /// [Reference](https://doc.rust-lang.org/reference/trait-bounds.html)
1683 struct TypeBound { T![lifetime], /* Question, */ T![const], /* Question, */ TypeRef }
1684
1685 /// Type bounds list.
1686 ///
1687 /// ```
1688 ///
1689 /// fn foo<T: ❰ ?Sized + Debug ❱>() {}
1690 ///
1691 /// trait Bar<T>
1692 /// where
1693 /// T: ❰ Send + Sync ❱
1694 /// {
1695 /// type Baz: ❰ !Sync + Debug ❱;
1696 /// }
1697 /// ```
1698 ///
1699 /// [Reference](https://doc.rust-lang.org/reference/trait-bounds.html)
1700 struct TypeBoundList { bounds: [TypeBound] }
1701
1702 /// Single where predicate.
1703 ///
1704 /// ```
1705 /// trait Foo<'a, 'b, T>
1706 /// where
1707 /// ❰ 'a: 'b ❱,
1708 /// ❰ T: IntoIterator ❱,
1709 /// ❰ for<'c> <T as IntoIterator>::Item: Bar<'c> ❱
1710 /// {}
1711 /// ```
1712 ///
1713 /// [Reference](https://doc.rust-lang.org/reference/items/generics.html#where-clauses)
1714 struct WherePred: TypeBoundsOwner { T![for], TypeParamList, T![lifetime], TypeRef }
1715
1716 /// Where clause.
1717 ///
1718 /// ```
1719 /// trait Foo<'a, T> ❰ where 'a: 'static, T: Debug ❱ {}
1720 ///
1721 /// ```
1722 ///
1723 /// [Reference](https://doc.rust-lang.org/reference/items/generics.html#where-clauses)
1724 struct WhereClause { T![where], predicates: [WherePred] }
1725
1726 /// Abi declaration.
1727 /// Note: the abi string is optional.
1728 ///
1729 /// ```
1730 /// ❰ extern "C" ❱ {
1731 /// fn foo() {}
1732 /// }
1733 ///
1734 /// type Bar = ❰ extern ❱ fn() -> u32;
1735 ///
1736 /// type Baz = ❰ extern r#"stdcall"# ❱ fn() -> bool;
1737 /// ```
1738 ///
1739 /// - [Extern blocks reference](https://doc.rust-lang.org/reference/items/external-blocks.html)
1740 /// - [FFI function pointers reference](https://doc.rust-lang.org/reference/items/functions.html#functions)
1741 struct Abi { /*String*/ }
1742
1743 /// Expression statement.
1744 ///
1745 /// ```
1746 /// ❰ 42; ❱
1747 /// ❰ foo(); ❱
1748 /// ❰ (); ❱
1749 /// ❰ {}; ❱
1750 ///
1751 /// // constructions with trailing curly brace can omit the semicolon
1752 /// // but only when there are satements immediately after them (this is important!)
1753 /// ❰ if bool_cond { } ❱
1754 /// ❰ loop {} ❱
1755 /// ❰ somestatment; ❱
1756 /// ```
1757 ///
1758 /// [Reference](https://doc.rust-lang.org/reference/statements.html)
1759 struct ExprStmt: AttrsOwner { Expr, T![;] }
1760
1761 /// Let statement.
1762 ///
1763 /// ```
1764 /// ❰ #[attr] let foo; ❱
1765 /// ❰ let bar: u64; ❱
1766 /// ❰ let baz = 42; ❱
1767 /// ❰ let bruh: bool = true; ❱
1768 /// ```
1769 ///
1770 /// [Reference](https://doc.rust-lang.org/reference/statements.html#let-statements)
1771 struct LetStmt: AttrsOwner, TypeAscriptionOwner {
1772 T![let],
1773 Pat,
1774 T![=],
1775 initializer: Expr,
1776 T![;],
1777 }
1778
1779 /// Condition of `if` or `while` expression.
1780 ///
1781 /// ```
1782 /// if ❰ true ❱ {}
1783 /// if ❰ let Pat(foo) = bar ❱ {}
1784 ///
1785 /// while ❰ true ❱ {}
1786 /// while ❰ let Pat(baz) = bruh ❱ {}
1787 /// ```
1788 ///
1789 /// [If expression reference](https://doc.rust-lang.org/reference/expressions/if-expr.html)
1790 /// [While expression reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-loops)
1791 struct Condition { T![let], Pat, T![=], Expr }
1792
1793 /// Parameter list **declaration**.
1794 ///
1795 /// ```
1796 /// fn foo❰ (a: u32, b: bool) ❱ -> u32 {}
1797 /// let bar = ❰ |a, b| ❱ {};
1798 ///
1799 /// impl Baz {
1800 /// fn bruh❰ (&self, a: u32) ❱ {}
1801 /// }
1802 /// ```
1803 ///
1804 /// [Reference](https://doc.rust-lang.org/reference/items/functions.html)ocs to codegen script
1805 struct ParamList { // FIXME: this node is used by closure expressions too, but hey use pipes instead of parens...
1806 T!['('],
1807 SelfParam,
1808 params: [Param],
1809 T![')']
1810 }
1811
1812 /// Self parameter **declaration**.
1813 ///
1814 /// ```
1815 /// impl Bruh {
1816 /// fn foo(❰ self ❱) {}
1817 /// fn bar(❰ &self ❱) {}
1818 /// fn baz(❰ &mut self ❱) {}
1819 /// fn blah<'a>(❰ &'a self ❱) {}
1820 /// fn blin(❰ self: Box<Self> ❱) {}
1821 /// }
1822 /// ```
1823 ///
1824 /// [Reference](https://doc.rust-lang.org/reference/items/functions.html)
1825 struct SelfParam: TypeAscriptionOwner, AttrsOwner { T![&], T![mut], T![lifetime], T![self] }
1826
1827 /// Parameter **declaration**.
1828 ///
1829 /// ```
1830 /// fn foo(❰ #[attr] Pat(bar): Pat(u32) ❱, ❰ #[attr] _: bool ❱) {}
1831 ///
1832 /// extern "C" {
1833 /// fn bar(❰ baz: u32 ❱, ❰ ... ❱) -> u32;
1834 /// }
1835 /// ```
1836 ///
1837 /// [Reference](https://doc.rust-lang.org/reference/items/functions.html)
1838 struct Param: TypeAscriptionOwner, AttrsOwner {
1839 Pat,
1840 T![...]
1841 }
1842
1843 /// Use declaration.
1844 ///
1845 /// ```
1846 /// ❰ #[attr] pub use foo; ❱
1847 /// ❰ use bar as baz; ❱
1848 /// ❰ use bruh::{self, bruuh}; ❱
1849 /// ❰ use { blin::blen, blah::* };
1850 /// ```
1851 ///
1852 /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html)
1853 struct UseItem: AttrsOwner, VisibilityOwner {
1854 T![use],
1855 UseTree,
1856 }
1857
1858 /// Use tree.
1859 ///
1860 /// ```
1861 /// pub use ❰ foo::❰ * ❱ ❱;
1862 /// use ❰ bar as baz ❱;
1863 /// use ❰ bruh::bruuh::{ ❰ self ❱, ❰ blin ❱ } ❱;
1864 /// use ❰ { ❰ blin::blen ❱ } ❱
1865 /// ```
1866 ///
1867 /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html)
1868 struct UseTree {
1869 Path, T![*], UseTreeList, Alias
1870 }
1871
1872 /// Item alias.
1873 /// Note: this is not the type alias.
1874 ///
1875 /// ```
1876 /// use foo ❰ as bar ❱;
1877 /// use baz::{bruh ❰ as _ ❱};
1878 /// extern crate bruuh ❰ as blin ❱;
1879 /// ```
1880 ///
1881 /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html)
1882 struct Alias: NameOwner { T![as] }
1883
1884 /// Sublist of use trees.
1885 ///
1886 /// ```
1887 /// use bruh::bruuh::❰ { ❰ self ❱, ❰ blin ❱ } ❱;
1888 /// use ❰ { blin::blen::❰ {} ❱ } ❱
1889 /// ```
1890 ///
1891 /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html)
1892 struct UseTreeList { T!['{'], use_trees: [UseTree], T!['}'] }
1893
1894 /// Extern crate item.
1895 ///
1896 /// ```
1897 /// ❰ #[attr] pub extern crate foo; ❱
1898 /// ❰ extern crate self as bar; ❱
1899 /// ```
1900 ///
1901 /// [Reference](https://doc.rust-lang.org/reference/items/extern-crates.html)
1902 struct ExternCrateItem: AttrsOwner, VisibilityOwner {
1903 T![extern], T![crate], NameRef, Alias,
1904 }
1905
1906 /// Call site arguments list.
1907 ///
1908 /// ```
1909 /// foo::<T, U>❰ (42, true) ❱;
1910 /// ```
1911 ///
1912 /// [Reference](https://doc.rust-lang.org/reference/expressions/call-expr.html)
1913 struct ArgList {
1914 T!['('],
1915 args: [Expr],
1916 T![')']
1917 }
1918
1919 /// Path to a symbol. Includes single identifier names and elaborate paths with
1920 /// generic parameters.
1921 ///
1922 /// ```
1923 /// (0..10).❰ ❰ collect ❱ ::<Vec<_>> ❱();
1924 /// ❰ ❰ ❰ Vec ❱ ::<u8> ❱ ::with_capacity ❱(1024);
1925 /// ❰ ❰ <❰ Foo ❱ as ❰ ❰ bar ❱ ::Bar ❱> ❱ ::baz ❱();
1926 /// ❰ ❰ <❰ bruh ❱> ❱ ::bruuh ❱();
1927 /// ```
1928 ///
1929 /// [Reference](https://doc.rust-lang.org/reference/paths.html)
1930 struct Path {
1931 segment: PathSegment,
1932 T![::],
1933 qualifier: Path,
1934 }
1935
1936 /// Segment of the path to a symbol.
1937 /// Only path segment of an absolute path holds the `::` token,
1938 /// all other `::` tokens that connect path segments reside under `Path` itself.`
1939 ///
1940 /// ```
1941 /// (0..10).❰ collect ❱ :: ❰ <Vec<_>> ❱();
1942 /// ❰ Vec ❱ :: ❰ <u8> ❱ :: ❰ with_capacity ❱(1024);
1943 /// ❰ <❰ Foo ❱ as ❰ bar ❱ :: ❰ Bar ❱> ❱ :: ❰ baz ❱();
1944 /// ❰ <❰ bruh ❱> ❱ :: ❰ bruuh ❱();
1945 ///
1946 /// // Note that only in this case `::` token is inlcuded:
1947 /// ❰ ::foo ❱;
1948 /// ```
1949 ///
1950 /// [Reference](https://doc.rust-lang.org/reference/paths.html)
1951 struct PathSegment {
1952 T![::], T![crate], T![self], T![super], T![<], NameRef, TypeArgList, ParamList, RetType, PathType, T![>]
1953 }
1954
1955 /// List of type arguments that are passed at generic instantiation site.
1956 ///
1957 /// ```
1958 /// type _ = Foo ❰ ::<'a, u64, Item = Bar, 42, {true}> ❱::Bar;
1959 ///
1960 /// Vec❰ ::<bool> ❱::();
1961 /// ```
1962 ///
1963 /// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions)
1964 struct TypeArgList {
1965 T![::],
1966 T![<],
1967 generic_args: [GenericArg],
1968 type_args: [TypeArg],
1969 lifetime_args: [LifetimeArg],
1970 assoc_type_args: [AssocTypeArg],
1971 const_args: [ConstArg],
1972 T![>]
1973 }
1974
1975 /// Type argument that is passed at generic instantiation site.
1976 ///
1977 /// ```
1978 /// type _ = Foo::<'a, ❰ u64 ❱, ❰ bool ❱, Item = Bar, 42>::Baz;
1979 /// ```
1980 ///
1981 /// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions)
1982 struct TypeArg { TypeRef }
1983
1984 /// Associated type argument that is passed at generic instantiation site.
1985 /// ```
1986 /// type Foo = Bar::<'a, u64, bool, ❰ Item = Baz ❱, 42>::Bruh;
1987 ///
1988 /// trait Bruh<T>: Iterator<❰ Item: Debug ❱> {}
1989 /// ```
1990 ///
1991 struct AssocTypeArg : TypeBoundsOwner { NameRef, T![=], TypeRef }
1992
1993 /// Lifetime argument that is passed at generic instantiation site.
1994 ///
1995 /// ```
1996 /// fn foo<'a>(s: &'a str) {
1997 /// bar::<❰ 'a ❱>(s);
1998 /// }
1999 /// ```
2000 ///
2001 /// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions)
2002 struct LifetimeArg { T![lifetime] }
2003
2004 /// Constant value argument that is passed at generic instantiation site.
2005 ///
2006 /// ```
2007 /// foo::<u32, ❰ { true } ❱>();
2008 ///
2009 /// bar::<❰ { 2 + 2} ❱>();
2010 /// ```
2011 ///
2012 /// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/2000-const-generics.md#declaring-a-const-parameter)
2013 struct ConstArg { Literal, BlockExpr }
2014
2015
2016 /// FIXME: (@edwin0cheng) Remove it to use ItemList instead
2017 /// https://github.com/rust-analyzer/rust-analyzer/pull/4083#discussion_r422666243
2018 ///
2019 /// [Reference](https://doc.rust-lang.org/reference/macros.html)
2020 struct MacroItems: ModuleItemOwner { }
2021
2022 /// FIXME: (@edwin0cheng) add some documentation here. As per the writing
2023 /// of this comment this ast node is not used.
2024 ///
2025 /// ```
2026 /// // FIXME: example here
2027 /// ```
2028 ///
2029 /// [Reference](https://doc.rust-lang.org/reference/macros.html)
2030 struct MacroStmts {
2031 statements: [Stmt],
2032 Expr,
2033 }
2034
2035 /// List of items in an extern block.
2036 ///
2037 /// ```
2038 /// extern "C" ❰
2039 /// {
2040 /// fn foo();
2041 /// static var: u32;
2042 /// }
2043 /// ❱
2044 /// ```
2045 ///
2046 /// [Reference](https://doc.rust-lang.org/reference/items/external-blocks.html)
2047 struct ExternItemList: ModuleItemOwner {
2048 T!['{'],
2049 extern_items: [ExternItem],
2050 T!['}']
2051 }
2052
2053 /// Extern block.
2054 ///
2055 /// ```
2056 /// ❰
2057 /// extern "C" {
2058 /// fn foo();
2059 /// }
2060 /// ❱
2061 ///
2062 /// ```
2063 ///
2064 /// [Reference](https://doc.rust-lang.org/reference/items/external-blocks.html)
2065 struct ExternBlock {
2066 Abi,
2067 ExternItemList
2068 }
2069
2070 /// Meta item in an attribute.
2071 ///
2072 /// ```
2073 /// #[❰ bar::baz = "42" ❱]
2074 /// #[❰ bruh(bruuh("true")) ❱]
2075 /// struct Foo;
2076 /// ```
2077 ///
2078 /// [Reference](https://doc.rust-lang.org/reference/attributes.html?highlight=meta,item#meta-item-attribute-syntax)
2079 struct MetaItem {
2080 Path, T![=], AttrInput, nested_meta_items: [MetaItem]
2081 }
2082
2083 /// Macro 2.0 definition.
2084 /// Their syntax is still WIP by rustc team...
2085 /// ```
2086 /// ❰
2087 /// macro foo { }
2088 /// ❱
2089 /// ```
2090 ///
2091 /// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/1584-macros.md)
2092 struct MacroDef {
2093 Name, TokenTree
2094 }
2095 },
2096 enums: ast_enums! {
2097 /// Any kind of nominal type definition.
2098 enum NominalDef: NameOwner, TypeParamsOwner, AttrsOwner {
2099 StructDef, EnumDef, UnionDef,
2100 }
2101
2102 /// Any kind of generic argument passed at instantiation site
2103 enum GenericArg {
2104 LifetimeArg,
2105 TypeArg,
2106 ConstArg,
2107 AssocTypeArg
2108 }
2109
2110 /// Any kind of construct valid in type context
2111 enum TypeRef {
2112 ParenType,
2113 TupleType,
2114 NeverType,
2115 PathType,
2116 PointerType,
2117 ArrayType,
2118 SliceType,
2119 ReferenceType,
2120 PlaceholderType,
2121 FnPointerType,
2122 ForType,
2123 ImplTraitType,
2124 DynTraitType,
2125 }
2126
2127 /// Any kind of top-level item that may appear in a module
2128 enum ModuleItem: NameOwner, AttrsOwner, VisibilityOwner {
2129 StructDef,
2130 UnionDef,
2131 EnumDef,
2132 FnDef,
2133 TraitDef,
2134 TypeAliasDef,
2135 ImplDef,
2136 UseItem,
2137 ExternCrateItem,
2138 ConstDef,
2139 StaticDef,
2140 Module,
2141 MacroCall,
2142 ExternBlock
2143 }
2144
2145
2146
2147 /// Any kind of item that may appear in an impl block
2148 ///
2149 /// // FIXME: impl blocks can also contain MacroCall
2150 enum AssocItem: NameOwner, AttrsOwner {
2151 FnDef, TypeAliasDef, ConstDef
2152 }
2153
2154 /// Any kind of item that may appear in an extern block
2155 ///
2156 /// // FIXME: extern blocks can also contain MacroCall
2157 enum ExternItem: NameOwner, AttrsOwner, VisibilityOwner {
2158 FnDef, StaticDef
2159 }
2160
2161 /// Any kind of expression
2162 enum Expr: AttrsOwner {
2163 TupleExpr,
2164 ArrayExpr,
2165 ParenExpr,
2166 PathExpr,
2167 LambdaExpr,
2168 IfExpr,
2169 LoopExpr,
2170 ForExpr,
2171 WhileExpr,
2172 ContinueExpr,
2173 BreakExpr,
2174 Label,
2175 BlockExpr,
2176 ReturnExpr,
2177 MatchExpr,
2178 RecordLit,
2179 CallExpr,
2180 IndexExpr,
2181 MethodCallExpr,
2182 FieldExpr,
2183 AwaitExpr,
2184 TryExpr,
2185 EffectExpr,
2186 CastExpr,
2187 RefExpr,
2188 PrefixExpr,
2189 RangeExpr,
2190 BinExpr,
2191 Literal,
2192 MacroCall,
2193 BoxExpr,
2194 }
2195
2196 /// Any kind of pattern
2197 enum Pat {
2198 OrPat,
2199 ParenPat,
2200 RefPat,
2201 BoxPat,
2202 BindPat,
2203 PlaceholderPat,
2204 DotDotPat,
2205 PathPat,
2206 RecordPat,
2207 TupleStructPat,
2208 TuplePat,
2209 SlicePat,
2210 RangePat,
2211 LiteralPat,
2212 MacroPat,
2213 }
2214
2215 /// Any kind of input to an attribute
2216 enum AttrInput { Literal, TokenTree }
2217
2218 /// Any kind of statement
2219 /// Note: there are no empty statements, these are just represented as
2220 /// bare semicolons without a dedicated statement ast node.
2221 enum Stmt {
2222 LetStmt,
2223 ExprStmt,
2224 // macro calls are parsed as expression statements
2225 }
2226
2227 /// Any kind of fields list (record or tuple field lists)
2228 enum FieldDefList {
2229 RecordFieldDefList,
2230 TupleFieldDefList,
2231 }
2232 },
2233 }
2234}
diff --git a/xtask/src/codegen/gen_syntax.rs b/xtask/src/codegen/gen_syntax.rs
index 5a18b3e2b..24e8be1fb 100644
--- a/xtask/src/codegen/gen_syntax.rs
+++ b/xtask/src/codegen/gen_syntax.rs
@@ -3,19 +3,27 @@
3//! Specifically, it generates the `SyntaxKind` enum and a number of newtype 3//! Specifically, it generates the `SyntaxKind` enum and a number of newtype
4//! wrappers around `SyntaxNode` which implement `ra_syntax::AstNode`. 4//! wrappers around `SyntaxNode` which implement `ra_syntax::AstNode`.
5 5
6use std::{collections::HashSet, fmt::Write}; 6use std::{
7 collections::{BTreeSet, HashSet},
8 fmt::Write,
9};
7 10
8use proc_macro2::{Punct, Spacing}; 11use proc_macro2::{Punct, Spacing};
9use quote::{format_ident, quote}; 12use quote::{format_ident, quote};
13use ungrammar::{Grammar, Rule};
10 14
11use crate::{ 15use crate::{
12 ast_src::{rust_ast, AstSrc, Field, FieldSrc, KindsSrc, KINDS_SRC}, 16 ast_src::{AstEnumSrc, AstNodeSrc, AstSrc, Field, FieldSrc, KindsSrc, KINDS_SRC},
13 codegen::{self, update, Mode}, 17 codegen::{self, update, Mode},
14 project_root, Result, 18 project_root, Result,
15}; 19};
16 20
17pub fn generate_syntax(mode: Mode) -> Result<()> { 21pub fn generate_syntax(mode: Mode) -> Result<()> {
18 let ast = rust_ast(); 22 let grammar = include_str!("rust.ungram")
23 .parse::<Grammar>()
24 .unwrap_or_else(|err| panic!("\n \x1b[91merror\x1b[0m: {}\n", err));
25 let ast = lower(&grammar);
26
19 let syntax_kinds_file = project_root().join(codegen::SYNTAX_KINDS); 27 let syntax_kinds_file = project_root().join(codegen::SYNTAX_KINDS);
20 let syntax_kinds = generate_syntax_kinds(KINDS_SRC)?; 28 let syntax_kinds = generate_syntax_kinds(KINDS_SRC)?;
21 update(syntax_kinds_file.as_path(), &syntax_kinds, mode)?; 29 update(syntax_kinds_file.as_path(), &syntax_kinds, mode)?;
@@ -215,7 +223,9 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: &AstSrc) -> Result<String> {
215 .map(|kind| to_pascal_case(kind)) 223 .map(|kind| to_pascal_case(kind))
216 .filter(|name| !defined_nodes.iter().any(|&it| it == name)) 224 .filter(|name| !defined_nodes.iter().any(|&it| it == name))
217 { 225 {
218 eprintln!("Warning: node {} not defined in ast source", node); 226 drop(node)
227 // TODO: restore this
228 // eprintln!("Warning: node {} not defined in ast source", node);
219 } 229 }
220 230
221 let ast = quote! { 231 let ast = quote! {
@@ -414,6 +424,10 @@ fn to_pascal_case(s: &str) -> String {
414 buf 424 buf
415} 425}
416 426
427fn pluralize(s: &str) -> String {
428 format!("{}s", s)
429}
430
417impl Field { 431impl Field {
418 fn is_many(&self) -> bool { 432 fn is_many(&self) -> bool {
419 matches!(self, Field::Node { src: FieldSrc::Many(_), .. }) 433 matches!(self, Field::Node { src: FieldSrc::Many(_), .. })
@@ -449,6 +463,7 @@ impl Field {
449 "." => "dot", 463 "." => "dot",
450 ".." => "dotdot", 464 ".." => "dotdot",
451 "..." => "dotdotdot", 465 "..." => "dotdotdot",
466 "..=" => "dotdoteq",
452 "=>" => "fat_arrow", 467 "=>" => "fat_arrow",
453 "@" => "at", 468 "@" => "at",
454 ":" => "colon", 469 ":" => "colon",
@@ -475,3 +490,204 @@ impl Field {
475 } 490 }
476 } 491 }
477} 492}
493
494fn lower(grammar: &Grammar) -> AstSrc {
495 let mut res = AstSrc::default();
496 res.tokens = vec!["Whitespace".into(), "Comment".into(), "String".into(), "RawString".into()];
497
498 let nodes = grammar
499 .iter()
500 .filter(|&node| match grammar[node].rule {
501 Rule::Node(it) if it == node => false,
502 _ => true,
503 })
504 .collect::<Vec<_>>();
505
506 for &node in &nodes {
507 let name = grammar[node].name.clone();
508 let rule = &grammar[node].rule;
509 match lower_enum(grammar, rule) {
510 Some(variants) => {
511 let enum_src = AstEnumSrc { doc: Vec::new(), name, traits: Vec::new(), variants };
512 res.enums.push(enum_src);
513 }
514 None => {
515 let mut fields = Vec::new();
516 lower_rule(&mut fields, grammar, rule);
517 res.nodes.push(AstNodeSrc { doc: Vec::new(), name, traits: Vec::new(), fields });
518 }
519 }
520 }
521
522 deduplicate_fields(&mut res);
523 extract_enums(&mut res);
524 extract_struct_traits(&mut res);
525 extract_enum_traits(&mut res);
526 res
527}
528
529fn lower_enum(grammar: &Grammar, rule: &Rule) -> Option<Vec<String>> {
530 let alternatives = match rule {
531 Rule::Alt(it) => it,
532 _ => return None,
533 };
534 let mut variants = Vec::new();
535 for alternative in alternatives {
536 match alternative {
537 Rule::Node(it) => variants.push(grammar[*it].name.clone()),
538 _ => return None,
539 }
540 }
541 Some(variants)
542}
543
544fn lower_rule(acc: &mut Vec<Field>, grammar: &Grammar, rule: &Rule) {
545 match rule {
546 Rule::Node(node) => {
547 let field = Field::Node { name: grammar[*node].name.clone(), src: FieldSrc::Shorthand };
548 acc.push(field);
549 }
550 Rule::Token(token) => {
551 let mut name = grammar[*token].name.clone();
552 if name != "int_number" && name != "string" {
553 if "[]{}()".contains(&name) {
554 name = format!("'{}'", name);
555 }
556 let field = Field::Token(name);
557 acc.push(field);
558 }
559 }
560 Rule::Rep(inner) => {
561 if let Rule::Node(node) = &**inner {
562 let name = grammar[*node].name.clone();
563 let label = pluralize(&to_lower_snake_case(&name));
564 let field = Field::Node { name: label.clone(), src: FieldSrc::Many(name) };
565 acc.push(field);
566 return;
567 }
568 todo!("{:?}", rule)
569 }
570 Rule::Labeled { label, rule } => {
571 let node = match &**rule {
572 Rule::Rep(inner) | Rule::Opt(inner) => match &**inner {
573 Rule::Node(node) => node,
574 _ => todo!("{:?}", rule),
575 },
576 Rule::Node(node) => node,
577 _ => todo!("{:?}", rule),
578 };
579 let field = Field::Node {
580 name: label.clone(),
581 src: match &**rule {
582 Rule::Rep(_) => FieldSrc::Many(grammar[*node].name.clone()),
583 _ => FieldSrc::Optional(grammar[*node].name.clone()),
584 },
585 };
586 acc.push(field);
587 }
588 Rule::Seq(rules) | Rule::Alt(rules) => {
589 for rule in rules {
590 lower_rule(acc, grammar, rule)
591 }
592 }
593 Rule::Opt(rule) => lower_rule(acc, grammar, rule),
594 }
595}
596
597fn deduplicate_fields(ast: &mut AstSrc) {
598 eprintln!();
599 for node in &mut ast.nodes {
600 let mut i = 0;
601 'outer: while i < node.fields.len() {
602 for j in 0..i {
603 let f1 = &node.fields[i];
604 let f2 = &node.fields[j];
605 if f1 == f2 {
606 node.fields.remove(i);
607 continue 'outer;
608 }
609 }
610 i += 1;
611 }
612 }
613}
614
615fn extract_enums(ast: &mut AstSrc) {
616 for node in &mut ast.nodes {
617 for enm in &ast.enums {
618 let mut to_remove = Vec::new();
619 for (i, field) in node.fields.iter().enumerate() {
620 let ty = field.ty().to_string();
621 if enm.variants.iter().any(|it| it == &ty) {
622 to_remove.push(i);
623 }
624 }
625 if to_remove.len() == enm.variants.len() {
626 node.remove_field(to_remove);
627 node.fields.push(Field::Node { name: enm.name.clone(), src: FieldSrc::Shorthand });
628 }
629 }
630 }
631}
632
633fn extract_struct_traits(ast: &mut AstSrc) {
634 let traits: &[(&str, &[&str])] = &[
635 ("AttrsOwner", &["attrs"]),
636 ("NameOwner", &["name"]),
637 ("VisibilityOwner", &["visibility"]),
638 ("TypeParamsOwner", &["type_param_list", "where_clause"]),
639 ("TypeBoundsOwner", &["type_bound_list", "colon_token"]),
640 ("ModuleItemOwner", &["items"]),
641 ("TypeAscriptionOwner", &["ascribed_type"]),
642 ("LoopBodyOwner", &["label", "loop_body"]),
643 ("ArgListOwner", &["arg_list"]),
644 ];
645
646 for node in &mut ast.nodes {
647 for (name, methods) in traits {
648 extract_struct_trait(node, name, methods);
649 }
650 }
651}
652
653fn extract_struct_trait(node: &mut AstNodeSrc, trait_name: &str, methods: &[&str]) {
654 let mut to_remove = Vec::new();
655 for (i, field) in node.fields.iter().enumerate() {
656 let method_name = field.method_name().to_string();
657 if methods.iter().any(|&it| it == &method_name) {
658 to_remove.push(i);
659 }
660 }
661 if to_remove.len() == methods.len() {
662 node.traits.push(trait_name.to_string());
663 node.remove_field(to_remove);
664 }
665}
666
667fn extract_enum_traits(ast: &mut AstSrc) {
668 for enm in &mut ast.enums {
669 let nodes = &ast.nodes;
670 let mut variant_traits = enm
671 .variants
672 .iter()
673 .map(|var| nodes.iter().find(|it| &it.name == var).unwrap())
674 .map(|node| node.traits.iter().cloned().collect::<BTreeSet<_>>());
675
676 let mut enum_traits = match variant_traits.next() {
677 Some(it) => it,
678 None => continue,
679 };
680 for traits in variant_traits {
681 enum_traits = enum_traits.intersection(&traits).cloned().collect();
682 }
683 enm.traits = enum_traits.into_iter().collect();
684 }
685}
686
687impl AstNodeSrc {
688 fn remove_field(&mut self, to_remove: Vec<usize>) {
689 to_remove.into_iter().rev().for_each(|idx| {
690 self.fields.remove(idx);
691 });
692 }
693}
diff --git a/xtask/src/codegen/rust.ungram b/xtask/src/codegen/rust.ungram
new file mode 100644
index 000000000..8a3eb7b29
--- /dev/null
+++ b/xtask/src/codegen/rust.ungram
@@ -0,0 +1,529 @@
1SourceFile =
2 Attr*
3 items:ModuleItem*
4
5FnDef =
6 Attr* Visibility? Abi? 'const' 'default' 'async' 'unsafe' 'fn' Name TypeParamList?
7 ParamList RetType?
8 WhereClause?
9 (body:BlockExpr | ';')
10
11RetType =
12 '->' TypeRef
13
14StructDef =
15 Attr* Visibility? 'struct' Name TypeParamList? (
16 WhereClause? (RecordFieldDefList | ';')
17 | TupleFieldDefList WhereClause? ';'
18 )
19
20UnionDef =
21 Attr* Visibility? 'union' Name TypeParamList? WhereClause?
22 RecordFieldDefList
23
24RecordFieldDefList =
25 '{' fields:RecordFieldDef* '}'
26
27RecordFieldDef =
28 Attr* Visibility? Name ':' ascribed_type:TypeRef
29
30TupleFieldDefList =
31 '(' fields:TupleFieldDef* ')'
32
33TupleFieldDef =
34 Attr* Visibility? Name TypeRef
35
36FieldDefList =
37 RecordFieldDefList
38| TupleFieldDefList
39
40EnumDef =
41 Attr* Visibility? 'enum' Name TypeParamList? WhereClause?
42 variant_list:EnumVariantList
43
44EnumVariantList =
45 '{' variants:EnumVariant* '}'
46
47EnumVariant =
48 Attr* Visibility? Name FieldDefList ('=' Expr)?
49
50TraitDef =
51 Attr* Visibility? 'unsafe'? 'auto'? 'trait' Name TypeParamList
52 (':' TypeBoundList?)? WhereClause
53 ItemList
54
55Module =
56 Attr* Visibility? 'mod' Name
57 (ItemList | ';')
58
59ItemList =
60 '{'
61 AssocItem*
62 items:ModuleItem*
63 '}'
64
65ConstDef =
66 Attr* Visibility? 'default'? 'const' Name ':' ascribed_type:TypeRef
67 '=' body:Expr ';'
68
69StaticDef =
70 Attr* Visibility? 'static'? 'mut'? 'static' Name ':' ascribed_type:TypeRef
71 '=' body:Expr ';'
72
73TypeAliasDef =
74 Attr* Visibility? 'default'? 'type' Name TypeParamList? WhereClause? (':' TypeBoundList?)?
75 '=' TypeRef ';'
76
77ImplDef =
78 Attr* Visibility? 'const'? 'default'? 'unsafe'? 'impl' TypeParamList? '!'? 'for'
79 WhereClause?
80 ItemList
81
82ParenType =
83 '(' TypeRef ')'
84
85TupleType =
86 '(' fields:TypeRef* ')'
87
88NeverType =
89 '!'
90
91PathType =
92 Path
93
94PointerType =
95 '*' ('const' | 'mut') TypeRef
96
97ArrayType =
98 '[' TypeRef ';' Expr ']'
99
100SliceType =
101 '[' TypeRef ']'
102
103ReferenceType =
104 '&' 'lifetime'? 'mut'? TypeRef
105
106PlaceholderType =
107 '_'
108
109FnPointerType =
110 Abi 'unsafe'? 'fn' ParamList RetType?
111
112ForType =
113 'for' TypeParamList TypeRef
114
115ImplTraitType =
116 'impl' TypeBoundList
117
118DynTraitType =
119 'dyn' TypeBoundList
120
121TupleExpr =
122 Attr* '(' Expr* ')'
123
124ArrayExpr =
125 Attr* '[' (Expr* | Expr ';' Expr) ']'
126
127ParenExpr =
128 Attr* '(' Expr ')'
129
130PathExpr =
131 Path
132
133LambdaExpr =
134 Attr* 'static'? 'async'? 'move'? ParamList RetType?
135 body:Expr
136
137IfExpr =
138 Attr* 'if' Condition
139
140Condition =
141 'let' Pat '=' Expr
142| Expr
143
144EffectExpr =
145 Attr* Label? ('try' | 'unsafe' | 'async') BlockExpr
146
147LoopExpr =
148 Attr* Label? 'loop'
149 loop_body:BlockExpr?
150
151ForExpr =
152 Attr* Label? 'for' Pat 'in' iterable:Expr
153 loop_body:BlockExpr?
154
155WhileExpr =
156 Attr* Label? 'while' Condition
157 loop_body:BlockExpr?
158
159ContinueExpr =
160 Attr* 'continue' 'lifetime'?
161
162BreakExpr =
163 Attr* 'break' 'lifetime'? Expr?
164
165Label =
166 'lifetime'
167
168BlockExpr =
169 Attr* Label
170 '{'
171 items:ModuleItem*
172 statements:Stmt*
173 Expr?
174 '}'
175
176ReturnExpr =
177 Attr* 'return' Expr
178
179CallExpr =
180 Attr* Expr ArgList
181
182MethodCallExpr =
183 Attr* Expr '.' NameRef TypeArgList? ArgList
184
185ArgList =
186 '(' args:Expr* ')'
187
188FieldExpr =
189 Attr* Expr '.' NameRef
190
191IndexExpr =
192 Attr* '[' ']'
193
194AwaitExpr =
195 Attr* Expr '.' 'await'
196
197TryExpr =
198 Attr* Expr '?'
199
200CastExpr =
201 Attr* Expr 'as' TypeRef
202
203RefExpr =
204 Attr* '&' ('raw' | 'mut' | 'const') Expr
205
206PrefixExpr =
207 Attr* Expr
208
209BoxExpr =
210 Attr* 'box' Expr
211
212RangeExpr =
213 Attr*
214
215BinExpr =
216 Attr*
217
218Literal =
219 'int_number'
220
221MatchExpr =
222 Attr* 'match' Expr MatchArmList
223
224MatchArmList =
225 '{' arms:MatchArm* '}'
226
227MatchArm =
228 Attr* Pat guard:MatchGuard? '=>' Expr
229
230MatchGuard =
231 'if' Expr
232
233RecordLit =
234 Path RecordFieldList
235
236RecordFieldList =
237 '{'
238 fields:RecordField*
239 ('..' spread:Expr)?
240 '}'
241
242RecordField =
243 Attr* NameRef (':' Expr)?
244
245OrPat =
246 Pat*
247
248ParenPat =
249 '(' Pat ')'
250
251RefPat =
252 '&' 'mut'? Pat
253
254BoxPat =
255 'box' Path
256
257BindPat =
258 Attr* 'ref'? 'mut'? Name ('@' Pat)?
259
260PlaceholderPat =
261 '_'
262
263DotDotPat =
264 '..'
265
266PathPat =
267 Path
268
269SlicePat =
270 '[' args:Pat* ']'
271
272RangePat =
273 '..' | '..='
274
275LiteralPat =
276 Literal
277
278MacroPat =
279 MacroCall
280
281RecordPat =
282 Path RecordFieldPatList
283
284RecordFieldPatList =
285 '{'
286 record_field_pats:RecordFieldPat*
287 BindPat*
288 '..'?
289 '}'
290
291RecordFieldPat =
292 Attr* NameRef ':' Pat
293
294TupleStructPat =
295 Path '(' args:Pat* ')'
296
297TuplePat =
298 '(' args:Pat* ')'
299
300Visibility =
301 'pub' ('(' 'super' | 'self' | 'crate' | 'in' Path ')')?
302
303Name =
304 'ident'
305
306NameRef =
307 'ident' | 'int_number'
308
309MacroCall =
310 Attr* Path '!' Name? TokenTree ';'?
311
312MacroDef =
313 Name TokenTree
314
315TokenTree =
316 '(' ')' | '{' '}' | '[' ']'
317
318MacroItems =
319 items:ModuleItem*
320
321MacroStmts =
322 statements:Stmt*
323 Expr?
324
325Attr =
326 '#' '!'? '[' Path ('=' input:AttrInput)? ']'
327
328TypeParamList =
329 '<'
330 TypeParam*
331 LifetimeParam*
332 ConstParam*
333 '>'
334
335TypeParam =
336 Attr* Name (':' TypeBoundList?)?
337 ('=' default_type:TypeRef)?
338
339ConstParam =
340 Attr* 'const' Name ':' ascribed_type:TypeRef
341 ('=' default_val:Expr)?
342
343LifetimeParam =
344 Attr* 'lifetime'
345
346TypeBound =
347 'lifetime' | 'const'? TypeRef
348
349TypeBoundList =
350 bounds:TypeBound*
351
352WherePred =
353 ('for' TypeParamList)? ('lifetime' | TypeRef) ':' TypeBoundList
354
355WhereClause =
356 'where' predicates:WherePred*
357
358Abi =
359 'string'
360
361ExprStmt =
362 Attr* Expr ';'
363
364LetStmt =
365 Attr* 'let' Pat (':' ascribed_type:TypeRef)
366 '=' initializer:Expr ';'
367
368ParamList =
369 '(' SelfParam Param* ')'
370
371SelfParam =
372 Attr* ('&' 'lifetime'?)? 'mut'? 'self' (':' ascribed_type:TypeRef)
373
374Param =
375 Attr* Pat (':' ascribed_type:TypeRef)
376| '...'
377
378UseItem =
379 Attr* Visibility? 'use' UseTree ';'
380
381UseTree =
382 Path ('::' ('*' | UseTreeList)) Alias?
383
384UseTreeList =
385 '{' UseTree* '}'
386
387Alias =
388 'as' Name
389
390ExternCrateItem =
391 Attr* Visibility? 'extern' 'crate' (NameRef | 'self') Alias? ';'
392
393Path =
394 (qualifier:Path '::')? segment:PathSegment
395
396PathSegment =
397 '::' | 'crate' | 'self' | 'super'
398| '<' NameRef TypeArgList ParamList RetType PathType '>'
399
400TypeArgList =
401 '::'? '<'
402 TypeArg*
403 LifetimeArg*
404 AssocTypeArg*
405 ConstArg*
406 '>'
407
408TypeArg =
409 TypeRef
410
411AssocTypeArg =
412 NameRef (':' TypeBoundList | '=' TypeRef)
413
414LifetimeArg =
415 'lifetime'
416
417ConstArg =
418 Literal | BlockExpr BlockExpr
419
420ExternBlock =
421 Attr* Abi ExternItemList
422
423ExternItemList =
424 '{' extern_items:ExternItem* '}'
425
426MetaItem =
427 Path '=' AttrInput nested_meta_items:MetaItem*
428
429NominalDef =
430 StructDef
431| EnumDef
432| UnionDef
433
434TypeRef =
435 ParenType
436| TupleType
437| NeverType
438| PathType
439| PointerType
440| ArrayType
441| SliceType
442| ReferenceType
443| PlaceholderType
444| FnPointerType
445| ForType
446| ImplTraitType
447| DynTraitType
448
449AssocItem =
450 FnDef
451| TypeAliasDef
452| ConstDef
453
454ExternItem =
455 FnDef | StaticDef
456
457ModuleItem =
458 StructDef
459| UnionDef
460| EnumDef
461| FnDef
462| TraitDef
463| TypeAliasDef
464| ImplDef
465| UseItem
466| ExternCrateItem
467| ConstDef
468| StaticDef
469| Module
470| MacroCall
471| ExternBlock
472
473AttrInput =
474 Literal
475| TokenTree
476
477Stmt =
478 LetStmt
479| ExprStmt
480
481Pat =
482 OrPat
483| ParenPat
484| RefPat
485| BoxPat
486| BindPat
487| PlaceholderPat
488| DotDotPat
489| PathPat
490| RecordPat
491| TupleStructPat
492| TuplePat
493| SlicePat
494| RangePat
495| LiteralPat
496| MacroPat
497
498Expr =
499 TupleExpr
500| ArrayExpr
501| ParenExpr
502| PathExpr
503| LambdaExpr
504| IfExpr
505| LoopExpr
506| ForExpr
507| WhileExpr
508| ContinueExpr
509| BreakExpr
510| Label
511| BlockExpr
512| ReturnExpr
513| MatchExpr
514| RecordLit
515| CallExpr
516| IndexExpr
517| MethodCallExpr
518| FieldExpr
519| AwaitExpr
520| TryExpr
521| EffectExpr
522| CastExpr
523| RefExpr
524| PrefixExpr
525| RangeExpr
526| BinExpr
527| Literal
528| MacroCall
529| BoxExpr