aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/flycheck/Cargo.toml2
-rw-r--r--crates/ra_assists/src/handlers/generate_derive.rs4
-rw-r--r--crates/ra_assists/src/handlers/generate_impl.rs2
-rw-r--r--crates/ra_hir_def/src/type_ref.rs2
-rw-r--r--crates/ra_ide/Cargo.toml2
-rw-r--r--crates/ra_ide/src/goto_implementation.rs10
-rw-r--r--crates/ra_ide/src/syntax_highlighting/html.rs10
-rw-r--r--crates/ra_ide/test_data/rainbow_highlighting.html12
-rw-r--r--crates/ra_proc_macro_srv/Cargo.toml2
-rw-r--r--crates/ra_project_model/Cargo.toml2
-rw-r--r--crates/ra_syntax/src/ast/expr_ext.rs2
-rw-r--r--crates/ra_syntax/src/ast/generated/nodes.rs3039
-rw-r--r--crates/ra_syntax/src/ast/node_ext.rs16
-rw-r--r--crates/rust-analyzer/Cargo.toml2
-rw-r--r--crates/rust-analyzer/src/cli/analysis_stats.rs25
15 files changed, 839 insertions, 2293 deletions
diff --git a/crates/flycheck/Cargo.toml b/crates/flycheck/Cargo.toml
index bea485694..ff8a1e568 100644
--- a/crates/flycheck/Cargo.toml
+++ b/crates/flycheck/Cargo.toml
@@ -11,7 +11,7 @@ doctest = false
11[dependencies] 11[dependencies]
12crossbeam-channel = "0.4.0" 12crossbeam-channel = "0.4.0"
13log = "0.4.8" 13log = "0.4.8"
14cargo_metadata = "0.10.0" 14cargo_metadata = "0.11.1"
15serde_json = "1.0.48" 15serde_json = "1.0.48"
16jod-thread = "0.1.1" 16jod-thread = "0.1.1"
17ra_toolchain = { path = "../ra_toolchain" } 17ra_toolchain = { path = "../ra_toolchain" }
diff --git a/crates/ra_assists/src/handlers/generate_derive.rs b/crates/ra_assists/src/handlers/generate_derive.rs
index 6ccf39900..90ece9fab 100644
--- a/crates/ra_assists/src/handlers/generate_derive.rs
+++ b/crates/ra_assists/src/handlers/generate_derive.rs
@@ -26,7 +26,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
26// ``` 26// ```
27pub(crate) fn generate_derive(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { 27pub(crate) fn generate_derive(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
28 let cap = ctx.config.snippet_cap?; 28 let cap = ctx.config.snippet_cap?;
29 let nominal = ctx.find_node_at_offset::<ast::NominalDef>()?; 29 let nominal = ctx.find_node_at_offset::<ast::AdtDef>()?;
30 let node_start = derive_insertion_offset(&nominal)?; 30 let node_start = derive_insertion_offset(&nominal)?;
31 let target = nominal.syntax().text_range(); 31 let target = nominal.syntax().text_range();
32 acc.add( 32 acc.add(
@@ -58,7 +58,7 @@ pub(crate) fn generate_derive(acc: &mut Assists, ctx: &AssistContext) -> Option<
58} 58}
59 59
60// Insert `derive` after doc comments. 60// Insert `derive` after doc comments.
61fn derive_insertion_offset(nominal: &ast::NominalDef) -> Option<TextSize> { 61fn derive_insertion_offset(nominal: &ast::AdtDef) -> Option<TextSize> {
62 let non_ws_child = nominal 62 let non_ws_child = nominal
63 .syntax() 63 .syntax()
64 .children_with_tokens() 64 .children_with_tokens()
diff --git a/crates/ra_assists/src/handlers/generate_impl.rs b/crates/ra_assists/src/handlers/generate_impl.rs
index cbbac1d7f..42eb4defa 100644
--- a/crates/ra_assists/src/handlers/generate_impl.rs
+++ b/crates/ra_assists/src/handlers/generate_impl.rs
@@ -23,7 +23,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
23// } 23// }
24// ``` 24// ```
25pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { 25pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
26 let nominal = ctx.find_node_at_offset::<ast::NominalDef>()?; 26 let nominal = ctx.find_node_at_offset::<ast::AdtDef>()?;
27 let name = nominal.name()?; 27 let name = nominal.name()?;
28 let target = nominal.syntax().text_range(); 28 let target = nominal.syntax().text_range();
29 acc.add( 29 acc.add(
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_ide/Cargo.toml b/crates/ra_ide/Cargo.toml
index 6f8107491..f4181c4eb 100644
--- a/crates/ra_ide/Cargo.toml
+++ b/crates/ra_ide/Cargo.toml
@@ -17,7 +17,7 @@ indexmap = "1.3.2"
17itertools = "0.9.0" 17itertools = "0.9.0"
18log = "0.4.8" 18log = "0.4.8"
19rustc-hash = "1.1.0" 19rustc-hash = "1.1.0"
20rand = { version = "0.7.3", features = ["small_rng"] } 20oorandom = "11.1.2"
21 21
22stdx = { path = "../stdx" } 22stdx = { path = "../stdx" }
23 23
diff --git a/crates/ra_ide/src/goto_implementation.rs b/crates/ra_ide/src/goto_implementation.rs
index 3ee048f28..16a61d071 100644
--- a/crates/ra_ide/src/goto_implementation.rs
+++ b/crates/ra_ide/src/goto_implementation.rs
@@ -23,7 +23,7 @@ pub(crate) fn goto_implementation(
23 23
24 let krate = sema.to_module_def(position.file_id)?.krate(); 24 let krate = sema.to_module_def(position.file_id)?.krate();
25 25
26 if let Some(nominal_def) = find_node_at_offset::<ast::NominalDef>(&syntax, position.offset) { 26 if let Some(nominal_def) = find_node_at_offset::<ast::AdtDef>(&syntax, position.offset) {
27 return Some(RangeInfo::new( 27 return Some(RangeInfo::new(
28 nominal_def.syntax().text_range(), 28 nominal_def.syntax().text_range(),
29 impls_for_def(&sema, &nominal_def, krate)?, 29 impls_for_def(&sema, &nominal_def, krate)?,
@@ -40,13 +40,13 @@ pub(crate) fn goto_implementation(
40 40
41fn impls_for_def( 41fn impls_for_def(
42 sema: &Semantics<RootDatabase>, 42 sema: &Semantics<RootDatabase>,
43 node: &ast::NominalDef, 43 node: &ast::AdtDef,
44 krate: Crate, 44 krate: Crate,
45) -> Option<Vec<NavigationTarget>> { 45) -> Option<Vec<NavigationTarget>> {
46 let ty = match node { 46 let ty = match node {
47 ast::NominalDef::StructDef(def) => sema.to_def(def)?.ty(sema.db), 47 ast::AdtDef::StructDef(def) => sema.to_def(def)?.ty(sema.db),
48 ast::NominalDef::EnumDef(def) => sema.to_def(def)?.ty(sema.db), 48 ast::AdtDef::EnumDef(def) => sema.to_def(def)?.ty(sema.db),
49 ast::NominalDef::UnionDef(def) => sema.to_def(def)?.ty(sema.db), 49 ast::AdtDef::UnionDef(def) => sema.to_def(def)?.ty(sema.db),
50 }; 50 };
51 51
52 let impls = ImplDef::all_in_crate(sema.db, krate); 52 let impls = ImplDef::all_in_crate(sema.db, krate);
diff --git a/crates/ra_ide/src/syntax_highlighting/html.rs b/crates/ra_ide/src/syntax_highlighting/html.rs
index 0be55bca9..a5e7d2867 100644
--- a/crates/ra_ide/src/syntax_highlighting/html.rs
+++ b/crates/ra_ide/src/syntax_highlighting/html.rs
@@ -1,5 +1,6 @@
1//! Renders a bit of code as HTML. 1//! Renders a bit of code as HTML.
2 2
3use oorandom::Rand32;
3use ra_db::SourceDatabase; 4use ra_db::SourceDatabase;
4use ra_syntax::{AstNode, TextRange, TextSize}; 5use ra_syntax::{AstNode, TextRange, TextSize};
5 6
@@ -9,13 +10,12 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo
9 let parse = db.parse(file_id); 10 let parse = db.parse(file_id);
10 11
11 fn rainbowify(seed: u64) -> String { 12 fn rainbowify(seed: u64) -> String {
12 use rand::prelude::*; 13 let mut rng = Rand32::new(seed);
13 let mut rng = SmallRng::seed_from_u64(seed);
14 format!( 14 format!(
15 "hsl({h},{s}%,{l}%)", 15 "hsl({h},{s}%,{l}%)",
16 h = rng.gen_range::<u16, _, _>(0, 361), 16 h = rng.rand_range(0..361),
17 s = rng.gen_range::<u16, _, _>(42, 99), 17 s = rng.rand_range(42..99),
18 l = rng.gen_range::<u16, _, _>(40, 91), 18 l = rng.rand_range(40..91),
19 ) 19 )
20 } 20 }
21 21
diff --git a/crates/ra_ide/test_data/rainbow_highlighting.html b/crates/ra_ide/test_data/rainbow_highlighting.html
index 08d83302c..401e87a73 100644
--- a/crates/ra_ide/test_data/rainbow_highlighting.html
+++ b/crates/ra_ide/test_data/rainbow_highlighting.html
@@ -36,14 +36,14 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
36.unresolved_reference { color: #FC5555; text-decoration: wavy underline; } 36.unresolved_reference { color: #FC5555; text-decoration: wavy underline; }
37</style> 37</style>
38<pre><code><span class="keyword">fn</span> <span class="function declaration">main</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span> 38<pre><code><span class="keyword">fn</span> <span class="function declaration">main</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span>
39 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span> <span class="operator">=</span> <span class="string_literal">"hello"</span><span class="punctuation">;</span> 39 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="8121853618659664005" style="color: hsl(273,88%,88%);">hello</span> <span class="operator">=</span> <span class="string_literal">"hello"</span><span class="punctuation">;</span>
40 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="2705725358298919760" style="color: hsl(17,51%,74%);">x</span> <span class="operator">=</span> <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span><span class="punctuation">.</span><span class="unresolved_reference">to_string</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> 40 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="2705725358298919760" style="color: hsl(76,47%,83%);">x</span> <span class="operator">=</span> <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(273,88%,88%);">hello</span><span class="punctuation">.</span><span class="unresolved_reference">to_string</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span>
41 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="3365759661443752373" style="color: hsl(127,76%,66%);">y</span> <span class="operator">=</span> <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span><span class="punctuation">.</span><span class="unresolved_reference">to_string</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> 41 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="3365759661443752373" style="color: hsl(15,86%,51%);">y</span> <span class="operator">=</span> <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(273,88%,88%);">hello</span><span class="punctuation">.</span><span class="unresolved_reference">to_string</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span>
42 42
43 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="794745962933817518" style="color: hsl(19,74%,76%);">x</span> <span class="operator">=</span> <span class="string_literal">"other color please!"</span><span class="punctuation">;</span> 43 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="794745962933817518" style="color: hsl(127,71%,87%);">x</span> <span class="operator">=</span> <span class="string_literal">"other color please!"</span><span class="punctuation">;</span>
44 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="6717528807933952652" style="color: hsl(85,49%,84%);">y</span> <span class="operator">=</span> <span class="variable" data-binding-hash="794745962933817518" style="color: hsl(19,74%,76%);">x</span><span class="punctuation">.</span><span class="unresolved_reference">to_string</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span> 44 <span class="keyword">let</span> <span class="variable declaration" data-binding-hash="6717528807933952652" style="color: hsl(90,74%,79%);">y</span> <span class="operator">=</span> <span class="variable" data-binding-hash="794745962933817518" style="color: hsl(127,71%,87%);">x</span><span class="punctuation">.</span><span class="unresolved_reference">to_string</span><span class="punctuation">(</span><span class="punctuation">)</span><span class="punctuation">;</span>
45<span class="punctuation">}</span> 45<span class="punctuation">}</span>
46 46
47<span class="keyword">fn</span> <span class="function declaration">bar</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span> 47<span class="keyword">fn</span> <span class="function declaration">bar</span><span class="punctuation">(</span><span class="punctuation">)</span> <span class="punctuation">{</span>
48 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span> <span class="operator">=</span> <span class="string_literal">"hello"</span><span class="punctuation">;</span> 48 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable declaration mutable" data-binding-hash="8121853618659664005" style="color: hsl(273,88%,88%);">hello</span> <span class="operator">=</span> <span class="string_literal">"hello"</span><span class="punctuation">;</span>
49<span class="punctuation">}</span></code></pre> \ No newline at end of file 49<span class="punctuation">}</span></code></pre> \ No newline at end of file
diff --git a/crates/ra_proc_macro_srv/Cargo.toml b/crates/ra_proc_macro_srv/Cargo.toml
index 12ce497f8..bc119a6c7 100644
--- a/crates/ra_proc_macro_srv/Cargo.toml
+++ b/crates/ra_proc_macro_srv/Cargo.toml
@@ -19,7 +19,7 @@ memmap = "0.7"
19test_utils = { path = "../test_utils" } 19test_utils = { path = "../test_utils" }
20 20
21[dev-dependencies] 21[dev-dependencies]
22cargo_metadata = "0.10.0" 22cargo_metadata = "0.11.1"
23difference = "2.0.0" 23difference = "2.0.0"
24# used as proc macro test target 24# used as proc macro test target
25serde_derive = "1.0.106" 25serde_derive = "1.0.106"
diff --git a/crates/ra_project_model/Cargo.toml b/crates/ra_project_model/Cargo.toml
index 827eb7e28..99adea8e4 100644
--- a/crates/ra_project_model/Cargo.toml
+++ b/crates/ra_project_model/Cargo.toml
@@ -12,7 +12,7 @@ doctest = false
12log = "0.4.8" 12log = "0.4.8"
13rustc-hash = "1.1.0" 13rustc-hash = "1.1.0"
14 14
15cargo_metadata = "0.10.0" 15cargo_metadata = "0.11.1"
16 16
17ra_arena = { path = "../ra_arena" } 17ra_arena = { path = "../ra_arena" }
18ra_cfg = { path = "../ra_cfg" } 18ra_cfg = { path = "../ra_cfg" }
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 58141da11..04a4d354c 100644
--- a/crates/ra_syntax/src/ast/generated/nodes.rs
+++ b/crates/ra_syntax/src/ast/generated/nodes.rs
@@ -5,50 +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 pub fn modules(&self) -> AstChildren<Module> { support::children(&self.syntax) } 15#[derive(Debug, Clone, PartialEq, Eq, Hash)]
20} 16pub struct Attr {
21/// Function definition either with body or not. 17 pub(crate) syntax: SyntaxNode,
22/// Includes all of its attributes and doc comments. 18}
23/// 19impl Attr {
24/// ``` 20 pub fn pound_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![#]) }
25/// ❰ 21 pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) }
26/// /// Docs 22 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
27/// #[attr] 23 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
28/// pub extern "C" fn foo<T>(#[attr] Patern {p}: Pattern) -> u32 24 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
29/// where 25 pub fn input(&self) -> Option<AttrInput> { support::child(&self.syntax) }
30/// T: Debug 26 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
31/// { 27}
32/// 42
33/// }
34/// ❱
35///
36/// extern "C" {
37/// ❰ fn fn_decl(also_variadic_ffi: u32, ...) -> u32; ❱
38/// }
39/// ```
40///
41/// - [Reference](https://doc.rust-lang.org/reference/items/functions.html)
42/// - [Nomicon](https://doc.rust-lang.org/nomicon/ffi.html#variadic-functions)
43#[derive(Debug, Clone, PartialEq, Eq, Hash)] 28#[derive(Debug, Clone, PartialEq, Eq, Hash)]
44pub struct FnDef { 29pub struct FnDef {
45 pub(crate) syntax: SyntaxNode, 30 pub(crate) syntax: SyntaxNode,
46} 31}
47impl ast::VisibilityOwner for FnDef {} 32impl ast::AttrsOwner for FnDef {}
48impl ast::NameOwner for FnDef {} 33impl ast::NameOwner for FnDef {}
34impl ast::VisibilityOwner for FnDef {}
49impl ast::TypeParamsOwner for FnDef {} 35impl ast::TypeParamsOwner for FnDef {}
50impl ast::DocCommentsOwner for FnDef {}
51impl ast::AttrsOwner for FnDef {}
52impl FnDef { 36impl FnDef {
53 pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) } 37 pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) }
54 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]) }
@@ -61,13 +45,53 @@ impl FnDef {
61 pub fn body(&self) -> Option<BlockExpr> { support::child(&self.syntax) } 45 pub fn body(&self) -> Option<BlockExpr> { support::child(&self.syntax) }
62 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![;]) }
63} 47}
64/// Return type annotation. 48#[derive(Debug, Clone, PartialEq, Eq, Hash)]
65/// 49pub struct Visibility {
66/// ``` 50 pub(crate) syntax: SyntaxNode,
67/// fn foo(a: u32) ❰ -> Option<u32> ❱ { Some(a) } 51}
68/// ``` 52impl Visibility {
69/// 53 pub fn pub_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![pub]) }
70/// [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}
71#[derive(Debug, Clone, PartialEq, Eq, Hash)] 95#[derive(Debug, Clone, PartialEq, Eq, Hash)]
72pub struct RetType { 96pub struct RetType {
73 pub(crate) syntax: SyntaxNode, 97 pub(crate) syntax: SyntaxNode,
@@ -76,204 +100,105 @@ impl RetType {
76 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![->]) }
77 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 101 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
78} 102}
79/// Struct definition. 103#[derive(Debug, Clone, PartialEq, Eq, Hash)]
80/// Includes all of its attributes and doc comments. 104pub struct WhereClause {
81/// 105 pub(crate) syntax: SyntaxNode,
82/// ``` 106}
83/// ❰ 107impl WhereClause {
84/// /// Docs 108 pub fn where_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![where]) }
85/// #[attr] 109 pub fn predicates(&self) -> AstChildren<WherePred> { support::children(&self.syntax) }
86/// struct Foo<T> where T: Debug { 110}
87/// /// Docs 111#[derive(Debug, Clone, PartialEq, Eq, Hash)]
88/// #[attr] 112pub struct BlockExpr {
89/// pub a: u32, 113 pub(crate) syntax: SyntaxNode,
90/// b: T, 114}
91/// } 115impl ast::AttrsOwner for BlockExpr {}
92/// ❱ 116impl ast::ModuleItemOwner for BlockExpr {}
93/// 117impl BlockExpr {
94/// ❰ struct Foo; ❱ 118 pub fn label(&self) -> Option<Label> { support::child(&self.syntax) }
95/// ❰ struct Foo<T>(#[attr] T) where T: Debug; ❱ 119 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
96/// ``` 120 pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) }
97/// 121 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
98/// [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}
99#[derive(Debug, Clone, PartialEq, Eq, Hash)] 124#[derive(Debug, Clone, PartialEq, Eq, Hash)]
100pub struct StructDef { 125pub struct StructDef {
101 pub(crate) syntax: SyntaxNode, 126 pub(crate) syntax: SyntaxNode,
102} 127}
103impl ast::VisibilityOwner for StructDef {} 128impl ast::AttrsOwner for StructDef {}
104impl ast::NameOwner for StructDef {} 129impl ast::NameOwner for StructDef {}
130impl ast::VisibilityOwner for StructDef {}
105impl ast::TypeParamsOwner for StructDef {} 131impl ast::TypeParamsOwner for StructDef {}
106impl ast::AttrsOwner for StructDef {}
107impl ast::DocCommentsOwner for StructDef {}
108impl StructDef { 132impl StructDef {
109 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]) }
110 pub fn field_def_list(&self) -> Option<FieldDefList> { support::child(&self.syntax) }
111 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![')']) }
112} 154}
113/// Union definition.
114/// Includes all of its attributes and doc comments.
115///
116/// ```
117/// ❰
118/// /// Docs
119/// #[attr]
120/// pub union Foo<T> where T: Debug {
121/// /// Docs
122/// #[attr]
123/// a: T,
124/// b: u32,
125/// }
126/// ❱
127/// ```
128///
129/// [Reference](https://doc.rust-lang.org/reference/items/unions.html)
130#[derive(Debug, Clone, PartialEq, Eq, Hash)] 155#[derive(Debug, Clone, PartialEq, Eq, Hash)]
131pub struct UnionDef { 156pub struct UnionDef {
132 pub(crate) syntax: SyntaxNode, 157 pub(crate) syntax: SyntaxNode,
133} 158}
134impl ast::VisibilityOwner for UnionDef {} 159impl ast::AttrsOwner for UnionDef {}
135impl ast::NameOwner for UnionDef {} 160impl ast::NameOwner for UnionDef {}
161impl ast::VisibilityOwner for UnionDef {}
136impl ast::TypeParamsOwner for UnionDef {} 162impl ast::TypeParamsOwner for UnionDef {}
137impl ast::AttrsOwner for UnionDef {}
138impl ast::DocCommentsOwner for UnionDef {}
139impl UnionDef { 163impl UnionDef {
140 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]) }
141 pub fn record_field_def_list(&self) -> Option<RecordFieldDefList> { 165 pub fn record_field_def_list(&self) -> Option<RecordFieldDefList> {
142 support::child(&self.syntax) 166 support::child(&self.syntax)
143 } 167 }
144} 168}
145/// Record field definition list including enclosing curly braces.
146///
147/// ```
148/// struct Foo // same for union
149/// ❰
150/// {
151/// a: u32,
152/// b: bool,
153/// }
154/// ❱
155/// ```
156///
157/// [Reference](https://doc.rust-lang.org/reference/items/structs.html)
158#[derive(Debug, Clone, PartialEq, Eq, Hash)]
159pub struct RecordFieldDefList {
160 pub(crate) syntax: SyntaxNode,
161}
162impl RecordFieldDefList {
163 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
164 pub fn fields(&self) -> AstChildren<RecordFieldDef> { support::children(&self.syntax) }
165 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
166}
167/// Record field definition including its attributes and doc comments.
168///
169/// ` ``
170/// same for union
171/// struct Foo {
172/// ❰
173/// /// Docs
174/// #[attr]
175/// pub a: u32
176/// ❱
177///
178/// ❰ b: bool ❱
179/// }
180/// ```
181///
182/// [Reference](https://doc.rust-lang.org/reference/items/structs.html)
183#[derive(Debug, Clone, PartialEq, Eq, Hash)] 169#[derive(Debug, Clone, PartialEq, Eq, Hash)]
184pub struct RecordFieldDef { 170pub struct RecordFieldDef {
185 pub(crate) syntax: SyntaxNode, 171 pub(crate) syntax: SyntaxNode,
186} 172}
187impl ast::VisibilityOwner for RecordFieldDef {}
188impl ast::NameOwner for RecordFieldDef {}
189impl ast::AttrsOwner for RecordFieldDef {} 173impl ast::AttrsOwner for RecordFieldDef {}
190impl ast::DocCommentsOwner for RecordFieldDef {} 174impl ast::NameOwner for RecordFieldDef {}
175impl ast::VisibilityOwner for RecordFieldDef {}
191impl ast::TypeAscriptionOwner for RecordFieldDef {} 176impl ast::TypeAscriptionOwner for RecordFieldDef {}
192impl RecordFieldDef {} 177impl RecordFieldDef {
193/// Tuple field definition list including enclosing parens. 178 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
194///
195/// ```
196/// struct Foo ❰ (u32, String, Vec<u32>) ❱;
197/// ```
198///
199/// [Reference](https://doc.rust-lang.org/reference/items/structs.html)
200#[derive(Debug, Clone, PartialEq, Eq, Hash)]
201pub struct TupleFieldDefList {
202 pub(crate) syntax: SyntaxNode,
203}
204impl TupleFieldDefList {
205 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
206 pub fn fields(&self) -> AstChildren<TupleFieldDef> { support::children(&self.syntax) }
207 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
208} 179}
209/// Tuple field definition including its attributes.
210///
211/// ```
212/// struct Foo(❰ #[attr] u32 ❱);
213/// ```
214///
215/// [Reference](https://doc.rust-lang.org/reference/items/structs.html)
216#[derive(Debug, Clone, PartialEq, Eq, Hash)] 180#[derive(Debug, Clone, PartialEq, Eq, Hash)]
217pub struct TupleFieldDef { 181pub struct TupleFieldDef {
218 pub(crate) syntax: SyntaxNode, 182 pub(crate) syntax: SyntaxNode,
219} 183}
220impl ast::VisibilityOwner for TupleFieldDef {}
221impl ast::AttrsOwner for TupleFieldDef {} 184impl ast::AttrsOwner for TupleFieldDef {}
185impl ast::NameOwner for TupleFieldDef {}
186impl ast::VisibilityOwner for TupleFieldDef {}
222impl TupleFieldDef { 187impl TupleFieldDef {
223 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 188 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
224} 189}
225/// Enum definition.
226/// Includes all of its attributes and doc comments.
227///
228/// ```
229/// ❰
230/// /// Docs
231/// #[attr]
232/// pub enum Foo<T> where T: Debug {
233/// /// Docs
234/// #[attr]
235/// Bar,
236/// Baz(#[attr] u32),
237/// Bruh {
238/// a: u32,
239/// /// Docs
240/// #[attr]
241/// b: T,
242/// }
243/// }
244/// ❱
245/// ```
246///
247/// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html)
248#[derive(Debug, Clone, PartialEq, Eq, Hash)] 190#[derive(Debug, Clone, PartialEq, Eq, Hash)]
249pub struct EnumDef { 191pub struct EnumDef {
250 pub(crate) syntax: SyntaxNode, 192 pub(crate) syntax: SyntaxNode,
251} 193}
252impl ast::VisibilityOwner for EnumDef {} 194impl ast::AttrsOwner for EnumDef {}
253impl ast::NameOwner for EnumDef {} 195impl ast::NameOwner for EnumDef {}
196impl ast::VisibilityOwner for EnumDef {}
254impl ast::TypeParamsOwner for EnumDef {} 197impl ast::TypeParamsOwner for EnumDef {}
255impl ast::AttrsOwner for EnumDef {}
256impl ast::DocCommentsOwner for EnumDef {}
257impl EnumDef { 198impl EnumDef {
258 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]) }
259 pub fn variant_list(&self) -> Option<EnumVariantList> { support::child(&self.syntax) } 200 pub fn variant_list(&self) -> Option<EnumVariantList> { support::child(&self.syntax) }
260} 201}
261/// Enum variant definition list including enclosing curly braces.
262///
263/// ```
264/// enum Foo
265/// ❰
266/// {
267/// Bar,
268/// Baz(u32),
269/// Bruh {
270/// a: u32
271/// }
272/// }
273/// ❱
274/// ```
275///
276/// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html)
277#[derive(Debug, Clone, PartialEq, Eq, Hash)] 202#[derive(Debug, Clone, PartialEq, Eq, Hash)]
278pub struct EnumVariantList { 203pub struct EnumVariantList {
279 pub(crate) syntax: SyntaxNode, 204 pub(crate) syntax: SyntaxNode,
@@ -283,56 +208,25 @@ impl EnumVariantList {
283 pub fn variants(&self) -> AstChildren<EnumVariant> { support::children(&self.syntax) } 208 pub fn variants(&self) -> AstChildren<EnumVariant> { support::children(&self.syntax) }
284 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!['}']) }
285} 210}
286/// Enum variant definition including its attributes and discriminant value definition.
287///
288/// ```
289/// enum Foo {
290/// ❰
291/// /// Docs
292/// #[attr]
293/// Bar
294/// ❱
295///
296/// // same for tuple and record variants
297/// }
298/// ```
299///
300/// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html)
301#[derive(Debug, Clone, PartialEq, Eq, Hash)] 211#[derive(Debug, Clone, PartialEq, Eq, Hash)]
302pub struct EnumVariant { 212pub struct EnumVariant {
303 pub(crate) syntax: SyntaxNode, 213 pub(crate) syntax: SyntaxNode,
304} 214}
305impl ast::VisibilityOwner for EnumVariant {}
306impl ast::NameOwner for EnumVariant {}
307impl ast::DocCommentsOwner for EnumVariant {}
308impl ast::AttrsOwner for EnumVariant {} 215impl ast::AttrsOwner for EnumVariant {}
216impl ast::NameOwner for EnumVariant {}
217impl ast::VisibilityOwner for EnumVariant {}
309impl EnumVariant { 218impl EnumVariant {
310 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) }
311 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![=]) }
312 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 221 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
313} 222}
314/// Trait definition.
315/// Includes all of its attributes and doc comments.
316///
317/// ```
318/// ❰
319/// /// Docs
320/// #[attr]
321/// pub unsafe trait Foo<T>: Debug where T: Debug {
322/// // ...
323/// }
324/// ❱
325/// ```
326///
327/// [Reference](https://doc.rust-lang.org/reference/items/traits.html)
328#[derive(Debug, Clone, PartialEq, Eq, Hash)] 223#[derive(Debug, Clone, PartialEq, Eq, Hash)]
329pub struct TraitDef { 224pub struct TraitDef {
330 pub(crate) syntax: SyntaxNode, 225 pub(crate) syntax: SyntaxNode,
331} 226}
332impl ast::VisibilityOwner for TraitDef {}
333impl ast::NameOwner for TraitDef {}
334impl ast::AttrsOwner for TraitDef {} 227impl ast::AttrsOwner for TraitDef {}
335impl ast::DocCommentsOwner for TraitDef {} 228impl ast::NameOwner for TraitDef {}
229impl ast::VisibilityOwner for TraitDef {}
336impl ast::TypeParamsOwner for TraitDef {} 230impl ast::TypeParamsOwner for TraitDef {}
337impl ast::TypeBoundsOwner for TraitDef {} 231impl ast::TypeBoundsOwner for TraitDef {}
338impl TraitDef { 232impl TraitDef {
@@ -341,62 +235,13 @@ impl TraitDef {
341 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]) }
342 pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } 236 pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) }
343} 237}
344/// Module definition either with body or not.
345/// Includes all of its inner and outer attributes, module items, doc comments.
346///
347/// ```
348/// ❰
349/// /// Docs
350/// #[attr]
351/// pub mod foo;
352/// ❱
353///
354/// ❰
355/// /// Docs
356/// #[attr]
357/// pub mod bar {
358/// //! Inner docs
359/// #![inner_attr]
360/// }
361/// ❱
362/// ```
363///
364/// [Reference](https://doc.rust-lang.org/reference/items/modules.html)
365#[derive(Debug, Clone, PartialEq, Eq, Hash)] 238#[derive(Debug, Clone, PartialEq, Eq, Hash)]
366pub struct Module { 239pub struct TypeBoundList {
367 pub(crate) syntax: SyntaxNode, 240 pub(crate) syntax: SyntaxNode,
368} 241}
369impl ast::VisibilityOwner for Module {} 242impl TypeBoundList {
370impl ast::NameOwner for Module {} 243 pub fn bounds(&self) -> AstChildren<TypeBound> { support::children(&self.syntax) }
371impl ast::AttrsOwner for Module {}
372impl ast::DocCommentsOwner for Module {}
373impl Module {
374 pub fn mod_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mod]) }
375 pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) }
376 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
377} 244}
378/// Item defintion list.
379/// This is used for both top-level items and impl block items.
380///
381/// ```
382/// ❰
383/// fn foo {}
384/// struct Bar;
385/// enum Baz;
386/// trait Bruh;
387/// const BRUUH: u32 = 42;
388/// ❱
389///
390/// impl Foo
391/// ❰
392/// {
393/// fn bar() {}
394/// const BAZ: u32 = 42;
395/// }
396/// ❱
397/// ```
398///
399/// [Reference](https://doc.rust-lang.org/reference/items.html)
400#[derive(Debug, Clone, PartialEq, Eq, Hash)] 245#[derive(Debug, Clone, PartialEq, Eq, Hash)]
401pub struct ItemList { 246pub struct ItemList {
402 pub(crate) syntax: SyntaxNode, 247 pub(crate) syntax: SyntaxNode,
@@ -407,91 +252,58 @@ impl ItemList {
407 pub fn assoc_items(&self) -> AstChildren<AssocItem> { support::children(&self.syntax) } 252 pub fn assoc_items(&self) -> AstChildren<AssocItem> { support::children(&self.syntax) }
408 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!['}']) }
409} 254}
410/// Constant variable definition. 255#[derive(Debug, Clone, PartialEq, Eq, Hash)]
411/// Includes all of its attributes and doc comments. 256pub struct Module {
412/// 257 pub(crate) syntax: SyntaxNode,
413/// ``` 258}
414/// 259impl ast::AttrsOwner for Module {}
415/// /// Docs 260impl ast::NameOwner for Module {}
416/// #[attr] 261impl ast::VisibilityOwner for Module {}
417/// pub const FOO: u32 = 42; 262impl Module {
418/// 263 pub fn mod_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mod]) }
419/// ``` 264 pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) }
420/// 265 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
421/// [Reference](https://doc.rust-lang.org/reference/items/constant-items.html) 266}
422#[derive(Debug, Clone, PartialEq, Eq, Hash)] 267#[derive(Debug, Clone, PartialEq, Eq, Hash)]
423pub struct ConstDef { 268pub struct ConstDef {
424 pub(crate) syntax: SyntaxNode, 269 pub(crate) syntax: SyntaxNode,
425} 270}
426impl ast::VisibilityOwner for ConstDef {}
427impl ast::NameOwner for ConstDef {}
428impl ast::TypeParamsOwner for ConstDef {}
429impl ast::AttrsOwner for ConstDef {} 271impl ast::AttrsOwner for ConstDef {}
430impl ast::DocCommentsOwner for ConstDef {} 272impl ast::NameOwner for ConstDef {}
273impl ast::VisibilityOwner for ConstDef {}
431impl ast::TypeAscriptionOwner for ConstDef {} 274impl ast::TypeAscriptionOwner for ConstDef {}
432impl ConstDef { 275impl ConstDef {
433 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]) }
434 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![:]) }
435 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![=]) }
436 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } 280 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) }
437 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![;]) }
438} 282}
439/// Static variable definition.
440/// Includes all of its attributes and doc comments.
441///
442/// ```
443/// ❰
444/// /// Docs
445/// #[attr]
446/// pub static mut FOO: u32 = 42;
447/// ❱
448/// ```
449///
450/// [Reference](https://doc.rust-lang.org/reference/items/static-items.html)
451#[derive(Debug, Clone, PartialEq, Eq, Hash)] 283#[derive(Debug, Clone, PartialEq, Eq, Hash)]
452pub struct StaticDef { 284pub struct StaticDef {
453 pub(crate) syntax: SyntaxNode, 285 pub(crate) syntax: SyntaxNode,
454} 286}
455impl ast::VisibilityOwner for StaticDef {}
456impl ast::NameOwner for StaticDef {}
457impl ast::TypeParamsOwner for StaticDef {}
458impl ast::AttrsOwner for StaticDef {} 287impl ast::AttrsOwner for StaticDef {}
459impl ast::DocCommentsOwner for StaticDef {} 288impl ast::NameOwner for StaticDef {}
289impl ast::VisibilityOwner for StaticDef {}
460impl ast::TypeAscriptionOwner for StaticDef {} 290impl ast::TypeAscriptionOwner for StaticDef {}
461impl StaticDef { 291impl StaticDef {
462 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]) }
463 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![:]) }
464 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![=]) }
465 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } 296 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) }
466 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![;]) }
467} 298}
468/// Type alias definition.
469/// Includes associated type clauses with type bounds.
470///
471/// ```
472/// ❰
473/// /// Docs
474/// #[attr]
475/// pub type Foo<T> where T: Debug = T;
476/// ❱
477///
478/// trait Bar {
479/// ❰ type Baz: Debug; ❱
480/// ❰ type Bruh = String; ❱
481/// ❰ type Bruuh: Debug = u32; ❱
482/// }
483/// ```
484///
485/// [Reference](https://doc.rust-lang.org/reference/items/type-aliases.html)
486#[derive(Debug, Clone, PartialEq, Eq, Hash)] 299#[derive(Debug, Clone, PartialEq, Eq, Hash)]
487pub struct TypeAliasDef { 300pub struct TypeAliasDef {
488 pub(crate) syntax: SyntaxNode, 301 pub(crate) syntax: SyntaxNode,
489} 302}
490impl ast::VisibilityOwner for TypeAliasDef {} 303impl ast::AttrsOwner for TypeAliasDef {}
491impl ast::NameOwner for TypeAliasDef {} 304impl ast::NameOwner for TypeAliasDef {}
305impl ast::VisibilityOwner for TypeAliasDef {}
492impl ast::TypeParamsOwner for TypeAliasDef {} 306impl ast::TypeParamsOwner for TypeAliasDef {}
493impl ast::AttrsOwner for TypeAliasDef {}
494impl ast::DocCommentsOwner for TypeAliasDef {}
495impl ast::TypeBoundsOwner for TypeAliasDef {} 307impl ast::TypeBoundsOwner for TypeAliasDef {}
496impl TypeAliasDef { 308impl TypeAliasDef {
497 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]) }
@@ -500,46 +312,22 @@ impl TypeAliasDef {
500 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 312 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
501 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![;]) }
502} 314}
503/// Inherent and trait impl definition.
504/// Includes all of its inner and outer attributes.
505///
506/// ```
507/// ❰
508/// #[attr]
509/// unsafe impl<T> const !Foo for Bar where T: Debug {
510/// #![inner_attr]
511/// // ...
512/// }
513/// ❱
514/// ```
515///
516/// [Reference](https://doc.rust-lang.org/reference/items/implementations.html)
517#[derive(Debug, Clone, PartialEq, Eq, Hash)] 315#[derive(Debug, Clone, PartialEq, Eq, Hash)]
518pub struct ImplDef { 316pub struct ImplDef {
519 pub(crate) syntax: SyntaxNode, 317 pub(crate) syntax: SyntaxNode,
520} 318}
521impl ast::TypeParamsOwner for ImplDef {}
522impl ast::AttrsOwner for ImplDef {} 319impl ast::AttrsOwner for ImplDef {}
523impl ast::DocCommentsOwner for ImplDef {} 320impl ast::VisibilityOwner for ImplDef {}
321impl ast::TypeParamsOwner for ImplDef {}
524impl ImplDef { 322impl ImplDef {
525 pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) }
526 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]) }
527 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]) }
528 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]) }
529 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![!]) }
530 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]) }
531 pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } 329 pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) }
532} 330}
533/// Parenthesized type reference.
534/// Note: parens are only used for grouping, this is not a tuple type.
535///
536/// ```
537/// // This is effectively just `u32`.
538/// // Single-item tuple must be defined with a trailing comma: `(u32,)`
539/// type Foo = ❰ (u32) ❱;
540///
541/// let bar: &'static ❰ (dyn Debug) ❱ = "bruh";
542/// ```
543#[derive(Debug, Clone, PartialEq, Eq, Hash)] 331#[derive(Debug, Clone, PartialEq, Eq, Hash)]
544pub struct ParenType { 332pub struct ParenType {
545 pub(crate) syntax: SyntaxNode, 333 pub(crate) syntax: SyntaxNode,
@@ -549,13 +337,6 @@ impl ParenType {
549 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 337 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
550 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![')']) }
551} 339}
552/// Unnamed tuple type.
553///
554/// ```
555/// let foo: ❰ (u32, bool) ❱ = (42, true);
556/// ```
557///
558/// [Reference](https://doc.rust-lang.org/reference/types/tuple.html)
559#[derive(Debug, Clone, PartialEq, Eq, Hash)] 340#[derive(Debug, Clone, PartialEq, Eq, Hash)]
560pub struct TupleType { 341pub struct TupleType {
561 pub(crate) syntax: SyntaxNode, 342 pub(crate) syntax: SyntaxNode,
@@ -565,17 +346,6 @@ impl TupleType {
565 pub fn fields(&self) -> AstChildren<TypeRef> { support::children(&self.syntax) } 346 pub fn fields(&self) -> AstChildren<TypeRef> { support::children(&self.syntax) }
566 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![')']) }
567} 348}
568/// The never type (i.e. the exclamation point).
569///
570/// ```
571/// type T = ❰ ! ❱;
572///
573/// fn no_return() -> ❰ ! ❱ {
574/// loop {}
575/// }
576/// ```
577///
578/// [Reference](https://doc.rust-lang.org/reference/types/never.html)
579#[derive(Debug, Clone, PartialEq, Eq, Hash)] 349#[derive(Debug, Clone, PartialEq, Eq, Hash)]
580pub struct NeverType { 350pub struct NeverType {
581 pub(crate) syntax: SyntaxNode, 351 pub(crate) syntax: SyntaxNode,
@@ -583,17 +353,6 @@ pub struct NeverType {
583impl NeverType { 353impl NeverType {
584 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![!]) }
585} 355}
586/// Path to a type.
587/// Includes single identifier type names and elaborate paths with
588/// generic parameters.
589///
590/// ```
591/// type Foo = ❰ String ❱;
592/// type Bar = ❰ std::vec::Vec<T> ❱;
593/// type Baz = ❰ ::bruh::<Bruuh as Iterator>::Item ❱;
594/// ```
595///
596/// [Reference](https://doc.rust-lang.org/reference/paths.html)
597#[derive(Debug, Clone, PartialEq, Eq, Hash)] 356#[derive(Debug, Clone, PartialEq, Eq, Hash)]
598pub struct PathType { 357pub struct PathType {
599 pub(crate) syntax: SyntaxNode, 358 pub(crate) syntax: SyntaxNode,
@@ -601,14 +360,15 @@ pub struct PathType {
601impl PathType { 360impl PathType {
602 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } 361 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
603} 362}
604/// Raw pointer type. 363#[derive(Debug, Clone, PartialEq, Eq, Hash)]
605/// 364pub struct Path {
606/// ``` 365 pub(crate) syntax: SyntaxNode,
607/// type Foo = ❰ *const u32 ❱; 366}
608/// type Bar = ❰ *mut u32 ❱; 367impl Path {
609/// ``` 368 pub fn qualifier(&self) -> Option<Path> { support::child(&self.syntax) }
610/// 369 pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) }
611/// [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}
612#[derive(Debug, Clone, PartialEq, Eq, Hash)] 372#[derive(Debug, Clone, PartialEq, Eq, Hash)]
613pub struct PointerType { 373pub struct PointerType {
614 pub(crate) syntax: SyntaxNode, 374 pub(crate) syntax: SyntaxNode,
@@ -619,13 +379,6 @@ impl PointerType {
619 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]) }
620 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 380 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
621} 381}
622/// Array type.
623///
624/// ```
625/// type Foo = ❰ [u32; 24 - 3] ❱;
626/// ```
627///
628/// [Reference](https://doc.rust-lang.org/reference/types/array.html)
629#[derive(Debug, Clone, PartialEq, Eq, Hash)] 382#[derive(Debug, Clone, PartialEq, Eq, Hash)]
630pub struct ArrayType { 383pub struct ArrayType {
631 pub(crate) syntax: SyntaxNode, 384 pub(crate) syntax: SyntaxNode,
@@ -637,13 +390,6 @@ impl ArrayType {
637 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 390 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
638 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![']']) }
639} 392}
640/// Slice type.
641///
642/// ```
643/// type Foo = ❰ [u8] ❱;
644/// ```
645///
646/// [Reference](https://doc.rust-lang.org/reference/types/slice.html)
647#[derive(Debug, Clone, PartialEq, Eq, Hash)] 393#[derive(Debug, Clone, PartialEq, Eq, Hash)]
648pub struct SliceType { 394pub struct SliceType {
649 pub(crate) syntax: SyntaxNode, 395 pub(crate) syntax: SyntaxNode,
@@ -653,13 +399,6 @@ impl SliceType {
653 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 399 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
654 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![']']) }
655} 401}
656/// Reference type.
657///
658/// ```
659/// type Foo = ❰ &'static str ❱;
660/// ```
661///
662/// [Reference](https://doc.rust-lang.org/reference/types/pointer.html)
663#[derive(Debug, Clone, PartialEq, Eq, Hash)] 402#[derive(Debug, Clone, PartialEq, Eq, Hash)]
664pub struct ReferenceType { 403pub struct ReferenceType {
665 pub(crate) syntax: SyntaxNode, 404 pub(crate) syntax: SyntaxNode,
@@ -672,13 +411,6 @@ impl ReferenceType {
672 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]) }
673 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 412 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
674} 413}
675/// Placeholder type (i.e. the underscore).
676///
677/// ```
678/// let foo: ❰ _ ❱ = 42_u32;
679/// ```
680///
681/// [Reference](https://doc.rust-lang.org/reference/types/inferred.html)
682#[derive(Debug, Clone, PartialEq, Eq, Hash)] 414#[derive(Debug, Clone, PartialEq, Eq, Hash)]
683pub struct PlaceholderType { 415pub struct PlaceholderType {
684 pub(crate) syntax: SyntaxNode, 416 pub(crate) syntax: SyntaxNode,
@@ -686,15 +418,6 @@ pub struct PlaceholderType {
686impl PlaceholderType { 418impl PlaceholderType {
687 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![_]) }
688} 420}
689/// Function pointer type (not to be confused with `Fn*` family of traits).
690///
691/// ```
692/// type Foo = ❰ async fn(#[attr] u32, named: bool) -> u32 ❱;
693///
694/// type Bar = ❰ extern "C" fn(variadic: u32, #[attr] ...) ❱;
695/// ```
696///
697/// [Reference](https://doc.rust-lang.org/reference/types/function-pointer.html)
698#[derive(Debug, Clone, PartialEq, Eq, Hash)] 421#[derive(Debug, Clone, PartialEq, Eq, Hash)]
699pub struct FnPointerType { 422pub struct FnPointerType {
700 pub(crate) syntax: SyntaxNode, 423 pub(crate) syntax: SyntaxNode,
@@ -706,13 +429,6 @@ impl FnPointerType {
706 pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) } 429 pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) }
707 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } 430 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) }
708} 431}
709/// Higher order type.
710///
711/// ```
712/// type Foo = ❰ for<'a> fn(&'a str) ❱;
713/// ```
714///
715/// [Reference](https://doc.rust-lang.org/nomicon/hrtb.html)
716#[derive(Debug, Clone, PartialEq, Eq, Hash)] 432#[derive(Debug, Clone, PartialEq, Eq, Hash)]
717pub struct ForType { 433pub struct ForType {
718 pub(crate) syntax: SyntaxNode, 434 pub(crate) syntax: SyntaxNode,
@@ -722,43 +438,22 @@ impl ForType {
722 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) }
723 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 439 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
724} 440}
725/// Opaque `impl Trait` type.
726///
727/// ```
728/// fn foo(bar: ❰ impl Debug + Eq ❱) {}
729/// ```
730///
731/// [Reference](https://doc.rust-lang.org/reference/types/impl-trait.html)
732#[derive(Debug, Clone, PartialEq, Eq, Hash)] 441#[derive(Debug, Clone, PartialEq, Eq, Hash)]
733pub struct ImplTraitType { 442pub struct ImplTraitType {
734 pub(crate) syntax: SyntaxNode, 443 pub(crate) syntax: SyntaxNode,
735} 444}
736impl ast::TypeBoundsOwner for ImplTraitType {}
737impl ImplTraitType { 445impl ImplTraitType {
738 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) }
739} 448}
740/// Trait object type.
741///
742/// ```
743/// type Foo = ❰ dyn Debug ❱;
744/// ```
745///
746/// [Reference](https://doc.rust-lang.org/reference/types/trait-object.html)
747#[derive(Debug, Clone, PartialEq, Eq, Hash)] 449#[derive(Debug, Clone, PartialEq, Eq, Hash)]
748pub struct DynTraitType { 450pub struct DynTraitType {
749 pub(crate) syntax: SyntaxNode, 451 pub(crate) syntax: SyntaxNode,
750} 452}
751impl ast::TypeBoundsOwner for DynTraitType {}
752impl DynTraitType { 453impl DynTraitType {
753 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) }
754} 456}
755/// Tuple literal.
756///
757/// ```
758/// ❰ (42, true) ❱;
759/// ```
760///
761/// [Reference](https://doc.rust-lang.org/reference/expressions/tuple-expr.html)
762#[derive(Debug, Clone, PartialEq, Eq, Hash)] 457#[derive(Debug, Clone, PartialEq, Eq, Hash)]
763pub struct TupleExpr { 458pub struct TupleExpr {
764 pub(crate) syntax: SyntaxNode, 459 pub(crate) syntax: SyntaxNode,
@@ -769,15 +464,6 @@ impl TupleExpr {
769 pub fn exprs(&self) -> AstChildren<Expr> { support::children(&self.syntax) } 464 pub fn exprs(&self) -> AstChildren<Expr> { support::children(&self.syntax) }
770 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![')']) }
771} 466}
772/// Array literal.
773///
774/// ```
775/// ❰ [#![inner_attr] true, false, true] ❱;
776///
777/// ❰ ["baz"; 24] ❱;
778/// ```
779///
780/// [Reference](https://doc.rust-lang.org/reference/expressions/array-expr.html)
781#[derive(Debug, Clone, PartialEq, Eq, Hash)] 467#[derive(Debug, Clone, PartialEq, Eq, Hash)]
782pub struct ArrayExpr { 468pub struct ArrayExpr {
783 pub(crate) syntax: SyntaxNode, 469 pub(crate) syntax: SyntaxNode,
@@ -786,17 +472,10 @@ impl ast::AttrsOwner for ArrayExpr {}
786impl ArrayExpr { 472impl ArrayExpr {
787 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!['[']) }
788 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) }
789 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![;]) }
790 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![']']) }
791} 478}
792/// Parenthesized expression.
793/// Note: parens are only used for grouping, this is not a tuple literal.
794///
795/// ```
796/// ❰ (#![inner_attr] 2 + 2) ❱ * 2;
797/// ```
798///
799/// [Reference](https://doc.rust-lang.org/reference/expressions/grouped-expr.html)
800#[derive(Debug, Clone, PartialEq, Eq, Hash)] 479#[derive(Debug, Clone, PartialEq, Eq, Hash)]
801pub struct ParenExpr { 480pub struct ParenExpr {
802 pub(crate) syntax: SyntaxNode, 481 pub(crate) syntax: SyntaxNode,
@@ -807,19 +486,6 @@ impl ParenExpr {
807 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 486 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
808 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![')']) }
809} 488}
810/// Path to a symbol in expression context.
811/// Includes single identifier variable names and elaborate paths with
812/// generic parameters.
813///
814/// ```
815/// ❰ Some::<i32> ❱;
816/// ❰ foo ❱ + 42;
817/// ❰ Vec::<i32>::push ❱;
818/// ❰ <[i32]>::reverse ❱;
819/// ❰ <String as std::borrow::Borrow<str>>::borrow ❱;
820/// ```
821///
822/// [Reference](https://doc.rust-lang.org/reference/expressions/path-expr.html)
823#[derive(Debug, Clone, PartialEq, Eq, Hash)] 489#[derive(Debug, Clone, PartialEq, Eq, Hash)]
824pub struct PathExpr { 490pub struct PathExpr {
825 pub(crate) syntax: SyntaxNode, 491 pub(crate) syntax: SyntaxNode,
@@ -827,17 +493,6 @@ pub struct PathExpr {
827impl PathExpr { 493impl PathExpr {
828 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } 494 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
829} 495}
830/// Anonymous callable object literal a.k.a. closure, lambda or functor.
831///
832/// ```
833/// ❰ || 42 ❱;
834/// ❰ |a: u32| val + 1 ❱;
835/// ❰ async |#[attr] Pattern(_): Pattern| { bar } ❱;
836/// ❰ move || baz ❱;
837/// ❰ || -> u32 { closure_with_ret_type_annotation_requires_block_expr } ❱
838/// ```
839///
840/// [Reference](https://doc.rust-lang.org/reference/expressions/closure-expr.html)
841#[derive(Debug, Clone, PartialEq, Eq, Hash)] 496#[derive(Debug, Clone, PartialEq, Eq, Hash)]
842pub struct LambdaExpr { 497pub struct LambdaExpr {
843 pub(crate) syntax: SyntaxNode, 498 pub(crate) syntax: SyntaxNode,
@@ -851,25 +506,6 @@ impl LambdaExpr {
851 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } 506 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) }
852 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } 507 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) }
853} 508}
854/// If expression. Includes both regular `if` and `if let` forms.
855/// Beware that `else if` is a special case syntax sugar, because in general
856/// there has to be block expression after `else`.
857///
858/// ```
859/// ❰ if bool_cond { 42 } ❱
860/// ❰ if bool_cond { 42 } else { 24 } ❱
861/// ❰ if bool_cond { 42 } else if bool_cond2 { 42 } ❱
862///
863/// ❰
864/// if let Pattern(foo) = bar {
865/// foo
866/// } else {
867/// panic!();
868/// }
869/// ❱
870/// ```
871///
872/// [Reference](https://doc.rust-lang.org/reference/expressions/if-expr.html)
873#[derive(Debug, Clone, PartialEq, Eq, Hash)] 509#[derive(Debug, Clone, PartialEq, Eq, Hash)]
874pub struct IfExpr { 510pub struct IfExpr {
875 pub(crate) syntax: SyntaxNode, 511 pub(crate) syntax: SyntaxNode,
@@ -879,40 +515,16 @@ impl IfExpr {
879 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]) }
880 pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } 516 pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) }
881} 517}
882/// Unconditional loop expression.
883///
884/// ```
885/// ❰
886/// loop {
887/// // yeah, it's that simple...
888/// }
889/// ❱
890/// ```
891///
892/// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html)
893#[derive(Debug, Clone, PartialEq, Eq, Hash)] 518#[derive(Debug, Clone, PartialEq, Eq, Hash)]
894pub struct LoopExpr { 519pub struct Condition {
895 pub(crate) syntax: SyntaxNode, 520 pub(crate) syntax: SyntaxNode,
896} 521}
897impl ast::AttrsOwner for LoopExpr {} 522impl Condition {
898impl ast::LoopBodyOwner for LoopExpr {} 523 pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) }
899impl LoopExpr { 524 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
900 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) }
901} 527}
902/// Block expression with an optional prefix (label, try ketword,
903/// unsafe keyword, async keyword...).
904///
905/// ```
906/// ❰
907/// 'label: try {
908/// None?
909/// }
910/// ❱
911/// ```
912///
913/// - [try block](https://doc.rust-lang.org/unstable-book/language-features/try-blocks.html)
914/// - [unsafe block](https://doc.rust-lang.org/reference/expressions/block-expr.html#unsafe-blocks)
915/// - [async block](https://doc.rust-lang.org/reference/expressions/block-expr.html#async-blocks)
916#[derive(Debug, Clone, PartialEq, Eq, Hash)] 528#[derive(Debug, Clone, PartialEq, Eq, Hash)]
917pub struct EffectExpr { 529pub struct EffectExpr {
918 pub(crate) syntax: SyntaxNode, 530 pub(crate) syntax: SyntaxNode,
@@ -925,19 +537,24 @@ impl EffectExpr {
925 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]) }
926 pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) } 538 pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) }
927} 539}
928/// For loop expression. 540#[derive(Debug, Clone, PartialEq, Eq, Hash)]
929/// Note: record struct literals are not valid as iterable expression 541pub struct Label {
930/// due to ambiguity. 542 pub(crate) syntax: SyntaxNode,
931/// 543}
932/// ``` 544impl Label {
933/// ❰ 545 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
934/// for i in (0..4) { 546 support::token(&self.syntax, T![lifetime])
935/// dbg!(i); 547 }
936/// } 548}
937/// ❱ 549#[derive(Debug, Clone, PartialEq, Eq, Hash)]
938/// ``` 550pub struct LoopExpr {
939/// 551 pub(crate) syntax: SyntaxNode,
940/// [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}
941#[derive(Debug, Clone, PartialEq, Eq, Hash)] 558#[derive(Debug, Clone, PartialEq, Eq, Hash)]
942pub struct ForExpr { 559pub struct ForExpr {
943 pub(crate) syntax: SyntaxNode, 560 pub(crate) syntax: SyntaxNode,
@@ -950,22 +567,6 @@ impl ForExpr {
950 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]) }
951 pub fn iterable(&self) -> Option<Expr> { support::child(&self.syntax) } 568 pub fn iterable(&self) -> Option<Expr> { support::child(&self.syntax) }
952} 569}
953/// While loop expression. Includes both regular `while` and `while let` forms.
954///
955/// ```
956/// ❰
957/// while bool_cond {
958/// 42;
959/// }
960/// ❱
961/// ❰
962/// while let Pattern(foo) = bar {
963/// bar += 1;
964/// }
965/// ❱
966/// ```
967///
968/// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-loops)
969#[derive(Debug, Clone, PartialEq, Eq, Hash)] 570#[derive(Debug, Clone, PartialEq, Eq, Hash)]
970pub struct WhileExpr { 571pub struct WhileExpr {
971 pub(crate) syntax: SyntaxNode, 572 pub(crate) syntax: SyntaxNode,
@@ -976,22 +577,6 @@ impl WhileExpr {
976 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]) }
977 pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } 578 pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) }
978} 579}
979/// Continue expression.
980///
981/// ```
982/// while bool_cond {
983/// ❰ continue ❱;
984/// }
985///
986/// 'outer: loop {
987/// loop {
988/// ❰ continue 'outer ❱;
989/// }
990/// }
991///
992/// ```
993///
994/// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#continue-expressions)
995#[derive(Debug, Clone, PartialEq, Eq, Hash)] 580#[derive(Debug, Clone, PartialEq, Eq, Hash)]
996pub struct ContinueExpr { 581pub struct ContinueExpr {
997 pub(crate) syntax: SyntaxNode, 582 pub(crate) syntax: SyntaxNode,
@@ -1005,25 +590,6 @@ impl ContinueExpr {
1005 support::token(&self.syntax, T![lifetime]) 590 support::token(&self.syntax, T![lifetime])
1006 } 591 }
1007} 592}
1008/// Break expression.
1009///
1010/// ```
1011/// while bool_cond {
1012/// ❰ break ❱;
1013/// }
1014/// 'outer: loop {
1015/// for foo in bar {
1016/// ❰ break 'outer ❱;
1017/// }
1018/// }
1019/// 'outer: loop {
1020/// loop {
1021/// ❰ break 'outer 42 ❱;
1022/// }
1023/// }
1024/// ```
1025///
1026/// [Refernce](https://doc.rust-lang.org/reference/expressions/loop-expr.html#break-expressions)
1027#[derive(Debug, Clone, PartialEq, Eq, Hash)] 593#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1028pub struct BreakExpr { 594pub struct BreakExpr {
1029 pub(crate) syntax: SyntaxNode, 595 pub(crate) syntax: SyntaxNode,
@@ -1036,104 +602,33 @@ impl BreakExpr {
1036 } 602 }
1037 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 603 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1038} 604}
1039/// Label.
1040///
1041/// ```
1042/// ❰ 'outer: ❱ loop {}
1043///
1044/// let foo = ❰ 'bar: ❱ loop {}
1045///
1046/// ❰ 'baz: ❱ {
1047/// break 'baz;
1048/// }
1049/// ```
1050///
1051/// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html?highlight=label#loop-labels)
1052/// [Labels for blocks RFC](https://github.com/rust-lang/rfcs/blob/master/text/2046-label-break-value.md)
1053#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1054pub struct Label {
1055 pub(crate) syntax: SyntaxNode,
1056}
1057impl Label {
1058 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
1059 support::token(&self.syntax, T![lifetime])
1060 }
1061}
1062/// Block expression. Includes unsafe blocks and block labels.
1063///
1064/// ```
1065/// let foo = ❰
1066/// {
1067/// #![inner_attr]
1068/// ❰ { } ❱
1069///
1070/// ❰ 'label: { break 'label } ❱
1071/// }
1072/// ❱;
1073/// ```
1074///
1075/// [Reference](https://doc.rust-lang.org/reference/expressions/block-expr.html)
1076/// [Labels for blocks RFC](https://github.com/rust-lang/rfcs/blob/master/text/2046-label-break-value.md)
1077#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1078pub struct BlockExpr {
1079 pub(crate) syntax: SyntaxNode,
1080}
1081impl ast::AttrsOwner for BlockExpr {}
1082impl ast::ModuleItemOwner for BlockExpr {}
1083impl BlockExpr {
1084 pub fn label(&self) -> Option<Label> { support::child(&self.syntax) }
1085 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
1086 pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) }
1087 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1088 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
1089}
1090/// Return expression.
1091///
1092/// ```
1093/// || ❰ return 42 ❱;
1094///
1095/// fn bar() {
1096/// ❰ return ❱;
1097/// }
1098/// ```
1099///
1100/// [Reference](https://doc.rust-lang.org/reference/expressions/return-expr.html)
1101#[derive(Debug, Clone, PartialEq, Eq, Hash)] 605#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1102pub struct ReturnExpr { 606pub struct ReturnExpr {
1103 pub(crate) syntax: SyntaxNode, 607 pub(crate) syntax: SyntaxNode,
1104} 608}
1105impl ast::AttrsOwner for ReturnExpr {} 609impl ast::AttrsOwner for ReturnExpr {}
1106impl ReturnExpr { 610impl ReturnExpr {
611 pub fn return_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![return]) }
1107 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 612 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1108} 613}
1109/// Call expression (not to be confused with method call expression, it is
1110/// a separate ast node).
1111///
1112/// ```
1113/// ❰ foo() ❱;
1114/// ❰ &str::len("bar") ❱;
1115/// ❰ <&str as PartialEq<&str>>::eq(&"", &"") ❱;
1116/// ```
1117///
1118/// [Reference](https://doc.rust-lang.org/reference/expressions/call-expr.html)
1119#[derive(Debug, Clone, PartialEq, Eq, Hash)] 614#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1120pub struct CallExpr { 615pub struct CallExpr {
1121 pub(crate) syntax: SyntaxNode, 616 pub(crate) syntax: SyntaxNode,
1122} 617}
618impl ast::AttrsOwner for CallExpr {}
1123impl ast::ArgListOwner for CallExpr {} 619impl ast::ArgListOwner for CallExpr {}
1124impl CallExpr { 620impl CallExpr {
1125 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 621 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1126} 622}
1127/// Method call expression. 623#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1128/// 624pub struct ArgList {
1129/// ``` 625 pub(crate) syntax: SyntaxNode,
1130/// ❰ receiver_expr.method() ❱; 626}
1131/// ❰ receiver_expr.method::<T>(42, true) ❱; 627impl ArgList {
1132/// 628 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
1133/// ❰ ❰ ❰ foo.bar() ❱ .baz() ❱ .bruh() ❱; 629 pub fn args(&self) -> AstChildren<Expr> { support::children(&self.syntax) }
1134/// ``` 630 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
1135/// 631}
1136/// [Reference](https://doc.rust-lang.org/reference/expressions/method-call-expr.html)
1137#[derive(Debug, Clone, PartialEq, Eq, Hash)] 632#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1138pub struct MethodCallExpr { 633pub struct MethodCallExpr {
1139 pub(crate) syntax: SyntaxNode, 634 pub(crate) syntax: SyntaxNode,
@@ -1146,31 +641,26 @@ impl MethodCallExpr {
1146 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } 641 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
1147 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) }
1148} 643}
1149/// Index expression a.k.a. subscript operator call.
1150///
1151/// ```
1152/// ❰ foo[42] ❱;
1153/// ```
1154///
1155/// [Reference](https://doc.rust-lang.org/reference/expressions/array-expr.html)
1156#[derive(Debug, Clone, PartialEq, Eq, Hash)] 644#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1157pub struct IndexExpr { 645pub struct NameRef {
1158 pub(crate) syntax: SyntaxNode, 646 pub(crate) syntax: SyntaxNode,
1159} 647}
1160impl ast::AttrsOwner for IndexExpr {} 648impl NameRef {
1161impl IndexExpr { 649 pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) }
1162 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } 650}
1163 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![>]) }
1164} 663}
1165/// Field access expression.
1166///
1167/// ```
1168/// ❰ expr.bar ❱;
1169///
1170/// ❰ ❰ ❰ foo.bar ❱ .baz ❱ .bruh ❱;
1171/// ```
1172///
1173/// [Reference](https://doc.rust-lang.org/reference/expressions/field-expr.html)
1174#[derive(Debug, Clone, PartialEq, Eq, Hash)] 664#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1175pub struct FieldExpr { 665pub struct FieldExpr {
1176 pub(crate) syntax: SyntaxNode, 666 pub(crate) syntax: SyntaxNode,
@@ -1181,13 +671,15 @@ impl FieldExpr {
1181 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![.]) }
1182 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } 672 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
1183} 673}
1184/// Await operator call expression. 674#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1185/// 675pub struct IndexExpr {
1186/// ``` 676 pub(crate) syntax: SyntaxNode,
1187/// ❰ expr.await ❱; 677}
1188/// ``` 678impl ast::AttrsOwner for IndexExpr {}
1189/// 679impl IndexExpr {
1190/// [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}
1191#[derive(Debug, Clone, PartialEq, Eq, Hash)] 683#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1192pub struct AwaitExpr { 684pub struct AwaitExpr {
1193 pub(crate) syntax: SyntaxNode, 685 pub(crate) syntax: SyntaxNode,
@@ -1198,13 +690,6 @@ impl AwaitExpr {
1198 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![.]) }
1199 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]) }
1200} 692}
1201/// The question mark operator call.
1202///
1203/// ```
1204/// ❰ expr? ❱;
1205/// ```
1206///
1207/// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#the-question-mark-operator)
1208#[derive(Debug, Clone, PartialEq, Eq, Hash)] 693#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1209pub struct TryExpr { 694pub struct TryExpr {
1210 pub(crate) syntax: SyntaxNode, 695 pub(crate) syntax: SyntaxNode,
@@ -1214,13 +699,6 @@ impl TryExpr {
1214 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 699 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1215 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![?]) }
1216} 701}
1217/// Type cast expression.
1218///
1219/// ```
1220/// ❰ expr as T ❱;
1221/// ```
1222///
1223/// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#type-cast-expressions)
1224#[derive(Debug, Clone, PartialEq, Eq, Hash)] 702#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1225pub struct CastExpr { 703pub struct CastExpr {
1226 pub(crate) syntax: SyntaxNode, 704 pub(crate) syntax: SyntaxNode,
@@ -1231,16 +709,6 @@ impl CastExpr {
1231 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]) }
1232 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 710 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
1233} 711}
1234/// Borrow operator call.
1235///
1236/// ```
1237/// ❰ &foo ❱;
1238/// ❰ &mut bar ❱;
1239/// ❰ &raw const bar ❱;
1240/// ❰ &raw mut bar ❱;
1241/// ```
1242///
1243/// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#borrow-operators)
1244#[derive(Debug, Clone, PartialEq, Eq, Hash)] 712#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1245pub struct RefExpr { 713pub struct RefExpr {
1246 pub(crate) syntax: SyntaxNode, 714 pub(crate) syntax: SyntaxNode,
@@ -1253,15 +721,6 @@ impl RefExpr {
1253 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]) }
1254 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 722 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1255} 723}
1256/// Prefix operator call. This is either `!` or `*` or `-`.
1257///
1258/// ```
1259/// ❰ !foo ❱;
1260/// ❰ *bar ❱;
1261/// ❰ -42 ❱;
1262/// ```
1263///
1264/// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html)
1265#[derive(Debug, Clone, PartialEq, Eq, Hash)] 724#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1266pub struct PrefixExpr { 725pub struct PrefixExpr {
1267 pub(crate) syntax: SyntaxNode, 726 pub(crate) syntax: SyntaxNode,
@@ -1270,13 +729,6 @@ impl ast::AttrsOwner for PrefixExpr {}
1270impl PrefixExpr { 729impl PrefixExpr {
1271 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 730 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1272} 731}
1273/// Box operator call.
1274///
1275/// ```
1276/// ❰ box 42 ❱;
1277/// ```
1278///
1279/// [RFC](https://github.com/rust-lang/rfcs/blob/0806be4f282144cfcd55b1d20284b43f87cbe1c6/text/0809-box-and-in-for-stdlib.md)
1280#[derive(Debug, Clone, PartialEq, Eq, Hash)] 732#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1281pub struct BoxExpr { 733pub struct BoxExpr {
1282 pub(crate) syntax: SyntaxNode, 734 pub(crate) syntax: SyntaxNode,
@@ -1286,69 +738,23 @@ impl BoxExpr {
1286 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]) }
1287 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 739 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1288} 740}
1289/// Range operator call.
1290///
1291/// ```
1292/// ❰ 0..42 ❱;
1293/// ❰ ..42 ❱;
1294/// ❰ 0.. ❱;
1295/// ❰ .. ❱;
1296/// ❰ 0..=42 ❱;
1297/// ❰ ..=42 ❱;
1298/// ```
1299///
1300/// [Reference](https://doc.rust-lang.org/reference/expressions/range-expr.html)
1301#[derive(Debug, Clone, PartialEq, Eq, Hash)] 741#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1302pub struct RangeExpr { 742pub struct RangeExpr {
1303 pub(crate) syntax: SyntaxNode, 743 pub(crate) syntax: SyntaxNode,
1304} 744}
1305impl ast::AttrsOwner for RangeExpr {} 745impl ast::AttrsOwner for RangeExpr {}
1306impl RangeExpr {} 746impl RangeExpr {}
1307/// Binary operator call.
1308/// Includes all arithmetic, logic, bitwise and assignment operators.
1309///
1310/// ```
1311/// ❰ 2 + ❰ 2 * 2 ❱ ❱;
1312/// ❰ ❰ true && false ❱ || true ❱;
1313/// ```
1314///
1315/// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#arithmetic-and-logical-binary-operators)
1316#[derive(Debug, Clone, PartialEq, Eq, Hash)] 747#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1317pub struct BinExpr { 748pub struct BinExpr {
1318 pub(crate) syntax: SyntaxNode, 749 pub(crate) syntax: SyntaxNode,
1319} 750}
1320impl ast::AttrsOwner for BinExpr {} 751impl ast::AttrsOwner for BinExpr {}
1321impl BinExpr {} 752impl BinExpr {}
1322/// [Raw] string, [raw] byte string, char, byte, integer, float or bool literal.
1323///
1324/// ```
1325/// ❰ "str" ❱;
1326/// ❰ br##"raw byte str"## ❱;
1327/// ❰ 'c' ❱;
1328/// ❰ b'c' ❱;
1329/// ❰ 42 ❱;
1330/// ❰ 1e9 ❱;
1331/// ❰ true ❱;
1332/// ```
1333///
1334/// [Reference](https://doc.rust-lang.org/reference/expressions/literal-expr.html)
1335#[derive(Debug, Clone, PartialEq, Eq, Hash)] 753#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1336pub struct Literal { 754pub struct Literal {
1337 pub(crate) syntax: SyntaxNode, 755 pub(crate) syntax: SyntaxNode,
1338} 756}
1339impl Literal {} 757impl Literal {}
1340/// Match expression.
1341///
1342/// ```
1343/// ❰
1344/// match expr {
1345/// Pat1 => {}
1346/// Pat2(_) => 42,
1347/// }
1348/// ❱
1349/// ```
1350///
1351/// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html)
1352#[derive(Debug, Clone, PartialEq, Eq, Hash)] 758#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1353pub struct MatchExpr { 759pub struct MatchExpr {
1354 pub(crate) syntax: SyntaxNode, 760 pub(crate) syntax: SyntaxNode,
@@ -1359,40 +765,15 @@ impl MatchExpr {
1359 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 765 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1360 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) }
1361} 767}
1362/// Match arm list part of match expression. Includes its inner attributes.
1363///
1364/// ```
1365/// match expr
1366/// ❰
1367/// {
1368/// #![inner_attr]
1369/// Pat1 => {}
1370/// Pat2(_) => 42,
1371/// }
1372/// ❱
1373/// ```
1374///
1375/// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html)
1376#[derive(Debug, Clone, PartialEq, Eq, Hash)] 768#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1377pub struct MatchArmList { 769pub struct MatchArmList {
1378 pub(crate) syntax: SyntaxNode, 770 pub(crate) syntax: SyntaxNode,
1379} 771}
1380impl ast::AttrsOwner for MatchArmList {}
1381impl MatchArmList { 772impl MatchArmList {
1382 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!['{']) }
1383 pub fn arms(&self) -> AstChildren<MatchArm> { support::children(&self.syntax) } 774 pub fn arms(&self) -> AstChildren<MatchArm> { support::children(&self.syntax) }
1384 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!['}']) }
1385} 776}
1386/// Match arm.
1387/// Note: record struct literals are not valid as target match expression
1388/// due to ambiguity.
1389/// ```
1390/// match expr {
1391/// ❰ #[attr] Pattern(it) if bool_cond => it ❱,
1392/// }
1393/// ```
1394///
1395/// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html)
1396#[derive(Debug, Clone, PartialEq, Eq, Hash)] 777#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1397pub struct MatchArm { 778pub struct MatchArm {
1398 pub(crate) syntax: SyntaxNode, 779 pub(crate) syntax: SyntaxNode,
@@ -1404,15 +785,6 @@ impl MatchArm {
1404 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![=>]) }
1405 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 786 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1406} 787}
1407/// Match guard.
1408///
1409/// ```
1410/// match expr {
1411/// Pattern(it) ❰ if bool_cond ❱ => it,
1412/// }
1413/// ```
1414///
1415/// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html#match-guards)
1416#[derive(Debug, Clone, PartialEq, Eq, Hash)] 788#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1417pub struct MatchGuard { 789pub struct MatchGuard {
1418 pub(crate) syntax: SyntaxNode, 790 pub(crate) syntax: SyntaxNode,
@@ -1421,21 +793,6 @@ impl MatchGuard {
1421 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]) }
1422 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 794 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1423} 795}
1424/// Record literal expression. The same syntax is used for structs,
1425/// unions and record enum variants.
1426///
1427/// ```
1428/// ❰
1429/// foo::Bar {
1430/// #![inner_attr]
1431/// baz: 42,
1432/// bruh: true,
1433/// ..spread
1434/// }
1435/// ❱
1436/// ```
1437///
1438/// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html)
1439#[derive(Debug, Clone, PartialEq, Eq, Hash)] 796#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1440pub struct RecordLit { 797pub struct RecordLit {
1441 pub(crate) syntax: SyntaxNode, 798 pub(crate) syntax: SyntaxNode,
@@ -1444,16 +801,6 @@ impl RecordLit {
1444 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } 801 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
1445 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) }
1446} 803}
1447/// Record field list including enclosing curly braces.
1448///
1449/// foo::Bar ❰
1450/// {
1451/// baz: 42,
1452/// ..spread
1453/// }
1454/// ❱
1455///
1456/// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html)
1457#[derive(Debug, Clone, PartialEq, Eq, Hash)] 804#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1458pub struct RecordFieldList { 805pub struct RecordFieldList {
1459 pub(crate) syntax: SyntaxNode, 806 pub(crate) syntax: SyntaxNode,
@@ -1465,15 +812,6 @@ impl RecordFieldList {
1465 pub fn spread(&self) -> Option<Expr> { support::child(&self.syntax) } 812 pub fn spread(&self) -> Option<Expr> { support::child(&self.syntax) }
1466 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!['}']) }
1467} 814}
1468/// Record field.
1469///
1470/// ```
1471/// foo::Bar {
1472/// ❰ #[attr] baz: 42 ❱
1473/// }
1474/// ```
1475///
1476/// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html)
1477#[derive(Debug, Clone, PartialEq, Eq, Hash)] 815#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1478pub struct RecordField { 816pub struct RecordField {
1479 pub(crate) syntax: SyntaxNode, 817 pub(crate) syntax: SyntaxNode,
@@ -1484,13 +822,6 @@ impl RecordField {
1484 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![:]) }
1485 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 823 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1486} 824}
1487/// Disjunction of patterns.
1488///
1489/// ```
1490/// let ❰ Foo(it) | Bar(it) | Baz(it) ❱ = bruh;
1491/// ```
1492///
1493/// [Reference](https://doc.rust-lang.org/reference/patterns.html)
1494#[derive(Debug, Clone, PartialEq, Eq, Hash)] 825#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1495pub struct OrPat { 826pub struct OrPat {
1496 pub(crate) syntax: SyntaxNode, 827 pub(crate) syntax: SyntaxNode,
@@ -1498,14 +829,6 @@ pub struct OrPat {
1498impl OrPat { 829impl OrPat {
1499 pub fn pats(&self) -> AstChildren<Pat> { support::children(&self.syntax) } 830 pub fn pats(&self) -> AstChildren<Pat> { support::children(&self.syntax) }
1500} 831}
1501/// Parenthesized pattern.
1502/// Note: parens are only used for grouping, this is not a tuple pattern.
1503///
1504/// ```
1505/// if let ❰ &(0..=42) ❱ = foo {}
1506/// ```
1507///
1508/// https://doc.rust-lang.org/reference/patterns.html#grouped-patterns
1509#[derive(Debug, Clone, PartialEq, Eq, Hash)] 832#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1510pub struct ParenPat { 833pub struct ParenPat {
1511 pub(crate) syntax: SyntaxNode, 834 pub(crate) syntax: SyntaxNode,
@@ -1515,16 +838,6 @@ impl ParenPat {
1515 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 838 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
1516 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![')']) }
1517} 840}
1518/// Reference pattern.
1519/// Note: this has nothing to do with `ref` keyword, the latter is used in bind patterns.
1520///
1521/// ```
1522/// let ❰ &mut foo ❱ = bar;
1523///
1524/// let ❰ & ❰ &mut ❰ &_ ❱ ❱ ❱ = baz;
1525/// ```
1526///
1527/// [Reference](https://doc.rust-lang.org/reference/patterns.html#reference-patterns)
1528#[derive(Debug, Clone, PartialEq, Eq, Hash)] 841#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1529pub struct RefPat { 842pub struct RefPat {
1530 pub(crate) syntax: SyntaxNode, 843 pub(crate) syntax: SyntaxNode,
@@ -1534,31 +847,14 @@ impl RefPat {
1534 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]) }
1535 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 848 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
1536} 849}
1537/// Box pattern.
1538///
1539/// ```
1540/// let ❰ box foo ❱ = box 42;
1541/// ```
1542///
1543/// [Unstable book](https://doc.rust-lang.org/unstable-book/language-features/box-patterns.html)
1544#[derive(Debug, Clone, PartialEq, Eq, Hash)] 850#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1545pub struct BoxPat { 851pub struct BoxPat {
1546 pub(crate) syntax: SyntaxNode, 852 pub(crate) syntax: SyntaxNode,
1547} 853}
1548impl BoxPat { 854impl BoxPat {
1549 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]) }
1550 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 856 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
1551} 857}
1552/// Bind pattern.
1553///
1554/// ```
1555/// match foo {
1556/// Some(❰ ref mut bar ❱) => {}
1557/// ❰ baz @ None ❱ => {}
1558/// }
1559/// ```
1560///
1561/// [Reference](https://doc.rust-lang.org/reference/patterns.html#identifier-patterns)
1562#[derive(Debug, Clone, PartialEq, Eq, Hash)] 858#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1563pub struct BindPat { 859pub struct BindPat {
1564 pub(crate) syntax: SyntaxNode, 860 pub(crate) syntax: SyntaxNode,
@@ -1571,13 +867,6 @@ impl BindPat {
1571 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![@]) }
1572 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 868 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
1573} 869}
1574/// Placeholder pattern a.k.a. the wildcard pattern or the underscore.
1575///
1576/// ```
1577/// let ❰ _ ❱ = foo;
1578/// ```
1579///
1580/// [Reference](https://doc.rust-lang.org/reference/patterns.html#wildcard-pattern)
1581#[derive(Debug, Clone, PartialEq, Eq, Hash)] 870#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1582pub struct PlaceholderPat { 871pub struct PlaceholderPat {
1583 pub(crate) syntax: SyntaxNode, 872 pub(crate) syntax: SyntaxNode,
@@ -1585,16 +874,6 @@ pub struct PlaceholderPat {
1585impl PlaceholderPat { 874impl PlaceholderPat {
1586 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![_]) }
1587} 876}
1588/// Rest-of-the record/tuple pattern.
1589/// Note: this is not the unbonded range pattern (even more: it doesn't exist).
1590///
1591/// ```
1592/// let Foo { bar, ❰ .. ❱ } = baz;
1593/// let (❰ .. ❱, bruh) = (42, 24, 42);
1594/// let Bruuh(❰ .. ❱) = bruuuh;
1595/// ```
1596///
1597/// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns)
1598#[derive(Debug, Clone, PartialEq, Eq, Hash)] 877#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1599pub struct DotDotPat { 878pub struct DotDotPat {
1600 pub(crate) syntax: SyntaxNode, 879 pub(crate) syntax: SyntaxNode,
@@ -1602,15 +881,6 @@ pub struct DotDotPat {
1602impl DotDotPat { 881impl DotDotPat {
1603 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![..]) }
1604} 883}
1605/// Path pattern.
1606/// Doesn't include the underscore pattern (it is a special case, namely `PlaceholderPat`).
1607///
1608/// ```
1609/// let ❰ foo::bar::Baz ❱ { .. } = bruh;
1610/// if let ❰ CONST ❱ = 42 {}
1611/// ```
1612///
1613/// [Reference](https://doc.rust-lang.org/reference/patterns.html#path-patterns)
1614#[derive(Debug, Clone, PartialEq, Eq, Hash)] 884#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1615pub struct PathPat { 885pub struct PathPat {
1616 pub(crate) syntax: SyntaxNode, 886 pub(crate) syntax: SyntaxNode,
@@ -1618,13 +888,6 @@ pub struct PathPat {
1618impl PathPat { 888impl PathPat {
1619 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } 889 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
1620} 890}
1621/// Slice pattern.
1622///
1623/// ```
1624/// let ❰ [foo, bar, baz] ❱ = [1, 2, 3];
1625/// ```
1626///
1627/// [Reference](https://doc.rust-lang.org/reference/patterns.html#slice-patterns)
1628#[derive(Debug, Clone, PartialEq, Eq, Hash)] 891#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1629pub struct SlicePat { 892pub struct SlicePat {
1630 pub(crate) syntax: SyntaxNode, 893 pub(crate) syntax: SyntaxNode,
@@ -1634,33 +897,14 @@ impl SlicePat {
1634 pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } 897 pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) }
1635 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![']']) }
1636} 899}
1637/// Range pattern.
1638///
1639/// ```
1640/// match foo {
1641/// ❰ 0..42 ❱ => {}
1642/// ❰ 0..=42 ❱ => {}
1643/// }
1644/// ```
1645///
1646/// [Reference](https://doc.rust-lang.org/reference/patterns.html#range-patterns)
1647#[derive(Debug, Clone, PartialEq, Eq, Hash)] 900#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1648pub struct RangePat { 901pub struct RangePat {
1649 pub(crate) syntax: SyntaxNode, 902 pub(crate) syntax: SyntaxNode,
1650} 903}
1651impl RangePat {} 904impl RangePat {
1652/// Literal pattern. 905 pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) }
1653/// Includes only bool, number, char, and string literals. 906 pub fn dotdoteq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..=]) }
1654/// 907}
1655/// ```
1656/// match foo {
1657/// Number(❰ 42 ❱) => {}
1658/// String(❰ "42" ❱) => {}
1659/// Bool(❰ true ❱) => {}
1660/// }
1661/// ```
1662///
1663/// [Reference](https://doc.rust-lang.org/reference/patterns.html#literal-patterns)
1664#[derive(Debug, Clone, PartialEq, Eq, Hash)] 908#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1665pub struct LiteralPat { 909pub struct LiteralPat {
1666 pub(crate) syntax: SyntaxNode, 910 pub(crate) syntax: SyntaxNode,
@@ -1668,13 +912,6 @@ pub struct LiteralPat {
1668impl LiteralPat { 912impl LiteralPat {
1669 pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) } 913 pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) }
1670} 914}
1671/// Macro invocation in pattern position.
1672///
1673/// ```
1674/// let ❰ foo!(my custom syntax) ❱ = baz;
1675///
1676/// ```
1677/// [Reference](https://doc.rust-lang.org/reference/macros.html#macro-invocation)
1678#[derive(Debug, Clone, PartialEq, Eq, Hash)] 915#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1679pub struct MacroPat { 916pub struct MacroPat {
1680 pub(crate) syntax: SyntaxNode, 917 pub(crate) syntax: SyntaxNode,
@@ -1682,37 +919,34 @@ pub struct MacroPat {
1682impl MacroPat { 919impl MacroPat {
1683 pub fn macro_call(&self) -> Option<MacroCall> { support::child(&self.syntax) } 920 pub fn macro_call(&self) -> Option<MacroCall> { support::child(&self.syntax) }
1684} 921}
1685/// Record literal pattern. 922#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1686/// 923pub struct MacroCall {
1687/// ``` 924 pub(crate) syntax: SyntaxNode,
1688/// let ❰ foo::Bar { baz, .. } ❱ = bruh; 925}
1689/// ``` 926impl ast::AttrsOwner for MacroCall {}
1690/// 927impl ast::NameOwner for MacroCall {}
1691/// [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}
1692#[derive(Debug, Clone, PartialEq, Eq, Hash)] 934#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1693pub struct RecordPat { 935pub struct RecordPat {
1694 pub(crate) syntax: SyntaxNode, 936 pub(crate) syntax: SyntaxNode,
1695} 937}
1696impl RecordPat { 938impl RecordPat {
939 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
1697 pub fn record_field_pat_list(&self) -> Option<RecordFieldPatList> { 940 pub fn record_field_pat_list(&self) -> Option<RecordFieldPatList> {
1698 support::child(&self.syntax) 941 support::child(&self.syntax)
1699 } 942 }
1700 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
1701} 943}
1702/// Record literal's field patterns list including enclosing curly braces.
1703///
1704/// ```
1705/// let foo::Bar ❰ { baz, bind @ bruh, .. } ❱ = bruuh;
1706/// ``
1707///
1708/// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns)
1709#[derive(Debug, Clone, PartialEq, Eq, Hash)] 944#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1710pub struct RecordFieldPatList { 945pub struct RecordFieldPatList {
1711 pub(crate) syntax: SyntaxNode, 946 pub(crate) syntax: SyntaxNode,
1712} 947}
1713impl RecordFieldPatList { 948impl RecordFieldPatList {
1714 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } 949 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
1715 pub fn pats(&self) -> AstChildren<RecordInnerPat> { support::children(&self.syntax) }
1716 pub fn record_field_pats(&self) -> AstChildren<RecordFieldPat> { 950 pub fn record_field_pats(&self) -> AstChildren<RecordFieldPat> {
1717 support::children(&self.syntax) 951 support::children(&self.syntax)
1718 } 952 }
@@ -1720,15 +954,6 @@ impl RecordFieldPatList {
1720 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![..]) }
1721 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!['}']) }
1722} 956}
1723/// Record literal's field pattern.
1724/// Note: record literal can also match tuple structs.
1725///
1726/// ```
1727/// let Foo { ❰ bar: _ ❱ } = baz;
1728/// let TupleStruct { ❰ 0: _ ❱ } = bruh;
1729/// ```
1730///
1731/// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns)
1732#[derive(Debug, Clone, PartialEq, Eq, Hash)] 957#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1733pub struct RecordFieldPat { 958pub struct RecordFieldPat {
1734 pub(crate) syntax: SyntaxNode, 959 pub(crate) syntax: SyntaxNode,
@@ -1739,13 +964,6 @@ impl RecordFieldPat {
1739 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![:]) }
1740 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 965 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
1741} 966}
1742/// Tuple struct literal pattern.
1743///
1744/// ```
1745/// let ❰ foo::Bar(baz, bruh) ❱ = bruuh;
1746/// ```
1747///
1748/// [Reference](https://doc.rust-lang.org/reference/patterns.html#tuple-struct-patterns)
1749#[derive(Debug, Clone, PartialEq, Eq, Hash)] 967#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1750pub struct TupleStructPat { 968pub struct TupleStructPat {
1751 pub(crate) syntax: SyntaxNode, 969 pub(crate) syntax: SyntaxNode,
@@ -1756,14 +974,6 @@ impl TupleStructPat {
1756 pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } 974 pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) }
1757 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![')']) }
1758} 976}
1759/// Tuple pattern.
1760/// Note: this doesn't include tuple structs (see `TupleStructPat`)
1761///
1762/// ```
1763/// let ❰ (foo, bar, .., baz) ❱ = bruh;
1764/// ```
1765///
1766/// [Reference](https://doc.rust-lang.org/reference/patterns.html#tuple-patterns)
1767#[derive(Debug, Clone, PartialEq, Eq, Hash)] 977#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1768pub struct TuplePat { 978pub struct TuplePat {
1769 pub(crate) syntax: SyntaxNode, 979 pub(crate) syntax: SyntaxNode,
@@ -1773,210 +983,51 @@ impl TuplePat {
1773 pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } 983 pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) }
1774 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![')']) }
1775} 985}
1776/// Visibility.
1777///
1778/// ```
1779/// ❰ pub mod ❱ foo;
1780/// ❰ pub(crate) ❱ struct Bar;
1781/// ❰ pub(self) ❱ enum Baz {}
1782/// ❰ pub(super) ❱ fn bruh() {}
1783/// ❰ pub(in bruuh::bruuuh) ❱ type T = u64;
1784/// ```
1785///
1786/// [Reference](https://doc.rust-lang.org/reference/visibility-and-privacy.html)
1787#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1788pub struct Visibility {
1789 pub(crate) syntax: SyntaxNode,
1790}
1791impl Visibility {
1792 pub fn pub_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![pub]) }
1793 pub fn super_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![super]) }
1794 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) }
1795 pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) }
1796}
1797/// Single identifier.
1798/// Note(@matklad): `Name` is for things that install a new name into the scope,
1799/// `NameRef` is a usage of a name. Most of the time, this definition/reference
1800/// distinction can be determined purely syntactically, ie in
1801/// ```
1802/// fn foo() { foo() }
1803/// ```
1804/// the first foo is `Name`, the second one is `NameRef`.
1805/// The notable exception are patterns, where in
1806/// ``
1807/// let x = 92
1808/// ```
1809/// `x` can be semantically either a name or a name ref, depeding on
1810/// wether there's an `x` constant in scope.
1811/// We use `Name` for patterns, and disambiguate semantically (see `NameClass` in ide_db).
1812///
1813/// ```
1814/// let ❰ foo ❱ = bar;
1815/// struct ❰ Baz ❱;
1816/// fn ❰ bruh ❱() {}
1817/// ```
1818///
1819/// [Reference](https://doc.rust-lang.org/reference/identifiers.html)
1820#[derive(Debug, Clone, PartialEq, Eq, Hash)] 986#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1821pub struct Name { 987pub struct TokenTree {
1822 pub(crate) syntax: SyntaxNode, 988 pub(crate) syntax: SyntaxNode,
1823} 989}
1824impl Name { 990impl TokenTree {
1825 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!['(']) }
1826} 992 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
1827/// Reference to a name. 993 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
1828/// See the explanation on the difference between `Name` and `NameRef` 994 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
1829/// in `Name` ast node docs. 995 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
1830/// 996 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
1831/// ```
1832/// let foo = ❰ bar ❱(❰ Baz(❰ bruh ❱) ❱;
1833/// ```
1834///
1835/// [Reference](https://doc.rust-lang.org/reference/identifiers.html)
1836#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1837pub struct NameRef {
1838 pub(crate) syntax: SyntaxNode,
1839} 997}
1840impl NameRef {}
1841/// Macro call.
1842/// Includes all of its attributes and doc comments.
1843///
1844/// ```
1845/// ❰
1846/// /// Docs
1847/// #[attr]
1848/// macro_rules! foo { // macro rules is also a macro call
1849/// ($bar: tt) => {}
1850/// }
1851/// ❱
1852///
1853/// // semicolon is a part of `MacroCall` when it is used in item positions
1854/// ❰ foo!(); ❱
1855///
1856/// fn main() {
1857/// ❰ foo!() ❱; // macro call in expression positions doesn't include the semi
1858/// }
1859/// ```
1860///
1861/// [Reference](https://doc.rust-lang.org/reference/macros.html)
1862#[derive(Debug, Clone, PartialEq, Eq, Hash)] 998#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1863pub struct MacroCall { 999pub struct MacroDef {
1864 pub(crate) syntax: SyntaxNode, 1000 pub(crate) syntax: SyntaxNode,
1865} 1001}
1866impl ast::NameOwner for MacroCall {} 1002impl ast::NameOwner for MacroDef {}
1867impl ast::AttrsOwner for MacroCall {} 1003impl MacroDef {
1868impl ast::DocCommentsOwner for MacroCall {}
1869impl MacroCall {
1870 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
1871 pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) }
1872 pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) } 1004 pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) }
1873 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
1874}
1875/// Attribute.
1876///
1877/// ```
1878/// ❰ #![inner_attr] ❱
1879///
1880/// ❰ #[attr] ❱
1881/// ❰ #[foo = "bar"] ❱
1882/// ❰ #[baz(bruh::bruuh = "42")] ❱
1883/// struct Foo;
1884/// ```
1885///
1886/// [Reference](https://doc.rust-lang.org/reference/attributes.html)
1887#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1888pub struct Attr {
1889 pub(crate) syntax: SyntaxNode,
1890}
1891impl Attr {
1892 pub fn pound_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![#]) }
1893 pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) }
1894 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
1895 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
1896 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
1897 pub fn input(&self) -> Option<AttrInput> { support::child(&self.syntax) }
1898 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
1899} 1005}
1900/// Stores a list of lexer tokens and other `TokenTree`s.
1901/// It appears in attributes, macro_rules and macro call (foo!)
1902///
1903/// ```
1904/// macro_call! ❰ { my syntax here } ❱;
1905/// ```
1906///
1907/// [Reference](https://doc.rust-lang.org/reference/macros.html)
1908#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1006#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1909pub struct TokenTree { 1007pub struct MacroItems {
1910 pub(crate) syntax: SyntaxNode, 1008 pub(crate) syntax: SyntaxNode,
1911} 1009}
1912impl TokenTree {} 1010impl ast::ModuleItemOwner for MacroItems {}
1913/// Generic lifetime, type and constants parameters list **declaration**. 1011impl MacroItems {}
1914///
1915/// ```
1916/// fn foo❰ <'a, 'b, T, U, const BAR: u64> ❱() {}
1917///
1918/// struct Baz❰ <T> ❱(T);
1919///
1920/// impl❰ <T> ❱ Bruh<T> {}
1921///
1922/// type Bruuh = for❰ <'a> ❱ fn(&'a str) -> &'a str;
1923/// ```
1924///
1925/// [Reference](https://doc.rust-lang.org/reference/items/generics.html)
1926#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1012#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1927pub struct TypeParamList { 1013pub struct MacroStmts {
1928 pub(crate) syntax: SyntaxNode, 1014 pub(crate) syntax: SyntaxNode,
1929} 1015}
1930impl TypeParamList { 1016impl MacroStmts {
1931 pub fn l_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![<]) } 1017 pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) }
1932 pub fn generic_params(&self) -> AstChildren<GenericParam> { support::children(&self.syntax) } 1018 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1933 pub fn type_params(&self) -> AstChildren<TypeParam> { support::children(&self.syntax) }
1934 pub fn lifetime_params(&self) -> AstChildren<LifetimeParam> { support::children(&self.syntax) }
1935 pub fn const_params(&self) -> AstChildren<ConstParam> { support::children(&self.syntax) }
1936 pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) }
1937} 1019}
1938/// Single type parameter **declaration**.
1939///
1940/// ```
1941/// fn foo<❰ K ❱, ❰ I ❱, ❰ E: Debug ❱, ❰ V = DefaultType ❱>() {}
1942/// ```
1943///
1944/// [Reference](https://doc.rust-lang.org/reference/items/generics.html)
1945#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1020#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1946pub struct TypeParam { 1021pub struct TypeParam {
1947 pub(crate) syntax: SyntaxNode, 1022 pub(crate) syntax: SyntaxNode,
1948} 1023}
1949impl ast::NameOwner for TypeParam {}
1950impl ast::AttrsOwner for TypeParam {} 1024impl ast::AttrsOwner for TypeParam {}
1025impl ast::NameOwner for TypeParam {}
1951impl ast::TypeBoundsOwner for TypeParam {} 1026impl ast::TypeBoundsOwner for TypeParam {}
1952impl TypeParam { 1027impl TypeParam {
1953 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![=]) }
1954 pub fn default_type(&self) -> Option<TypeRef> { support::child(&self.syntax) } 1029 pub fn default_type(&self) -> Option<TypeRef> { support::child(&self.syntax) }
1955} 1030}
1956/// Const generic parameter **declaration**.
1957/// ```
1958/// fn foo<T, U, ❰ const BAR: usize ❱, ❰ const BAZ: bool ❱>() {}
1959/// ```
1960///
1961/// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/2000-const-generics.md#declaring-a-const-parameter)
1962#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1963pub struct ConstParam {
1964 pub(crate) syntax: SyntaxNode,
1965}
1966impl ast::NameOwner for ConstParam {}
1967impl ast::AttrsOwner for ConstParam {}
1968impl ast::TypeAscriptionOwner for ConstParam {}
1969impl ConstParam {
1970 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
1971 pub fn default_val(&self) -> Option<Expr> { support::child(&self.syntax) }
1972}
1973/// Lifetime parameter **declaration**.
1974///
1975/// ```
1976/// fn foo<❰ 'a ❱, ❰ 'b ❱, V, G, D>(bar: &'a str, baz: &'b mut str) {}
1977/// ```
1978///
1979/// [Reference](https://doc.rust-lang.org/reference/items/generics.html)
1980#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1031#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1981pub struct LifetimeParam { 1032pub struct LifetimeParam {
1982 pub(crate) syntax: SyntaxNode, 1033 pub(crate) syntax: SyntaxNode,
@@ -1987,20 +1038,19 @@ impl LifetimeParam {
1987 support::token(&self.syntax, T![lifetime]) 1038 support::token(&self.syntax, T![lifetime])
1988 } 1039 }
1989} 1040}
1990/// Type bound declaration clause. 1041#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1991/// 1042pub struct ConstParam {
1992/// ``` 1043 pub(crate) syntax: SyntaxNode,
1993/// fn foo<T: ❰ ?Sized ❱ + ❰ Debug ❱>() {} 1044}
1994/// 1045impl ast::AttrsOwner for ConstParam {}
1995/// trait Bar<T> 1046impl ast::NameOwner for ConstParam {}
1996/// where 1047impl ast::TypeAscriptionOwner for ConstParam {}
1997/// T: ❰ Send ❱ + ❰ Sync ❱ 1048impl ConstParam {
1998/// { 1049 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
1999/// type Baz: ❰ !Sync ❱ + ❰ Debug ❱ + ❰ ?const Add ❱; 1050 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
2000/// } 1051 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
2001/// ``` 1052 pub fn default_val(&self) -> Option<Expr> { support::child(&self.syntax) }
2002/// 1053}
2003/// [Reference](https://doc.rust-lang.org/reference/trait-bounds.html)
2004#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1054#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2005pub struct TypeBound { 1055pub struct TypeBound {
2006 pub(crate) syntax: SyntaxNode, 1056 pub(crate) syntax: SyntaxNode,
@@ -2012,40 +1062,6 @@ impl TypeBound {
2012 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]) }
2013 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 1063 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
2014} 1064}
2015/// Type bounds list.
2016///
2017/// ```
2018///
2019/// fn foo<T: ❰ ?Sized + Debug ❱>() {}
2020///
2021/// trait Bar<T>
2022/// where
2023/// T: ❰ Send + Sync ❱
2024/// {
2025/// type Baz: ❰ !Sync + Debug ❱;
2026/// }
2027/// ```
2028///
2029/// [Reference](https://doc.rust-lang.org/reference/trait-bounds.html)
2030#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2031pub struct TypeBoundList {
2032 pub(crate) syntax: SyntaxNode,
2033}
2034impl TypeBoundList {
2035 pub fn bounds(&self) -> AstChildren<TypeBound> { support::children(&self.syntax) }
2036}
2037/// Single where predicate.
2038///
2039/// ```
2040/// trait Foo<'a, 'b, T>
2041/// where
2042/// ❰ 'a: 'b ❱,
2043/// ❰ T: IntoIterator ❱,
2044/// ❰ for<'c> <T as IntoIterator>::Item: Bar<'c> ❱
2045/// {}
2046/// ```
2047///
2048/// [Reference](https://doc.rust-lang.org/reference/items/generics.html#where-clauses)
2049#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1065#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2050pub struct WherePred { 1066pub struct WherePred {
2051 pub(crate) syntax: SyntaxNode, 1067 pub(crate) syntax: SyntaxNode,
@@ -2059,58 +1075,6 @@ impl WherePred {
2059 } 1075 }
2060 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 1076 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
2061} 1077}
2062/// Where clause.
2063///
2064/// ```
2065/// trait Foo<'a, T> ❰ where 'a: 'static, T: Debug ❱ {}
2066///
2067/// ```
2068///
2069/// [Reference](https://doc.rust-lang.org/reference/items/generics.html#where-clauses)
2070#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2071pub struct WhereClause {
2072 pub(crate) syntax: SyntaxNode,
2073}
2074impl WhereClause {
2075 pub fn where_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![where]) }
2076 pub fn predicates(&self) -> AstChildren<WherePred> { support::children(&self.syntax) }
2077}
2078/// Abi declaration.
2079/// Note: the abi string is optional.
2080///
2081/// ```
2082/// ❰ extern "C" ❱ {
2083/// fn foo() {}
2084/// }
2085///
2086/// type Bar = ❰ extern ❱ fn() -> u32;
2087///
2088/// type Baz = ❰ extern r#"stdcall"# ❱ fn() -> bool;
2089/// ```
2090///
2091/// - [Extern blocks reference](https://doc.rust-lang.org/reference/items/external-blocks.html)
2092/// - [FFI function pointers reference](https://doc.rust-lang.org/reference/items/functions.html#functions)
2093#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2094pub struct Abi {
2095 pub(crate) syntax: SyntaxNode,
2096}
2097impl Abi {}
2098/// Expression statement.
2099///
2100/// ```
2101/// ❰ 42; ❱
2102/// ❰ foo(); ❱
2103/// ❰ (); ❱
2104/// ❰ {}; ❱
2105///
2106/// // constructions with trailing curly brace can omit the semicolon
2107/// // but only when there are satements immediately after them (this is important!)
2108/// ❰ if bool_cond { } ❱
2109/// ❰ loop {} ❱
2110/// ❰ somestatment; ❱
2111/// ```
2112///
2113/// [Reference](https://doc.rust-lang.org/reference/statements.html)
2114#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1078#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2115pub struct ExprStmt { 1079pub struct ExprStmt {
2116 pub(crate) syntax: SyntaxNode, 1080 pub(crate) syntax: SyntaxNode,
@@ -2120,16 +1084,6 @@ impl ExprStmt {
2120 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 1084 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
2121 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![;]) }
2122} 1086}
2123/// Let statement.
2124///
2125/// ```
2126/// ❰ #[attr] let foo; ❱
2127/// ❰ let bar: u64; ❱
2128/// ❰ let baz = 42; ❱
2129/// ❰ let bruh: bool = true; ❱
2130/// ```
2131///
2132/// [Reference](https://doc.rust-lang.org/reference/statements.html#let-statements)
2133#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1087#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2134pub struct LetStmt { 1088pub struct LetStmt {
2135 pub(crate) syntax: SyntaxNode, 1089 pub(crate) syntax: SyntaxNode,
@@ -2139,112 +1093,37 @@ impl ast::TypeAscriptionOwner for LetStmt {}
2139impl LetStmt { 1093impl LetStmt {
2140 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]) }
2141 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![:]) }
2142 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![=]) }
2143 pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) } 1098 pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) }
2144 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![;]) }
2145} 1100}
2146/// Condition of `if` or `while` expression.
2147///
2148/// ```
2149/// if ❰ true ❱ {}
2150/// if ❰ let Pat(foo) = bar ❱ {}
2151///
2152/// while ❰ true ❱ {}
2153/// while ❰ let Pat(baz) = bruh ❱ {}
2154/// ```
2155///
2156/// [If expression reference](https://doc.rust-lang.org/reference/expressions/if-expr.html)
2157/// [While expression reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-loops)
2158#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2159pub struct Condition {
2160 pub(crate) syntax: SyntaxNode,
2161}
2162impl Condition {
2163 pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) }
2164 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
2165 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
2166 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
2167}
2168/// Parameter list **declaration**.
2169///
2170/// ```
2171/// fn foo❰ (a: u32, b: bool) ❱ -> u32 {}
2172/// let bar = ❰ |a, b| ❱ {};
2173///
2174/// impl Baz {
2175/// fn bruh❰ (&self, a: u32) ❱ {}
2176/// }
2177/// ```
2178///
2179/// [Reference](https://doc.rust-lang.org/reference/items/functions.html)ocs to codegen script
2180#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2181pub struct ParamList {
2182 pub(crate) syntax: SyntaxNode,
2183}
2184impl ParamList {
2185 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
2186 pub fn self_param(&self) -> Option<SelfParam> { support::child(&self.syntax) }
2187 pub fn params(&self) -> AstChildren<Param> { support::children(&self.syntax) }
2188 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
2189}
2190/// Self parameter **declaration**.
2191///
2192/// ```
2193/// impl Bruh {
2194/// fn foo(❰ self ❱) {}
2195/// fn bar(❰ &self ❱) {}
2196/// fn baz(❰ &mut self ❱) {}
2197/// fn blah<'a>(❰ &'a self ❱) {}
2198/// fn blin(❰ self: Box<Self> ❱) {}
2199/// }
2200/// ```
2201///
2202/// [Reference](https://doc.rust-lang.org/reference/items/functions.html)
2203#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1101#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2204pub struct SelfParam { 1102pub struct SelfParam {
2205 pub(crate) syntax: SyntaxNode, 1103 pub(crate) syntax: SyntaxNode,
2206} 1104}
2207impl ast::TypeAscriptionOwner for SelfParam {}
2208impl ast::AttrsOwner for SelfParam {} 1105impl ast::AttrsOwner for SelfParam {}
1106impl ast::TypeAscriptionOwner for SelfParam {}
2209impl SelfParam { 1107impl SelfParam {
2210 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![&]) }
2211 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
2212 pub fn lifetime_token(&self) -> Option<SyntaxToken> { 1109 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
2213 support::token(&self.syntax, T![lifetime]) 1110 support::token(&self.syntax, T![lifetime])
2214 } 1111 }
1112 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
2215 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![:]) }
2216} 1115}
2217/// Parameter **declaration**.
2218///
2219/// ```
2220/// fn foo(❰ #[attr] Pat(bar): Pat(u32) ❱, ❰ #[attr] _: bool ❱) {}
2221///
2222/// extern "C" {
2223/// fn bar(❰ baz: u32 ❱, ❰ ... ❱) -> u32;
2224/// }
2225/// ```
2226///
2227/// [Reference](https://doc.rust-lang.org/reference/items/functions.html)
2228#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1116#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2229pub struct Param { 1117pub struct Param {
2230 pub(crate) syntax: SyntaxNode, 1118 pub(crate) syntax: SyntaxNode,
2231} 1119}
2232impl ast::TypeAscriptionOwner for Param {}
2233impl ast::AttrsOwner for Param {} 1120impl ast::AttrsOwner for Param {}
1121impl ast::TypeAscriptionOwner for Param {}
2234impl Param { 1122impl Param {
2235 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![:]) }
2236 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![...]) }
2237} 1126}
2238/// Use declaration.
2239///
2240/// ```
2241/// ❰ #[attr] pub use foo; ❱
2242/// ❰ use bar as baz; ❱
2243/// ❰ use bruh::{self, bruuh}; ❱
2244/// ❰ use { blin::blen, blah::* };
2245/// ```
2246///
2247/// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html)
2248#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1127#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2249pub struct UseItem { 1128pub struct UseItem {
2250 pub(crate) syntax: SyntaxNode, 1129 pub(crate) syntax: SyntaxNode,
@@ -2254,53 +1133,19 @@ impl ast::VisibilityOwner for UseItem {}
2254impl UseItem { 1133impl UseItem {
2255 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]) }
2256 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![;]) }
2257} 1137}
2258/// Use tree.
2259///
2260/// ```
2261/// pub use ❰ foo::❰ * ❱ ❱;
2262/// use ❰ bar as baz ❱;
2263/// use ❰ bruh::bruuh::{ ❰ self ❱, ❰ blin ❱ } ❱;
2264/// use ❰ { ❰ blin::blen ❱ } ❱
2265/// ```
2266///
2267/// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html)
2268#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1138#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2269pub struct UseTree { 1139pub struct UseTree {
2270 pub(crate) syntax: SyntaxNode, 1140 pub(crate) syntax: SyntaxNode,
2271} 1141}
2272impl UseTree { 1142impl UseTree {
2273 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![::]) }
2274 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![*]) }
2275 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) }
2276 pub fn alias(&self) -> Option<Alias> { support::child(&self.syntax) } 1147 pub fn alias(&self) -> Option<Alias> { support::child(&self.syntax) }
2277} 1148}
2278/// Item alias.
2279/// Note: this is not the type alias.
2280///
2281/// ```
2282/// use foo ❰ as bar ❱;
2283/// use baz::{bruh ❰ as _ ❱};
2284/// extern crate bruuh ❰ as blin ❱;
2285/// ```
2286///
2287/// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html)
2288#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2289pub struct Alias {
2290 pub(crate) syntax: SyntaxNode,
2291}
2292impl ast::NameOwner for Alias {}
2293impl Alias {
2294 pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) }
2295}
2296/// Sublist of use trees.
2297///
2298/// ```
2299/// use bruh::bruuh::❰ { ❰ self ❱, ❰ blin ❱ } ❱;
2300/// use ❰ { blin::blen::❰ {} ❱ } ❱
2301/// ```
2302///
2303/// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html)
2304#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1149#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2305pub struct UseTreeList { 1150pub struct UseTreeList {
2306 pub(crate) syntax: SyntaxNode, 1151 pub(crate) syntax: SyntaxNode,
@@ -2310,14 +1155,14 @@ impl UseTreeList {
2310 pub fn use_trees(&self) -> AstChildren<UseTree> { support::children(&self.syntax) } 1155 pub fn use_trees(&self) -> AstChildren<UseTree> { support::children(&self.syntax) }
2311 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!['}']) }
2312} 1157}
2313/// Extern crate item. 1158#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2314/// 1159pub struct Alias {
2315/// ``` 1160 pub(crate) syntax: SyntaxNode,
2316/// ❰ #[attr] pub extern crate foo; ❱ 1161}
2317/// ❰ extern crate self as bar; ❱ 1162impl ast::NameOwner for Alias {}
2318/// ``` 1163impl Alias {
2319/// 1164 pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) }
2320/// [Reference](https://doc.rust-lang.org/reference/items/extern-crates.html) 1165}
2321#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1166#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2322pub struct ExternCrateItem { 1167pub struct ExternCrateItem {
2323 pub(crate) syntax: SyntaxNode, 1168 pub(crate) syntax: SyntaxNode,
@@ -2328,59 +1173,10 @@ impl ExternCrateItem {
2328 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]) }
2329 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]) }
2330 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]) }
2331 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![;]) }
2332} 1179}
2333/// Call site arguments list.
2334///
2335/// ```
2336/// foo::<T, U>❰ (42, true) ❱;
2337/// ```
2338///
2339/// [Reference](https://doc.rust-lang.org/reference/expressions/call-expr.html)
2340#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2341pub struct ArgList {
2342 pub(crate) syntax: SyntaxNode,
2343}
2344impl ArgList {
2345 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
2346 pub fn args(&self) -> AstChildren<Expr> { support::children(&self.syntax) }
2347 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
2348}
2349/// Path to a symbol. Includes single identifier names and elaborate paths with
2350/// generic parameters.
2351///
2352/// ```
2353/// (0..10).❰ ❰ collect ❱ ::<Vec<_>> ❱();
2354/// ❰ ❰ ❰ Vec ❱ ::<u8> ❱ ::with_capacity ❱(1024);
2355/// ❰ ❰ <❰ Foo ❱ as ❰ ❰ bar ❱ ::Bar ❱> ❱ ::baz ❱();
2356/// ❰ ❰ <❰ bruh ❱> ❱ ::bruuh ❱();
2357/// ```
2358///
2359/// [Reference](https://doc.rust-lang.org/reference/paths.html)
2360#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2361pub struct Path {
2362 pub(crate) syntax: SyntaxNode,
2363}
2364impl Path {
2365 pub fn segment(&self) -> Option<PathSegment> { support::child(&self.syntax) }
2366 pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) }
2367 pub fn qualifier(&self) -> Option<Path> { support::child(&self.syntax) }
2368}
2369/// Segment of the path to a symbol.
2370/// Only path segment of an absolute path holds the `::` token,
2371/// all other `::` tokens that connect path segments reside under `Path` itself.`
2372///
2373/// ```
2374/// (0..10).❰ collect ❱ :: ❰ <Vec<_>> ❱();
2375/// ❰ Vec ❱ :: ❰ <u8> ❱ :: ❰ with_capacity ❱(1024);
2376/// ❰ <❰ Foo ❱ as ❰ bar ❱ :: ❰ Bar ❱> ❱ :: ❰ baz ❱();
2377/// ❰ <❰ bruh ❱> ❱ :: ❰ bruuh ❱();
2378///
2379/// // Note that only in this case `::` token is inlcuded:
2380/// ❰ ::foo ❱;
2381/// ```
2382///
2383/// [Reference](https://doc.rust-lang.org/reference/paths.html)
2384#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1180#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2385pub struct PathSegment { 1181pub struct PathSegment {
2386 pub(crate) syntax: SyntaxNode, 1182 pub(crate) syntax: SyntaxNode,
@@ -2398,50 +1194,22 @@ impl PathSegment {
2398 pub fn path_type(&self) -> Option<PathType> { support::child(&self.syntax) } 1194 pub fn path_type(&self) -> Option<PathType> { support::child(&self.syntax) }
2399 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![>]) }
2400} 1196}
2401/// List of type arguments that are passed at generic instantiation site.
2402///
2403/// ```
2404/// type _ = Foo ❰ ::<'a, u64, Item = Bar, 42, {true}> ❱::Bar;
2405///
2406/// Vec❰ ::<bool> ❱::();
2407/// ```
2408///
2409/// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions)
2410#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1197#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2411pub struct TypeArgList { 1198pub struct TypeArg {
2412 pub(crate) syntax: SyntaxNode, 1199 pub(crate) syntax: SyntaxNode,
2413} 1200}
2414impl TypeArgList { 1201impl TypeArg {
2415 pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) } 1202 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
2416 pub fn l_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![<]) }
2417 pub fn generic_args(&self) -> AstChildren<GenericArg> { support::children(&self.syntax) }
2418 pub fn type_args(&self) -> AstChildren<TypeArg> { support::children(&self.syntax) }
2419 pub fn lifetime_args(&self) -> AstChildren<LifetimeArg> { support::children(&self.syntax) }
2420 pub fn assoc_type_args(&self) -> AstChildren<AssocTypeArg> { support::children(&self.syntax) }
2421 pub fn const_args(&self) -> AstChildren<ConstArg> { support::children(&self.syntax) }
2422 pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) }
2423} 1203}
2424/// Type argument that is passed at generic instantiation site.
2425///
2426/// ```
2427/// type _ = Foo::<'a, ❰ u64 ❱, ❰ bool ❱, Item = Bar, 42>::Baz;
2428/// ```
2429///
2430/// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions)
2431#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1204#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2432pub struct TypeArg { 1205pub struct LifetimeArg {
2433 pub(crate) syntax: SyntaxNode, 1206 pub(crate) syntax: SyntaxNode,
2434} 1207}
2435impl TypeArg { 1208impl LifetimeArg {
2436 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 }
2437} 1212}
2438/// Associated type argument that is passed at generic instantiation site.
2439/// ```
2440/// type Foo = Bar::<'a, u64, bool, ❰ Item = Baz ❱, 42>::Bruh;
2441///
2442/// trait Bruh<T>: Iterator<❰ Item: Debug ❱> {}
2443/// ```
2444///
2445#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1213#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2446pub struct AssocTypeArg { 1214pub struct AssocTypeArg {
2447 pub(crate) syntax: SyntaxNode, 1215 pub(crate) syntax: SyntaxNode,
@@ -2452,33 +1220,6 @@ impl AssocTypeArg {
2452 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![=]) }
2453 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 1221 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
2454} 1222}
2455/// Lifetime argument that is passed at generic instantiation site.
2456///
2457/// ```
2458/// fn foo<'a>(s: &'a str) {
2459/// bar::<❰ 'a ❱>(s);
2460/// }
2461/// ```
2462///
2463/// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions)
2464#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2465pub struct LifetimeArg {
2466 pub(crate) syntax: SyntaxNode,
2467}
2468impl LifetimeArg {
2469 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
2470 support::token(&self.syntax, T![lifetime])
2471 }
2472}
2473/// Constant value argument that is passed at generic instantiation site.
2474///
2475/// ```
2476/// foo::<u32, ❰ { true } ❱>();
2477///
2478/// bar::<❰ { 2 + 2} ❱>();
2479/// ```
2480///
2481/// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/2000-const-generics.md#declaring-a-const-parameter)
2482#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1223#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2483pub struct ConstArg { 1224pub struct ConstArg {
2484 pub(crate) syntax: SyntaxNode, 1225 pub(crate) syntax: SyntaxNode,
@@ -2487,83 +1228,24 @@ impl ConstArg {
2487 pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) } 1228 pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) }
2488 pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) } 1229 pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) }
2489} 1230}
2490/// FIXME: (@edwin0cheng) Remove it to use ItemList instead
2491/// https://github.com/rust-analyzer/rust-analyzer/pull/4083#discussion_r422666243
2492///
2493/// [Reference](https://doc.rust-lang.org/reference/macros.html)
2494#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2495pub struct MacroItems {
2496 pub(crate) syntax: SyntaxNode,
2497}
2498impl ast::ModuleItemOwner for MacroItems {}
2499impl MacroItems {}
2500/// FIXME: (@edwin0cheng) add some documentation here. As per the writing
2501/// of this comment this ast node is not used.
2502///
2503/// ```
2504/// // FIXME: example here
2505/// ```
2506///
2507/// [Reference](https://doc.rust-lang.org/reference/macros.html)
2508#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1231#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2509pub struct MacroStmts { 1232pub struct ExternBlock {
2510 pub(crate) syntax: SyntaxNode, 1233 pub(crate) syntax: SyntaxNode,
2511} 1234}
2512impl MacroStmts { 1235impl ast::AttrsOwner for ExternBlock {}
2513 pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) } 1236impl ExternBlock {
2514 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) }
2515} 1239}
2516/// List of items in an extern block.
2517///
2518/// ```
2519/// extern "C" ❰
2520/// {
2521/// fn foo();
2522/// static var: u32;
2523/// }
2524/// ❱
2525/// ```
2526///
2527/// [Reference](https://doc.rust-lang.org/reference/items/external-blocks.html)
2528#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1240#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2529pub struct ExternItemList { 1241pub struct ExternItemList {
2530 pub(crate) syntax: SyntaxNode, 1242 pub(crate) syntax: SyntaxNode,
2531} 1243}
2532impl ast::ModuleItemOwner for ExternItemList {}
2533impl ExternItemList { 1244impl ExternItemList {
2534 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!['{']) }
2535 pub fn extern_items(&self) -> AstChildren<ExternItem> { support::children(&self.syntax) } 1246 pub fn extern_items(&self) -> AstChildren<ExternItem> { support::children(&self.syntax) }
2536 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!['}']) }
2537} 1248}
2538/// Extern block.
2539///
2540/// ```
2541/// ❰
2542/// extern "C" {
2543/// fn foo();
2544/// }
2545/// ❱
2546///
2547/// ```
2548///
2549/// [Reference](https://doc.rust-lang.org/reference/items/external-blocks.html)
2550#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2551pub struct ExternBlock {
2552 pub(crate) syntax: SyntaxNode,
2553}
2554impl ExternBlock {
2555 pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) }
2556 pub fn extern_item_list(&self) -> Option<ExternItemList> { support::child(&self.syntax) }
2557}
2558/// Meta item in an attribute.
2559///
2560/// ```
2561/// #[❰ bar::baz = "42" ❱]
2562/// #[❰ bruh(bruuh("true")) ❱]
2563/// struct Foo;
2564/// ```
2565///
2566/// [Reference](https://doc.rust-lang.org/reference/attributes.html?highlight=meta,item#meta-item-attribute-syntax)
2567#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1249#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2568pub struct MetaItem { 1250pub struct MetaItem {
2569 pub(crate) syntax: SyntaxNode, 1251 pub(crate) syntax: SyntaxNode,
@@ -2574,66 +1256,6 @@ impl MetaItem {
2574 pub fn attr_input(&self) -> Option<AttrInput> { support::child(&self.syntax) } 1256 pub fn attr_input(&self) -> Option<AttrInput> { support::child(&self.syntax) }
2575 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) }
2576} 1258}
2577/// Macro 2.0 definition.
2578/// Their syntax is still WIP by rustc team...
2579/// ```
2580/// ❰
2581/// macro foo { }
2582/// ❱
2583/// ```
2584///
2585/// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/1584-macros.md)
2586#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2587pub struct MacroDef {
2588 pub(crate) syntax: SyntaxNode,
2589}
2590impl MacroDef {
2591 pub fn name(&self) -> Option<Name> { support::child(&self.syntax) }
2592 pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) }
2593}
2594/// Any kind of nominal type definition.
2595#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2596pub enum NominalDef {
2597 StructDef(StructDef),
2598 EnumDef(EnumDef),
2599 UnionDef(UnionDef),
2600}
2601impl ast::NameOwner for NominalDef {}
2602impl ast::TypeParamsOwner for NominalDef {}
2603impl ast::AttrsOwner for NominalDef {}
2604/// Any kind of **declared** generic parameter
2605#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2606pub enum GenericParam {
2607 LifetimeParam(LifetimeParam),
2608 TypeParam(TypeParam),
2609 ConstParam(ConstParam),
2610}
2611/// Any kind of generic argument passed at instantiation site
2612#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2613pub enum GenericArg {
2614 LifetimeArg(LifetimeArg),
2615 TypeArg(TypeArg),
2616 ConstArg(ConstArg),
2617 AssocTypeArg(AssocTypeArg),
2618}
2619/// Any kind of construct valid in type context
2620#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2621pub enum TypeRef {
2622 ParenType(ParenType),
2623 TupleType(TupleType),
2624 NeverType(NeverType),
2625 PathType(PathType),
2626 PointerType(PointerType),
2627 ArrayType(ArrayType),
2628 SliceType(SliceType),
2629 ReferenceType(ReferenceType),
2630 PlaceholderType(PlaceholderType),
2631 FnPointerType(FnPointerType),
2632 ForType(ForType),
2633 ImplTraitType(ImplTraitType),
2634 DynTraitType(DynTraitType),
2635}
2636/// Any kind of top-level item that may appear in a module
2637#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1259#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2638pub enum ModuleItem { 1260pub enum ModuleItem {
2639 StructDef(StructDef), 1261 StructDef(StructDef),
@@ -2651,32 +1273,28 @@ pub enum ModuleItem {
2651 MacroCall(MacroCall), 1273 MacroCall(MacroCall),
2652 ExternBlock(ExternBlock), 1274 ExternBlock(ExternBlock),
2653} 1275}
2654impl ast::NameOwner for ModuleItem {}
2655impl ast::AttrsOwner for ModuleItem {} 1276impl ast::AttrsOwner for ModuleItem {}
2656impl ast::VisibilityOwner for ModuleItem {}
2657/// Any kind of item that may appear in an impl block
2658///
2659/// // FIXME: impl blocks can also contain MacroCall
2660#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1277#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2661pub enum AssocItem { 1278pub enum TypeRef {
2662 FnDef(FnDef), 1279 ParenType(ParenType),
2663 TypeAliasDef(TypeAliasDef), 1280 TupleType(TupleType),
2664 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),
2665} 1292}
2666impl ast::NameOwner for AssocItem {}
2667impl ast::AttrsOwner for AssocItem {}
2668/// Any kind of item that may appear in an extern block
2669///
2670/// // FIXME: extern blocks can also contain MacroCall
2671#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1293#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2672pub enum ExternItem { 1294pub enum FieldDefList {
2673 FnDef(FnDef), 1295 RecordFieldDefList(RecordFieldDefList),
2674 StaticDef(StaticDef), 1296 TupleFieldDefList(TupleFieldDefList),
2675} 1297}
2676impl ast::NameOwner for ExternItem {}
2677impl ast::AttrsOwner for ExternItem {}
2678impl ast::VisibilityOwner for ExternItem {}
2679/// Any kind of expression
2680#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1298#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2681pub enum Expr { 1299pub enum Expr {
2682 TupleExpr(TupleExpr), 1300 TupleExpr(TupleExpr),
@@ -2711,8 +1329,15 @@ pub enum Expr {
2711 MacroCall(MacroCall), 1329 MacroCall(MacroCall),
2712 BoxExpr(BoxExpr), 1330 BoxExpr(BoxExpr),
2713} 1331}
2714impl ast::AttrsOwner for Expr {} 1332#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2715/// 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 {}
2716#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1341#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2717pub enum Pat { 1342pub enum Pat {
2718 OrPat(OrPat), 1343 OrPat(OrPat),
@@ -2731,33 +1356,35 @@ pub enum Pat {
2731 LiteralPat(LiteralPat), 1356 LiteralPat(LiteralPat),
2732 MacroPat(MacroPat), 1357 MacroPat(MacroPat),
2733} 1358}
2734/// Any kind of pattern that appears directly inside of the curly
2735/// braces of a record pattern
2736#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1359#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2737pub enum RecordInnerPat { 1360pub enum Stmt {
2738 RecordFieldPat(RecordFieldPat), 1361 LetStmt(LetStmt),
2739 BindPat(BindPat), 1362 ExprStmt(ExprStmt),
2740} 1363}
2741/// Any kind of input to an attribute 1364impl ast::AttrsOwner for Stmt {}
2742#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1365#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2743pub enum AttrInput { 1366pub enum AttrInput {
2744 Literal(Literal), 1367 Literal(Literal),
2745 TokenTree(TokenTree), 1368 TokenTree(TokenTree),
2746} 1369}
2747/// Any kind of statement
2748/// Note: there are no empty statements, these are just represented as
2749/// bare semicolons without a dedicated statement ast node.
2750#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1370#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2751pub enum Stmt { 1371pub enum ExternItem {
2752 LetStmt(LetStmt), 1372 FnDef(FnDef),
2753 ExprStmt(ExprStmt), 1373 StaticDef(StaticDef),
2754} 1374}
2755/// 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 {}
2756#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1378#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2757pub enum FieldDefList { 1379pub enum AdtDef {
2758 RecordFieldDefList(RecordFieldDefList), 1380 StructDef(StructDef),
2759 TupleFieldDefList(TupleFieldDefList), 1381 EnumDef(EnumDef),
1382 UnionDef(UnionDef),
2760} 1383}
1384impl ast::AttrsOwner for AdtDef {}
1385impl ast::NameOwner for AdtDef {}
1386impl ast::TypeParamsOwner for AdtDef {}
1387impl ast::VisibilityOwner for AdtDef {}
2761impl AstNode for SourceFile { 1388impl AstNode for SourceFile {
2762 fn can_cast(kind: SyntaxKind) -> bool { kind == SOURCE_FILE } 1389 fn can_cast(kind: SyntaxKind) -> bool { kind == SOURCE_FILE }
2763 fn cast(syntax: SyntaxNode) -> Option<Self> { 1390 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -2769,6 +1396,17 @@ impl AstNode for SourceFile {
2769 } 1396 }
2770 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1397 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2771} 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}
2772impl AstNode for FnDef { 1410impl AstNode for FnDef {
2773 fn can_cast(kind: SyntaxKind) -> bool { kind == FN_DEF } 1411 fn can_cast(kind: SyntaxKind) -> bool { kind == FN_DEF }
2774 fn cast(syntax: SyntaxNode) -> Option<Self> { 1412 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -2780,6 +1418,61 @@ impl AstNode for FnDef {
2780 } 1418 }
2781 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1419 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2782} 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}
2783impl AstNode for RetType { 1476impl AstNode for RetType {
2784 fn can_cast(kind: SyntaxKind) -> bool { kind == RET_TYPE } 1477 fn can_cast(kind: SyntaxKind) -> bool { kind == RET_TYPE }
2785 fn cast(syntax: SyntaxNode) -> Option<Self> { 1478 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -2791,8 +1484,8 @@ impl AstNode for RetType {
2791 } 1484 }
2792 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1485 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2793} 1486}
2794impl AstNode for StructDef { 1487impl AstNode for WhereClause {
2795 fn can_cast(kind: SyntaxKind) -> bool { kind == STRUCT_DEF } 1488 fn can_cast(kind: SyntaxKind) -> bool { kind == WHERE_CLAUSE }
2796 fn cast(syntax: SyntaxNode) -> Option<Self> { 1489 fn cast(syntax: SyntaxNode) -> Option<Self> {
2797 if Self::can_cast(syntax.kind()) { 1490 if Self::can_cast(syntax.kind()) {
2798 Some(Self { syntax }) 1491 Some(Self { syntax })
@@ -2802,8 +1495,8 @@ impl AstNode for StructDef {
2802 } 1495 }
2803 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1496 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2804} 1497}
2805impl AstNode for UnionDef { 1498impl AstNode for BlockExpr {
2806 fn can_cast(kind: SyntaxKind) -> bool { kind == UNION_DEF } 1499 fn can_cast(kind: SyntaxKind) -> bool { kind == BLOCK_EXPR }
2807 fn cast(syntax: SyntaxNode) -> Option<Self> { 1500 fn cast(syntax: SyntaxNode) -> Option<Self> {
2808 if Self::can_cast(syntax.kind()) { 1501 if Self::can_cast(syntax.kind()) {
2809 Some(Self { syntax }) 1502 Some(Self { syntax })
@@ -2813,8 +1506,8 @@ impl AstNode for UnionDef {
2813 } 1506 }
2814 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1507 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2815} 1508}
2816impl AstNode for RecordFieldDefList { 1509impl AstNode for StructDef {
2817 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_DEF_LIST } 1510 fn can_cast(kind: SyntaxKind) -> bool { kind == STRUCT_DEF }
2818 fn cast(syntax: SyntaxNode) -> Option<Self> { 1511 fn cast(syntax: SyntaxNode) -> Option<Self> {
2819 if Self::can_cast(syntax.kind()) { 1512 if Self::can_cast(syntax.kind()) {
2820 Some(Self { syntax }) 1513 Some(Self { syntax })
@@ -2824,8 +1517,8 @@ impl AstNode for RecordFieldDefList {
2824 } 1517 }
2825 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1518 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2826} 1519}
2827impl AstNode for RecordFieldDef { 1520impl AstNode for RecordFieldDefList {
2828 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_DEF } 1521 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_DEF_LIST }
2829 fn cast(syntax: SyntaxNode) -> Option<Self> { 1522 fn cast(syntax: SyntaxNode) -> Option<Self> {
2830 if Self::can_cast(syntax.kind()) { 1523 if Self::can_cast(syntax.kind()) {
2831 Some(Self { syntax }) 1524 Some(Self { syntax })
@@ -2846,6 +1539,28 @@ impl AstNode for TupleFieldDefList {
2846 } 1539 }
2847 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1540 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2848} 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}
2849impl AstNode for TupleFieldDef { 1564impl AstNode for TupleFieldDef {
2850 fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_FIELD_DEF } 1565 fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_FIELD_DEF }
2851 fn cast(syntax: SyntaxNode) -> Option<Self> { 1566 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -2901,8 +1616,8 @@ impl AstNode for TraitDef {
2901 } 1616 }
2902 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1617 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2903} 1618}
2904impl AstNode for Module { 1619impl AstNode for TypeBoundList {
2905 fn can_cast(kind: SyntaxKind) -> bool { kind == MODULE } 1620 fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_BOUND_LIST }
2906 fn cast(syntax: SyntaxNode) -> Option<Self> { 1621 fn cast(syntax: SyntaxNode) -> Option<Self> {
2907 if Self::can_cast(syntax.kind()) { 1622 if Self::can_cast(syntax.kind()) {
2908 Some(Self { syntax }) 1623 Some(Self { syntax })
@@ -2923,6 +1638,17 @@ impl AstNode for ItemList {
2923 } 1638 }
2924 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1639 fn syntax(&self) -> &SyntaxNode { &self.syntax }
2925} 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}
2926impl AstNode for ConstDef { 1652impl AstNode for ConstDef {
2927 fn can_cast(kind: SyntaxKind) -> bool { kind == CONST_DEF } 1653 fn can_cast(kind: SyntaxKind) -> bool { kind == CONST_DEF }
2928 fn cast(syntax: SyntaxNode) -> Option<Self> { 1654 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -3011,6 +1737,17 @@ impl AstNode for PathType {
3011 } 1737 }
3012 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1738 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3013} 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}
3014impl AstNode for PointerType { 1751impl AstNode for PointerType {
3015 fn can_cast(kind: SyntaxKind) -> bool { kind == POINTER_TYPE } 1752 fn can_cast(kind: SyntaxKind) -> bool { kind == POINTER_TYPE }
3016 fn cast(syntax: SyntaxNode) -> Option<Self> { 1753 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -3176,8 +1913,8 @@ impl AstNode for IfExpr {
3176 } 1913 }
3177 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1914 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3178} 1915}
3179impl AstNode for LoopExpr { 1916impl AstNode for Condition {
3180 fn can_cast(kind: SyntaxKind) -> bool { kind == LOOP_EXPR } 1917 fn can_cast(kind: SyntaxKind) -> bool { kind == CONDITION }
3181 fn cast(syntax: SyntaxNode) -> Option<Self> { 1918 fn cast(syntax: SyntaxNode) -> Option<Self> {
3182 if Self::can_cast(syntax.kind()) { 1919 if Self::can_cast(syntax.kind()) {
3183 Some(Self { syntax }) 1920 Some(Self { syntax })
@@ -3198,6 +1935,28 @@ impl AstNode for EffectExpr {
3198 } 1935 }
3199 fn syntax(&self) -> &SyntaxNode { &self.syntax } 1936 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3200} 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}
3201impl AstNode for ForExpr { 1960impl AstNode for ForExpr {
3202 fn can_cast(kind: SyntaxKind) -> bool { kind == FOR_EXPR } 1961 fn can_cast(kind: SyntaxKind) -> bool { kind == FOR_EXPR }
3203 fn cast(syntax: SyntaxNode) -> Option<Self> { 1962 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -3242,8 +2001,8 @@ impl AstNode for BreakExpr {
3242 } 2001 }
3243 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2002 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3244} 2003}
3245impl AstNode for Label { 2004impl AstNode for ReturnExpr {
3246 fn can_cast(kind: SyntaxKind) -> bool { kind == LABEL } 2005 fn can_cast(kind: SyntaxKind) -> bool { kind == RETURN_EXPR }
3247 fn cast(syntax: SyntaxNode) -> Option<Self> { 2006 fn cast(syntax: SyntaxNode) -> Option<Self> {
3248 if Self::can_cast(syntax.kind()) { 2007 if Self::can_cast(syntax.kind()) {
3249 Some(Self { syntax }) 2008 Some(Self { syntax })
@@ -3253,8 +2012,8 @@ impl AstNode for Label {
3253 } 2012 }
3254 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2013 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3255} 2014}
3256impl AstNode for BlockExpr { 2015impl AstNode for CallExpr {
3257 fn can_cast(kind: SyntaxKind) -> bool { kind == BLOCK_EXPR } 2016 fn can_cast(kind: SyntaxKind) -> bool { kind == CALL_EXPR }
3258 fn cast(syntax: SyntaxNode) -> Option<Self> { 2017 fn cast(syntax: SyntaxNode) -> Option<Self> {
3259 if Self::can_cast(syntax.kind()) { 2018 if Self::can_cast(syntax.kind()) {
3260 Some(Self { syntax }) 2019 Some(Self { syntax })
@@ -3264,8 +2023,8 @@ impl AstNode for BlockExpr {
3264 } 2023 }
3265 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2024 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3266} 2025}
3267impl AstNode for ReturnExpr { 2026impl AstNode for ArgList {
3268 fn can_cast(kind: SyntaxKind) -> bool { kind == RETURN_EXPR } 2027 fn can_cast(kind: SyntaxKind) -> bool { kind == ARG_LIST }
3269 fn cast(syntax: SyntaxNode) -> Option<Self> { 2028 fn cast(syntax: SyntaxNode) -> Option<Self> {
3270 if Self::can_cast(syntax.kind()) { 2029 if Self::can_cast(syntax.kind()) {
3271 Some(Self { syntax }) 2030 Some(Self { syntax })
@@ -3275,8 +2034,8 @@ impl AstNode for ReturnExpr {
3275 } 2034 }
3276 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2035 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3277} 2036}
3278impl AstNode for CallExpr { 2037impl AstNode for MethodCallExpr {
3279 fn can_cast(kind: SyntaxKind) -> bool { kind == CALL_EXPR } 2038 fn can_cast(kind: SyntaxKind) -> bool { kind == METHOD_CALL_EXPR }
3280 fn cast(syntax: SyntaxNode) -> Option<Self> { 2039 fn cast(syntax: SyntaxNode) -> Option<Self> {
3281 if Self::can_cast(syntax.kind()) { 2040 if Self::can_cast(syntax.kind()) {
3282 Some(Self { syntax }) 2041 Some(Self { syntax })
@@ -3286,8 +2045,8 @@ impl AstNode for CallExpr {
3286 } 2045 }
3287 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2046 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3288} 2047}
3289impl AstNode for MethodCallExpr { 2048impl AstNode for NameRef {
3290 fn can_cast(kind: SyntaxKind) -> bool { kind == METHOD_CALL_EXPR } 2049 fn can_cast(kind: SyntaxKind) -> bool { kind == NAME_REF }
3291 fn cast(syntax: SyntaxNode) -> Option<Self> { 2050 fn cast(syntax: SyntaxNode) -> Option<Self> {
3292 if Self::can_cast(syntax.kind()) { 2051 if Self::can_cast(syntax.kind()) {
3293 Some(Self { syntax }) 2052 Some(Self { syntax })
@@ -3297,8 +2056,8 @@ impl AstNode for MethodCallExpr {
3297 } 2056 }
3298 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2057 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3299} 2058}
3300impl AstNode for IndexExpr { 2059impl AstNode for TypeArgList {
3301 fn can_cast(kind: SyntaxKind) -> bool { kind == INDEX_EXPR } 2060 fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_ARG_LIST }
3302 fn cast(syntax: SyntaxNode) -> Option<Self> { 2061 fn cast(syntax: SyntaxNode) -> Option<Self> {
3303 if Self::can_cast(syntax.kind()) { 2062 if Self::can_cast(syntax.kind()) {
3304 Some(Self { syntax }) 2063 Some(Self { syntax })
@@ -3319,6 +2078,17 @@ impl AstNode for FieldExpr {
3319 } 2078 }
3320 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2079 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3321} 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}
3322impl AstNode for AwaitExpr { 2092impl AstNode for AwaitExpr {
3323 fn can_cast(kind: SyntaxKind) -> bool { kind == AWAIT_EXPR } 2093 fn can_cast(kind: SyntaxKind) -> bool { kind == AWAIT_EXPR }
3324 fn cast(syntax: SyntaxNode) -> Option<Self> { 2094 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -3627,6 +2397,17 @@ impl AstNode for MacroPat {
3627 } 2397 }
3628 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2398 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3629} 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}
3630impl AstNode for RecordPat { 2411impl AstNode for RecordPat {
3631 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_PAT } 2412 fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_PAT }
3632 fn cast(syntax: SyntaxNode) -> Option<Self> { 2413 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -3682,41 +2463,8 @@ impl AstNode for TuplePat {
3682 } 2463 }
3683 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2464 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3684} 2465}
3685impl AstNode for Visibility { 2466impl AstNode for TokenTree {
3686 fn can_cast(kind: SyntaxKind) -> bool { kind == VISIBILITY } 2467 fn can_cast(kind: SyntaxKind) -> bool { kind == TOKEN_TREE }
3687 fn cast(syntax: SyntaxNode) -> Option<Self> {
3688 if Self::can_cast(syntax.kind()) {
3689 Some(Self { syntax })
3690 } else {
3691 None
3692 }
3693 }
3694 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3695}
3696impl AstNode for Name {
3697 fn can_cast(kind: SyntaxKind) -> bool { kind == NAME }
3698 fn cast(syntax: SyntaxNode) -> Option<Self> {
3699 if Self::can_cast(syntax.kind()) {
3700 Some(Self { syntax })
3701 } else {
3702 None
3703 }
3704 }
3705 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3706}
3707impl AstNode for NameRef {
3708 fn can_cast(kind: SyntaxKind) -> bool { kind == NAME_REF }
3709 fn cast(syntax: SyntaxNode) -> Option<Self> {
3710 if Self::can_cast(syntax.kind()) {
3711 Some(Self { syntax })
3712 } else {
3713 None
3714 }
3715 }
3716 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3717}
3718impl AstNode for MacroCall {
3719 fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_CALL }
3720 fn cast(syntax: SyntaxNode) -> Option<Self> { 2468 fn cast(syntax: SyntaxNode) -> Option<Self> {
3721 if Self::can_cast(syntax.kind()) { 2469 if Self::can_cast(syntax.kind()) {
3722 Some(Self { syntax }) 2470 Some(Self { syntax })
@@ -3726,8 +2474,8 @@ impl AstNode for MacroCall {
3726 } 2474 }
3727 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2475 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3728} 2476}
3729impl AstNode for Attr { 2477impl AstNode for MacroDef {
3730 fn can_cast(kind: SyntaxKind) -> bool { kind == ATTR } 2478 fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_DEF }
3731 fn cast(syntax: SyntaxNode) -> Option<Self> { 2479 fn cast(syntax: SyntaxNode) -> Option<Self> {
3732 if Self::can_cast(syntax.kind()) { 2480 if Self::can_cast(syntax.kind()) {
3733 Some(Self { syntax }) 2481 Some(Self { syntax })
@@ -3737,8 +2485,8 @@ impl AstNode for Attr {
3737 } 2485 }
3738 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2486 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3739} 2487}
3740impl AstNode for TokenTree { 2488impl AstNode for MacroItems {
3741 fn can_cast(kind: SyntaxKind) -> bool { kind == TOKEN_TREE } 2489 fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_ITEMS }
3742 fn cast(syntax: SyntaxNode) -> Option<Self> { 2490 fn cast(syntax: SyntaxNode) -> Option<Self> {
3743 if Self::can_cast(syntax.kind()) { 2491 if Self::can_cast(syntax.kind()) {
3744 Some(Self { syntax }) 2492 Some(Self { syntax })
@@ -3748,8 +2496,8 @@ impl AstNode for TokenTree {
3748 } 2496 }
3749 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2497 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3750} 2498}
3751impl AstNode for TypeParamList { 2499impl AstNode for MacroStmts {
3752 fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_PARAM_LIST } 2500 fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_STMTS }
3753 fn cast(syntax: SyntaxNode) -> Option<Self> { 2501 fn cast(syntax: SyntaxNode) -> Option<Self> {
3754 if Self::can_cast(syntax.kind()) { 2502 if Self::can_cast(syntax.kind()) {
3755 Some(Self { syntax }) 2503 Some(Self { syntax })
@@ -3770,17 +2518,6 @@ impl AstNode for TypeParam {
3770 } 2518 }
3771 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2519 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3772} 2520}
3773impl AstNode for ConstParam {
3774 fn can_cast(kind: SyntaxKind) -> bool { kind == CONST_PARAM }
3775 fn cast(syntax: SyntaxNode) -> Option<Self> {
3776 if Self::can_cast(syntax.kind()) {
3777 Some(Self { syntax })
3778 } else {
3779 None
3780 }
3781 }
3782 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3783}
3784impl AstNode for LifetimeParam { 2521impl AstNode for LifetimeParam {
3785 fn can_cast(kind: SyntaxKind) -> bool { kind == LIFETIME_PARAM } 2522 fn can_cast(kind: SyntaxKind) -> bool { kind == LIFETIME_PARAM }
3786 fn cast(syntax: SyntaxNode) -> Option<Self> { 2523 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -3792,8 +2529,8 @@ impl AstNode for LifetimeParam {
3792 } 2529 }
3793 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2530 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3794} 2531}
3795impl AstNode for TypeBound { 2532impl AstNode for ConstParam {
3796 fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_BOUND } 2533 fn can_cast(kind: SyntaxKind) -> bool { kind == CONST_PARAM }
3797 fn cast(syntax: SyntaxNode) -> Option<Self> { 2534 fn cast(syntax: SyntaxNode) -> Option<Self> {
3798 if Self::can_cast(syntax.kind()) { 2535 if Self::can_cast(syntax.kind()) {
3799 Some(Self { syntax }) 2536 Some(Self { syntax })
@@ -3803,8 +2540,8 @@ impl AstNode for TypeBound {
3803 } 2540 }
3804 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2541 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3805} 2542}
3806impl AstNode for TypeBoundList { 2543impl AstNode for TypeBound {
3807 fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_BOUND_LIST } 2544 fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_BOUND }
3808 fn cast(syntax: SyntaxNode) -> Option<Self> { 2545 fn cast(syntax: SyntaxNode) -> Option<Self> {
3809 if Self::can_cast(syntax.kind()) { 2546 if Self::can_cast(syntax.kind()) {
3810 Some(Self { syntax }) 2547 Some(Self { syntax })
@@ -3825,28 +2562,6 @@ impl AstNode for WherePred {
3825 } 2562 }
3826 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2563 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3827} 2564}
3828impl AstNode for WhereClause {
3829 fn can_cast(kind: SyntaxKind) -> bool { kind == WHERE_CLAUSE }
3830 fn cast(syntax: SyntaxNode) -> Option<Self> {
3831 if Self::can_cast(syntax.kind()) {
3832 Some(Self { syntax })
3833 } else {
3834 None
3835 }
3836 }
3837 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3838}
3839impl AstNode for Abi {
3840 fn can_cast(kind: SyntaxKind) -> bool { kind == ABI }
3841 fn cast(syntax: SyntaxNode) -> Option<Self> {
3842 if Self::can_cast(syntax.kind()) {
3843 Some(Self { syntax })
3844 } else {
3845 None
3846 }
3847 }
3848 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3849}
3850impl AstNode for ExprStmt { 2565impl AstNode for ExprStmt {
3851 fn can_cast(kind: SyntaxKind) -> bool { kind == EXPR_STMT } 2566 fn can_cast(kind: SyntaxKind) -> bool { kind == EXPR_STMT }
3852 fn cast(syntax: SyntaxNode) -> Option<Self> { 2567 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -3869,28 +2584,6 @@ impl AstNode for LetStmt {
3869 } 2584 }
3870 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2585 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3871} 2586}
3872impl AstNode for Condition {
3873 fn can_cast(kind: SyntaxKind) -> bool { kind == CONDITION }
3874 fn cast(syntax: SyntaxNode) -> Option<Self> {
3875 if Self::can_cast(syntax.kind()) {
3876 Some(Self { syntax })
3877 } else {
3878 None
3879 }
3880 }
3881 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3882}
3883impl AstNode for ParamList {
3884 fn can_cast(kind: SyntaxKind) -> bool { kind == PARAM_LIST }
3885 fn cast(syntax: SyntaxNode) -> Option<Self> {
3886 if Self::can_cast(syntax.kind()) {
3887 Some(Self { syntax })
3888 } else {
3889 None
3890 }
3891 }
3892 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3893}
3894impl AstNode for SelfParam { 2587impl AstNode for SelfParam {
3895 fn can_cast(kind: SyntaxKind) -> bool { kind == SELF_PARAM } 2588 fn can_cast(kind: SyntaxKind) -> bool { kind == SELF_PARAM }
3896 fn cast(syntax: SyntaxNode) -> Option<Self> { 2589 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -3935,17 +2628,6 @@ impl AstNode for UseTree {
3935 } 2628 }
3936 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2629 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3937} 2630}
3938impl AstNode for Alias {
3939 fn can_cast(kind: SyntaxKind) -> bool { kind == ALIAS }
3940 fn cast(syntax: SyntaxNode) -> Option<Self> {
3941 if Self::can_cast(syntax.kind()) {
3942 Some(Self { syntax })
3943 } else {
3944 None
3945 }
3946 }
3947 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3948}
3949impl AstNode for UseTreeList { 2631impl AstNode for UseTreeList {
3950 fn can_cast(kind: SyntaxKind) -> bool { kind == USE_TREE_LIST } 2632 fn can_cast(kind: SyntaxKind) -> bool { kind == USE_TREE_LIST }
3951 fn cast(syntax: SyntaxNode) -> Option<Self> { 2633 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -3957,19 +2639,8 @@ impl AstNode for UseTreeList {
3957 } 2639 }
3958 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2640 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3959} 2641}
3960impl AstNode for ExternCrateItem { 2642impl AstNode for Alias {
3961 fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_CRATE_ITEM } 2643 fn can_cast(kind: SyntaxKind) -> bool { kind == ALIAS }
3962 fn cast(syntax: SyntaxNode) -> Option<Self> {
3963 if Self::can_cast(syntax.kind()) {
3964 Some(Self { syntax })
3965 } else {
3966 None
3967 }
3968 }
3969 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3970}
3971impl AstNode for ArgList {
3972 fn can_cast(kind: SyntaxKind) -> bool { kind == ARG_LIST }
3973 fn cast(syntax: SyntaxNode) -> Option<Self> { 2644 fn cast(syntax: SyntaxNode) -> Option<Self> {
3974 if Self::can_cast(syntax.kind()) { 2645 if Self::can_cast(syntax.kind()) {
3975 Some(Self { syntax }) 2646 Some(Self { syntax })
@@ -3979,8 +2650,8 @@ impl AstNode for ArgList {
3979 } 2650 }
3980 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2651 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3981} 2652}
3982impl AstNode for Path { 2653impl AstNode for ExternCrateItem {
3983 fn can_cast(kind: SyntaxKind) -> bool { kind == PATH } 2654 fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_CRATE_ITEM }
3984 fn cast(syntax: SyntaxNode) -> Option<Self> { 2655 fn cast(syntax: SyntaxNode) -> Option<Self> {
3985 if Self::can_cast(syntax.kind()) { 2656 if Self::can_cast(syntax.kind()) {
3986 Some(Self { syntax }) 2657 Some(Self { syntax })
@@ -4001,17 +2672,6 @@ impl AstNode for PathSegment {
4001 } 2672 }
4002 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2673 fn syntax(&self) -> &SyntaxNode { &self.syntax }
4003} 2674}
4004impl AstNode for TypeArgList {
4005 fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_ARG_LIST }
4006 fn cast(syntax: SyntaxNode) -> Option<Self> {
4007 if Self::can_cast(syntax.kind()) {
4008 Some(Self { syntax })
4009 } else {
4010 None
4011 }
4012 }
4013 fn syntax(&self) -> &SyntaxNode { &self.syntax }
4014}
4015impl AstNode for TypeArg { 2675impl AstNode for TypeArg {
4016 fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_ARG } 2676 fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_ARG }
4017 fn cast(syntax: SyntaxNode) -> Option<Self> { 2677 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -4023,17 +2683,6 @@ impl AstNode for TypeArg {
4023 } 2683 }
4024 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2684 fn syntax(&self) -> &SyntaxNode { &self.syntax }
4025} 2685}
4026impl AstNode for AssocTypeArg {
4027 fn can_cast(kind: SyntaxKind) -> bool { kind == ASSOC_TYPE_ARG }
4028 fn cast(syntax: SyntaxNode) -> Option<Self> {
4029 if Self::can_cast(syntax.kind()) {
4030 Some(Self { syntax })
4031 } else {
4032 None
4033 }
4034 }
4035 fn syntax(&self) -> &SyntaxNode { &self.syntax }
4036}
4037impl AstNode for LifetimeArg { 2686impl AstNode for LifetimeArg {
4038 fn can_cast(kind: SyntaxKind) -> bool { kind == LIFETIME_ARG } 2687 fn can_cast(kind: SyntaxKind) -> bool { kind == LIFETIME_ARG }
4039 fn cast(syntax: SyntaxNode) -> Option<Self> { 2688 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -4045,8 +2694,8 @@ impl AstNode for LifetimeArg {
4045 } 2694 }
4046 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2695 fn syntax(&self) -> &SyntaxNode { &self.syntax }
4047} 2696}
4048impl AstNode for ConstArg { 2697impl AstNode for AssocTypeArg {
4049 fn can_cast(kind: SyntaxKind) -> bool { kind == CONST_ARG } 2698 fn can_cast(kind: SyntaxKind) -> bool { kind == ASSOC_TYPE_ARG }
4050 fn cast(syntax: SyntaxNode) -> Option<Self> { 2699 fn cast(syntax: SyntaxNode) -> Option<Self> {
4051 if Self::can_cast(syntax.kind()) { 2700 if Self::can_cast(syntax.kind()) {
4052 Some(Self { syntax }) 2701 Some(Self { syntax })
@@ -4056,8 +2705,8 @@ impl AstNode for ConstArg {
4056 } 2705 }
4057 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2706 fn syntax(&self) -> &SyntaxNode { &self.syntax }
4058} 2707}
4059impl AstNode for MacroItems { 2708impl AstNode for ConstArg {
4060 fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_ITEMS } 2709 fn can_cast(kind: SyntaxKind) -> bool { kind == CONST_ARG }
4061 fn cast(syntax: SyntaxNode) -> Option<Self> { 2710 fn cast(syntax: SyntaxNode) -> Option<Self> {
4062 if Self::can_cast(syntax.kind()) { 2711 if Self::can_cast(syntax.kind()) {
4063 Some(Self { syntax }) 2712 Some(Self { syntax })
@@ -4067,8 +2716,8 @@ impl AstNode for MacroItems {
4067 } 2716 }
4068 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2717 fn syntax(&self) -> &SyntaxNode { &self.syntax }
4069} 2718}
4070impl AstNode for MacroStmts { 2719impl AstNode for ExternBlock {
4071 fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_STMTS } 2720 fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_BLOCK }
4072 fn cast(syntax: SyntaxNode) -> Option<Self> { 2721 fn cast(syntax: SyntaxNode) -> Option<Self> {
4073 if Self::can_cast(syntax.kind()) { 2722 if Self::can_cast(syntax.kind()) {
4074 Some(Self { syntax }) 2723 Some(Self { syntax })
@@ -4089,17 +2738,6 @@ impl AstNode for ExternItemList {
4089 } 2738 }
4090 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2739 fn syntax(&self) -> &SyntaxNode { &self.syntax }
4091} 2740}
4092impl AstNode for ExternBlock {
4093 fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_BLOCK }
4094 fn cast(syntax: SyntaxNode) -> Option<Self> {
4095 if Self::can_cast(syntax.kind()) {
4096 Some(Self { syntax })
4097 } else {
4098 None
4099 }
4100 }
4101 fn syntax(&self) -> &SyntaxNode { &self.syntax }
4102}
4103impl AstNode for MetaItem { 2741impl AstNode for MetaItem {
4104 fn can_cast(kind: SyntaxKind) -> bool { kind == META_ITEM } 2742 fn can_cast(kind: SyntaxKind) -> bool { kind == META_ITEM }
4105 fn cast(syntax: SyntaxNode) -> Option<Self> { 2743 fn cast(syntax: SyntaxNode) -> Option<Self> {
@@ -4111,118 +2749,93 @@ impl AstNode for MetaItem {
4111 } 2749 }
4112 fn syntax(&self) -> &SyntaxNode { &self.syntax } 2750 fn syntax(&self) -> &SyntaxNode { &self.syntax }
4113} 2751}
4114impl AstNode for MacroDef { 2752impl From<StructDef> for ModuleItem {
4115 fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_DEF } 2753 fn from(node: StructDef) -> ModuleItem { ModuleItem::StructDef(node) }
4116 fn cast(syntax: SyntaxNode) -> Option<Self> {
4117 if Self::can_cast(syntax.kind()) {
4118 Some(Self { syntax })
4119 } else {
4120 None
4121 }
4122 }
4123 fn syntax(&self) -> &SyntaxNode { &self.syntax }
4124} 2754}
4125impl From<StructDef> for NominalDef { 2755impl From<UnionDef> for ModuleItem {
4126 fn from(node: StructDef) -> NominalDef { NominalDef::StructDef(node) } 2756 fn from(node: UnionDef) -> ModuleItem { ModuleItem::UnionDef(node) }
4127} 2757}
4128impl From<EnumDef> for NominalDef { 2758impl From<EnumDef> for ModuleItem {
4129 fn from(node: EnumDef) -> NominalDef { NominalDef::EnumDef(node) } 2759 fn from(node: EnumDef) -> ModuleItem { ModuleItem::EnumDef(node) }
4130} 2760}
4131impl From<UnionDef> for NominalDef { 2761impl From<FnDef> for ModuleItem {
4132 fn from(node: UnionDef) -> NominalDef { NominalDef::UnionDef(node) } 2762 fn from(node: FnDef) -> ModuleItem { ModuleItem::FnDef(node) }
4133} 2763}
4134impl AstNode for NominalDef { 2764impl From<TraitDef> for ModuleItem {
4135 fn can_cast(kind: SyntaxKind) -> bool { 2765 fn from(node: TraitDef) -> ModuleItem { ModuleItem::TraitDef(node) }
4136 match kind {
4137 STRUCT_DEF | ENUM_DEF | UNION_DEF => true,
4138 _ => false,
4139 }
4140 }
4141 fn cast(syntax: SyntaxNode) -> Option<Self> {
4142 let res = match syntax.kind() {
4143 STRUCT_DEF => NominalDef::StructDef(StructDef { syntax }),
4144 ENUM_DEF => NominalDef::EnumDef(EnumDef { syntax }),
4145 UNION_DEF => NominalDef::UnionDef(UnionDef { syntax }),
4146 _ => return None,
4147 };
4148 Some(res)
4149 }
4150 fn syntax(&self) -> &SyntaxNode {
4151 match self {
4152 NominalDef::StructDef(it) => &it.syntax,
4153 NominalDef::EnumDef(it) => &it.syntax,
4154 NominalDef::UnionDef(it) => &it.syntax,
4155 }
4156 }
4157} 2766}
4158impl From<LifetimeParam> for GenericParam { 2767impl From<TypeAliasDef> for ModuleItem {
4159 fn from(node: LifetimeParam) -> GenericParam { GenericParam::LifetimeParam(node) } 2768 fn from(node: TypeAliasDef) -> ModuleItem { ModuleItem::TypeAliasDef(node) }
4160} 2769}
4161impl From<TypeParam> for GenericParam { 2770impl From<ImplDef> for ModuleItem {
4162 fn from(node: TypeParam) -> GenericParam { GenericParam::TypeParam(node) } 2771 fn from(node: ImplDef) -> ModuleItem { ModuleItem::ImplDef(node) }
4163} 2772}
4164impl From<ConstParam> for GenericParam { 2773impl From<UseItem> for ModuleItem {
4165 fn from(node: ConstParam) -> GenericParam { GenericParam::ConstParam(node) } 2774 fn from(node: UseItem) -> ModuleItem { ModuleItem::UseItem(node) }
4166} 2775}
4167impl AstNode for GenericParam { 2776impl From<ExternCrateItem> for ModuleItem {
4168 fn can_cast(kind: SyntaxKind) -> bool { 2777 fn from(node: ExternCrateItem) -> ModuleItem { ModuleItem::ExternCrateItem(node) }
4169 match kind {
4170 LIFETIME_PARAM | TYPE_PARAM | CONST_PARAM => true,
4171 _ => false,
4172 }
4173 }
4174 fn cast(syntax: SyntaxNode) -> Option<Self> {
4175 let res = match syntax.kind() {
4176 LIFETIME_PARAM => GenericParam::LifetimeParam(LifetimeParam { syntax }),
4177 TYPE_PARAM => GenericParam::TypeParam(TypeParam { syntax }),
4178 CONST_PARAM => GenericParam::ConstParam(ConstParam { syntax }),
4179 _ => return None,
4180 };
4181 Some(res)
4182 }
4183 fn syntax(&self) -> &SyntaxNode {
4184 match self {
4185 GenericParam::LifetimeParam(it) => &it.syntax,
4186 GenericParam::TypeParam(it) => &it.syntax,
4187 GenericParam::ConstParam(it) => &it.syntax,
4188 }
4189 }
4190} 2778}
4191impl From<LifetimeArg> for GenericArg { 2779impl From<ConstDef> for ModuleItem {
4192 fn from(node: LifetimeArg) -> GenericArg { GenericArg::LifetimeArg(node) } 2780 fn from(node: ConstDef) -> ModuleItem { ModuleItem::ConstDef(node) }
2781}
2782impl From<StaticDef> for ModuleItem {
2783 fn from(node: StaticDef) -> ModuleItem { ModuleItem::StaticDef(node) }
4193} 2784}
4194impl From<TypeArg> for GenericArg { 2785impl From<Module> for ModuleItem {
4195 fn from(node: TypeArg) -> GenericArg { GenericArg::TypeArg(node) } 2786 fn from(node: Module) -> ModuleItem { ModuleItem::Module(node) }
4196} 2787}
4197impl From<ConstArg> for GenericArg { 2788impl From<MacroCall> for ModuleItem {
4198 fn from(node: ConstArg) -> GenericArg { GenericArg::ConstArg(node) } 2789 fn from(node: MacroCall) -> ModuleItem { ModuleItem::MacroCall(node) }
4199} 2790}
4200impl From<AssocTypeArg> for GenericArg { 2791impl From<ExternBlock> for ModuleItem {
4201 fn from(node: AssocTypeArg) -> GenericArg { GenericArg::AssocTypeArg(node) } 2792 fn from(node: ExternBlock) -> ModuleItem { ModuleItem::ExternBlock(node) }
4202} 2793}
4203impl AstNode for GenericArg { 2794impl AstNode for ModuleItem {
4204 fn can_cast(kind: SyntaxKind) -> bool { 2795 fn can_cast(kind: SyntaxKind) -> bool {
4205 match kind { 2796 match kind {
4206 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,
4207 _ => false, 2800 _ => false,
4208 } 2801 }
4209 } 2802 }
4210 fn cast(syntax: SyntaxNode) -> Option<Self> { 2803 fn cast(syntax: SyntaxNode) -> Option<Self> {
4211 let res = match syntax.kind() { 2804 let res = match syntax.kind() {
4212 LIFETIME_ARG => GenericArg::LifetimeArg(LifetimeArg { syntax }), 2805 STRUCT_DEF => ModuleItem::StructDef(StructDef { syntax }),
4213 TYPE_ARG => GenericArg::TypeArg(TypeArg { syntax }), 2806 UNION_DEF => ModuleItem::UnionDef(UnionDef { syntax }),
4214 CONST_ARG => GenericArg::ConstArg(ConstArg { syntax }), 2807 ENUM_DEF => ModuleItem::EnumDef(EnumDef { syntax }),
4215 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 }),
4216 _ => return None, 2819 _ => return None,
4217 }; 2820 };
4218 Some(res) 2821 Some(res)
4219 } 2822 }
4220 fn syntax(&self) -> &SyntaxNode { 2823 fn syntax(&self) -> &SyntaxNode {
4221 match self { 2824 match self {
4222 GenericArg::LifetimeArg(it) => &it.syntax, 2825 ModuleItem::StructDef(it) => &it.syntax,
4223 GenericArg::TypeArg(it) => &it.syntax, 2826 ModuleItem::UnionDef(it) => &it.syntax,
4224 GenericArg::ConstArg(it) => &it.syntax, 2827 ModuleItem::EnumDef(it) => &it.syntax,
4225 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,
4226 } 2839 }
4227 } 2840 }
4228} 2841}
@@ -4311,154 +2924,33 @@ impl AstNode for TypeRef {
4311 } 2924 }
4312 } 2925 }
4313} 2926}
4314impl From<StructDef> for ModuleItem { 2927impl From<RecordFieldDefList> for FieldDefList {
4315 fn from(node: StructDef) -> ModuleItem { ModuleItem::StructDef(node) } 2928 fn from(node: RecordFieldDefList) -> FieldDefList { FieldDefList::RecordFieldDefList(node) }
4316}
4317impl From<UnionDef> for ModuleItem {
4318 fn from(node: UnionDef) -> ModuleItem { ModuleItem::UnionDef(node) }
4319}
4320impl From<EnumDef> for ModuleItem {
4321 fn from(node: EnumDef) -> ModuleItem { ModuleItem::EnumDef(node) }
4322}
4323impl From<FnDef> for ModuleItem {
4324 fn from(node: FnDef) -> ModuleItem { ModuleItem::FnDef(node) }
4325}
4326impl From<TraitDef> for ModuleItem {
4327 fn from(node: TraitDef) -> ModuleItem { ModuleItem::TraitDef(node) }
4328}
4329impl From<TypeAliasDef> for ModuleItem {
4330 fn from(node: TypeAliasDef) -> ModuleItem { ModuleItem::TypeAliasDef(node) }
4331}
4332impl From<ImplDef> for ModuleItem {
4333 fn from(node: ImplDef) -> ModuleItem { ModuleItem::ImplDef(node) }
4334}
4335impl From<UseItem> for ModuleItem {
4336 fn from(node: UseItem) -> ModuleItem { ModuleItem::UseItem(node) }
4337}
4338impl From<ExternCrateItem> for ModuleItem {
4339 fn from(node: ExternCrateItem) -> ModuleItem { ModuleItem::ExternCrateItem(node) }
4340}
4341impl From<ConstDef> for ModuleItem {
4342 fn from(node: ConstDef) -> ModuleItem { ModuleItem::ConstDef(node) }
4343}
4344impl From<StaticDef> for ModuleItem {
4345 fn from(node: StaticDef) -> ModuleItem { ModuleItem::StaticDef(node) }
4346}
4347impl From<Module> for ModuleItem {
4348 fn from(node: Module) -> ModuleItem { ModuleItem::Module(node) }
4349}
4350impl From<MacroCall> for ModuleItem {
4351 fn from(node: MacroCall) -> ModuleItem { ModuleItem::MacroCall(node) }
4352}
4353impl From<ExternBlock> for ModuleItem {
4354 fn from(node: ExternBlock) -> ModuleItem { ModuleItem::ExternBlock(node) }
4355}
4356impl AstNode for ModuleItem {
4357 fn can_cast(kind: SyntaxKind) -> bool {
4358 match kind {
4359 STRUCT_DEF | UNION_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_DEF
4360 | USE_ITEM | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE | MACRO_CALL
4361 | EXTERN_BLOCK => true,
4362 _ => false,
4363 }
4364 }
4365 fn cast(syntax: SyntaxNode) -> Option<Self> {
4366 let res = match syntax.kind() {
4367 STRUCT_DEF => ModuleItem::StructDef(StructDef { syntax }),
4368 UNION_DEF => ModuleItem::UnionDef(UnionDef { syntax }),
4369 ENUM_DEF => ModuleItem::EnumDef(EnumDef { syntax }),
4370 FN_DEF => ModuleItem::FnDef(FnDef { syntax }),
4371 TRAIT_DEF => ModuleItem::TraitDef(TraitDef { syntax }),
4372 TYPE_ALIAS_DEF => ModuleItem::TypeAliasDef(TypeAliasDef { syntax }),
4373 IMPL_DEF => ModuleItem::ImplDef(ImplDef { syntax }),
4374 USE_ITEM => ModuleItem::UseItem(UseItem { syntax }),
4375 EXTERN_CRATE_ITEM => ModuleItem::ExternCrateItem(ExternCrateItem { syntax }),
4376 CONST_DEF => ModuleItem::ConstDef(ConstDef { syntax }),
4377 STATIC_DEF => ModuleItem::StaticDef(StaticDef { syntax }),
4378 MODULE => ModuleItem::Module(Module { syntax }),
4379 MACRO_CALL => ModuleItem::MacroCall(MacroCall { syntax }),
4380 EXTERN_BLOCK => ModuleItem::ExternBlock(ExternBlock { syntax }),
4381 _ => return None,
4382 };
4383 Some(res)
4384 }
4385 fn syntax(&self) -> &SyntaxNode {
4386 match self {
4387 ModuleItem::StructDef(it) => &it.syntax,
4388 ModuleItem::UnionDef(it) => &it.syntax,
4389 ModuleItem::EnumDef(it) => &it.syntax,
4390 ModuleItem::FnDef(it) => &it.syntax,
4391 ModuleItem::TraitDef(it) => &it.syntax,
4392 ModuleItem::TypeAliasDef(it) => &it.syntax,
4393 ModuleItem::ImplDef(it) => &it.syntax,
4394 ModuleItem::UseItem(it) => &it.syntax,
4395 ModuleItem::ExternCrateItem(it) => &it.syntax,
4396 ModuleItem::ConstDef(it) => &it.syntax,
4397 ModuleItem::StaticDef(it) => &it.syntax,
4398 ModuleItem::Module(it) => &it.syntax,
4399 ModuleItem::MacroCall(it) => &it.syntax,
4400 ModuleItem::ExternBlock(it) => &it.syntax,
4401 }
4402 }
4403}
4404impl From<FnDef> for AssocItem {
4405 fn from(node: FnDef) -> AssocItem { AssocItem::FnDef(node) }
4406}
4407impl From<TypeAliasDef> for AssocItem {
4408 fn from(node: TypeAliasDef) -> AssocItem { AssocItem::TypeAliasDef(node) }
4409}
4410impl From<ConstDef> for AssocItem {
4411 fn from(node: ConstDef) -> AssocItem { AssocItem::ConstDef(node) }
4412}
4413impl AstNode for AssocItem {
4414 fn can_cast(kind: SyntaxKind) -> bool {
4415 match kind {
4416 FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true,
4417 _ => false,
4418 }
4419 }
4420 fn cast(syntax: SyntaxNode) -> Option<Self> {
4421 let res = match syntax.kind() {
4422 FN_DEF => AssocItem::FnDef(FnDef { syntax }),
4423 TYPE_ALIAS_DEF => AssocItem::TypeAliasDef(TypeAliasDef { syntax }),
4424 CONST_DEF => AssocItem::ConstDef(ConstDef { syntax }),
4425 _ => return None,
4426 };
4427 Some(res)
4428 }
4429 fn syntax(&self) -> &SyntaxNode {
4430 match self {
4431 AssocItem::FnDef(it) => &it.syntax,
4432 AssocItem::TypeAliasDef(it) => &it.syntax,
4433 AssocItem::ConstDef(it) => &it.syntax,
4434 }
4435 }
4436}
4437impl From<FnDef> for ExternItem {
4438 fn from(node: FnDef) -> ExternItem { ExternItem::FnDef(node) }
4439} 2929}
4440impl From<StaticDef> for ExternItem { 2930impl From<TupleFieldDefList> for FieldDefList {
4441 fn from(node: StaticDef) -> ExternItem { ExternItem::StaticDef(node) } 2931 fn from(node: TupleFieldDefList) -> FieldDefList { FieldDefList::TupleFieldDefList(node) }
4442} 2932}
4443impl AstNode for ExternItem { 2933impl AstNode for FieldDefList {
4444 fn can_cast(kind: SyntaxKind) -> bool { 2934 fn can_cast(kind: SyntaxKind) -> bool {
4445 match kind { 2935 match kind {
4446 FN_DEF | STATIC_DEF => true, 2936 RECORD_FIELD_DEF_LIST | TUPLE_FIELD_DEF_LIST => true,
4447 _ => false, 2937 _ => false,
4448 } 2938 }
4449 } 2939 }
4450 fn cast(syntax: SyntaxNode) -> Option<Self> { 2940 fn cast(syntax: SyntaxNode) -> Option<Self> {
4451 let res = match syntax.kind() { 2941 let res = match syntax.kind() {
4452 FN_DEF => ExternItem::FnDef(FnDef { syntax }), 2942 RECORD_FIELD_DEF_LIST => {
4453 STATIC_DEF => ExternItem::StaticDef(StaticDef { syntax }), 2943 FieldDefList::RecordFieldDefList(RecordFieldDefList { syntax })
2944 }
2945 TUPLE_FIELD_DEF_LIST => FieldDefList::TupleFieldDefList(TupleFieldDefList { syntax }),
4454 _ => return None, 2946 _ => return None,
4455 }; 2947 };
4456 Some(res) 2948 Some(res)
4457 } 2949 }
4458 fn syntax(&self) -> &SyntaxNode { 2950 fn syntax(&self) -> &SyntaxNode {
4459 match self { 2951 match self {
4460 ExternItem::FnDef(it) => &it.syntax, 2952 FieldDefList::RecordFieldDefList(it) => &it.syntax,
4461 ExternItem::StaticDef(it) => &it.syntax, 2953 FieldDefList::TupleFieldDefList(it) => &it.syntax,
4462 } 2954 }
4463 } 2955 }
4464} 2956}
@@ -4641,6 +3133,39 @@ impl AstNode for Expr {
4641 } 3133 }
4642 } 3134 }
4643} 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}
4644impl From<OrPat> for Pat { 3169impl From<OrPat> for Pat {
4645 fn from(node: OrPat) -> Pat { Pat::OrPat(node) } 3170 fn from(node: OrPat) -> Pat { Pat::OrPat(node) }
4646} 3171}
@@ -4736,31 +3261,31 @@ impl AstNode for Pat {
4736 } 3261 }
4737 } 3262 }
4738} 3263}
4739impl From<RecordFieldPat> for RecordInnerPat { 3264impl From<LetStmt> for Stmt {
4740 fn from(node: RecordFieldPat) -> RecordInnerPat { RecordInnerPat::RecordFieldPat(node) } 3265 fn from(node: LetStmt) -> Stmt { Stmt::LetStmt(node) }
4741} 3266}
4742impl From<BindPat> for RecordInnerPat { 3267impl From<ExprStmt> for Stmt {
4743 fn from(node: BindPat) -> RecordInnerPat { RecordInnerPat::BindPat(node) } 3268 fn from(node: ExprStmt) -> Stmt { Stmt::ExprStmt(node) }
4744} 3269}
4745impl AstNode for RecordInnerPat { 3270impl AstNode for Stmt {
4746 fn can_cast(kind: SyntaxKind) -> bool { 3271 fn can_cast(kind: SyntaxKind) -> bool {
4747 match kind { 3272 match kind {
4748 RECORD_FIELD_PAT | BIND_PAT => true, 3273 LET_STMT | EXPR_STMT => true,
4749 _ => false, 3274 _ => false,
4750 } 3275 }
4751 } 3276 }
4752 fn cast(syntax: SyntaxNode) -> Option<Self> { 3277 fn cast(syntax: SyntaxNode) -> Option<Self> {
4753 let res = match syntax.kind() { 3278 let res = match syntax.kind() {
4754 RECORD_FIELD_PAT => RecordInnerPat::RecordFieldPat(RecordFieldPat { syntax }), 3279 LET_STMT => Stmt::LetStmt(LetStmt { syntax }),
4755 BIND_PAT => RecordInnerPat::BindPat(BindPat { syntax }), 3280 EXPR_STMT => Stmt::ExprStmt(ExprStmt { syntax }),
4756 _ => return None, 3281 _ => return None,
4757 }; 3282 };
4758 Some(res) 3283 Some(res)
4759 } 3284 }
4760 fn syntax(&self) -> &SyntaxNode { 3285 fn syntax(&self) -> &SyntaxNode {
4761 match self { 3286 match self {
4762 RecordInnerPat::RecordFieldPat(it) => &it.syntax, 3287 Stmt::LetStmt(it) => &it.syntax,
4763 RecordInnerPat::BindPat(it) => &it.syntax, 3288 Stmt::ExprStmt(it) => &it.syntax,
4764 } 3289 }
4765 } 3290 }
4766} 3291}
@@ -4792,90 +3317,103 @@ impl AstNode for AttrInput {
4792 } 3317 }
4793 } 3318 }
4794} 3319}
4795impl From<LetStmt> for Stmt { 3320impl From<FnDef> for ExternItem {
4796 fn from(node: LetStmt) -> Stmt { Stmt::LetStmt(node) } 3321 fn from(node: FnDef) -> ExternItem { ExternItem::FnDef(node) }
4797} 3322}
4798impl From<ExprStmt> for Stmt { 3323impl From<StaticDef> for ExternItem {
4799 fn from(node: ExprStmt) -> Stmt { Stmt::ExprStmt(node) } 3324 fn from(node: StaticDef) -> ExternItem { ExternItem::StaticDef(node) }
4800} 3325}
4801impl AstNode for Stmt { 3326impl AstNode for ExternItem {
4802 fn can_cast(kind: SyntaxKind) -> bool { 3327 fn can_cast(kind: SyntaxKind) -> bool {
4803 match kind { 3328 match kind {
4804 LET_STMT | EXPR_STMT => true, 3329 FN_DEF | STATIC_DEF => true,
4805 _ => false, 3330 _ => false,
4806 } 3331 }
4807 } 3332 }
4808 fn cast(syntax: SyntaxNode) -> Option<Self> { 3333 fn cast(syntax: SyntaxNode) -> Option<Self> {
4809 let res = match syntax.kind() { 3334 let res = match syntax.kind() {
4810 LET_STMT => Stmt::LetStmt(LetStmt { syntax }), 3335 FN_DEF => ExternItem::FnDef(FnDef { syntax }),
4811 EXPR_STMT => Stmt::ExprStmt(ExprStmt { syntax }), 3336 STATIC_DEF => ExternItem::StaticDef(StaticDef { syntax }),
4812 _ => return None, 3337 _ => return None,
4813 }; 3338 };
4814 Some(res) 3339 Some(res)
4815 } 3340 }
4816 fn syntax(&self) -> &SyntaxNode { 3341 fn syntax(&self) -> &SyntaxNode {
4817 match self { 3342 match self {
4818 Stmt::LetStmt(it) => &it.syntax, 3343 ExternItem::FnDef(it) => &it.syntax,
4819 Stmt::ExprStmt(it) => &it.syntax, 3344 ExternItem::StaticDef(it) => &it.syntax,
4820 } 3345 }
4821 } 3346 }
4822} 3347}
4823impl From<RecordFieldDefList> for FieldDefList { 3348impl From<StructDef> for AdtDef {
4824 fn from(node: RecordFieldDefList) -> FieldDefList { FieldDefList::RecordFieldDefList(node) } 3349 fn from(node: StructDef) -> AdtDef { AdtDef::StructDef(node) }
4825} 3350}
4826impl From<TupleFieldDefList> for FieldDefList { 3351impl From<EnumDef> for AdtDef {
4827 fn from(node: TupleFieldDefList) -> FieldDefList { FieldDefList::TupleFieldDefList(node) } 3352 fn from(node: EnumDef) -> AdtDef { AdtDef::EnumDef(node) }
4828} 3353}
4829impl AstNode for FieldDefList { 3354impl From<UnionDef> for AdtDef {
3355 fn from(node: UnionDef) -> AdtDef { AdtDef::UnionDef(node) }
3356}
3357impl AstNode for AdtDef {
4830 fn can_cast(kind: SyntaxKind) -> bool { 3358 fn can_cast(kind: SyntaxKind) -> bool {
4831 match kind { 3359 match kind {
4832 RECORD_FIELD_DEF_LIST | TUPLE_FIELD_DEF_LIST => true, 3360 STRUCT_DEF | ENUM_DEF | UNION_DEF => true,
4833 _ => false, 3361 _ => false,
4834 } 3362 }
4835 } 3363 }
4836 fn cast(syntax: SyntaxNode) -> Option<Self> { 3364 fn cast(syntax: SyntaxNode) -> Option<Self> {
4837 let res = match syntax.kind() { 3365 let res = match syntax.kind() {
4838 RECORD_FIELD_DEF_LIST => { 3366 STRUCT_DEF => AdtDef::StructDef(StructDef { syntax }),
4839 FieldDefList::RecordFieldDefList(RecordFieldDefList { syntax }) 3367 ENUM_DEF => AdtDef::EnumDef(EnumDef { syntax }),
4840 } 3368 UNION_DEF => AdtDef::UnionDef(UnionDef { syntax }),
4841 TUPLE_FIELD_DEF_LIST => FieldDefList::TupleFieldDefList(TupleFieldDefList { syntax }),
4842 _ => return None, 3369 _ => return None,
4843 }; 3370 };
4844 Some(res) 3371 Some(res)
4845 } 3372 }
4846 fn syntax(&self) -> &SyntaxNode { 3373 fn syntax(&self) -> &SyntaxNode {
4847 match self { 3374 match self {
4848 FieldDefList::RecordFieldDefList(it) => &it.syntax, 3375 AdtDef::StructDef(it) => &it.syntax,
4849 FieldDefList::TupleFieldDefList(it) => &it.syntax, 3376 AdtDef::EnumDef(it) => &it.syntax,
3377 AdtDef::UnionDef(it) => &it.syntax,
4850 } 3378 }
4851 } 3379 }
4852} 3380}
4853impl std::fmt::Display for NominalDef { 3381impl std::fmt::Display for ModuleItem {
3382 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3383 std::fmt::Display::fmt(self.syntax(), f)
3384 }
3385}
3386impl std::fmt::Display for TypeRef {
4854 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3387 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4855 std::fmt::Display::fmt(self.syntax(), f) 3388 std::fmt::Display::fmt(self.syntax(), f)
4856 } 3389 }
4857} 3390}
4858impl std::fmt::Display for GenericParam { 3391impl std::fmt::Display for FieldDefList {
4859 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3392 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4860 std::fmt::Display::fmt(self.syntax(), f) 3393 std::fmt::Display::fmt(self.syntax(), f)
4861 } 3394 }
4862} 3395}
4863impl std::fmt::Display for GenericArg { 3396impl std::fmt::Display for Expr {
4864 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3397 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4865 std::fmt::Display::fmt(self.syntax(), f) 3398 std::fmt::Display::fmt(self.syntax(), f)
4866 } 3399 }
4867} 3400}
4868impl std::fmt::Display for TypeRef { 3401impl std::fmt::Display for AssocItem {
4869 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3402 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4870 std::fmt::Display::fmt(self.syntax(), f) 3403 std::fmt::Display::fmt(self.syntax(), f)
4871 } 3404 }
4872} 3405}
4873impl std::fmt::Display for ModuleItem { 3406impl std::fmt::Display for Pat {
4874 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3407 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4875 std::fmt::Display::fmt(self.syntax(), f) 3408 std::fmt::Display::fmt(self.syntax(), f)
4876 } 3409 }
4877} 3410}
4878impl std::fmt::Display for AssocItem { 3411impl std::fmt::Display for Stmt {
3412 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3413 std::fmt::Display::fmt(self.syntax(), f)
3414 }
3415}
3416impl std::fmt::Display for AttrInput {
4879 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3417 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4880 std::fmt::Display::fmt(self.syntax(), f) 3418 std::fmt::Display::fmt(self.syntax(), f)
4881 } 3419 }
@@ -4885,42 +3423,47 @@ impl std::fmt::Display for ExternItem {
4885 std::fmt::Display::fmt(self.syntax(), f) 3423 std::fmt::Display::fmt(self.syntax(), f)
4886 } 3424 }
4887} 3425}
4888impl std::fmt::Display for Expr { 3426impl std::fmt::Display for AdtDef {
4889 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3427 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4890 std::fmt::Display::fmt(self.syntax(), f) 3428 std::fmt::Display::fmt(self.syntax(), f)
4891 } 3429 }
4892} 3430}
4893impl std::fmt::Display for Pat { 3431impl std::fmt::Display for SourceFile {
4894 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3432 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4895 std::fmt::Display::fmt(self.syntax(), f) 3433 std::fmt::Display::fmt(self.syntax(), f)
4896 } 3434 }
4897} 3435}
4898impl std::fmt::Display for RecordInnerPat { 3436impl std::fmt::Display for Attr {
4899 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3437 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4900 std::fmt::Display::fmt(self.syntax(), f) 3438 std::fmt::Display::fmt(self.syntax(), f)
4901 } 3439 }
4902} 3440}
4903impl std::fmt::Display for AttrInput { 3441impl std::fmt::Display for FnDef {
4904 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3442 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4905 std::fmt::Display::fmt(self.syntax(), f) 3443 std::fmt::Display::fmt(self.syntax(), f)
4906 } 3444 }
4907} 3445}
4908impl std::fmt::Display for Stmt { 3446impl std::fmt::Display for Visibility {
4909 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3447 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4910 std::fmt::Display::fmt(self.syntax(), f) 3448 std::fmt::Display::fmt(self.syntax(), f)
4911 } 3449 }
4912} 3450}
4913impl std::fmt::Display for FieldDefList { 3451impl std::fmt::Display for Abi {
4914 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3452 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4915 std::fmt::Display::fmt(self.syntax(), f) 3453 std::fmt::Display::fmt(self.syntax(), f)
4916 } 3454 }
4917} 3455}
4918impl std::fmt::Display for SourceFile { 3456impl std::fmt::Display for Name {
4919 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3457 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4920 std::fmt::Display::fmt(self.syntax(), f) 3458 std::fmt::Display::fmt(self.syntax(), f)
4921 } 3459 }
4922} 3460}
4923impl std::fmt::Display for FnDef { 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 {
4924 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3467 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4925 std::fmt::Display::fmt(self.syntax(), f) 3468 std::fmt::Display::fmt(self.syntax(), f)
4926 } 3469 }
@@ -4930,22 +3473,22 @@ impl std::fmt::Display for RetType {
4930 std::fmt::Display::fmt(self.syntax(), f) 3473 std::fmt::Display::fmt(self.syntax(), f)
4931 } 3474 }
4932} 3475}
4933impl std::fmt::Display for StructDef { 3476impl std::fmt::Display for WhereClause {
4934 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3477 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4935 std::fmt::Display::fmt(self.syntax(), f) 3478 std::fmt::Display::fmt(self.syntax(), f)
4936 } 3479 }
4937} 3480}
4938impl std::fmt::Display for UnionDef { 3481impl std::fmt::Display for BlockExpr {
4939 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3482 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4940 std::fmt::Display::fmt(self.syntax(), f) 3483 std::fmt::Display::fmt(self.syntax(), f)
4941 } 3484 }
4942} 3485}
4943impl std::fmt::Display for RecordFieldDefList { 3486impl std::fmt::Display for StructDef {
4944 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3487 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4945 std::fmt::Display::fmt(self.syntax(), f) 3488 std::fmt::Display::fmt(self.syntax(), f)
4946 } 3489 }
4947} 3490}
4948impl std::fmt::Display for RecordFieldDef { 3491impl std::fmt::Display for RecordFieldDefList {
4949 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3492 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4950 std::fmt::Display::fmt(self.syntax(), f) 3493 std::fmt::Display::fmt(self.syntax(), f)
4951 } 3494 }
@@ -4955,6 +3498,16 @@ impl std::fmt::Display for TupleFieldDefList {
4955 std::fmt::Display::fmt(self.syntax(), f) 3498 std::fmt::Display::fmt(self.syntax(), f)
4956 } 3499 }
4957} 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}
4958impl std::fmt::Display for TupleFieldDef { 3511impl std::fmt::Display for TupleFieldDef {
4959 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3512 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4960 std::fmt::Display::fmt(self.syntax(), f) 3513 std::fmt::Display::fmt(self.syntax(), f)
@@ -4980,7 +3533,7 @@ impl std::fmt::Display for TraitDef {
4980 std::fmt::Display::fmt(self.syntax(), f) 3533 std::fmt::Display::fmt(self.syntax(), f)
4981 } 3534 }
4982} 3535}
4983impl std::fmt::Display for Module { 3536impl std::fmt::Display for TypeBoundList {
4984 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3537 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4985 std::fmt::Display::fmt(self.syntax(), f) 3538 std::fmt::Display::fmt(self.syntax(), f)
4986 } 3539 }
@@ -4990,6 +3543,11 @@ impl std::fmt::Display for ItemList {
4990 std::fmt::Display::fmt(self.syntax(), f) 3543 std::fmt::Display::fmt(self.syntax(), f)
4991 } 3544 }
4992} 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}
4993impl std::fmt::Display for ConstDef { 3551impl std::fmt::Display for ConstDef {
4994 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3552 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4995 std::fmt::Display::fmt(self.syntax(), f) 3553 std::fmt::Display::fmt(self.syntax(), f)
@@ -5030,6 +3588,11 @@ impl std::fmt::Display for PathType {
5030 std::fmt::Display::fmt(self.syntax(), f) 3588 std::fmt::Display::fmt(self.syntax(), f)
5031 } 3589 }
5032} 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}
5033impl std::fmt::Display for PointerType { 3596impl std::fmt::Display for PointerType {
5034 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3597 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5035 std::fmt::Display::fmt(self.syntax(), f) 3598 std::fmt::Display::fmt(self.syntax(), f)
@@ -5105,7 +3668,7 @@ impl std::fmt::Display for IfExpr {
5105 std::fmt::Display::fmt(self.syntax(), f) 3668 std::fmt::Display::fmt(self.syntax(), f)
5106 } 3669 }
5107} 3670}
5108impl std::fmt::Display for LoopExpr { 3671impl std::fmt::Display for Condition {
5109 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3672 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5110 std::fmt::Display::fmt(self.syntax(), f) 3673 std::fmt::Display::fmt(self.syntax(), f)
5111 } 3674 }
@@ -5115,6 +3678,16 @@ impl std::fmt::Display for EffectExpr {
5115 std::fmt::Display::fmt(self.syntax(), f) 3678 std::fmt::Display::fmt(self.syntax(), f)
5116 } 3679 }
5117} 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}
5118impl std::fmt::Display for ForExpr { 3691impl std::fmt::Display for ForExpr {
5119 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3692 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5120 std::fmt::Display::fmt(self.syntax(), f) 3693 std::fmt::Display::fmt(self.syntax(), f)
@@ -5135,32 +3708,32 @@ impl std::fmt::Display for BreakExpr {
5135 std::fmt::Display::fmt(self.syntax(), f) 3708 std::fmt::Display::fmt(self.syntax(), f)
5136 } 3709 }
5137} 3710}
5138impl std::fmt::Display for Label { 3711impl std::fmt::Display for ReturnExpr {
5139 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3712 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5140 std::fmt::Display::fmt(self.syntax(), f) 3713 std::fmt::Display::fmt(self.syntax(), f)
5141 } 3714 }
5142} 3715}
5143impl std::fmt::Display for BlockExpr { 3716impl std::fmt::Display for CallExpr {
5144 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3717 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5145 std::fmt::Display::fmt(self.syntax(), f) 3718 std::fmt::Display::fmt(self.syntax(), f)
5146 } 3719 }
5147} 3720}
5148impl std::fmt::Display for ReturnExpr { 3721impl std::fmt::Display for ArgList {
5149 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3722 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5150 std::fmt::Display::fmt(self.syntax(), f) 3723 std::fmt::Display::fmt(self.syntax(), f)
5151 } 3724 }
5152} 3725}
5153impl std::fmt::Display for CallExpr { 3726impl std::fmt::Display for MethodCallExpr {
5154 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3727 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5155 std::fmt::Display::fmt(self.syntax(), f) 3728 std::fmt::Display::fmt(self.syntax(), f)
5156 } 3729 }
5157} 3730}
5158impl std::fmt::Display for MethodCallExpr { 3731impl std::fmt::Display for NameRef {
5159 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3732 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5160 std::fmt::Display::fmt(self.syntax(), f) 3733 std::fmt::Display::fmt(self.syntax(), f)
5161 } 3734 }
5162} 3735}
5163impl std::fmt::Display for IndexExpr { 3736impl std::fmt::Display for TypeArgList {
5164 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3737 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5165 std::fmt::Display::fmt(self.syntax(), f) 3738 std::fmt::Display::fmt(self.syntax(), f)
5166 } 3739 }
@@ -5170,6 +3743,11 @@ impl std::fmt::Display for FieldExpr {
5170 std::fmt::Display::fmt(self.syntax(), f) 3743 std::fmt::Display::fmt(self.syntax(), f)
5171 } 3744 }
5172} 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}
5173impl std::fmt::Display for AwaitExpr { 3751impl std::fmt::Display for AwaitExpr {
5174 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3752 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5175 std::fmt::Display::fmt(self.syntax(), f) 3753 std::fmt::Display::fmt(self.syntax(), f)
@@ -5310,6 +3888,11 @@ impl std::fmt::Display for MacroPat {
5310 std::fmt::Display::fmt(self.syntax(), f) 3888 std::fmt::Display::fmt(self.syntax(), f)
5311 } 3889 }
5312} 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}
5313impl std::fmt::Display for RecordPat { 3896impl std::fmt::Display for RecordPat {
5314 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3897 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5315 std::fmt::Display::fmt(self.syntax(), f) 3898 std::fmt::Display::fmt(self.syntax(), f)
@@ -5335,37 +3918,22 @@ impl std::fmt::Display for TuplePat {
5335 std::fmt::Display::fmt(self.syntax(), f) 3918 std::fmt::Display::fmt(self.syntax(), f)
5336 } 3919 }
5337} 3920}
5338impl std::fmt::Display for Visibility { 3921impl std::fmt::Display for TokenTree {
5339 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5340 std::fmt::Display::fmt(self.syntax(), f)
5341 }
5342}
5343impl std::fmt::Display for Name {
5344 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5345 std::fmt::Display::fmt(self.syntax(), f)
5346 }
5347}
5348impl std::fmt::Display for NameRef {
5349 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5350 std::fmt::Display::fmt(self.syntax(), f)
5351 }
5352}
5353impl std::fmt::Display for MacroCall {
5354 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3922 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5355 std::fmt::Display::fmt(self.syntax(), f) 3923 std::fmt::Display::fmt(self.syntax(), f)
5356 } 3924 }
5357} 3925}
5358impl std::fmt::Display for Attr { 3926impl std::fmt::Display for MacroDef {
5359 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3927 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5360 std::fmt::Display::fmt(self.syntax(), f) 3928 std::fmt::Display::fmt(self.syntax(), f)
5361 } 3929 }
5362} 3930}
5363impl std::fmt::Display for TokenTree { 3931impl std::fmt::Display for MacroItems {
5364 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3932 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5365 std::fmt::Display::fmt(self.syntax(), f) 3933 std::fmt::Display::fmt(self.syntax(), f)
5366 } 3934 }
5367} 3935}
5368impl std::fmt::Display for TypeParamList { 3936impl std::fmt::Display for MacroStmts {
5369 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3937 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5370 std::fmt::Display::fmt(self.syntax(), f) 3938 std::fmt::Display::fmt(self.syntax(), f)
5371 } 3939 }
@@ -5375,22 +3943,17 @@ impl std::fmt::Display for TypeParam {
5375 std::fmt::Display::fmt(self.syntax(), f) 3943 std::fmt::Display::fmt(self.syntax(), f)
5376 } 3944 }
5377} 3945}
5378impl std::fmt::Display for ConstParam {
5379 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5380 std::fmt::Display::fmt(self.syntax(), f)
5381 }
5382}
5383impl std::fmt::Display for LifetimeParam { 3946impl std::fmt::Display for LifetimeParam {
5384 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3947 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5385 std::fmt::Display::fmt(self.syntax(), f) 3948 std::fmt::Display::fmt(self.syntax(), f)
5386 } 3949 }
5387} 3950}
5388impl std::fmt::Display for TypeBound { 3951impl std::fmt::Display for ConstParam {
5389 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3952 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5390 std::fmt::Display::fmt(self.syntax(), f) 3953 std::fmt::Display::fmt(self.syntax(), f)
5391 } 3954 }
5392} 3955}
5393impl std::fmt::Display for TypeBoundList { 3956impl std::fmt::Display for TypeBound {
5394 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3957 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5395 std::fmt::Display::fmt(self.syntax(), f) 3958 std::fmt::Display::fmt(self.syntax(), f)
5396 } 3959 }
@@ -5400,16 +3963,6 @@ impl std::fmt::Display for WherePred {
5400 std::fmt::Display::fmt(self.syntax(), f) 3963 std::fmt::Display::fmt(self.syntax(), f)
5401 } 3964 }
5402} 3965}
5403impl std::fmt::Display for WhereClause {
5404 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5405 std::fmt::Display::fmt(self.syntax(), f)
5406 }
5407}
5408impl std::fmt::Display for Abi {
5409 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5410 std::fmt::Display::fmt(self.syntax(), f)
5411 }
5412}
5413impl std::fmt::Display for ExprStmt { 3966impl std::fmt::Display for ExprStmt {
5414 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3967 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5415 std::fmt::Display::fmt(self.syntax(), f) 3968 std::fmt::Display::fmt(self.syntax(), f)
@@ -5420,16 +3973,6 @@ impl std::fmt::Display for LetStmt {
5420 std::fmt::Display::fmt(self.syntax(), f) 3973 std::fmt::Display::fmt(self.syntax(), f)
5421 } 3974 }
5422} 3975}
5423impl std::fmt::Display for Condition {
5424 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5425 std::fmt::Display::fmt(self.syntax(), f)
5426 }
5427}
5428impl std::fmt::Display for ParamList {
5429 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5430 std::fmt::Display::fmt(self.syntax(), f)
5431 }
5432}
5433impl std::fmt::Display for SelfParam { 3976impl std::fmt::Display for SelfParam {
5434 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3977 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5435 std::fmt::Display::fmt(self.syntax(), f) 3978 std::fmt::Display::fmt(self.syntax(), f)
@@ -5450,27 +3993,17 @@ impl std::fmt::Display for UseTree {
5450 std::fmt::Display::fmt(self.syntax(), f) 3993 std::fmt::Display::fmt(self.syntax(), f)
5451 } 3994 }
5452} 3995}
5453impl std::fmt::Display for Alias {
5454 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5455 std::fmt::Display::fmt(self.syntax(), f)
5456 }
5457}
5458impl std::fmt::Display for UseTreeList { 3996impl std::fmt::Display for UseTreeList {
5459 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 3997 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5460 std::fmt::Display::fmt(self.syntax(), f) 3998 std::fmt::Display::fmt(self.syntax(), f)
5461 } 3999 }
5462} 4000}
5463impl std::fmt::Display for ExternCrateItem { 4001impl std::fmt::Display for Alias {
5464 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5465 std::fmt::Display::fmt(self.syntax(), f)
5466 }
5467}
5468impl std::fmt::Display for ArgList {
5469 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 4002 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5470 std::fmt::Display::fmt(self.syntax(), f) 4003 std::fmt::Display::fmt(self.syntax(), f)
5471 } 4004 }
5472} 4005}
5473impl std::fmt::Display for Path { 4006impl std::fmt::Display for ExternCrateItem {
5474 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 4007 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5475 std::fmt::Display::fmt(self.syntax(), f) 4008 std::fmt::Display::fmt(self.syntax(), f)
5476 } 4009 }
@@ -5480,37 +4013,27 @@ impl std::fmt::Display for PathSegment {
5480 std::fmt::Display::fmt(self.syntax(), f) 4013 std::fmt::Display::fmt(self.syntax(), f)
5481 } 4014 }
5482} 4015}
5483impl std::fmt::Display for TypeArgList {
5484 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5485 std::fmt::Display::fmt(self.syntax(), f)
5486 }
5487}
5488impl std::fmt::Display for TypeArg { 4016impl std::fmt::Display for TypeArg {
5489 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 4017 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5490 std::fmt::Display::fmt(self.syntax(), f) 4018 std::fmt::Display::fmt(self.syntax(), f)
5491 } 4019 }
5492} 4020}
5493impl std::fmt::Display for AssocTypeArg {
5494 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5495 std::fmt::Display::fmt(self.syntax(), f)
5496 }
5497}
5498impl std::fmt::Display for LifetimeArg { 4021impl std::fmt::Display for LifetimeArg {
5499 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 4022 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5500 std::fmt::Display::fmt(self.syntax(), f) 4023 std::fmt::Display::fmt(self.syntax(), f)
5501 } 4024 }
5502} 4025}
5503impl std::fmt::Display for ConstArg { 4026impl std::fmt::Display for AssocTypeArg {
5504 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 4027 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5505 std::fmt::Display::fmt(self.syntax(), f) 4028 std::fmt::Display::fmt(self.syntax(), f)
5506 } 4029 }
5507} 4030}
5508impl std::fmt::Display for MacroItems { 4031impl std::fmt::Display for ConstArg {
5509 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 4032 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5510 std::fmt::Display::fmt(self.syntax(), f) 4033 std::fmt::Display::fmt(self.syntax(), f)
5511 } 4034 }
5512} 4035}
5513impl std::fmt::Display for MacroStmts { 4036impl std::fmt::Display for ExternBlock {
5514 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 4037 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5515 std::fmt::Display::fmt(self.syntax(), f) 4038 std::fmt::Display::fmt(self.syntax(), f)
5516 } 4039 }
@@ -5520,18 +4043,8 @@ impl std::fmt::Display for ExternItemList {
5520 std::fmt::Display::fmt(self.syntax(), f) 4043 std::fmt::Display::fmt(self.syntax(), f)
5521 } 4044 }
5522} 4045}
5523impl std::fmt::Display for ExternBlock {
5524 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5525 std::fmt::Display::fmt(self.syntax(), f)
5526 }
5527}
5528impl std::fmt::Display for MetaItem { 4046impl std::fmt::Display for MetaItem {
5529 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 4047 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5530 std::fmt::Display::fmt(self.syntax(), f) 4048 std::fmt::Display::fmt(self.syntax(), f)
5531 } 4049 }
5532} 4050}
5533impl std::fmt::Display for MacroDef {
5534 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
5535 std::fmt::Display::fmt(self.syntax(), f)
5536 }
5537}
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/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml
index 3f9c820c5..931fc61ed 100644
--- a/crates/rust-analyzer/Cargo.toml
+++ b/crates/rust-analyzer/Cargo.toml
@@ -23,7 +23,7 @@ log = "0.4.8"
23lsp-types = { version = "0.78.0", features = ["proposed"] } 23lsp-types = { version = "0.78.0", features = ["proposed"] }
24parking_lot = "0.11.0" 24parking_lot = "0.11.0"
25pico-args = "0.3.1" 25pico-args = "0.3.1"
26rand = { version = "0.7.3", features = ["small_rng"] } 26oorandom = "11.1.2"
27rustc-hash = "1.1.0" 27rustc-hash = "1.1.0"
28serde = { version = "1.0.106", features = ["derive"] } 28serde = { version = "1.0.106", features = ["derive"] }
29serde_json = "1.0.48" 29serde_json = "1.0.48"
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs
index ccc058682..66d201ba6 100644
--- a/crates/rust-analyzer/src/cli/analysis_stats.rs
+++ b/crates/rust-analyzer/src/cli/analysis_stats.rs
@@ -1,7 +1,10 @@
1//! Fully type-check project and print various stats, like the number of type 1//! Fully type-check project and print various stats, like the number of type
2//! errors. 2//! errors.
3 3
4use std::{path::Path, time::Instant}; 4use std::{
5 path::Path,
6 time::{Instant, SystemTime, UNIX_EPOCH},
7};
5 8
6use hir::{ 9use hir::{
7 db::{AstDatabase, DefDatabase, HirDatabase}, 10 db::{AstDatabase, DefDatabase, HirDatabase},
@@ -10,12 +13,12 @@ use hir::{
10use hir_def::FunctionId; 13use hir_def::FunctionId;
11use hir_ty::{Ty, TypeWalk}; 14use hir_ty::{Ty, TypeWalk};
12use itertools::Itertools; 15use itertools::Itertools;
16use oorandom::Rand32;
13use ra_db::{ 17use ra_db::{
14 salsa::{self, ParallelDatabase}, 18 salsa::{self, ParallelDatabase},
15 SourceDatabaseExt, 19 SourceDatabaseExt,
16}; 20};
17use ra_syntax::AstNode; 21use ra_syntax::AstNode;
18use rand::{seq::SliceRandom, thread_rng};
19use rayon::prelude::*; 22use rayon::prelude::*;
20use rustc_hash::FxHashSet; 23use rustc_hash::FxHashSet;
21use stdx::format_to; 24use stdx::format_to;
@@ -46,6 +49,11 @@ pub fn analysis_stats(
46 load_output_dirs: bool, 49 load_output_dirs: bool,
47 with_proc_macro: bool, 50 with_proc_macro: bool,
48) -> Result<()> { 51) -> Result<()> {
52 let mut rng = {
53 let seed = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis() as u64;
54 Rand32::new(seed)
55 };
56
49 let db_load_time = Instant::now(); 57 let db_load_time = Instant::now();
50 let (host, vfs) = load_cargo(path, load_output_dirs, with_proc_macro)?; 58 let (host, vfs) = load_cargo(path, load_output_dirs, with_proc_macro)?;
51 let db = host.raw_database(); 59 let db = host.raw_database();
@@ -57,7 +65,7 @@ pub fn analysis_stats(
57 65
58 let mut krates = Crate::all(db); 66 let mut krates = Crate::all(db);
59 if randomize { 67 if randomize {
60 krates.shuffle(&mut thread_rng()); 68 shuffle(&mut rng, &mut krates);
61 } 69 }
62 for krate in krates { 70 for krate in krates {
63 let module = krate.root_module(db).expect("crate without root module"); 71 let module = krate.root_module(db).expect("crate without root module");
@@ -72,7 +80,7 @@ pub fn analysis_stats(
72 } 80 }
73 81
74 if randomize { 82 if randomize {
75 visit_queue.shuffle(&mut thread_rng()); 83 shuffle(&mut rng, &mut visit_queue);
76 } 84 }
77 85
78 eprintln!("Crates in this dir: {}", num_crates); 86 eprintln!("Crates in this dir: {}", num_crates);
@@ -110,7 +118,7 @@ pub fn analysis_stats(
110 ); 118 );
111 119
112 if randomize { 120 if randomize {
113 funcs.shuffle(&mut thread_rng()); 121 shuffle(&mut rng, &mut funcs);
114 } 122 }
115 123
116 let mut bar = match verbosity { 124 let mut bar = match verbosity {
@@ -306,3 +314,10 @@ pub fn analysis_stats(
306 314
307 Ok(()) 315 Ok(())
308} 316}
317
318fn shuffle<T>(rng: &mut Rand32, slice: &mut [T]) {
319 for i in (1..slice.len()).rev() {
320 let idx = rng.rand_range(0..i as u32) as usize;
321 slice.swap(idx, i)
322 }
323}