diff options
author | Zac Pullar-Strecker <[email protected]> | 2020-07-31 03:12:44 +0100 |
---|---|---|
committer | Zac Pullar-Strecker <[email protected]> | 2020-07-31 03:12:44 +0100 |
commit | f05d7b41a719d848844b054a16477b29d0f063c6 (patch) | |
tree | 0a8a0946e8aef2ce64d4c13d0035ba41cce2daf3 /crates/ra_syntax | |
parent | 73ff610e41959e3e7c78a2b4b25b086883132956 (diff) | |
parent | 6b7cb8b5ab539fc4333ce34bc29bf77c976f232a (diff) |
Merge remote-tracking branch 'upstream/master' into 503-hover-doc-links
Hasn't fixed tests yet.
Diffstat (limited to 'crates/ra_syntax')
300 files changed, 2258 insertions, 3592 deletions
diff --git a/crates/ra_syntax/Cargo.toml b/crates/ra_syntax/Cargo.toml index 49696ce75..fc4d7aa04 100644 --- a/crates/ra_syntax/Cargo.toml +++ b/crates/ra_syntax/Cargo.toml | |||
@@ -13,7 +13,7 @@ doctest = false | |||
13 | [dependencies] | 13 | [dependencies] |
14 | itertools = "0.9.0" | 14 | itertools = "0.9.0" |
15 | rowan = "0.10.0" | 15 | rowan = "0.10.0" |
16 | rustc_lexer = { version = "666.0.0", package = "rustc-ap-rustc_lexer" } | 16 | rustc_lexer = { version = "671.0.0", package = "rustc-ap-rustc_lexer" } |
17 | rustc-hash = "1.1.0" | 17 | rustc-hash = "1.1.0" |
18 | arrayvec = "0.5.1" | 18 | arrayvec = "0.5.1" |
19 | once_cell = "1.3.1" | 19 | once_cell = "1.3.1" |
@@ -31,4 +31,6 @@ serde = { version = "1.0.106", features = ["derive"] } | |||
31 | 31 | ||
32 | [dev-dependencies] | 32 | [dev-dependencies] |
33 | test_utils = { path = "../test_utils" } | 33 | test_utils = { path = "../test_utils" } |
34 | expect = { path = "../expect" } | ||
34 | walkdir = "2.3.1" | 35 | walkdir = "2.3.1" |
36 | rayon = "1" | ||
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index 9d02aeef3..fd426ece9 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs | |||
@@ -2,9 +2,9 @@ | |||
2 | 2 | ||
3 | mod generated; | 3 | mod generated; |
4 | mod traits; | 4 | mod traits; |
5 | mod tokens; | 5 | mod token_ext; |
6 | mod extensions; | 6 | mod node_ext; |
7 | mod expr_extensions; | 7 | mod expr_ext; |
8 | pub mod edit; | 8 | pub mod edit; |
9 | pub mod make; | 9 | pub mod make; |
10 | 10 | ||
@@ -16,13 +16,13 @@ use crate::{ | |||
16 | }; | 16 | }; |
17 | 17 | ||
18 | pub use self::{ | 18 | pub use self::{ |
19 | expr_extensions::{ArrayExprKind, BinOp, Effect, ElseBranch, LiteralKind, PrefixOp, RangeOp}, | 19 | expr_ext::{ArrayExprKind, BinOp, Effect, ElseBranch, LiteralKind, PrefixOp, RangeOp}, |
20 | extensions::{ | 20 | generated::{nodes::*, tokens::*}, |
21 | node_ext::{ | ||
21 | AttrKind, FieldKind, NameOrNameRef, PathSegmentKind, SelfParamKind, SlicePatComponents, | 22 | AttrKind, FieldKind, NameOrNameRef, PathSegmentKind, SelfParamKind, SlicePatComponents, |
22 | StructKind, TypeBoundKind, VisibilityKind, | 23 | StructKind, TypeBoundKind, VisibilityKind, |
23 | }, | 24 | }, |
24 | generated::{nodes::*, tokens::*}, | 25 | token_ext::*, |
25 | tokens::*, | ||
26 | traits::*, | 26 | traits::*, |
27 | }; | 27 | }; |
28 | 28 | ||
@@ -139,7 +139,7 @@ fn test_doc_comment_of_statics() { | |||
139 | ) | 139 | ) |
140 | .ok() | 140 | .ok() |
141 | .unwrap(); | 141 | .unwrap(); |
142 | let st = file.syntax().descendants().find_map(StaticDef::cast).unwrap(); | 142 | let st = file.syntax().descendants().find_map(Static::cast).unwrap(); |
143 | assert_eq!("Number of levels", st.doc_comment_text().unwrap()); | 143 | assert_eq!("Number of levels", st.doc_comment_text().unwrap()); |
144 | } | 144 | } |
145 | 145 | ||
@@ -235,7 +235,7 @@ fn test_comments_preserve_trailing_whitespace() { | |||
235 | ) | 235 | ) |
236 | .ok() | 236 | .ok() |
237 | .unwrap(); | 237 | .unwrap(); |
238 | let def = file.syntax().descendants().find_map(StructDef::cast).unwrap(); | 238 | let def = file.syntax().descendants().find_map(Struct::cast).unwrap(); |
239 | assert_eq!( | 239 | assert_eq!( |
240 | "Representation of a Realm. \nIn the specification these are called Realm Records.", | 240 | "Representation of a Realm. \nIn the specification these are called Realm Records.", |
241 | def.doc_comment_text().unwrap() | 241 | def.doc_comment_text().unwrap() |
@@ -286,7 +286,7 @@ where | |||
286 | let mut bounds = pred.type_bound_list().unwrap().bounds(); | 286 | let mut bounds = pred.type_bound_list().unwrap().bounds(); |
287 | 287 | ||
288 | assert!(pred.for_token().is_none()); | 288 | assert!(pred.for_token().is_none()); |
289 | assert!(pred.type_param_list().is_none()); | 289 | assert!(pred.generic_param_list().is_none()); |
290 | assert_eq!("T", pred.type_ref().unwrap().syntax().text().to_string()); | 290 | assert_eq!("T", pred.type_ref().unwrap().syntax().text().to_string()); |
291 | assert_bound("Clone", bounds.next()); | 291 | assert_bound("Clone", bounds.next()); |
292 | assert_bound("Copy", bounds.next()); | 292 | assert_bound("Copy", bounds.next()); |
@@ -325,7 +325,7 @@ where | |||
325 | let mut bounds = pred.type_bound_list().unwrap().bounds(); | 325 | let mut bounds = pred.type_bound_list().unwrap().bounds(); |
326 | 326 | ||
327 | assert!(pred.for_token().is_some()); | 327 | assert!(pred.for_token().is_some()); |
328 | assert_eq!("<'a>", pred.type_param_list().unwrap().syntax().text().to_string()); | 328 | assert_eq!("<'a>", pred.generic_param_list().unwrap().syntax().text().to_string()); |
329 | assert_eq!("F", pred.type_ref().unwrap().syntax().text().to_string()); | 329 | assert_eq!("F", pred.type_ref().unwrap().syntax().text().to_string()); |
330 | assert_bound("Fn(&'a str)", bounds.next()); | 330 | assert_bound("Fn(&'a str)", bounds.next()); |
331 | } | 331 | } |
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs index 2ef173a03..8d3e42f25 100644 --- a/crates/ra_syntax/src/ast/edit.rs +++ b/crates/ra_syntax/src/ast/edit.rs | |||
@@ -29,9 +29,9 @@ impl ast::BinExpr { | |||
29 | } | 29 | } |
30 | } | 30 | } |
31 | 31 | ||
32 | impl ast::FnDef { | 32 | impl ast::Fn { |
33 | #[must_use] | 33 | #[must_use] |
34 | pub fn with_body(&self, body: ast::BlockExpr) -> ast::FnDef { | 34 | pub fn with_body(&self, body: ast::BlockExpr) -> ast::Fn { |
35 | let mut to_insert: ArrayVec<[SyntaxElement; 2]> = ArrayVec::new(); | 35 | let mut to_insert: ArrayVec<[SyntaxElement; 2]> = ArrayVec::new(); |
36 | let old_body_or_semi: SyntaxElement = if let Some(old_body) = self.body() { | 36 | let old_body_or_semi: SyntaxElement = if let Some(old_body) = self.body() { |
37 | old_body.syntax().clone().into() | 37 | old_body.syntax().clone().into() |
@@ -80,9 +80,12 @@ where | |||
80 | } | 80 | } |
81 | } | 81 | } |
82 | 82 | ||
83 | impl ast::ItemList { | 83 | impl ast::AssocItemList { |
84 | #[must_use] | 84 | #[must_use] |
85 | pub fn append_items(&self, items: impl IntoIterator<Item = ast::AssocItem>) -> ast::ItemList { | 85 | pub fn append_items( |
86 | &self, | ||
87 | items: impl IntoIterator<Item = ast::AssocItem>, | ||
88 | ) -> ast::AssocItemList { | ||
86 | let mut res = self.clone(); | 89 | let mut res = self.clone(); |
87 | if !self.syntax().text().contains_char('\n') { | 90 | if !self.syntax().text().contains_char('\n') { |
88 | res = make_multiline(res); | 91 | res = make_multiline(res); |
@@ -92,7 +95,7 @@ impl ast::ItemList { | |||
92 | } | 95 | } |
93 | 96 | ||
94 | #[must_use] | 97 | #[must_use] |
95 | pub fn append_item(&self, item: ast::AssocItem) -> ast::ItemList { | 98 | pub fn append_item(&self, item: ast::AssocItem) -> ast::AssocItemList { |
96 | let (indent, position) = match self.assoc_items().last() { | 99 | let (indent, position) = match self.assoc_items().last() { |
97 | Some(it) => ( | 100 | Some(it) => ( |
98 | leading_indent(it.syntax()).unwrap_or_default().to_string(), | 101 | leading_indent(it.syntax()).unwrap_or_default().to_string(), |
@@ -113,18 +116,18 @@ impl ast::ItemList { | |||
113 | } | 116 | } |
114 | } | 117 | } |
115 | 118 | ||
116 | impl ast::RecordFieldList { | 119 | impl ast::RecordExprFieldList { |
117 | #[must_use] | 120 | #[must_use] |
118 | pub fn append_field(&self, field: &ast::RecordField) -> ast::RecordFieldList { | 121 | pub fn append_field(&self, field: &ast::RecordExprField) -> ast::RecordExprFieldList { |
119 | self.insert_field(InsertPosition::Last, field) | 122 | self.insert_field(InsertPosition::Last, field) |
120 | } | 123 | } |
121 | 124 | ||
122 | #[must_use] | 125 | #[must_use] |
123 | pub fn insert_field( | 126 | pub fn insert_field( |
124 | &self, | 127 | &self, |
125 | position: InsertPosition<&'_ ast::RecordField>, | 128 | position: InsertPosition<&'_ ast::RecordExprField>, |
126 | field: &ast::RecordField, | 129 | field: &ast::RecordExprField, |
127 | ) -> ast::RecordFieldList { | 130 | ) -> ast::RecordExprFieldList { |
128 | let is_multiline = self.syntax().text().contains_char('\n'); | 131 | let is_multiline = self.syntax().text().contains_char('\n'); |
129 | let ws; | 132 | let ws; |
130 | let space = if is_multiline { | 133 | let space = if is_multiline { |
@@ -189,6 +192,21 @@ impl ast::RecordFieldList { | |||
189 | } | 192 | } |
190 | } | 193 | } |
191 | 194 | ||
195 | impl ast::TypeAlias { | ||
196 | #[must_use] | ||
197 | pub fn remove_bounds(&self) -> ast::TypeAlias { | ||
198 | let colon = match self.colon_token() { | ||
199 | Some(it) => it, | ||
200 | None => return self.clone(), | ||
201 | }; | ||
202 | let end = match self.type_bound_list() { | ||
203 | Some(it) => it.syntax().clone().into(), | ||
204 | None => colon.clone().into(), | ||
205 | }; | ||
206 | self.replace_children(colon.into()..=end, iter::empty()) | ||
207 | } | ||
208 | } | ||
209 | |||
192 | impl ast::TypeParam { | 210 | impl ast::TypeParam { |
193 | #[must_use] | 211 | #[must_use] |
194 | pub fn remove_bounds(&self) -> ast::TypeParam { | 212 | pub fn remove_bounds(&self) -> ast::TypeParam { |
@@ -244,9 +262,9 @@ impl ast::PathSegment { | |||
244 | } | 262 | } |
245 | } | 263 | } |
246 | 264 | ||
247 | impl ast::UseItem { | 265 | impl ast::Use { |
248 | #[must_use] | 266 | #[must_use] |
249 | pub fn with_use_tree(&self, use_tree: ast::UseTree) -> ast::UseItem { | 267 | pub fn with_use_tree(&self, use_tree: ast::UseTree) -> ast::Use { |
250 | if let Some(old) = self.use_tree() { | 268 | if let Some(old) = self.use_tree() { |
251 | return self.replace_descendant(old, use_tree); | 269 | return self.replace_descendant(old, use_tree); |
252 | } | 270 | } |
@@ -300,9 +318,9 @@ impl ast::UseTree { | |||
300 | None => return self.clone(), | 318 | None => return self.clone(), |
301 | }; | 319 | }; |
302 | let use_tree = make::use_tree( | 320 | let use_tree = make::use_tree( |
303 | suffix.clone(), | 321 | suffix, |
304 | self.use_tree_list(), | 322 | self.use_tree_list(), |
305 | self.alias(), | 323 | self.rename(), |
306 | self.star_token().is_some(), | 324 | self.star_token().is_some(), |
307 | ); | 325 | ); |
308 | let nested = make::use_tree_list(iter::once(use_tree)); | 326 | let nested = make::use_tree_list(iter::once(use_tree)); |
diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_ext.rs index db5438d68..f5ba87223 100644 --- a/crates/ra_syntax/src/ast/expr_extensions.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 | ||
10 | impl ast::AttrsOwner for ast::Expr {} | ||
11 | |||
10 | impl ast::Expr { | 12 | impl ast::Expr { |
11 | pub fn is_block_like(&self) -> bool { | 13 | pub fn is_block_like(&self) -> bool { |
12 | match self { | 14 | match self { |
@@ -331,13 +333,12 @@ impl ast::Literal { | |||
331 | 333 | ||
332 | match token.kind() { | 334 | match token.kind() { |
333 | INT_NUMBER => { | 335 | INT_NUMBER => { |
334 | // FYI: there was a bug here previously, thus an if statement bellow is necessary. | 336 | // FYI: there was a bug here previously, thus the if statement below is necessary. |
335 | // The lexer treats e.g. `1f64` as an integer literal. See | 337 | // The lexer treats e.g. `1f64` as an integer literal. See |
336 | // https://github.com/rust-analyzer/rust-analyzer/issues/1592 | 338 | // https://github.com/rust-analyzer/rust-analyzer/issues/1592 |
337 | // and the comments on the linked PR. | 339 | // and the comments on the linked PR. |
338 | 340 | ||
339 | let text = token.text(); | 341 | let text = token.text(); |
340 | |||
341 | if let suffix @ Some(_) = Self::find_suffix(&text, &FLOAT_SUFFIXES) { | 342 | if let suffix @ Some(_) = Self::find_suffix(&text, &FLOAT_SUFFIXES) { |
342 | LiteralKind::FloatNumber { suffix } | 343 | LiteralKind::FloatNumber { suffix } |
343 | } else { | 344 | } else { |
@@ -399,7 +400,7 @@ impl ast::BlockExpr { | |||
399 | Some(it) => it, | 400 | Some(it) => it, |
400 | None => return true, | 401 | None => return true, |
401 | }; | 402 | }; |
402 | !matches!(parent.kind(), FN_DEF | IF_EXPR | WHILE_EXPR | LOOP_EXPR | EFFECT_EXPR) | 403 | !matches!(parent.kind(), FN | IF_EXPR | WHILE_EXPR | LOOP_EXPR | EFFECT_EXPR) |
403 | } | 404 | } |
404 | } | 405 | } |
405 | 406 | ||
@@ -410,8 +411,8 @@ fn test_literal_with_attr() { | |||
410 | assert_eq!(lit.token().text(), r#""Hello""#); | 411 | assert_eq!(lit.token().text(), r#""Hello""#); |
411 | } | 412 | } |
412 | 413 | ||
413 | impl ast::RecordField { | 414 | impl ast::RecordExprField { |
414 | pub fn parent_record_lit(&self) -> ast::RecordLit { | 415 | pub fn parent_record_lit(&self) -> ast::RecordExpr { |
415 | self.syntax().ancestors().find_map(ast::RecordLit::cast).unwrap() | 416 | self.syntax().ancestors().find_map(ast::RecordExpr::cast).unwrap() |
416 | } | 417 | } |
417 | } | 418 | } |
diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index 58141da11..4306efe13 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs | |||
@@ -5,557 +5,529 @@ 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)] |
12 | pub struct SourceFile { | 9 | pub struct SourceFile { |
13 | pub(crate) syntax: SyntaxNode, | 10 | pub(crate) syntax: SyntaxNode, |
14 | } | 11 | } |
15 | impl ast::ModuleItemOwner for SourceFile {} | ||
16 | impl ast::AttrsOwner for SourceFile {} | 12 | impl ast::AttrsOwner for SourceFile {} |
17 | impl ast::DocCommentsOwner for SourceFile {} | 13 | impl ast::ModuleItemOwner for SourceFile {} |
18 | impl SourceFile { | 14 | impl SourceFile { |
19 | pub fn modules(&self) -> AstChildren<Module> { support::children(&self.syntax) } | 15 | pub fn shebang_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![shebang]) } |
20 | } | 16 | } |
21 | /// Function definition either with body or not. | 17 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
22 | /// Includes all of its attributes and doc comments. | 18 | pub struct Attr { |
23 | /// | ||
24 | /// ``` | ||
25 | /// ❰ | ||
26 | /// /// Docs | ||
27 | /// #[attr] | ||
28 | /// pub extern "C" fn foo<T>(#[attr] Patern {p}: Pattern) -> u32 | ||
29 | /// where | ||
30 | /// T: Debug | ||
31 | /// { | ||
32 | /// 42 | ||
33 | /// } | ||
34 | /// ❱ | ||
35 | /// | ||
36 | /// extern "C" { | ||
37 | /// ❰ fn fn_decl(also_variadic_ffi: u32, ...) -> u32; ❱ | ||
38 | /// } | ||
39 | /// ``` | ||
40 | /// | ||
41 | /// - [Reference](https://doc.rust-lang.org/reference/items/functions.html) | ||
42 | /// - [Nomicon](https://doc.rust-lang.org/nomicon/ffi.html#variadic-functions) | ||
43 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
44 | pub struct FnDef { | ||
45 | pub(crate) syntax: SyntaxNode, | 19 | pub(crate) syntax: SyntaxNode, |
46 | } | 20 | } |
47 | impl ast::VisibilityOwner for FnDef {} | 21 | impl Attr { |
48 | impl ast::NameOwner for FnDef {} | 22 | pub fn pound_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![#]) } |
49 | impl ast::TypeParamsOwner for FnDef {} | 23 | pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) } |
50 | impl ast::DocCommentsOwner for FnDef {} | 24 | pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } |
51 | impl ast::AttrsOwner for FnDef {} | 25 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } |
52 | impl FnDef { | 26 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } |
53 | pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) } | 27 | pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) } |
28 | pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) } | ||
29 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | ||
30 | } | ||
31 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
32 | pub struct Const { | ||
33 | pub(crate) syntax: SyntaxNode, | ||
34 | } | ||
35 | impl ast::AttrsOwner for Const {} | ||
36 | impl ast::NameOwner for Const {} | ||
37 | impl ast::VisibilityOwner for Const {} | ||
38 | impl Const { | ||
39 | pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) } | ||
54 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } | 40 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } |
41 | pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) } | ||
42 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } | ||
43 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
44 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | ||
45 | pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
46 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | ||
47 | } | ||
48 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
49 | pub struct Enum { | ||
50 | pub(crate) syntax: SyntaxNode, | ||
51 | } | ||
52 | impl ast::AttrsOwner for Enum {} | ||
53 | impl ast::NameOwner for Enum {} | ||
54 | impl ast::VisibilityOwner for Enum {} | ||
55 | impl ast::GenericParamsOwner for Enum {} | ||
56 | impl Enum { | ||
57 | pub fn enum_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![enum]) } | ||
58 | pub fn variant_list(&self) -> Option<VariantList> { support::child(&self.syntax) } | ||
59 | } | ||
60 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
61 | pub struct ExternBlock { | ||
62 | pub(crate) syntax: SyntaxNode, | ||
63 | } | ||
64 | impl ast::AttrsOwner for ExternBlock {} | ||
65 | impl ExternBlock { | ||
66 | pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) } | ||
67 | pub fn extern_item_list(&self) -> Option<ExternItemList> { support::child(&self.syntax) } | ||
68 | } | ||
69 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
70 | pub struct ExternCrate { | ||
71 | pub(crate) syntax: SyntaxNode, | ||
72 | } | ||
73 | impl ast::AttrsOwner for ExternCrate {} | ||
74 | impl ast::VisibilityOwner for ExternCrate {} | ||
75 | impl ExternCrate { | ||
76 | pub fn extern_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![extern]) } | ||
77 | pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) } | ||
78 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } | ||
79 | pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) } | ||
80 | pub fn rename(&self) -> Option<Rename> { support::child(&self.syntax) } | ||
81 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | ||
82 | } | ||
83 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
84 | pub struct Fn { | ||
85 | pub(crate) syntax: SyntaxNode, | ||
86 | } | ||
87 | impl ast::AttrsOwner for Fn {} | ||
88 | impl ast::NameOwner for Fn {} | ||
89 | impl ast::VisibilityOwner for Fn {} | ||
90 | impl ast::GenericParamsOwner for Fn {} | ||
91 | impl Fn { | ||
55 | pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) } | 92 | pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) } |
56 | pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) } | 93 | pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) } |
94 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } | ||
57 | pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) } | 95 | pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) } |
96 | pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) } | ||
58 | pub fn fn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![fn]) } | 97 | pub fn fn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![fn]) } |
59 | pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) } | 98 | pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) } |
60 | pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } | 99 | pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } |
61 | pub fn body(&self) -> Option<BlockExpr> { support::child(&self.syntax) } | 100 | pub fn body(&self) -> Option<BlockExpr> { support::child(&self.syntax) } |
62 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 101 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
63 | } | 102 | } |
64 | /// Return type annotation. | ||
65 | /// | ||
66 | /// ``` | ||
67 | /// fn foo(a: u32) ❰ -> Option<u32> ❱ { Some(a) } | ||
68 | /// ``` | ||
69 | /// | ||
70 | /// [Reference](https://doc.rust-lang.org/reference/items/functions.html) | ||
71 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 103 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
72 | pub struct RetType { | 104 | pub struct Impl { |
73 | pub(crate) syntax: SyntaxNode, | 105 | pub(crate) syntax: SyntaxNode, |
74 | } | 106 | } |
75 | impl RetType { | 107 | impl ast::AttrsOwner for Impl {} |
76 | pub fn thin_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![->]) } | 108 | impl ast::VisibilityOwner for Impl {} |
109 | impl ast::GenericParamsOwner for Impl {} | ||
110 | impl Impl { | ||
111 | pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) } | ||
112 | pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) } | ||
113 | pub fn impl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![impl]) } | ||
114 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } | ||
77 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 115 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
116 | pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) } | ||
117 | pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) } | ||
118 | pub fn assoc_item_list(&self) -> Option<AssocItemList> { support::child(&self.syntax) } | ||
119 | } | ||
120 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
121 | pub struct MacroCall { | ||
122 | pub(crate) syntax: SyntaxNode, | ||
123 | } | ||
124 | impl ast::AttrsOwner for MacroCall {} | ||
125 | impl ast::NameOwner for MacroCall {} | ||
126 | impl MacroCall { | ||
127 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | ||
128 | pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) } | ||
129 | pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) } | ||
130 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | ||
131 | } | ||
132 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
133 | pub struct Module { | ||
134 | pub(crate) syntax: SyntaxNode, | ||
135 | } | ||
136 | impl ast::AttrsOwner for Module {} | ||
137 | impl ast::NameOwner for Module {} | ||
138 | impl ast::VisibilityOwner for Module {} | ||
139 | impl Module { | ||
140 | pub fn mod_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mod]) } | ||
141 | pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } | ||
142 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | ||
143 | } | ||
144 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
145 | pub struct Static { | ||
146 | pub(crate) syntax: SyntaxNode, | ||
147 | } | ||
148 | impl ast::AttrsOwner for Static {} | ||
149 | impl ast::NameOwner for Static {} | ||
150 | impl ast::VisibilityOwner for Static {} | ||
151 | impl Static { | ||
152 | pub fn static_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![static]) } | ||
153 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } | ||
154 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } | ||
155 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
156 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | ||
157 | pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
158 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | ||
78 | } | 159 | } |
79 | /// Struct definition. | 160 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
80 | /// Includes all of its attributes and doc comments. | 161 | pub struct Struct { |
81 | /// | ||
82 | /// ``` | ||
83 | /// ❰ | ||
84 | /// /// Docs | ||
85 | /// #[attr] | ||
86 | /// struct Foo<T> where T: Debug { | ||
87 | /// /// Docs | ||
88 | /// #[attr] | ||
89 | /// pub a: u32, | ||
90 | /// b: T, | ||
91 | /// } | ||
92 | /// ❱ | ||
93 | /// | ||
94 | /// ❰ struct Foo; ❱ | ||
95 | /// ❰ struct Foo<T>(#[attr] T) where T: Debug; ❱ | ||
96 | /// ``` | ||
97 | /// | ||
98 | /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) | ||
99 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
100 | pub struct StructDef { | ||
101 | pub(crate) syntax: SyntaxNode, | 162 | pub(crate) syntax: SyntaxNode, |
102 | } | 163 | } |
103 | impl ast::VisibilityOwner for StructDef {} | 164 | impl ast::AttrsOwner for Struct {} |
104 | impl ast::NameOwner for StructDef {} | 165 | impl ast::NameOwner for Struct {} |
105 | impl ast::TypeParamsOwner for StructDef {} | 166 | impl ast::VisibilityOwner for Struct {} |
106 | impl ast::AttrsOwner for StructDef {} | 167 | impl ast::GenericParamsOwner for Struct {} |
107 | impl ast::DocCommentsOwner for StructDef {} | 168 | impl Struct { |
108 | impl StructDef { | ||
109 | pub fn struct_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![struct]) } | 169 | 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![;]) } | 170 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
171 | pub fn field_list(&self) -> Option<FieldList> { support::child(&self.syntax) } | ||
112 | } | 172 | } |
113 | /// Union definition. | 173 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
114 | /// Includes all of its attributes and doc comments. | 174 | pub struct Trait { |
115 | /// | 175 | pub(crate) syntax: SyntaxNode, |
116 | /// ``` | 176 | } |
117 | /// ❰ | 177 | impl ast::AttrsOwner for Trait {} |
118 | /// /// Docs | 178 | impl ast::NameOwner for Trait {} |
119 | /// #[attr] | 179 | impl ast::VisibilityOwner for Trait {} |
120 | /// pub union Foo<T> where T: Debug { | 180 | impl ast::GenericParamsOwner for Trait {} |
121 | /// /// Docs | 181 | impl ast::TypeBoundsOwner for Trait {} |
122 | /// #[attr] | 182 | impl Trait { |
123 | /// a: T, | 183 | pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) } |
124 | /// b: u32, | 184 | pub fn auto_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![auto]) } |
125 | /// } | 185 | pub fn trait_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![trait]) } |
126 | /// ❱ | 186 | pub fn assoc_item_list(&self) -> Option<AssocItemList> { support::child(&self.syntax) } |
127 | /// ``` | 187 | } |
128 | /// | 188 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
129 | /// [Reference](https://doc.rust-lang.org/reference/items/unions.html) | 189 | pub struct TypeAlias { |
130 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
131 | pub struct UnionDef { | ||
132 | pub(crate) syntax: SyntaxNode, | 190 | pub(crate) syntax: SyntaxNode, |
133 | } | 191 | } |
134 | impl ast::VisibilityOwner for UnionDef {} | 192 | impl ast::AttrsOwner for TypeAlias {} |
135 | impl ast::NameOwner for UnionDef {} | 193 | impl ast::NameOwner for TypeAlias {} |
136 | impl ast::TypeParamsOwner for UnionDef {} | 194 | impl ast::VisibilityOwner for TypeAlias {} |
137 | impl ast::AttrsOwner for UnionDef {} | 195 | impl ast::GenericParamsOwner for TypeAlias {} |
138 | impl ast::DocCommentsOwner for UnionDef {} | 196 | impl ast::TypeBoundsOwner for TypeAlias {} |
139 | impl UnionDef { | 197 | impl TypeAlias { |
198 | pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) } | ||
199 | pub fn type_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![type]) } | ||
200 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | ||
201 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
202 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | ||
203 | } | ||
204 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
205 | pub struct Union { | ||
206 | pub(crate) syntax: SyntaxNode, | ||
207 | } | ||
208 | impl ast::AttrsOwner for Union {} | ||
209 | impl ast::NameOwner for Union {} | ||
210 | impl ast::VisibilityOwner for Union {} | ||
211 | impl ast::GenericParamsOwner for Union {} | ||
212 | impl Union { | ||
140 | pub fn union_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![union]) } | 213 | pub fn union_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![union]) } |
141 | pub fn record_field_def_list(&self) -> Option<RecordFieldDefList> { | 214 | pub fn record_field_list(&self) -> Option<RecordFieldList> { support::child(&self.syntax) } |
142 | support::child(&self.syntax) | 215 | } |
143 | } | 216 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
217 | pub struct Use { | ||
218 | pub(crate) syntax: SyntaxNode, | ||
219 | } | ||
220 | impl ast::AttrsOwner for Use {} | ||
221 | impl ast::VisibilityOwner for Use {} | ||
222 | impl Use { | ||
223 | pub fn use_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![use]) } | ||
224 | pub fn use_tree(&self) -> Option<UseTree> { support::child(&self.syntax) } | ||
225 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | ||
226 | } | ||
227 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
228 | pub struct Visibility { | ||
229 | pub(crate) syntax: SyntaxNode, | ||
230 | } | ||
231 | impl Visibility { | ||
232 | pub fn pub_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![pub]) } | ||
233 | pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } | ||
234 | pub fn super_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![super]) } | ||
235 | pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) } | ||
236 | pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) } | ||
237 | pub fn in_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![in]) } | ||
238 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | ||
239 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | ||
240 | } | ||
241 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
242 | pub struct Name { | ||
243 | pub(crate) syntax: SyntaxNode, | ||
244 | } | ||
245 | impl Name { | ||
246 | pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) } | ||
247 | } | ||
248 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
249 | pub struct ItemList { | ||
250 | pub(crate) syntax: SyntaxNode, | ||
251 | } | ||
252 | impl ast::AttrsOwner for ItemList {} | ||
253 | impl ast::ModuleItemOwner for ItemList {} | ||
254 | impl ItemList { | ||
255 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | ||
256 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | ||
257 | } | ||
258 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
259 | pub struct NameRef { | ||
260 | pub(crate) syntax: SyntaxNode, | ||
144 | } | 261 | } |
145 | /// Record field definition list including enclosing curly braces. | 262 | impl NameRef { |
146 | /// | 263 | pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) } |
147 | /// ``` | 264 | } |
148 | /// struct Foo // same for union | 265 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
149 | /// ❰ | 266 | pub struct Rename { |
150 | /// { | 267 | pub(crate) syntax: SyntaxNode, |
151 | /// a: u32, | 268 | } |
152 | /// b: bool, | 269 | impl ast::NameOwner for Rename {} |
153 | /// } | 270 | impl Rename { |
154 | /// ❱ | 271 | pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) } |
155 | /// ``` | 272 | pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) } |
156 | /// | 273 | } |
157 | /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) | 274 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
158 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 275 | pub struct UseTree { |
159 | pub struct RecordFieldDefList { | 276 | pub(crate) syntax: SyntaxNode, |
277 | } | ||
278 | impl UseTree { | ||
279 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | ||
280 | pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) } | ||
281 | pub fn star_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![*]) } | ||
282 | pub fn use_tree_list(&self) -> Option<UseTreeList> { support::child(&self.syntax) } | ||
283 | pub fn rename(&self) -> Option<Rename> { support::child(&self.syntax) } | ||
284 | } | ||
285 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
286 | pub struct Path { | ||
287 | pub(crate) syntax: SyntaxNode, | ||
288 | } | ||
289 | impl Path { | ||
290 | pub fn qualifier(&self) -> Option<Path> { support::child(&self.syntax) } | ||
291 | pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) } | ||
292 | pub fn segment(&self) -> Option<PathSegment> { support::child(&self.syntax) } | ||
293 | } | ||
294 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
295 | pub struct UseTreeList { | ||
160 | pub(crate) syntax: SyntaxNode, | 296 | pub(crate) syntax: SyntaxNode, |
161 | } | 297 | } |
162 | impl RecordFieldDefList { | 298 | impl UseTreeList { |
163 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | 299 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } |
164 | pub fn fields(&self) -> AstChildren<RecordFieldDef> { support::children(&self.syntax) } | 300 | pub fn use_trees(&self) -> AstChildren<UseTree> { support::children(&self.syntax) } |
165 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 301 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
166 | } | 302 | } |
167 | /// Record field definition including its attributes and doc comments. | 303 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
168 | /// | 304 | pub struct Abi { |
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)] | ||
184 | pub struct RecordFieldDef { | ||
185 | pub(crate) syntax: SyntaxNode, | 305 | pub(crate) syntax: SyntaxNode, |
186 | } | 306 | } |
187 | impl ast::VisibilityOwner for RecordFieldDef {} | 307 | impl Abi { |
188 | impl ast::NameOwner for RecordFieldDef {} | 308 | pub fn extern_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![extern]) } |
189 | impl ast::AttrsOwner for RecordFieldDef {} | 309 | } |
190 | impl ast::DocCommentsOwner for RecordFieldDef {} | 310 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
191 | impl ast::TypeAscriptionOwner for RecordFieldDef {} | 311 | pub struct GenericParamList { |
192 | impl RecordFieldDef {} | 312 | pub(crate) syntax: SyntaxNode, |
193 | /// Tuple field definition list including enclosing parens. | 313 | } |
194 | /// | 314 | impl GenericParamList { |
195 | /// ``` | 315 | pub fn l_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![<]) } |
196 | /// struct Foo ❰ (u32, String, Vec<u32>) ❱; | 316 | pub fn generic_params(&self) -> AstChildren<GenericParam> { support::children(&self.syntax) } |
197 | /// ``` | 317 | pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) } |
198 | /// | 318 | } |
199 | /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) | 319 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
200 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 320 | pub struct ParamList { |
201 | pub struct TupleFieldDefList { | ||
202 | pub(crate) syntax: SyntaxNode, | 321 | pub(crate) syntax: SyntaxNode, |
203 | } | 322 | } |
204 | impl TupleFieldDefList { | 323 | impl ParamList { |
205 | pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } | 324 | pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } |
206 | pub fn fields(&self) -> AstChildren<TupleFieldDef> { support::children(&self.syntax) } | 325 | pub fn self_param(&self) -> Option<SelfParam> { support::child(&self.syntax) } |
326 | pub fn comma_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![,]) } | ||
327 | pub fn params(&self) -> AstChildren<Param> { support::children(&self.syntax) } | ||
207 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 328 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
208 | } | 329 | } |
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)] | 330 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
217 | pub struct TupleFieldDef { | 331 | pub struct RetType { |
218 | pub(crate) syntax: SyntaxNode, | 332 | pub(crate) syntax: SyntaxNode, |
219 | } | 333 | } |
220 | impl ast::VisibilityOwner for TupleFieldDef {} | 334 | impl RetType { |
221 | impl ast::AttrsOwner for TupleFieldDef {} | 335 | pub fn thin_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![->]) } |
222 | impl TupleFieldDef { | 336 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
223 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
224 | } | 337 | } |
225 | /// Enum definition. | 338 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
226 | /// Includes all of its attributes and doc comments. | 339 | pub struct WhereClause { |
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)] | ||
249 | pub struct EnumDef { | ||
250 | pub(crate) syntax: SyntaxNode, | 340 | pub(crate) syntax: SyntaxNode, |
251 | } | 341 | } |
252 | impl ast::VisibilityOwner for EnumDef {} | 342 | impl WhereClause { |
253 | impl ast::NameOwner for EnumDef {} | 343 | pub fn where_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![where]) } |
254 | impl ast::TypeParamsOwner for EnumDef {} | 344 | pub fn predicates(&self) -> AstChildren<WherePred> { support::children(&self.syntax) } |
255 | impl ast::AttrsOwner for EnumDef {} | 345 | } |
256 | impl ast::DocCommentsOwner for EnumDef {} | 346 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
257 | impl EnumDef { | 347 | pub struct BlockExpr { |
258 | 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) } | ||
260 | } | ||
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)] | ||
278 | pub struct EnumVariantList { | ||
279 | pub(crate) syntax: SyntaxNode, | 348 | pub(crate) syntax: SyntaxNode, |
280 | } | 349 | } |
281 | impl EnumVariantList { | 350 | impl ast::AttrsOwner for BlockExpr {} |
351 | impl ast::ModuleItemOwner for BlockExpr {} | ||
352 | impl BlockExpr { | ||
353 | pub fn label(&self) -> Option<Label> { support::child(&self.syntax) } | ||
282 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | 354 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } |
283 | pub fn variants(&self) -> AstChildren<EnumVariant> { support::children(&self.syntax) } | 355 | pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) } |
356 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
284 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 357 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
285 | } | 358 | } |
286 | /// Enum variant definition including its attributes and discriminant value definition. | 359 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
287 | /// | 360 | pub struct SelfParam { |
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)] | ||
302 | pub struct EnumVariant { | ||
303 | pub(crate) syntax: SyntaxNode, | 361 | pub(crate) syntax: SyntaxNode, |
304 | } | 362 | } |
305 | impl ast::VisibilityOwner for EnumVariant {} | 363 | impl ast::AttrsOwner for SelfParam {} |
306 | impl ast::NameOwner for EnumVariant {} | 364 | impl SelfParam { |
307 | impl ast::DocCommentsOwner for EnumVariant {} | 365 | pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) } |
308 | impl ast::AttrsOwner for EnumVariant {} | 366 | pub fn lifetime_token(&self) -> Option<SyntaxToken> { |
309 | impl EnumVariant { | 367 | support::token(&self.syntax, T![lifetime]) |
310 | pub fn field_def_list(&self) -> Option<FieldDefList> { support::child(&self.syntax) } | 368 | } |
311 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | 369 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } |
312 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 370 | pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) } |
371 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } | ||
372 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
313 | } | 373 | } |
314 | /// Trait definition. | 374 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
315 | /// Includes all of its attributes and doc comments. | 375 | pub struct Param { |
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)] | ||
329 | pub struct TraitDef { | ||
330 | pub(crate) syntax: SyntaxNode, | 376 | pub(crate) syntax: SyntaxNode, |
331 | } | 377 | } |
332 | impl ast::VisibilityOwner for TraitDef {} | 378 | impl ast::AttrsOwner for Param {} |
333 | impl ast::NameOwner for TraitDef {} | 379 | impl Param { |
334 | impl ast::AttrsOwner for TraitDef {} | 380 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } |
335 | impl ast::DocCommentsOwner for TraitDef {} | 381 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } |
336 | impl ast::TypeParamsOwner for TraitDef {} | 382 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
337 | impl ast::TypeBoundsOwner for TraitDef {} | 383 | pub fn dotdotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![...]) } |
338 | impl TraitDef { | ||
339 | pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) } | ||
340 | pub fn auto_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![auto]) } | ||
341 | 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) } | ||
343 | } | 384 | } |
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)] | 385 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
366 | pub struct Module { | 386 | pub struct TypeBoundList { |
367 | pub(crate) syntax: SyntaxNode, | 387 | pub(crate) syntax: SyntaxNode, |
368 | } | 388 | } |
369 | impl ast::VisibilityOwner for Module {} | 389 | impl TypeBoundList { |
370 | impl ast::NameOwner for Module {} | 390 | pub fn bounds(&self) -> AstChildren<TypeBound> { support::children(&self.syntax) } |
371 | impl ast::AttrsOwner for Module {} | ||
372 | impl ast::DocCommentsOwner for Module {} | ||
373 | impl 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 | } | 391 | } |
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)] | 392 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
401 | pub struct ItemList { | 393 | pub struct RecordFieldList { |
402 | pub(crate) syntax: SyntaxNode, | 394 | pub(crate) syntax: SyntaxNode, |
403 | } | 395 | } |
404 | impl ast::ModuleItemOwner for ItemList {} | 396 | impl RecordFieldList { |
405 | impl ItemList { | ||
406 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | 397 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } |
407 | pub fn assoc_items(&self) -> AstChildren<AssocItem> { support::children(&self.syntax) } | 398 | pub fn fields(&self) -> AstChildren<RecordField> { support::children(&self.syntax) } |
408 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 399 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
409 | } | 400 | } |
410 | /// Constant variable definition. | 401 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
411 | /// Includes all of its attributes and doc comments. | 402 | pub struct TupleFieldList { |
412 | /// | ||
413 | /// ``` | ||
414 | /// ❰ | ||
415 | /// /// Docs | ||
416 | /// #[attr] | ||
417 | /// pub const FOO: u32 = 42; | ||
418 | /// ❱ | ||
419 | /// ``` | ||
420 | /// | ||
421 | /// [Reference](https://doc.rust-lang.org/reference/items/constant-items.html) | ||
422 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
423 | pub struct ConstDef { | ||
424 | pub(crate) syntax: SyntaxNode, | 403 | pub(crate) syntax: SyntaxNode, |
425 | } | 404 | } |
426 | impl ast::VisibilityOwner for ConstDef {} | 405 | impl TupleFieldList { |
427 | impl ast::NameOwner for ConstDef {} | 406 | pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } |
428 | impl ast::TypeParamsOwner for ConstDef {} | 407 | pub fn fields(&self) -> AstChildren<TupleField> { support::children(&self.syntax) } |
429 | impl ast::AttrsOwner for ConstDef {} | 408 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
430 | impl ast::DocCommentsOwner for ConstDef {} | 409 | } |
431 | impl ast::TypeAscriptionOwner for ConstDef {} | 410 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
432 | impl ConstDef { | 411 | pub struct RecordField { |
433 | pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) } | 412 | pub(crate) syntax: SyntaxNode, |
434 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } | 413 | } |
435 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | 414 | impl ast::AttrsOwner for RecordField {} |
436 | pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } | 415 | impl ast::NameOwner for RecordField {} |
437 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 416 | impl ast::VisibilityOwner for RecordField {} |
417 | impl RecordField { | ||
418 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } | ||
419 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
438 | } | 420 | } |
439 | /// Static variable definition. | 421 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
440 | /// Includes all of its attributes and doc comments. | 422 | pub struct TupleField { |
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)] | ||
452 | pub struct StaticDef { | ||
453 | pub(crate) syntax: SyntaxNode, | 423 | pub(crate) syntax: SyntaxNode, |
454 | } | 424 | } |
455 | impl ast::VisibilityOwner for StaticDef {} | 425 | impl ast::AttrsOwner for TupleField {} |
456 | impl ast::NameOwner for StaticDef {} | 426 | impl ast::VisibilityOwner for TupleField {} |
457 | impl ast::TypeParamsOwner for StaticDef {} | 427 | impl TupleField { |
458 | impl ast::AttrsOwner for StaticDef {} | 428 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
459 | impl ast::DocCommentsOwner for StaticDef {} | 429 | } |
460 | impl ast::TypeAscriptionOwner for StaticDef {} | 430 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
461 | impl StaticDef { | 431 | pub struct VariantList { |
462 | pub fn static_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![static]) } | 432 | pub(crate) syntax: SyntaxNode, |
463 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } | 433 | } |
434 | impl VariantList { | ||
435 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | ||
436 | pub fn variants(&self) -> AstChildren<Variant> { support::children(&self.syntax) } | ||
437 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | ||
438 | } | ||
439 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
440 | pub struct Variant { | ||
441 | pub(crate) syntax: SyntaxNode, | ||
442 | } | ||
443 | impl ast::AttrsOwner for Variant {} | ||
444 | impl ast::NameOwner for Variant {} | ||
445 | impl ast::VisibilityOwner for Variant {} | ||
446 | impl Variant { | ||
447 | pub fn field_list(&self) -> Option<FieldList> { support::child(&self.syntax) } | ||
464 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | 448 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } |
465 | pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } | 449 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
466 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | ||
467 | } | 450 | } |
468 | /// Type alias definition. | 451 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
469 | /// Includes associated type clauses with type bounds. | 452 | pub struct AssocItemList { |
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)] | ||
487 | pub struct TypeAliasDef { | ||
488 | pub(crate) syntax: SyntaxNode, | 453 | pub(crate) syntax: SyntaxNode, |
489 | } | 454 | } |
490 | impl ast::VisibilityOwner for TypeAliasDef {} | 455 | impl ast::AttrsOwner for AssocItemList {} |
491 | impl ast::NameOwner for TypeAliasDef {} | 456 | impl AssocItemList { |
492 | impl ast::TypeParamsOwner for TypeAliasDef {} | 457 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } |
493 | impl ast::AttrsOwner for TypeAliasDef {} | 458 | pub fn assoc_items(&self) -> AstChildren<AssocItem> { support::children(&self.syntax) } |
494 | impl ast::DocCommentsOwner for TypeAliasDef {} | 459 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
495 | impl ast::TypeBoundsOwner for TypeAliasDef {} | 460 | } |
496 | impl TypeAliasDef { | 461 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
497 | pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) } | 462 | pub struct ExternItemList { |
498 | pub fn type_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![type]) } | 463 | pub(crate) syntax: SyntaxNode, |
464 | } | ||
465 | impl ast::AttrsOwner for ExternItemList {} | ||
466 | impl ExternItemList { | ||
467 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | ||
468 | pub fn extern_items(&self) -> AstChildren<ExternItem> { support::children(&self.syntax) } | ||
469 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | ||
470 | } | ||
471 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
472 | pub struct LifetimeParam { | ||
473 | pub(crate) syntax: SyntaxNode, | ||
474 | } | ||
475 | impl ast::AttrsOwner for LifetimeParam {} | ||
476 | impl LifetimeParam { | ||
477 | pub fn lifetime_token(&self) -> Option<SyntaxToken> { | ||
478 | support::token(&self.syntax, T![lifetime]) | ||
479 | } | ||
480 | } | ||
481 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
482 | pub struct TypeParam { | ||
483 | pub(crate) syntax: SyntaxNode, | ||
484 | } | ||
485 | impl ast::AttrsOwner for TypeParam {} | ||
486 | impl ast::NameOwner for TypeParam {} | ||
487 | impl ast::TypeBoundsOwner for TypeParam {} | ||
488 | impl TypeParam { | ||
499 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | 489 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } |
500 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 490 | pub fn default_type(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
501 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | ||
502 | } | 491 | } |
503 | /// Inherent and trait impl definition. | 492 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
504 | /// Includes all of its inner and outer attributes. | 493 | pub struct ConstParam { |
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)] | ||
518 | pub struct ImplDef { | ||
519 | pub(crate) syntax: SyntaxNode, | 494 | pub(crate) syntax: SyntaxNode, |
520 | } | 495 | } |
521 | impl ast::TypeParamsOwner for ImplDef {} | 496 | impl ast::AttrsOwner for ConstParam {} |
522 | impl ast::AttrsOwner for ImplDef {} | 497 | impl ast::NameOwner for ConstParam {} |
523 | impl ast::DocCommentsOwner for ImplDef {} | 498 | impl ConstParam { |
524 | impl 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]) } | 499 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } |
527 | pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) } | 500 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } |
528 | pub fn impl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![impl]) } | 501 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
529 | pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) } | 502 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } |
530 | pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) } | 503 | pub fn default_val(&self) -> Option<Expr> { support::child(&self.syntax) } |
531 | pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } | 504 | } |
505 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
506 | pub struct Literal { | ||
507 | pub(crate) syntax: SyntaxNode, | ||
508 | } | ||
509 | impl Literal {} | ||
510 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
511 | pub struct TokenTree { | ||
512 | pub(crate) syntax: SyntaxNode, | ||
513 | } | ||
514 | impl TokenTree { | ||
515 | pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } | ||
516 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | ||
517 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | ||
518 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | ||
519 | pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } | ||
520 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | ||
532 | } | 521 | } |
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)] | 522 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
544 | pub struct ParenType { | 523 | pub struct ParenType { |
545 | pub(crate) syntax: SyntaxNode, | 524 | pub(crate) syntax: SyntaxNode, |
546 | } | 525 | } |
547 | impl ParenType { | 526 | impl ParenType { |
548 | pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } | 527 | pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } |
549 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 528 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
550 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 529 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
551 | } | 530 | } |
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)] | 531 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
560 | pub struct TupleType { | 532 | pub struct TupleType { |
561 | pub(crate) syntax: SyntaxNode, | 533 | pub(crate) syntax: SyntaxNode, |
@@ -565,17 +537,6 @@ impl TupleType { | |||
565 | pub fn fields(&self) -> AstChildren<TypeRef> { support::children(&self.syntax) } | 537 | pub fn fields(&self) -> AstChildren<TypeRef> { support::children(&self.syntax) } |
566 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 538 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
567 | } | 539 | } |
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)] | 540 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
580 | pub struct NeverType { | 541 | pub struct NeverType { |
581 | pub(crate) syntax: SyntaxNode, | 542 | pub(crate) syntax: SyntaxNode, |
@@ -583,17 +544,6 @@ pub struct NeverType { | |||
583 | impl NeverType { | 544 | impl NeverType { |
584 | pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) } | 545 | pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) } |
585 | } | 546 | } |
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)] | 547 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
598 | pub struct PathType { | 548 | pub struct PathType { |
599 | pub(crate) syntax: SyntaxNode, | 549 | pub(crate) syntax: SyntaxNode, |
@@ -601,14 +551,6 @@ pub struct PathType { | |||
601 | impl PathType { | 551 | impl PathType { |
602 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | 552 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } |
603 | } | 553 | } |
604 | /// Raw pointer type. | ||
605 | /// | ||
606 | /// ``` | ||
607 | /// type Foo = ❰ *const u32 ❱; | ||
608 | /// type Bar = ❰ *mut u32 ❱; | ||
609 | /// ``` | ||
610 | /// | ||
611 | /// [Reference](https://doc.rust-lang.org/reference/types/pointer.html#raw-pointers-const-and-mut) | ||
612 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 554 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
613 | pub struct PointerType { | 555 | pub struct PointerType { |
614 | pub(crate) syntax: SyntaxNode, | 556 | pub(crate) syntax: SyntaxNode, |
@@ -617,49 +559,28 @@ impl PointerType { | |||
617 | pub fn star_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![*]) } | 559 | pub fn star_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![*]) } |
618 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } | 560 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } |
619 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } | 561 | 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) } | 562 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
621 | } | 563 | } |
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)] | 564 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
630 | pub struct ArrayType { | 565 | pub struct ArrayType { |
631 | pub(crate) syntax: SyntaxNode, | 566 | pub(crate) syntax: SyntaxNode, |
632 | } | 567 | } |
633 | impl ArrayType { | 568 | impl ArrayType { |
634 | pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } | 569 | pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } |
635 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 570 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
636 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 571 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
637 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 572 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
638 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | 573 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } |
639 | } | 574 | } |
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)] | 575 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
648 | pub struct SliceType { | 576 | pub struct SliceType { |
649 | pub(crate) syntax: SyntaxNode, | 577 | pub(crate) syntax: SyntaxNode, |
650 | } | 578 | } |
651 | impl SliceType { | 579 | impl SliceType { |
652 | pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } | 580 | pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } |
653 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 581 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
654 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | 582 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } |
655 | } | 583 | } |
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)] | 584 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
664 | pub struct ReferenceType { | 585 | pub struct ReferenceType { |
665 | pub(crate) syntax: SyntaxNode, | 586 | pub(crate) syntax: SyntaxNode, |
@@ -670,15 +591,8 @@ impl ReferenceType { | |||
670 | support::token(&self.syntax, T![lifetime]) | 591 | support::token(&self.syntax, T![lifetime]) |
671 | } | 592 | } |
672 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } | 593 | 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) } | 594 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
674 | } | 595 | } |
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)] | 596 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
683 | pub struct PlaceholderType { | 597 | pub struct PlaceholderType { |
684 | pub(crate) syntax: SyntaxNode, | 598 | pub(crate) syntax: SyntaxNode, |
@@ -686,15 +600,6 @@ pub struct PlaceholderType { | |||
686 | impl PlaceholderType { | 600 | impl PlaceholderType { |
687 | pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) } | 601 | pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) } |
688 | } | 602 | } |
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)] | 603 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
699 | pub struct FnPointerType { | 604 | pub struct FnPointerType { |
700 | pub(crate) syntax: SyntaxNode, | 605 | pub(crate) syntax: SyntaxNode, |
@@ -706,59 +611,31 @@ impl FnPointerType { | |||
706 | pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) } | 611 | pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) } |
707 | pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } | 612 | pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } |
708 | } | 613 | } |
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)] | 614 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
717 | pub struct ForType { | 615 | pub struct ForType { |
718 | pub(crate) syntax: SyntaxNode, | 616 | pub(crate) syntax: SyntaxNode, |
719 | } | 617 | } |
720 | impl ForType { | 618 | impl ForType { |
721 | pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) } | 619 | pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) } |
722 | pub fn type_param_list(&self) -> Option<TypeParamList> { support::child(&self.syntax) } | 620 | pub fn generic_param_list(&self) -> Option<GenericParamList> { support::child(&self.syntax) } |
723 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 621 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
724 | } | 622 | } |
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)] | 623 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
733 | pub struct ImplTraitType { | 624 | pub struct ImplTraitType { |
734 | pub(crate) syntax: SyntaxNode, | 625 | pub(crate) syntax: SyntaxNode, |
735 | } | 626 | } |
736 | impl ast::TypeBoundsOwner for ImplTraitType {} | ||
737 | impl ImplTraitType { | 627 | impl ImplTraitType { |
738 | pub fn impl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![impl]) } | 628 | pub fn impl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![impl]) } |
629 | pub fn type_bound_list(&self) -> Option<TypeBoundList> { support::child(&self.syntax) } | ||
739 | } | 630 | } |
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)] | 631 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
748 | pub struct DynTraitType { | 632 | pub struct DynTraitType { |
749 | pub(crate) syntax: SyntaxNode, | 633 | pub(crate) syntax: SyntaxNode, |
750 | } | 634 | } |
751 | impl ast::TypeBoundsOwner for DynTraitType {} | ||
752 | impl DynTraitType { | 635 | impl DynTraitType { |
753 | pub fn dyn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![dyn]) } | 636 | pub fn dyn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![dyn]) } |
637 | pub fn type_bound_list(&self) -> Option<TypeBoundList> { support::child(&self.syntax) } | ||
754 | } | 638 | } |
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)] | 639 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
763 | pub struct TupleExpr { | 640 | pub struct TupleExpr { |
764 | pub(crate) syntax: SyntaxNode, | 641 | pub(crate) syntax: SyntaxNode, |
@@ -769,15 +646,6 @@ impl TupleExpr { | |||
769 | pub fn exprs(&self) -> AstChildren<Expr> { support::children(&self.syntax) } | 646 | pub fn exprs(&self) -> AstChildren<Expr> { support::children(&self.syntax) } |
770 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 647 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
771 | } | 648 | } |
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)] | 649 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
782 | pub struct ArrayExpr { | 650 | pub struct ArrayExpr { |
783 | pub(crate) syntax: SyntaxNode, | 651 | pub(crate) syntax: SyntaxNode, |
@@ -786,17 +654,10 @@ impl ast::AttrsOwner for ArrayExpr {} | |||
786 | impl ArrayExpr { | 654 | impl ArrayExpr { |
787 | pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } | 655 | pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } |
788 | pub fn exprs(&self) -> AstChildren<Expr> { support::children(&self.syntax) } | 656 | pub fn exprs(&self) -> AstChildren<Expr> { support::children(&self.syntax) } |
657 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
789 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 658 | 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![']']) } | 659 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } |
791 | } | 660 | } |
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)] | 661 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
801 | pub struct ParenExpr { | 662 | pub struct ParenExpr { |
802 | pub(crate) syntax: SyntaxNode, | 663 | pub(crate) syntax: SyntaxNode, |
@@ -807,19 +668,6 @@ impl ParenExpr { | |||
807 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 668 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
808 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 669 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
809 | } | 670 | } |
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)] | 671 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
824 | pub struct PathExpr { | 672 | pub struct PathExpr { |
825 | pub(crate) syntax: SyntaxNode, | 673 | pub(crate) syntax: SyntaxNode, |
@@ -827,17 +675,6 @@ pub struct PathExpr { | |||
827 | impl PathExpr { | 675 | impl PathExpr { |
828 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | 676 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } |
829 | } | 677 | } |
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)] | 678 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
842 | pub struct LambdaExpr { | 679 | pub struct LambdaExpr { |
843 | pub(crate) syntax: SyntaxNode, | 680 | pub(crate) syntax: SyntaxNode, |
@@ -851,25 +688,6 @@ impl LambdaExpr { | |||
851 | pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } | 688 | pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } |
852 | pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } | 689 | pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } |
853 | } | 690 | } |
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)] | 691 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
874 | pub struct IfExpr { | 692 | pub struct IfExpr { |
875 | pub(crate) syntax: SyntaxNode, | 693 | pub(crate) syntax: SyntaxNode, |
@@ -879,40 +697,16 @@ impl IfExpr { | |||
879 | pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) } | 697 | pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) } |
880 | pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } | 698 | pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } |
881 | } | 699 | } |
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)] | 700 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
894 | pub struct LoopExpr { | 701 | pub struct Condition { |
895 | pub(crate) syntax: SyntaxNode, | 702 | pub(crate) syntax: SyntaxNode, |
896 | } | 703 | } |
897 | impl ast::AttrsOwner for LoopExpr {} | 704 | impl Condition { |
898 | impl ast::LoopBodyOwner for LoopExpr {} | 705 | pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) } |
899 | impl LoopExpr { | 706 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } |
900 | pub fn loop_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![loop]) } | 707 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } |
708 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
901 | } | 709 | } |
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)] | 710 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
917 | pub struct EffectExpr { | 711 | pub struct EffectExpr { |
918 | pub(crate) syntax: SyntaxNode, | 712 | pub(crate) syntax: SyntaxNode, |
@@ -925,19 +719,24 @@ impl EffectExpr { | |||
925 | pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) } | 719 | 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) } | 720 | pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) } |
927 | } | 721 | } |
928 | /// For loop expression. | 722 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
929 | /// Note: record struct literals are not valid as iterable expression | 723 | pub struct Label { |
930 | /// due to ambiguity. | 724 | pub(crate) syntax: SyntaxNode, |
931 | /// | 725 | } |
932 | /// ``` | 726 | impl Label { |
933 | /// ❰ | 727 | pub fn lifetime_token(&self) -> Option<SyntaxToken> { |
934 | /// for i in (0..4) { | 728 | support::token(&self.syntax, T![lifetime]) |
935 | /// dbg!(i); | 729 | } |
936 | /// } | 730 | } |
937 | /// ❱ | 731 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
938 | /// ``` | 732 | pub struct LoopExpr { |
939 | /// | 733 | pub(crate) syntax: SyntaxNode, |
940 | /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#iterator-loops) | 734 | } |
735 | impl ast::AttrsOwner for LoopExpr {} | ||
736 | impl ast::LoopBodyOwner for LoopExpr {} | ||
737 | impl LoopExpr { | ||
738 | pub fn loop_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![loop]) } | ||
739 | } | ||
941 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 740 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
942 | pub struct ForExpr { | 741 | pub struct ForExpr { |
943 | pub(crate) syntax: SyntaxNode, | 742 | pub(crate) syntax: SyntaxNode, |
@@ -950,22 +749,6 @@ impl ForExpr { | |||
950 | pub fn in_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![in]) } | 749 | pub fn in_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![in]) } |
951 | pub fn iterable(&self) -> Option<Expr> { support::child(&self.syntax) } | 750 | pub fn iterable(&self) -> Option<Expr> { support::child(&self.syntax) } |
952 | } | 751 | } |
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)] | 752 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
970 | pub struct WhileExpr { | 753 | pub struct WhileExpr { |
971 | pub(crate) syntax: SyntaxNode, | 754 | pub(crate) syntax: SyntaxNode, |
@@ -976,22 +759,6 @@ impl WhileExpr { | |||
976 | pub fn while_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![while]) } | 759 | pub fn while_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![while]) } |
977 | pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } | 760 | pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } |
978 | } | 761 | } |
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)] | 762 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
996 | pub struct ContinueExpr { | 763 | pub struct ContinueExpr { |
997 | pub(crate) syntax: SyntaxNode, | 764 | pub(crate) syntax: SyntaxNode, |
@@ -1005,25 +772,6 @@ impl ContinueExpr { | |||
1005 | support::token(&self.syntax, T![lifetime]) | 772 | support::token(&self.syntax, T![lifetime]) |
1006 | } | 773 | } |
1007 | } | 774 | } |
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)] | 775 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1028 | pub struct BreakExpr { | 776 | pub struct BreakExpr { |
1029 | pub(crate) syntax: SyntaxNode, | 777 | pub(crate) syntax: SyntaxNode, |
@@ -1036,104 +784,33 @@ impl BreakExpr { | |||
1036 | } | 784 | } |
1037 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 785 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1038 | } | 786 | } |
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)] | ||
1054 | pub struct Label { | ||
1055 | pub(crate) syntax: SyntaxNode, | ||
1056 | } | ||
1057 | impl 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)] | ||
1078 | pub struct BlockExpr { | ||
1079 | pub(crate) syntax: SyntaxNode, | ||
1080 | } | ||
1081 | impl ast::AttrsOwner for BlockExpr {} | ||
1082 | impl ast::ModuleItemOwner for BlockExpr {} | ||
1083 | impl 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)] | 787 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1102 | pub struct ReturnExpr { | 788 | pub struct ReturnExpr { |
1103 | pub(crate) syntax: SyntaxNode, | 789 | pub(crate) syntax: SyntaxNode, |
1104 | } | 790 | } |
1105 | impl ast::AttrsOwner for ReturnExpr {} | 791 | impl ast::AttrsOwner for ReturnExpr {} |
1106 | impl ReturnExpr { | 792 | impl ReturnExpr { |
793 | pub fn return_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![return]) } | ||
1107 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 794 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1108 | } | 795 | } |
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)] | 796 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1120 | pub struct CallExpr { | 797 | pub struct CallExpr { |
1121 | pub(crate) syntax: SyntaxNode, | 798 | pub(crate) syntax: SyntaxNode, |
1122 | } | 799 | } |
800 | impl ast::AttrsOwner for CallExpr {} | ||
1123 | impl ast::ArgListOwner for CallExpr {} | 801 | impl ast::ArgListOwner for CallExpr {} |
1124 | impl CallExpr { | 802 | impl CallExpr { |
1125 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 803 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1126 | } | 804 | } |
1127 | /// Method call expression. | 805 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1128 | /// | 806 | pub struct ArgList { |
1129 | /// ``` | 807 | pub(crate) syntax: SyntaxNode, |
1130 | /// ❰ receiver_expr.method() ❱; | 808 | } |
1131 | /// ❰ receiver_expr.method::<T>(42, true) ❱; | 809 | impl ArgList { |
1132 | /// | 810 | pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } |
1133 | /// ❰ ❰ ❰ foo.bar() ❱ .baz() ❱ .bruh() ❱; | 811 | pub fn args(&self) -> AstChildren<Expr> { support::children(&self.syntax) } |
1134 | /// ``` | 812 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
1135 | /// | 813 | } |
1136 | /// [Reference](https://doc.rust-lang.org/reference/expressions/method-call-expr.html) | ||
1137 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 814 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1138 | pub struct MethodCallExpr { | 815 | pub struct MethodCallExpr { |
1139 | pub(crate) syntax: SyntaxNode, | 816 | pub(crate) syntax: SyntaxNode, |
@@ -1146,31 +823,19 @@ impl MethodCallExpr { | |||
1146 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } | 823 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } |
1147 | pub fn type_arg_list(&self) -> Option<TypeArgList> { support::child(&self.syntax) } | 824 | pub fn type_arg_list(&self) -> Option<TypeArgList> { support::child(&self.syntax) } |
1148 | } | 825 | } |
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)] | 826 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1157 | pub struct IndexExpr { | 827 | pub struct TypeArgList { |
1158 | pub(crate) syntax: SyntaxNode, | 828 | pub(crate) syntax: SyntaxNode, |
1159 | } | 829 | } |
1160 | impl ast::AttrsOwner for IndexExpr {} | 830 | impl TypeArgList { |
1161 | impl IndexExpr { | 831 | pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) } |
1162 | pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } | 832 | pub fn l_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![<]) } |
1163 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | 833 | pub fn type_args(&self) -> AstChildren<TypeArg> { support::children(&self.syntax) } |
834 | pub fn lifetime_args(&self) -> AstChildren<LifetimeArg> { support::children(&self.syntax) } | ||
835 | pub fn assoc_type_args(&self) -> AstChildren<AssocTypeArg> { support::children(&self.syntax) } | ||
836 | pub fn const_args(&self) -> AstChildren<ConstArg> { support::children(&self.syntax) } | ||
837 | pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) } | ||
1164 | } | 838 | } |
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)] | 839 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1175 | pub struct FieldExpr { | 840 | pub struct FieldExpr { |
1176 | pub(crate) syntax: SyntaxNode, | 841 | pub(crate) syntax: SyntaxNode, |
@@ -1181,13 +846,15 @@ impl FieldExpr { | |||
1181 | pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) } | 846 | pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) } |
1182 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } | 847 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } |
1183 | } | 848 | } |
1184 | /// Await operator call expression. | 849 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1185 | /// | 850 | pub struct IndexExpr { |
1186 | /// ``` | 851 | pub(crate) syntax: SyntaxNode, |
1187 | /// ❰ expr.await ❱; | 852 | } |
1188 | /// ``` | 853 | impl ast::AttrsOwner for IndexExpr {} |
1189 | /// | 854 | impl IndexExpr { |
1190 | /// [Reference](https://doc.rust-lang.org/reference/expressions/await-expr.html) | 855 | pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } |
856 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | ||
857 | } | ||
1191 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 858 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1192 | pub struct AwaitExpr { | 859 | pub struct AwaitExpr { |
1193 | pub(crate) syntax: SyntaxNode, | 860 | pub(crate) syntax: SyntaxNode, |
@@ -1198,13 +865,6 @@ impl AwaitExpr { | |||
1198 | pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) } | 865 | 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]) } | 866 | pub fn await_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![await]) } |
1200 | } | 867 | } |
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)] | 868 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1209 | pub struct TryExpr { | 869 | pub struct TryExpr { |
1210 | pub(crate) syntax: SyntaxNode, | 870 | pub(crate) syntax: SyntaxNode, |
@@ -1214,13 +874,6 @@ impl TryExpr { | |||
1214 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 874 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1215 | pub fn question_mark_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![?]) } | 875 | pub fn question_mark_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![?]) } |
1216 | } | 876 | } |
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)] | 877 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1225 | pub struct CastExpr { | 878 | pub struct CastExpr { |
1226 | pub(crate) syntax: SyntaxNode, | 879 | pub(crate) syntax: SyntaxNode, |
@@ -1229,18 +882,8 @@ impl ast::AttrsOwner for CastExpr {} | |||
1229 | impl CastExpr { | 882 | impl CastExpr { |
1230 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 883 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1231 | pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) } | 884 | 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) } | 885 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
1233 | } | 886 | } |
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)] | 887 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1245 | pub struct RefExpr { | 888 | pub struct RefExpr { |
1246 | pub(crate) syntax: SyntaxNode, | 889 | pub(crate) syntax: SyntaxNode, |
@@ -1253,15 +896,6 @@ impl RefExpr { | |||
1253 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } | 896 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } |
1254 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 897 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1255 | } | 898 | } |
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)] | 899 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1266 | pub struct PrefixExpr { | 900 | pub struct PrefixExpr { |
1267 | pub(crate) syntax: SyntaxNode, | 901 | pub(crate) syntax: SyntaxNode, |
@@ -1270,13 +904,6 @@ impl ast::AttrsOwner for PrefixExpr {} | |||
1270 | impl PrefixExpr { | 904 | impl PrefixExpr { |
1271 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 905 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1272 | } | 906 | } |
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)] | 907 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1281 | pub struct BoxExpr { | 908 | pub struct BoxExpr { |
1282 | pub(crate) syntax: SyntaxNode, | 909 | pub(crate) syntax: SyntaxNode, |
@@ -1286,69 +913,18 @@ impl BoxExpr { | |||
1286 | pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) } | 913 | pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) } |
1287 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 914 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1288 | } | 915 | } |
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)] | 916 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1302 | pub struct RangeExpr { | 917 | pub struct RangeExpr { |
1303 | pub(crate) syntax: SyntaxNode, | 918 | pub(crate) syntax: SyntaxNode, |
1304 | } | 919 | } |
1305 | impl ast::AttrsOwner for RangeExpr {} | 920 | impl ast::AttrsOwner for RangeExpr {} |
1306 | impl RangeExpr {} | 921 | impl 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)] | 922 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1317 | pub struct BinExpr { | 923 | pub struct BinExpr { |
1318 | pub(crate) syntax: SyntaxNode, | 924 | pub(crate) syntax: SyntaxNode, |
1319 | } | 925 | } |
1320 | impl ast::AttrsOwner for BinExpr {} | 926 | impl ast::AttrsOwner for BinExpr {} |
1321 | impl BinExpr {} | 927 | impl 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)] | ||
1336 | pub struct Literal { | ||
1337 | pub(crate) syntax: SyntaxNode, | ||
1338 | } | ||
1339 | impl 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)] | 928 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1353 | pub struct MatchExpr { | 929 | pub struct MatchExpr { |
1354 | pub(crate) syntax: SyntaxNode, | 930 | pub(crate) syntax: SyntaxNode, |
@@ -1359,40 +935,15 @@ impl MatchExpr { | |||
1359 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 935 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1360 | pub fn match_arm_list(&self) -> Option<MatchArmList> { support::child(&self.syntax) } | 936 | pub fn match_arm_list(&self) -> Option<MatchArmList> { support::child(&self.syntax) } |
1361 | } | 937 | } |
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)] | 938 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1377 | pub struct MatchArmList { | 939 | pub struct MatchArmList { |
1378 | pub(crate) syntax: SyntaxNode, | 940 | pub(crate) syntax: SyntaxNode, |
1379 | } | 941 | } |
1380 | impl ast::AttrsOwner for MatchArmList {} | ||
1381 | impl MatchArmList { | 942 | impl MatchArmList { |
1382 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | 943 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } |
1383 | pub fn arms(&self) -> AstChildren<MatchArm> { support::children(&self.syntax) } | 944 | pub fn arms(&self) -> AstChildren<MatchArm> { support::children(&self.syntax) } |
1384 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 945 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
1385 | } | 946 | } |
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)] | 947 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1397 | pub struct MatchArm { | 948 | pub struct MatchArm { |
1398 | pub(crate) syntax: SyntaxNode, | 949 | pub(crate) syntax: SyntaxNode, |
@@ -1404,15 +955,6 @@ impl MatchArm { | |||
1404 | pub fn fat_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=>]) } | 955 | pub fn fat_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=>]) } |
1405 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 956 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1406 | } | 957 | } |
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)] | 958 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1417 | pub struct MatchGuard { | 959 | pub struct MatchGuard { |
1418 | pub(crate) syntax: SyntaxNode, | 960 | pub(crate) syntax: SyntaxNode, |
@@ -1421,76 +963,37 @@ impl MatchGuard { | |||
1421 | pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) } | 963 | pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) } |
1422 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 964 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1423 | } | 965 | } |
1424 | /// Record literal expression. The same syntax is used for structs, | 966 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1425 | /// unions and record enum variants. | 967 | pub struct RecordExpr { |
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)] | ||
1440 | pub struct RecordLit { | ||
1441 | pub(crate) syntax: SyntaxNode, | 968 | pub(crate) syntax: SyntaxNode, |
1442 | } | 969 | } |
1443 | impl RecordLit { | 970 | impl RecordExpr { |
1444 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | 971 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } |
1445 | pub fn record_field_list(&self) -> Option<RecordFieldList> { support::child(&self.syntax) } | 972 | pub fn record_expr_field_list(&self) -> Option<RecordExprFieldList> { |
973 | support::child(&self.syntax) | ||
974 | } | ||
1446 | } | 975 | } |
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)] | 976 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1458 | pub struct RecordFieldList { | 977 | pub struct RecordExprFieldList { |
1459 | pub(crate) syntax: SyntaxNode, | 978 | pub(crate) syntax: SyntaxNode, |
1460 | } | 979 | } |
1461 | impl RecordFieldList { | 980 | impl RecordExprFieldList { |
1462 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | 981 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } |
1463 | pub fn fields(&self) -> AstChildren<RecordField> { support::children(&self.syntax) } | 982 | pub fn fields(&self) -> AstChildren<RecordExprField> { support::children(&self.syntax) } |
1464 | pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } | 983 | pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } |
1465 | pub fn spread(&self) -> Option<Expr> { support::child(&self.syntax) } | 984 | pub fn spread(&self) -> Option<Expr> { support::child(&self.syntax) } |
1466 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 985 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
1467 | } | 986 | } |
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)] | 987 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1478 | pub struct RecordField { | 988 | pub struct RecordExprField { |
1479 | pub(crate) syntax: SyntaxNode, | 989 | pub(crate) syntax: SyntaxNode, |
1480 | } | 990 | } |
1481 | impl ast::AttrsOwner for RecordField {} | 991 | impl ast::AttrsOwner for RecordExprField {} |
1482 | impl RecordField { | 992 | impl RecordExprField { |
1483 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } | 993 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } |
1484 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } | 994 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } |
1485 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 995 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1486 | } | 996 | } |
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)] | 997 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1495 | pub struct OrPat { | 998 | pub struct OrPat { |
1496 | pub(crate) syntax: SyntaxNode, | 999 | pub(crate) syntax: SyntaxNode, |
@@ -1498,14 +1001,6 @@ pub struct OrPat { | |||
1498 | impl OrPat { | 1001 | impl OrPat { |
1499 | pub fn pats(&self) -> AstChildren<Pat> { support::children(&self.syntax) } | 1002 | pub fn pats(&self) -> AstChildren<Pat> { support::children(&self.syntax) } |
1500 | } | 1003 | } |
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)] | 1004 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1510 | pub struct ParenPat { | 1005 | pub struct ParenPat { |
1511 | pub(crate) syntax: SyntaxNode, | 1006 | pub(crate) syntax: SyntaxNode, |
@@ -1515,16 +1010,6 @@ impl ParenPat { | |||
1515 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | 1010 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } |
1516 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 1011 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
1517 | } | 1012 | } |
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)] | 1013 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1529 | pub struct RefPat { | 1014 | pub struct RefPat { |
1530 | pub(crate) syntax: SyntaxNode, | 1015 | pub(crate) syntax: SyntaxNode, |
@@ -1534,31 +1019,14 @@ impl RefPat { | |||
1534 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } | 1019 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } |
1535 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | 1020 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } |
1536 | } | 1021 | } |
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)] | 1022 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1545 | pub struct BoxPat { | 1023 | pub struct BoxPat { |
1546 | pub(crate) syntax: SyntaxNode, | 1024 | pub(crate) syntax: SyntaxNode, |
1547 | } | 1025 | } |
1548 | impl BoxPat { | 1026 | impl BoxPat { |
1549 | pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) } | 1027 | pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) } |
1550 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | 1028 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } |
1551 | } | 1029 | } |
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)] | 1030 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1563 | pub struct BindPat { | 1031 | pub struct BindPat { |
1564 | pub(crate) syntax: SyntaxNode, | 1032 | pub(crate) syntax: SyntaxNode, |
@@ -1571,13 +1039,6 @@ impl BindPat { | |||
1571 | pub fn at_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![@]) } | 1039 | pub fn at_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![@]) } |
1572 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | 1040 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } |
1573 | } | 1041 | } |
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)] | 1042 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1582 | pub struct PlaceholderPat { | 1043 | pub struct PlaceholderPat { |
1583 | pub(crate) syntax: SyntaxNode, | 1044 | pub(crate) syntax: SyntaxNode, |
@@ -1585,16 +1046,6 @@ pub struct PlaceholderPat { | |||
1585 | impl PlaceholderPat { | 1046 | impl PlaceholderPat { |
1586 | pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) } | 1047 | pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) } |
1587 | } | 1048 | } |
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)] | 1049 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1599 | pub struct DotDotPat { | 1050 | pub struct DotDotPat { |
1600 | pub(crate) syntax: SyntaxNode, | 1051 | pub(crate) syntax: SyntaxNode, |
@@ -1602,15 +1053,6 @@ pub struct DotDotPat { | |||
1602 | impl DotDotPat { | 1053 | impl DotDotPat { |
1603 | pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } | 1054 | pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } |
1604 | } | 1055 | } |
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)] | 1056 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1615 | pub struct PathPat { | 1057 | pub struct PathPat { |
1616 | pub(crate) syntax: SyntaxNode, | 1058 | pub(crate) syntax: SyntaxNode, |
@@ -1618,13 +1060,6 @@ pub struct PathPat { | |||
1618 | impl PathPat { | 1060 | impl PathPat { |
1619 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | 1061 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } |
1620 | } | 1062 | } |
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)] | 1063 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1629 | pub struct SlicePat { | 1064 | pub struct SlicePat { |
1630 | pub(crate) syntax: SyntaxNode, | 1065 | pub(crate) syntax: SyntaxNode, |
@@ -1634,33 +1069,14 @@ impl SlicePat { | |||
1634 | pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } | 1069 | pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } |
1635 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | 1070 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } |
1636 | } | 1071 | } |
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)] | 1072 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1648 | pub struct RangePat { | 1073 | pub struct RangePat { |
1649 | pub(crate) syntax: SyntaxNode, | 1074 | pub(crate) syntax: SyntaxNode, |
1650 | } | 1075 | } |
1651 | impl RangePat {} | 1076 | impl RangePat { |
1652 | /// Literal pattern. | 1077 | pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } |
1653 | /// Includes only bool, number, char, and string literals. | 1078 | pub fn dotdoteq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..=]) } |
1654 | /// | 1079 | } |
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)] | 1080 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1665 | pub struct LiteralPat { | 1081 | pub struct LiteralPat { |
1666 | pub(crate) syntax: SyntaxNode, | 1082 | pub(crate) syntax: SyntaxNode, |
@@ -1668,13 +1084,6 @@ pub struct LiteralPat { | |||
1668 | impl LiteralPat { | 1084 | impl LiteralPat { |
1669 | pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) } | 1085 | pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) } |
1670 | } | 1086 | } |
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)] | 1087 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1679 | pub struct MacroPat { | 1088 | pub struct MacroPat { |
1680 | pub(crate) syntax: SyntaxNode, | 1089 | pub(crate) syntax: SyntaxNode, |
@@ -1682,37 +1091,22 @@ pub struct MacroPat { | |||
1682 | impl MacroPat { | 1091 | impl MacroPat { |
1683 | pub fn macro_call(&self) -> Option<MacroCall> { support::child(&self.syntax) } | 1092 | pub fn macro_call(&self) -> Option<MacroCall> { support::child(&self.syntax) } |
1684 | } | 1093 | } |
1685 | /// Record literal pattern. | ||
1686 | /// | ||
1687 | /// ``` | ||
1688 | /// let ❰ foo::Bar { baz, .. } ❱ = bruh; | ||
1689 | /// ``` | ||
1690 | /// | ||
1691 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns) | ||
1692 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1094 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1693 | pub struct RecordPat { | 1095 | pub struct RecordPat { |
1694 | pub(crate) syntax: SyntaxNode, | 1096 | pub(crate) syntax: SyntaxNode, |
1695 | } | 1097 | } |
1696 | impl RecordPat { | 1098 | impl RecordPat { |
1099 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | ||
1697 | pub fn record_field_pat_list(&self) -> Option<RecordFieldPatList> { | 1100 | pub fn record_field_pat_list(&self) -> Option<RecordFieldPatList> { |
1698 | support::child(&self.syntax) | 1101 | support::child(&self.syntax) |
1699 | } | 1102 | } |
1700 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | ||
1701 | } | 1103 | } |
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)] | 1104 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1710 | pub struct RecordFieldPatList { | 1105 | pub struct RecordFieldPatList { |
1711 | pub(crate) syntax: SyntaxNode, | 1106 | pub(crate) syntax: SyntaxNode, |
1712 | } | 1107 | } |
1713 | impl RecordFieldPatList { | 1108 | impl RecordFieldPatList { |
1714 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | 1109 | 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> { | 1110 | pub fn record_field_pats(&self) -> AstChildren<RecordFieldPat> { |
1717 | support::children(&self.syntax) | 1111 | support::children(&self.syntax) |
1718 | } | 1112 | } |
@@ -1720,15 +1114,6 @@ impl RecordFieldPatList { | |||
1720 | pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } | 1114 | 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!['}']) } | 1115 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
1722 | } | 1116 | } |
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)] | 1117 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1733 | pub struct RecordFieldPat { | 1118 | pub struct RecordFieldPat { |
1734 | pub(crate) syntax: SyntaxNode, | 1119 | pub(crate) syntax: SyntaxNode, |
@@ -1739,13 +1124,6 @@ impl RecordFieldPat { | |||
1739 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } | 1124 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } |
1740 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | 1125 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } |
1741 | } | 1126 | } |
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)] | 1127 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1750 | pub struct TupleStructPat { | 1128 | pub struct TupleStructPat { |
1751 | pub(crate) syntax: SyntaxNode, | 1129 | pub(crate) syntax: SyntaxNode, |
@@ -1756,14 +1134,6 @@ impl TupleStructPat { | |||
1756 | pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } | 1134 | pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } |
1757 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 1135 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
1758 | } | 1136 | } |
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)] | 1137 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1768 | pub struct TuplePat { | 1138 | pub struct TuplePat { |
1769 | pub(crate) syntax: SyntaxNode, | 1139 | pub(crate) syntax: SyntaxNode, |
@@ -1773,234 +1143,28 @@ impl TuplePat { | |||
1773 | pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } | 1143 | pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } |
1774 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 1144 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
1775 | } | 1145 | } |
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)] | ||
1788 | pub struct Visibility { | ||
1789 | pub(crate) syntax: SyntaxNode, | ||
1790 | } | ||
1791 | impl 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)] | ||
1821 | pub struct Name { | ||
1822 | pub(crate) syntax: SyntaxNode, | ||
1823 | } | ||
1824 | impl Name { | ||
1825 | pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) } | ||
1826 | } | ||
1827 | /// Reference to a name. | ||
1828 | /// See the explanation on the difference between `Name` and `NameRef` | ||
1829 | /// in `Name` ast node docs. | ||
1830 | /// | ||
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)] | ||
1837 | pub struct NameRef { | ||
1838 | pub(crate) syntax: SyntaxNode, | ||
1839 | } | ||
1840 | impl 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)] | 1146 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1863 | pub struct MacroCall { | 1147 | pub struct MacroDef { |
1864 | pub(crate) syntax: SyntaxNode, | 1148 | pub(crate) syntax: SyntaxNode, |
1865 | } | 1149 | } |
1866 | impl ast::NameOwner for MacroCall {} | 1150 | impl ast::NameOwner for MacroDef {} |
1867 | impl ast::AttrsOwner for MacroCall {} | 1151 | impl MacroDef { |
1868 | impl ast::DocCommentsOwner for MacroCall {} | ||
1869 | impl 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) } | 1152 | 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)] | ||
1888 | pub struct Attr { | ||
1889 | pub(crate) syntax: SyntaxNode, | ||
1890 | } | 1153 | } |
1891 | impl 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 | } | ||
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)] | 1154 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1909 | pub struct TokenTree { | 1155 | pub struct MacroItems { |
1910 | pub(crate) syntax: SyntaxNode, | ||
1911 | } | ||
1912 | impl TokenTree {} | ||
1913 | /// Generic lifetime, type and constants parameters list **declaration**. | ||
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)] | ||
1927 | pub struct TypeParamList { | ||
1928 | pub(crate) syntax: SyntaxNode, | ||
1929 | } | ||
1930 | impl TypeParamList { | ||
1931 | pub fn l_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![<]) } | ||
1932 | pub fn generic_params(&self) -> AstChildren<GenericParam> { support::children(&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 | } | ||
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)] | ||
1946 | pub struct TypeParam { | ||
1947 | pub(crate) syntax: SyntaxNode, | ||
1948 | } | ||
1949 | impl ast::NameOwner for TypeParam {} | ||
1950 | impl ast::AttrsOwner for TypeParam {} | ||
1951 | impl ast::TypeBoundsOwner for TypeParam {} | ||
1952 | impl TypeParam { | ||
1953 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | ||
1954 | pub fn default_type(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
1955 | } | ||
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)] | ||
1963 | pub struct ConstParam { | ||
1964 | pub(crate) syntax: SyntaxNode, | 1156 | pub(crate) syntax: SyntaxNode, |
1965 | } | 1157 | } |
1966 | impl ast::NameOwner for ConstParam {} | 1158 | impl ast::ModuleItemOwner for MacroItems {} |
1967 | impl ast::AttrsOwner for ConstParam {} | 1159 | impl MacroItems {} |
1968 | impl ast::TypeAscriptionOwner for ConstParam {} | ||
1969 | impl 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)] | 1160 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1981 | pub struct LifetimeParam { | 1161 | pub struct MacroStmts { |
1982 | pub(crate) syntax: SyntaxNode, | 1162 | pub(crate) syntax: SyntaxNode, |
1983 | } | 1163 | } |
1984 | impl ast::AttrsOwner for LifetimeParam {} | 1164 | impl MacroStmts { |
1985 | impl LifetimeParam { | 1165 | pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) } |
1986 | pub fn lifetime_token(&self) -> Option<SyntaxToken> { | 1166 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1987 | support::token(&self.syntax, T![lifetime]) | ||
1988 | } | ||
1989 | } | 1167 | } |
1990 | /// Type bound declaration clause. | ||
1991 | /// | ||
1992 | /// ``` | ||
1993 | /// fn foo<T: ❰ ?Sized ❱ + ❰ Debug ❱>() {} | ||
1994 | /// | ||
1995 | /// trait Bar<T> | ||
1996 | /// where | ||
1997 | /// T: ❰ Send ❱ + ❰ Sync ❱ | ||
1998 | /// { | ||
1999 | /// type Baz: ❰ !Sync ❱ + ❰ Debug ❱ + ❰ ?const Add ❱; | ||
2000 | /// } | ||
2001 | /// ``` | ||
2002 | /// | ||
2003 | /// [Reference](https://doc.rust-lang.org/reference/trait-bounds.html) | ||
2004 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1168 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2005 | pub struct TypeBound { | 1169 | pub struct TypeBound { |
2006 | pub(crate) syntax: SyntaxNode, | 1170 | pub(crate) syntax: SyntaxNode, |
@@ -2012,40 +1176,6 @@ impl TypeBound { | |||
2012 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } | 1176 | 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) } | 1177 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
2014 | } | 1178 | } |
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)] | ||
2031 | pub struct TypeBoundList { | ||
2032 | pub(crate) syntax: SyntaxNode, | ||
2033 | } | ||
2034 | impl 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)] | 1179 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2050 | pub struct WherePred { | 1180 | pub struct WherePred { |
2051 | pub(crate) syntax: SyntaxNode, | 1181 | pub(crate) syntax: SyntaxNode, |
@@ -2053,64 +1183,12 @@ pub struct WherePred { | |||
2053 | impl ast::TypeBoundsOwner for WherePred {} | 1183 | impl ast::TypeBoundsOwner for WherePred {} |
2054 | impl WherePred { | 1184 | impl WherePred { |
2055 | pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) } | 1185 | pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) } |
2056 | pub fn type_param_list(&self) -> Option<TypeParamList> { support::child(&self.syntax) } | 1186 | pub fn generic_param_list(&self) -> Option<GenericParamList> { support::child(&self.syntax) } |
2057 | pub fn lifetime_token(&self) -> Option<SyntaxToken> { | 1187 | pub fn lifetime_token(&self) -> Option<SyntaxToken> { |
2058 | support::token(&self.syntax, T![lifetime]) | 1188 | support::token(&self.syntax, T![lifetime]) |
2059 | } | 1189 | } |
2060 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 1190 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
2061 | } | 1191 | } |
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)] | ||
2071 | pub struct WhereClause { | ||
2072 | pub(crate) syntax: SyntaxNode, | ||
2073 | } | ||
2074 | impl 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)] | ||
2094 | pub struct Abi { | ||
2095 | pub(crate) syntax: SyntaxNode, | ||
2096 | } | ||
2097 | impl 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)] | 1192 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2115 | pub struct ExprStmt { | 1193 | pub struct ExprStmt { |
2116 | pub(crate) syntax: SyntaxNode, | 1194 | pub(crate) syntax: SyntaxNode, |
@@ -2120,267 +1198,20 @@ impl ExprStmt { | |||
2120 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 1198 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
2121 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 1199 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
2122 | } | 1200 | } |
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)] | 1201 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2134 | pub struct LetStmt { | 1202 | pub struct LetStmt { |
2135 | pub(crate) syntax: SyntaxNode, | 1203 | pub(crate) syntax: SyntaxNode, |
2136 | } | 1204 | } |
2137 | impl ast::AttrsOwner for LetStmt {} | 1205 | impl ast::AttrsOwner for LetStmt {} |
2138 | impl ast::TypeAscriptionOwner for LetStmt {} | ||
2139 | impl LetStmt { | 1206 | impl LetStmt { |
2140 | pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) } | 1207 | pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) } |
2141 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | 1208 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } |
1209 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } | ||
1210 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
2142 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | 1211 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } |
2143 | pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) } | 1212 | pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) } |
2144 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 1213 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
2145 | } | 1214 | } |
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)] | ||
2159 | pub struct Condition { | ||
2160 | pub(crate) syntax: SyntaxNode, | ||
2161 | } | ||
2162 | impl 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)] | ||
2181 | pub struct ParamList { | ||
2182 | pub(crate) syntax: SyntaxNode, | ||
2183 | } | ||
2184 | impl 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)] | ||
2204 | pub struct SelfParam { | ||
2205 | pub(crate) syntax: SyntaxNode, | ||
2206 | } | ||
2207 | impl ast::TypeAscriptionOwner for SelfParam {} | ||
2208 | impl ast::AttrsOwner for SelfParam {} | ||
2209 | impl SelfParam { | ||
2210 | 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> { | ||
2213 | support::token(&self.syntax, T![lifetime]) | ||
2214 | } | ||
2215 | pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) } | ||
2216 | } | ||
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)] | ||
2229 | pub struct Param { | ||
2230 | pub(crate) syntax: SyntaxNode, | ||
2231 | } | ||
2232 | impl ast::TypeAscriptionOwner for Param {} | ||
2233 | impl ast::AttrsOwner for Param {} | ||
2234 | impl Param { | ||
2235 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | ||
2236 | pub fn dotdotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![...]) } | ||
2237 | } | ||
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)] | ||
2249 | pub struct UseItem { | ||
2250 | pub(crate) syntax: SyntaxNode, | ||
2251 | } | ||
2252 | impl ast::AttrsOwner for UseItem {} | ||
2253 | impl ast::VisibilityOwner for UseItem {} | ||
2254 | impl UseItem { | ||
2255 | 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) } | ||
2257 | } | ||
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)] | ||
2269 | pub struct UseTree { | ||
2270 | pub(crate) syntax: SyntaxNode, | ||
2271 | } | ||
2272 | impl UseTree { | ||
2273 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | ||
2274 | 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) } | ||
2276 | pub fn alias(&self) -> Option<Alias> { support::child(&self.syntax) } | ||
2277 | } | ||
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)] | ||
2289 | pub struct Alias { | ||
2290 | pub(crate) syntax: SyntaxNode, | ||
2291 | } | ||
2292 | impl ast::NameOwner for Alias {} | ||
2293 | impl 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)] | ||
2305 | pub struct UseTreeList { | ||
2306 | pub(crate) syntax: SyntaxNode, | ||
2307 | } | ||
2308 | impl UseTreeList { | ||
2309 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | ||
2310 | 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!['}']) } | ||
2312 | } | ||
2313 | /// Extern crate item. | ||
2314 | /// | ||
2315 | /// ``` | ||
2316 | /// ❰ #[attr] pub extern crate foo; ❱ | ||
2317 | /// ❰ extern crate self as bar; ❱ | ||
2318 | /// ``` | ||
2319 | /// | ||
2320 | /// [Reference](https://doc.rust-lang.org/reference/items/extern-crates.html) | ||
2321 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
2322 | pub struct ExternCrateItem { | ||
2323 | pub(crate) syntax: SyntaxNode, | ||
2324 | } | ||
2325 | impl ast::AttrsOwner for ExternCrateItem {} | ||
2326 | impl ast::VisibilityOwner for ExternCrateItem {} | ||
2327 | impl ExternCrateItem { | ||
2328 | 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]) } | ||
2330 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } | ||
2331 | pub fn alias(&self) -> Option<Alias> { support::child(&self.syntax) } | ||
2332 | } | ||
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)] | ||
2341 | pub struct ArgList { | ||
2342 | pub(crate) syntax: SyntaxNode, | ||
2343 | } | ||
2344 | impl 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)] | ||
2361 | pub struct Path { | ||
2362 | pub(crate) syntax: SyntaxNode, | ||
2363 | } | ||
2364 | impl 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)] | 1215 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2385 | pub struct PathSegment { | 1216 | pub struct PathSegment { |
2386 | pub(crate) syntax: SyntaxNode, | 1217 | pub(crate) syntax: SyntaxNode, |
@@ -2398,50 +1229,22 @@ impl PathSegment { | |||
2398 | pub fn path_type(&self) -> Option<PathType> { support::child(&self.syntax) } | 1229 | 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![>]) } | 1230 | pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) } |
2400 | } | 1231 | } |
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)] | 1232 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2411 | pub struct TypeArgList { | 1233 | pub struct TypeArg { |
2412 | pub(crate) syntax: SyntaxNode, | 1234 | pub(crate) syntax: SyntaxNode, |
2413 | } | 1235 | } |
2414 | impl TypeArgList { | 1236 | impl TypeArg { |
2415 | pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) } | 1237 | 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 | } | 1238 | } |
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)] | 1239 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2432 | pub struct TypeArg { | 1240 | pub struct LifetimeArg { |
2433 | pub(crate) syntax: SyntaxNode, | 1241 | pub(crate) syntax: SyntaxNode, |
2434 | } | 1242 | } |
2435 | impl TypeArg { | 1243 | impl LifetimeArg { |
2436 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 1244 | pub fn lifetime_token(&self) -> Option<SyntaxToken> { |
1245 | support::token(&self.syntax, T![lifetime]) | ||
1246 | } | ||
2437 | } | 1247 | } |
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)] | 1248 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2446 | pub struct AssocTypeArg { | 1249 | pub struct AssocTypeArg { |
2447 | pub(crate) syntax: SyntaxNode, | 1250 | pub(crate) syntax: SyntaxNode, |
@@ -2452,33 +1255,6 @@ impl AssocTypeArg { | |||
2452 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | 1255 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } |
2453 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 1256 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
2454 | } | 1257 | } |
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)] | ||
2465 | pub struct LifetimeArg { | ||
2466 | pub(crate) syntax: SyntaxNode, | ||
2467 | } | ||
2468 | impl 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)] | 1258 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2483 | pub struct ConstArg { | 1259 | pub struct ConstArg { |
2484 | pub(crate) syntax: SyntaxNode, | 1260 | pub(crate) syntax: SyntaxNode, |
@@ -2487,136 +1263,24 @@ impl ConstArg { | |||
2487 | pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) } | 1263 | pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) } |
2488 | pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) } | 1264 | pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) } |
2489 | } | 1265 | } |
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)] | ||
2495 | pub struct MacroItems { | ||
2496 | pub(crate) syntax: SyntaxNode, | ||
2497 | } | ||
2498 | impl ast::ModuleItemOwner for MacroItems {} | ||
2499 | impl 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)] | ||
2509 | pub struct MacroStmts { | ||
2510 | pub(crate) syntax: SyntaxNode, | ||
2511 | } | ||
2512 | impl MacroStmts { | ||
2513 | pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) } | ||
2514 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
2515 | } | ||
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)] | ||
2529 | pub struct ExternItemList { | ||
2530 | pub(crate) syntax: SyntaxNode, | ||
2531 | } | ||
2532 | impl ast::ModuleItemOwner for ExternItemList {} | ||
2533 | impl ExternItemList { | ||
2534 | 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) } | ||
2536 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | ||
2537 | } | ||
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)] | ||
2551 | pub struct ExternBlock { | ||
2552 | pub(crate) syntax: SyntaxNode, | ||
2553 | } | ||
2554 | impl 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)] | ||
2568 | pub struct MetaItem { | ||
2569 | pub(crate) syntax: SyntaxNode, | ||
2570 | } | ||
2571 | impl MetaItem { | ||
2572 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | ||
2573 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | ||
2574 | pub fn attr_input(&self) -> Option<AttrInput> { support::child(&self.syntax) } | ||
2575 | pub fn nested_meta_items(&self) -> AstChildren<MetaItem> { support::children(&self.syntax) } | ||
2576 | } | ||
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)] | ||
2587 | pub struct MacroDef { | ||
2588 | pub(crate) syntax: SyntaxNode, | ||
2589 | } | ||
2590 | impl 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. | ||