aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src
diff options
context:
space:
mode:
authorDmitry <[email protected]>2020-08-09 14:35:51 +0100
committerDmitry <[email protected]>2020-08-09 14:39:32 +0100
commit8068302fefc75440b823f4bf1731a5f347d7c767 (patch)
tree251b967182e79bc82a58c2fb208c688f6152df1f /crates/ra_syntax/src
parent1a43a0f63e0008787225abb6fb2baef97b6a39e0 (diff)
parent8a57afe5a4bfab40072a83f7dc4ca560bf860919 (diff)
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r--crates/ra_syntax/src/ast.rs20
-rw-r--r--crates/ra_syntax/src/ast/edit.rs51
-rw-r--r--crates/ra_syntax/src/ast/expr_ext.rs13
-rw-r--r--crates/ra_syntax/src/ast/generated.rs41
-rw-r--r--crates/ra_syntax/src/ast/generated/nodes.rs4754
-rw-r--r--crates/ra_syntax/src/ast/make.rs28
-rw-r--r--crates/ra_syntax/src/ast/node_ext.rs141
-rw-r--r--crates/ra_syntax/src/ast/traits.rs12
-rw-r--r--crates/ra_syntax/src/lib.rs10
-rw-r--r--crates/ra_syntax/src/parsing/text_tree_sink.rs4
-rw-r--r--crates/ra_syntax/src/ptr.rs2
-rw-r--r--crates/ra_syntax/src/tests.rs4
-rw-r--r--crates/ra_syntax/src/validation.rs10
-rw-r--r--crates/ra_syntax/src/validation/block.rs2
14 files changed, 1835 insertions, 3257 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs
index c65c485cb..d536bb1e7 100644
--- a/crates/ra_syntax/src/ast.rs
+++ b/crates/ra_syntax/src/ast.rs
@@ -17,7 +17,7 @@ use crate::{
17 17
18pub use self::{ 18pub use self::{
19 expr_ext::{ArrayExprKind, BinOp, Effect, ElseBranch, LiteralKind, PrefixOp, RangeOp}, 19 expr_ext::{ArrayExprKind, BinOp, Effect, ElseBranch, LiteralKind, PrefixOp, RangeOp},
20 generated::{nodes::*, tokens::*}, 20 generated::*,
21 node_ext::{ 21 node_ext::{
22 AttrKind, FieldKind, NameOrNameRef, PathSegmentKind, SelfParamKind, SlicePatComponents, 22 AttrKind, FieldKind, NameOrNameRef, PathSegmentKind, SelfParamKind, SlicePatComponents,
23 StructKind, TypeBoundKind, VisibilityKind, 23 StructKind, TypeBoundKind, VisibilityKind,
@@ -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,8 +286,8 @@ 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.ty().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());
293 assert_bound("Debug", bounds.next()); 293 assert_bound("Debug", bounds.next());
@@ -304,20 +304,20 @@ where
304 let pred = predicates.next().unwrap(); 304 let pred = predicates.next().unwrap();
305 let mut bounds = pred.type_bound_list().unwrap().bounds(); 305 let mut bounds = pred.type_bound_list().unwrap().bounds();
306 306
307 assert_eq!("Iterator::Item", pred.type_ref().unwrap().syntax().text().to_string()); 307 assert_eq!("Iterator::Item", pred.ty().unwrap().syntax().text().to_string());
308 assert_bound("'a", bounds.next()); 308 assert_bound("'a", bounds.next());
309 309
310 let pred = predicates.next().unwrap(); 310 let pred = predicates.next().unwrap();
311 let mut bounds = pred.type_bound_list().unwrap().bounds(); 311 let mut bounds = pred.type_bound_list().unwrap().bounds();
312 312
313 assert_eq!("Iterator::Item", pred.type_ref().unwrap().syntax().text().to_string()); 313 assert_eq!("Iterator::Item", pred.ty().unwrap().syntax().text().to_string());
314 assert_bound("Debug", bounds.next()); 314 assert_bound("Debug", bounds.next());
315 assert_bound("'a", bounds.next()); 315 assert_bound("'a", bounds.next());
316 316
317 let pred = predicates.next().unwrap(); 317 let pred = predicates.next().unwrap();
318 let mut bounds = pred.type_bound_list().unwrap().bounds(); 318 let mut bounds = pred.type_bound_list().unwrap().bounds();
319 319
320 assert_eq!("<T as Iterator>::Item", pred.type_ref().unwrap().syntax().text().to_string()); 320 assert_eq!("<T as Iterator>::Item", pred.ty().unwrap().syntax().text().to_string());
321 assert_bound("Debug", bounds.next()); 321 assert_bound("Debug", bounds.next());
322 assert_bound("'a", bounds.next()); 322 assert_bound("'a", bounds.next());
323 323
@@ -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.ty().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 abc7a646c..5ed123f91 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
32impl ast::FnDef { 32impl 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
83impl ast::ItemList { 83impl 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
116impl ast::RecordFieldList { 119impl 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,9 +192,9 @@ impl ast::RecordFieldList {
189 } 192 }
190} 193}
191 194
192impl ast::TypeAliasDef { 195impl ast::TypeAlias {
193 #[must_use] 196 #[must_use]
194 pub fn remove_bounds(&self) -> ast::TypeAliasDef { 197 pub fn remove_bounds(&self) -> ast::TypeAlias {
195 let colon = match self.colon_token() { 198 let colon = match self.colon_token() {
196 Some(it) => it, 199 Some(it) => it,
197 None => return self.clone(), 200 None => return self.clone(),
@@ -234,17 +237,17 @@ impl ast::Path {
234 237
235impl ast::PathSegment { 238impl ast::PathSegment {
236 #[must_use] 239 #[must_use]
237 pub fn with_type_args(&self, type_args: ast::TypeArgList) -> ast::PathSegment { 240 pub fn with_type_args(&self, type_args: ast::GenericArgList) -> ast::PathSegment {
238 self._with_type_args(type_args, false) 241 self._with_type_args(type_args, false)
239 } 242 }
240 243
241 #[must_use] 244 #[must_use]
242 pub fn with_turbo_fish(&self, type_args: ast::TypeArgList) -> ast::PathSegment { 245 pub fn with_turbo_fish(&self, type_args: ast::GenericArgList) -> ast::PathSegment {
243 self._with_type_args(type_args, true) 246 self._with_type_args(type_args, true)
244 } 247 }
245 248
246 fn _with_type_args(&self, type_args: ast::TypeArgList, turbo: bool) -> ast::PathSegment { 249 fn _with_type_args(&self, type_args: ast::GenericArgList, turbo: bool) -> ast::PathSegment {
247 if let Some(old) = self.type_arg_list() { 250 if let Some(old) = self.generic_arg_list() {
248 return self.replace_children( 251 return self.replace_children(
249 single_node(old.syntax().clone()), 252 single_node(old.syntax().clone()),
250 iter::once(type_args.syntax().clone().into()), 253 iter::once(type_args.syntax().clone().into()),
@@ -259,9 +262,9 @@ impl ast::PathSegment {
259 } 262 }
260} 263}
261 264
262impl ast::UseItem { 265impl ast::Use {
263 #[must_use] 266 #[must_use]
264 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 {
265 if let Some(old) = self.use_tree() { 268 if let Some(old) = self.use_tree() {
266 return self.replace_descendant(old, use_tree); 269 return self.replace_descendant(old, use_tree);
267 } 270 }
@@ -314,8 +317,12 @@ impl ast::UseTree {
314 Some(it) => it, 317 Some(it) => it,
315 None => return self.clone(), 318 None => return self.clone(),
316 }; 319 };
317 let use_tree = 320 let use_tree = make::use_tree(
318 make::use_tree(suffix, self.use_tree_list(), self.alias(), self.star_token().is_some()); 321 suffix,
322 self.use_tree_list(),
323 self.rename(),
324 self.star_token().is_some(),
325 );
319 let nested = make::use_tree_list(iter::once(use_tree)); 326 let nested = make::use_tree_list(iter::once(use_tree));
320 return make::use_tree(prefix.clone(), Some(nested), None, false); 327 return make::use_tree(prefix.clone(), Some(nested), None, false);
321 328
@@ -383,7 +390,7 @@ impl ast::MatchArmList {
383 #[must_use] 390 #[must_use]
384 pub fn remove_placeholder(&self) -> ast::MatchArmList { 391 pub fn remove_placeholder(&self) -> ast::MatchArmList {
385 let placeholder = 392 let placeholder =
386 self.arms().find(|arm| matches!(arm.pat(), Some(ast::Pat::PlaceholderPat(_)))); 393 self.arms().find(|arm| matches!(arm.pat(), Some(ast::Pat::WildcardPat(_))));
387 if let Some(placeholder) = placeholder { 394 if let Some(placeholder) = placeholder {
388 self.remove_arm(&placeholder) 395 self.remove_arm(&placeholder)
389 } else { 396 } else {
@@ -614,7 +621,7 @@ fn single_node(element: impl Into<SyntaxElement>) -> RangeInclusive<SyntaxElemen
614#[test] 621#[test]
615fn test_increase_indent() { 622fn test_increase_indent() {
616 let arm_list = { 623 let arm_list = {
617 let arm = make::match_arm(iter::once(make::placeholder_pat().into()), make::expr_unit()); 624 let arm = make::match_arm(iter::once(make::wildcard_pat().into()), make::expr_unit());
618 make::match_arm_list(vec![arm.clone(), arm]) 625 make::match_arm_list(vec![arm.clone(), arm])
619 }; 626 };
620 assert_eq!( 627 assert_eq!(
diff --git a/crates/ra_syntax/src/ast/expr_ext.rs b/crates/ra_syntax/src/ast/expr_ext.rs
index db5438d68..f5ba87223 100644
--- a/crates/ra_syntax/src/ast/expr_ext.rs
+++ b/crates/ra_syntax/src/ast/expr_ext.rs
@@ -7,6 +7,8 @@ use crate::{
7 SyntaxToken, T, 7 SyntaxToken, T,
8}; 8};
9 9
10impl ast::AttrsOwner for ast::Expr {}
11
10impl ast::Expr { 12impl ast::Expr {
11 pub fn is_block_like(&self) -> bool { 13 pub fn is_block_like(&self) -> bool {
12 match self { 14 match self {
@@ -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
413impl ast::RecordField { 414impl 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.rs b/crates/ra_syntax/src/ast/generated.rs
index f5199e09f..4a6f41ee7 100644
--- a/crates/ra_syntax/src/ast/generated.rs
+++ b/crates/ra_syntax/src/ast/generated.rs
@@ -1,6 +1,41 @@
1//! This file is actually hand-written, but the submodules are indeed generated. 1//! This file is actually hand-written, but the submodules are indeed generated.
2
3#[rustfmt::skip] 2#[rustfmt::skip]
4pub(super) mod nodes; 3mod nodes;
5#[rustfmt::skip] 4#[rustfmt::skip]
6pub(super) mod tokens; 5mod tokens;
6
7use crate::{
8 AstNode,
9 SyntaxKind::{self, *},
10 SyntaxNode,
11};
12
13pub use {nodes::*, tokens::*};
14
15// Stmt is the only nested enum, so it's easier to just hand-write it
16impl AstNode for Stmt {
17 fn can_cast(kind: SyntaxKind) -> bool {
18 match kind {
19 LET_STMT | EXPR_STMT => true,
20 _ => Item::can_cast(kind),
21 }
22 }
23 fn cast(syntax: SyntaxNode) -> Option<Self> {
24 let res = match syntax.kind() {
25 LET_STMT => Stmt::LetStmt(LetStmt { syntax }),
26 EXPR_STMT => Stmt::ExprStmt(ExprStmt { syntax }),
27 _ => {
28 let item = Item::cast(syntax)?;
29 Stmt::Item(item)
30 }
31 };
32 Some(res)
33 }
34 fn syntax(&self) -> &SyntaxNode {
35 match self {
36 Stmt::LetStmt(it) => &it.syntax,
37 Stmt::ExprStmt(it) => &it.syntax,
38 Stmt::Item(it) => it.syntax(),
39 }
40 }
41}
diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs
index 58141da11..3d49309d1 100644
--- a/crates/ra_syntax/src/ast/generated/nodes.rs
+++ b/crates/ra_syntax/src/ast/generated/nodes.rs
@@ -5,1189 +5,649 @@ use crate::{
5 SyntaxKind::{self, *}, 5 SyntaxKind::{self, *},
6 SyntaxNode, SyntaxToken, T, 6 SyntaxNode, SyntaxToken, T,
7}; 7};
8/// The entire Rust source file. Includes all top-level inner attributes and module items.
9///
10/// [Reference](https://doc.rust-lang.org/reference/crates-and-source-files.html)
11#[derive(Debug, Clone, PartialEq, Eq, Hash)] 8#[derive(Debug, Clone, PartialEq, Eq, Hash)]
12pub struct SourceFile { 9pub struct Name {
13 pub(crate) syntax: SyntaxNode, 10 pub(crate) syntax: SyntaxNode,
14} 11}
15impl ast::ModuleItemOwner for SourceFile {} 12impl Name {
16impl ast::AttrsOwner for SourceFile {} 13 pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) }
17impl ast::DocCommentsOwner for SourceFile {} 14}
18impl SourceFile { 15#[derive(Debug, Clone, PartialEq, Eq, Hash)]
19 pub fn modules(&self) -> AstChildren<Module> { support::children(&self.syntax) } 16pub struct NameRef {
20}
21/// Function definition either with body or not.
22/// Includes all of its attributes and doc comments.
23///
24/// ```
25/// ❰
26/// /// Docs
27/// #[attr]
28/// pub extern "C" fn foo<T>(#[attr] Patern {p}: Pattern) -> u32
29/// where
30/// T: Debug
31/// {
32/// 42
33/// }
34/// ❱
35///
36/// extern "C" {
37/// ❰ fn fn_decl(also_variadic_ffi: u32, ...) -> u32; ❱
38/// }
39/// ```
40///
41/// - [Reference](https://doc.rust-lang.org/reference/items/functions.html)
42/// - [Nomicon](https://doc.rust-lang.org/nomicon/ffi.html#variadic-functions)
43#[derive(Debug, Clone, PartialEq, Eq, Hash)]
44pub struct FnDef {
45 pub(crate) syntax: SyntaxNode, 17 pub(crate) syntax: SyntaxNode,
46} 18}
47impl ast::VisibilityOwner for FnDef {} 19impl NameRef {
48impl ast::NameOwner for FnDef {} 20 pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) }
49impl ast::TypeParamsOwner for FnDef {} 21}
50impl ast::DocCommentsOwner for FnDef {} 22#[derive(Debug, Clone, PartialEq, Eq, Hash)]
51impl ast::AttrsOwner for FnDef {} 23pub struct Path {
52impl FnDef { 24 pub(crate) syntax: SyntaxNode,
53 pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) } 25}
54 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } 26impl Path {
55 pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) } 27 pub fn qualifier(&self) -> Option<Path> { support::child(&self.syntax) }
56 pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) } 28 pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) }
57 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) } 29 pub fn segment(&self) -> Option<PathSegment> { support::child(&self.syntax) }
58 pub fn fn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![fn]) } 30}
31#[derive(Debug, Clone, PartialEq, Eq, Hash)]
32pub struct PathSegment {
33 pub(crate) syntax: SyntaxNode,
34}
35impl PathSegment {
36 pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) }
37 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) }
38 pub fn super_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![super]) }
39 pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) }
40 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
41 pub fn generic_arg_list(&self) -> Option<GenericArgList> { support::child(&self.syntax) }
59 pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) } 42 pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) }
60 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } 43 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) }
61 pub fn body(&self) -> Option<BlockExpr> { support::child(&self.syntax) } 44 pub fn l_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![<]) }
62 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 45 pub fn path_type(&self) -> Option<PathType> { support::child(&self.syntax) }
46 pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) }
47 pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) }
48}
49#[derive(Debug, Clone, PartialEq, Eq, Hash)]
50pub struct GenericArgList {
51 pub(crate) syntax: SyntaxNode,
52}
53impl GenericArgList {
54 pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) }
55 pub fn l_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![<]) }
56 pub fn generic_args(&self) -> AstChildren<GenericArg> { support::children(&self.syntax) }
57 pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) }
58}
59#[derive(Debug, Clone, PartialEq, Eq, Hash)]
60pub struct ParamList {
61 pub(crate) syntax: SyntaxNode,
62}
63impl ParamList {
64 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
65 pub fn self_param(&self) -> Option<SelfParam> { support::child(&self.syntax) }
66 pub fn comma_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![,]) }
67 pub fn params(&self) -> AstChildren<Param> { support::children(&self.syntax) }
68 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
63} 69}
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)] 70#[derive(Debug, Clone, PartialEq, Eq, Hash)]
72pub struct RetType { 71pub struct RetType {
73 pub(crate) syntax: SyntaxNode, 72 pub(crate) syntax: SyntaxNode,
74} 73}
75impl RetType { 74impl RetType {
76 pub fn thin_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![->]) } 75 pub fn thin_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![->]) }
77 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 76 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
78} 77}
79/// Struct definition. 78#[derive(Debug, Clone, PartialEq, Eq, Hash)]
80/// Includes all of its attributes and doc comments. 79pub struct PathType {
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)]
100pub struct StructDef {
101 pub(crate) syntax: SyntaxNode, 80 pub(crate) syntax: SyntaxNode,
102} 81}
103impl ast::VisibilityOwner for StructDef {} 82impl PathType {
104impl ast::NameOwner for StructDef {} 83 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
105impl ast::TypeParamsOwner for StructDef {}
106impl ast::AttrsOwner for StructDef {}
107impl ast::DocCommentsOwner for StructDef {}
108impl StructDef {
109 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![;]) }
112} 84}
113/// Union definition. 85#[derive(Debug, Clone, PartialEq, Eq, Hash)]
114/// Includes all of its attributes and doc comments. 86pub struct TypeArg {
115///
116/// ```
117/// ❰
118/// /// Docs
119/// #[attr]
120/// pub union Foo<T> where T: Debug {
121/// /// Docs
122/// #[attr]
123/// a: T,
124/// b: u32,
125/// }
126/// ❱
127/// ```
128///
129/// [Reference](https://doc.rust-lang.org/reference/items/unions.html)
130#[derive(Debug, Clone, PartialEq, Eq, Hash)]
131pub struct UnionDef {
132 pub(crate) syntax: SyntaxNode, 87 pub(crate) syntax: SyntaxNode,
133} 88}
134impl ast::VisibilityOwner for UnionDef {} 89impl TypeArg {
135impl ast::NameOwner for UnionDef {} 90 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
136impl ast::TypeParamsOwner for UnionDef {}
137impl ast::AttrsOwner for UnionDef {}
138impl ast::DocCommentsOwner for UnionDef {}
139impl UnionDef {
140 pub fn union_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![union]) }
141 pub fn record_field_def_list(&self) -> Option<RecordFieldDefList> {
142 support::child(&self.syntax)
143 }
144} 91}
145/// Record field definition list including enclosing curly braces. 92#[derive(Debug, Clone, PartialEq, Eq, Hash)]
146/// 93pub struct AssocTypeArg {
147/// ```
148/// struct Foo // same for union
149/// ❰
150/// {
151/// a: u32,
152/// b: bool,
153/// }
154/// ❱
155/// ```
156///
157/// [Reference](https://doc.rust-lang.org/reference/items/structs.html)
158#[derive(Debug, Clone, PartialEq, Eq, Hash)]
159pub struct RecordFieldDefList {
160 pub(crate) syntax: SyntaxNode, 94 pub(crate) syntax: SyntaxNode,
161} 95}
162impl RecordFieldDefList { 96impl ast::TypeBoundsOwner for AssocTypeArg {}
163 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } 97impl AssocTypeArg {
164 pub fn fields(&self) -> AstChildren<RecordFieldDef> { support::children(&self.syntax) } 98 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
165 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } 99 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
100 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
166} 101}
167/// Record field definition including its attributes and doc comments. 102#[derive(Debug, Clone, PartialEq, Eq, Hash)]
168/// 103pub struct LifetimeArg {
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)]
184pub struct RecordFieldDef {
185 pub(crate) syntax: SyntaxNode, 104 pub(crate) syntax: SyntaxNode,
186} 105}
187impl ast::VisibilityOwner for RecordFieldDef {} 106impl LifetimeArg {
188impl ast::NameOwner for RecordFieldDef {} 107 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
189impl ast::AttrsOwner for RecordFieldDef {} 108 support::token(&self.syntax, T![lifetime])
190impl ast::DocCommentsOwner for RecordFieldDef {} 109 }
191impl ast::TypeAscriptionOwner for RecordFieldDef {} 110}
192impl RecordFieldDef {} 111#[derive(Debug, Clone, PartialEq, Eq, Hash)]
193/// Tuple field definition list including enclosing parens. 112pub struct ConstArg {
194///
195/// ```
196/// struct Foo ❰ (u32, String, Vec<u32>) ❱;
197/// ```
198///
199/// [Reference](https://doc.rust-lang.org/reference/items/structs.html)
200#[derive(Debug, Clone, PartialEq, Eq, Hash)]
201pub struct TupleFieldDefList {
202 pub(crate) syntax: SyntaxNode, 113 pub(crate) syntax: SyntaxNode,
203} 114}
204impl TupleFieldDefList { 115impl ConstArg {
205 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } 116 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
206 pub fn fields(&self) -> AstChildren<TupleFieldDef> { support::children(&self.syntax) }
207 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
208} 117}
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)] 118#[derive(Debug, Clone, PartialEq, Eq, Hash)]
217pub struct TupleFieldDef { 119pub struct TypeBoundList {
218 pub(crate) syntax: SyntaxNode, 120 pub(crate) syntax: SyntaxNode,
219} 121}
220impl ast::VisibilityOwner for TupleFieldDef {} 122impl TypeBoundList {
221impl ast::AttrsOwner for TupleFieldDef {} 123 pub fn bounds(&self) -> AstChildren<TypeBound> { support::children(&self.syntax) }
222impl TupleFieldDef {
223 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
224}
225/// Enum definition.
226/// Includes all of its attributes and doc comments.
227///
228/// ```
229/// ❰
230/// /// Docs
231/// #[attr]
232/// pub enum Foo<T> where T: Debug {
233/// /// Docs
234/// #[attr]
235/// Bar,
236/// Baz(#[attr] u32),
237/// Bruh {
238/// a: u32,
239/// /// Docs
240/// #[attr]
241/// b: T,
242/// }
243/// }
244/// ❱
245/// ```
246///
247/// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html)
248#[derive(Debug, Clone, PartialEq, Eq, Hash)]
249pub struct EnumDef {
250 pub(crate) syntax: SyntaxNode,
251} 124}
252impl ast::VisibilityOwner for EnumDef {} 125#[derive(Debug, Clone, PartialEq, Eq, Hash)]
253impl ast::NameOwner for EnumDef {} 126pub struct MacroCall {
254impl ast::TypeParamsOwner for EnumDef {}
255impl ast::AttrsOwner for EnumDef {}
256impl ast::DocCommentsOwner for EnumDef {}
257impl EnumDef {
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)]
278pub struct EnumVariantList {
279 pub(crate) syntax: SyntaxNode, 127 pub(crate) syntax: SyntaxNode,
280} 128}
281impl EnumVariantList { 129impl ast::AttrsOwner for MacroCall {}
282 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } 130impl ast::NameOwner for MacroCall {}
283 pub fn variants(&self) -> AstChildren<EnumVariant> { support::children(&self.syntax) } 131impl MacroCall {
284 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } 132 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
133 pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) }
134 pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) }
135 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
285} 136}
286/// Enum variant definition including its attributes and discriminant value definition. 137#[derive(Debug, Clone, PartialEq, Eq, Hash)]
287/// 138pub struct Attr {
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)]
302pub struct EnumVariant {
303 pub(crate) syntax: SyntaxNode, 139 pub(crate) syntax: SyntaxNode,
304} 140}
305impl ast::VisibilityOwner for EnumVariant {} 141impl Attr {
306impl ast::NameOwner for EnumVariant {} 142 pub fn pound_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![#]) }
307impl ast::DocCommentsOwner for EnumVariant {} 143 pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) }
308impl ast::AttrsOwner for EnumVariant {} 144 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
309impl EnumVariant { 145 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
310 pub fn field_def_list(&self) -> Option<FieldDefList> { support::child(&self.syntax) }
311 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } 146 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
312 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 147 pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) }
148 pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) }
149 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
313} 150}
314/// Trait definition. 151#[derive(Debug, Clone, PartialEq, Eq, Hash)]
315/// Includes all of its attributes and doc comments. 152pub struct TokenTree {
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)]
329pub struct TraitDef {
330 pub(crate) syntax: SyntaxNode, 153 pub(crate) syntax: SyntaxNode,
331} 154}
332impl ast::VisibilityOwner for TraitDef {} 155impl TokenTree {
333impl ast::NameOwner for TraitDef {} 156 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
334impl ast::AttrsOwner for TraitDef {} 157 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
335impl ast::DocCommentsOwner for TraitDef {} 158 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
336impl ast::TypeParamsOwner for TraitDef {} 159 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
337impl ast::TypeBoundsOwner for TraitDef {} 160 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
338impl TraitDef { 161 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
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} 162}
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)] 163#[derive(Debug, Clone, PartialEq, Eq, Hash)]
366pub struct Module { 164pub struct MacroItems {
367 pub(crate) syntax: SyntaxNode, 165 pub(crate) syntax: SyntaxNode,
368} 166}
369impl ast::VisibilityOwner for Module {} 167impl ast::ModuleItemOwner for MacroItems {}
370impl ast::NameOwner for Module {} 168impl MacroItems {}
371impl ast::AttrsOwner for Module {} 169#[derive(Debug, Clone, PartialEq, Eq, Hash)]
372impl ast::DocCommentsOwner for Module {} 170pub struct MacroStmts {
373impl Module { 171 pub(crate) syntax: SyntaxNode,
374 pub fn mod_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mod]) } 172}
375 pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } 173impl MacroStmts {
376 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 174 pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) }
175 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
377} 176}
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)] 177#[derive(Debug, Clone, PartialEq, Eq, Hash)]
401pub struct ItemList { 178pub struct SourceFile {
402 pub(crate) syntax: SyntaxNode, 179 pub(crate) syntax: SyntaxNode,
403} 180}
404impl ast::ModuleItemOwner for ItemList {} 181impl ast::AttrsOwner for SourceFile {}
405impl ItemList { 182impl ast::ModuleItemOwner for SourceFile {}
406 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } 183impl SourceFile {
407 pub fn assoc_items(&self) -> AstChildren<AssocItem> { support::children(&self.syntax) } 184 pub fn shebang_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![shebang]) }
408 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
409} 185}
410/// Constant variable definition. 186#[derive(Debug, Clone, PartialEq, Eq, Hash)]
411/// Includes all of its attributes and doc comments. 187pub struct Const {
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)]
423pub struct ConstDef {
424 pub(crate) syntax: SyntaxNode, 188 pub(crate) syntax: SyntaxNode,
425} 189}
426impl ast::VisibilityOwner for ConstDef {} 190impl ast::AttrsOwner for Const {}
427impl ast::NameOwner for ConstDef {} 191impl ast::NameOwner for Const {}
428impl ast::TypeParamsOwner for ConstDef {} 192impl ast::VisibilityOwner for Const {}
429impl ast::AttrsOwner for ConstDef {} 193impl Const {
430impl ast::DocCommentsOwner for ConstDef {}
431impl ast::TypeAscriptionOwner for ConstDef {}
432impl ConstDef {
433 pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) } 194 pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) }
434 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } 195 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
196 pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) }
197 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
198 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
435 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } 199 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
436 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } 200 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) }
437 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 201 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
438} 202}
439/// Static variable definition. 203#[derive(Debug, Clone, PartialEq, Eq, Hash)]
440/// Includes all of its attributes and doc comments. 204pub struct Enum {
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)]
452pub struct StaticDef {
453 pub(crate) syntax: SyntaxNode, 205 pub(crate) syntax: SyntaxNode,
454} 206}
455impl ast::VisibilityOwner for StaticDef {} 207impl ast::AttrsOwner for Enum {}
456impl ast::NameOwner for StaticDef {} 208impl ast::NameOwner for Enum {}
457impl ast::TypeParamsOwner for StaticDef {} 209impl ast::VisibilityOwner for Enum {}
458impl ast::AttrsOwner for StaticDef {} 210impl ast::GenericParamsOwner for Enum {}
459impl ast::DocCommentsOwner for StaticDef {} 211impl Enum {
460impl ast::TypeAscriptionOwner for StaticDef {} 212 pub fn enum_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![enum]) }
461impl StaticDef { 213 pub fn variant_list(&self) -> Option<VariantList> { support::child(&self.syntax) }
462 pub fn static_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![static]) } 214}
463 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } 215#[derive(Debug, Clone, PartialEq, Eq, Hash)]
464 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } 216pub struct ExternBlock {
465 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } 217 pub(crate) syntax: SyntaxNode,
218}
219impl ast::AttrsOwner for ExternBlock {}
220impl ExternBlock {
221 pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) }
222 pub fn extern_item_list(&self) -> Option<ExternItemList> { support::child(&self.syntax) }
223}
224#[derive(Debug, Clone, PartialEq, Eq, Hash)]
225pub struct ExternCrate {
226 pub(crate) syntax: SyntaxNode,
227}
228impl ast::AttrsOwner for ExternCrate {}
229impl ast::VisibilityOwner for ExternCrate {}
230impl ExternCrate {
231 pub fn extern_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![extern]) }
232 pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) }
233 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
234 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) }
235 pub fn rename(&self) -> Option<Rename> { support::child(&self.syntax) }
466 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 236 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
467} 237}
468/// Type alias definition. 238#[derive(Debug, Clone, PartialEq, Eq, Hash)]
469/// Includes associated type clauses with type bounds. 239pub struct Fn {
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)]
487pub struct TypeAliasDef {
488 pub(crate) syntax: SyntaxNode, 240 pub(crate) syntax: SyntaxNode,
489} 241}
490impl ast::VisibilityOwner for TypeAliasDef {} 242impl ast::AttrsOwner for Fn {}
491impl ast::NameOwner for TypeAliasDef {} 243impl ast::NameOwner for Fn {}
492impl ast::TypeParamsOwner for TypeAliasDef {} 244impl ast::VisibilityOwner for Fn {}
493impl ast::AttrsOwner for TypeAliasDef {} 245impl ast::GenericParamsOwner for Fn {}
494impl ast::DocCommentsOwner for TypeAliasDef {} 246impl Fn {
495impl ast::TypeBoundsOwner for TypeAliasDef {}
496impl TypeAliasDef {
497 pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) } 247 pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) }
498 pub fn type_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![type]) } 248 pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) }
499 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } 249 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
500 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 250 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) }
251 pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) }
252 pub fn fn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![fn]) }
253 pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) }
254 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) }
255 pub fn body(&self) -> Option<BlockExpr> { support::child(&self.syntax) }
501 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 256 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
502} 257}
503/// Inherent and trait impl definition. 258#[derive(Debug, Clone, PartialEq, Eq, Hash)]
504/// Includes all of its inner and outer attributes. 259pub struct Impl {
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)]
518pub struct ImplDef {
519 pub(crate) syntax: SyntaxNode, 260 pub(crate) syntax: SyntaxNode,
520} 261}
521impl ast::TypeParamsOwner for ImplDef {} 262impl ast::AttrsOwner for Impl {}
522impl ast::AttrsOwner for ImplDef {} 263impl ast::VisibilityOwner for Impl {}
523impl ast::DocCommentsOwner for ImplDef {} 264impl ast::GenericParamsOwner for Impl {}
524impl ImplDef { 265impl Impl {
525 pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) } 266 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]) }
527 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) } 267 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) }
528 pub fn impl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![impl]) } 268 pub fn impl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![impl]) }
269 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
529 pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) } 270 pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) }
530 pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) } 271 pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) }
272 pub fn assoc_item_list(&self) -> Option<AssocItemList> { support::child(&self.syntax) }
273}
274#[derive(Debug, Clone, PartialEq, Eq, Hash)]
275pub struct Module {
276 pub(crate) syntax: SyntaxNode,
277}
278impl ast::AttrsOwner for Module {}
279impl ast::NameOwner for Module {}
280impl ast::VisibilityOwner for Module {}
281impl Module {
282 pub fn mod_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mod]) }
531 pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } 283 pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) }
284 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
532} 285}
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)] 286#[derive(Debug, Clone, PartialEq, Eq, Hash)]
544pub struct ParenType { 287pub struct Static {
545 pub(crate) syntax: SyntaxNode, 288 pub(crate) syntax: SyntaxNode,
546} 289}
547impl ParenType { 290impl ast::AttrsOwner for Static {}
548 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } 291impl ast::NameOwner for Static {}
549 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 292impl ast::VisibilityOwner for Static {}
550 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 293impl Static {
294 pub fn static_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![static]) }
295 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
296 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
297 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
298 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
299 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) }
300 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
551} 301}
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)] 302#[derive(Debug, Clone, PartialEq, Eq, Hash)]
560pub struct TupleType { 303pub struct Struct {
561 pub(crate) syntax: SyntaxNode, 304 pub(crate) syntax: SyntaxNode,
562} 305}
563impl TupleType { 306impl ast::AttrsOwner for Struct {}
564 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } 307impl ast::NameOwner for Struct {}
565 pub fn fields(&self) -> AstChildren<TypeRef> { support::children(&self.syntax) } 308impl ast::VisibilityOwner for Struct {}
566 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 309impl ast::GenericParamsOwner for Struct {}
310impl Struct {
311 pub fn struct_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![struct]) }
312 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
313 pub fn field_list(&self) -> Option<FieldList> { support::child(&self.syntax) }
567} 314}
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)] 315#[derive(Debug, Clone, PartialEq, Eq, Hash)]
580pub struct NeverType { 316pub struct Trait {
581 pub(crate) syntax: SyntaxNode, 317 pub(crate) syntax: SyntaxNode,
582} 318}
583impl NeverType { 319impl ast::AttrsOwner for Trait {}
584 pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) } 320impl ast::NameOwner for Trait {}
321impl ast::VisibilityOwner for Trait {}
322impl ast::GenericParamsOwner for Trait {}
323impl ast::TypeBoundsOwner for Trait {}
324impl Trait {
325 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) }
326 pub fn auto_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![auto]) }
327 pub fn trait_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![trait]) }
328 pub fn assoc_item_list(&self) -> Option<AssocItemList> { support::child(&self.syntax) }
585} 329}
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)] 330#[derive(Debug, Clone, PartialEq, Eq, Hash)]
598pub struct PathType { 331pub struct TypeAlias {
599 pub(crate) syntax: SyntaxNode, 332 pub(crate) syntax: SyntaxNode,
600} 333}
601impl PathType { 334impl ast::AttrsOwner for TypeAlias {}
602 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } 335impl ast::NameOwner for TypeAlias {}
336impl ast::VisibilityOwner for TypeAlias {}
337impl ast::GenericParamsOwner for TypeAlias {}
338impl ast::TypeBoundsOwner for TypeAlias {}
339impl TypeAlias {
340 pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) }
341 pub fn type_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![type]) }
342 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
343 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
344 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
603} 345}
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)] 346#[derive(Debug, Clone, PartialEq, Eq, Hash)]
613pub struct PointerType { 347pub struct Union {
614 pub(crate) syntax: SyntaxNode, 348 pub(crate) syntax: SyntaxNode,
615} 349}
616impl PointerType { 350impl ast::AttrsOwner for Union {}
617 pub fn star_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![*]) } 351impl ast::NameOwner for Union {}
618 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } 352impl ast::VisibilityOwner for Union {}
619 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } 353impl ast::GenericParamsOwner for Union {}
620 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 354impl Union {
355 pub fn union_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![union]) }
356 pub fn record_field_list(&self) -> Option<RecordFieldList> { support::child(&self.syntax) }
621} 357}
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)] 358#[derive(Debug, Clone, PartialEq, Eq, Hash)]
630pub struct ArrayType { 359pub struct Use {
631 pub(crate) syntax: SyntaxNode, 360 pub(crate) syntax: SyntaxNode,
632} 361}
633impl ArrayType { 362impl ast::AttrsOwner for Use {}
634 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } 363impl ast::VisibilityOwner for Use {}
635 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 364impl Use {
365 pub fn use_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![use]) }
366 pub fn use_tree(&self) -> Option<UseTree> { support::child(&self.syntax) }
636 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 367 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
637 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
638 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
639} 368}
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)] 369#[derive(Debug, Clone, PartialEq, Eq, Hash)]
648pub struct SliceType { 370pub struct Visibility {
649 pub(crate) syntax: SyntaxNode, 371 pub(crate) syntax: SyntaxNode,
650} 372}
651impl SliceType { 373impl Visibility {
652 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } 374 pub fn pub_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![pub]) }
653 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 375 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
654 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } 376 pub fn super_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![super]) }
377 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) }
378 pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) }
379 pub fn in_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![in]) }
380 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
381 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
655} 382}
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)] 383#[derive(Debug, Clone, PartialEq, Eq, Hash)]
664pub struct ReferenceType { 384pub struct ItemList {
665 pub(crate) syntax: SyntaxNode, 385 pub(crate) syntax: SyntaxNode,
666} 386}
667impl ReferenceType { 387impl ast::AttrsOwner for ItemList {}
668 pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) } 388impl ast::ModuleItemOwner for ItemList {}
669 pub fn lifetime_token(&self) -> Option<SyntaxToken> { 389impl ItemList {
670 support::token(&self.syntax, T![lifetime]) 390 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
671 } 391 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
672 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) }
674} 392}
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)] 393#[derive(Debug, Clone, PartialEq, Eq, Hash)]
683pub struct PlaceholderType { 394pub struct Rename {
684 pub(crate) syntax: SyntaxNode, 395 pub(crate) syntax: SyntaxNode,
685} 396}
686impl PlaceholderType { 397impl ast::NameOwner for Rename {}
398impl Rename {
399 pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) }
687 pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) } 400 pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) }
688} 401}
689/// Function pointer type (not to be confused with `Fn*` family of traits). 402#[derive(Debug, Clone, PartialEq, Eq, Hash)]
690/// 403pub struct UseTree {
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)]
699pub struct FnPointerType {
700 pub(crate) syntax: SyntaxNode, 404 pub(crate) syntax: SyntaxNode,
701} 405}
702impl FnPointerType { 406impl UseTree {
703 pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) } 407 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
704 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) } 408 pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) }
705 pub fn fn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![fn]) } 409 pub fn star_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![*]) }
706 pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) } 410 pub fn use_tree_list(&self) -> Option<UseTreeList> { support::child(&self.syntax) }
707 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } 411 pub fn rename(&self) -> Option<Rename> { support::child(&self.syntax) }
708} 412}
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)] 413#[derive(Debug, Clone, PartialEq, Eq, Hash)]
717pub struct ForType { 414pub struct UseTreeList {
718 pub(crate) syntax: SyntaxNode, 415 pub(crate) syntax: SyntaxNode,
719} 416}
720impl ForType { 417impl UseTreeList {
721 pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) } 418 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
722 pub fn type_param_list(&self) -> Option<TypeParamList> { support::child(&self.syntax) } 419 pub fn use_trees(&self) -> AstChildren<UseTree> { support::children(&self.syntax) }
723 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } 420 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
724} 421}
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)] 422#[derive(Debug, Clone, PartialEq, Eq, Hash)]
733pub struct ImplTraitType { 423pub struct Abi {
734 pub(crate) syntax: SyntaxNode, 424 pub(crate) syntax: SyntaxNode,
735} 425}
736impl ast::TypeBoundsOwner for ImplTraitType {} 426impl Abi {
737impl ImplTraitType { 427 pub fn extern_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![extern]) }
738 pub fn impl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![impl]) }
739} 428}
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)] 429#[derive(Debug, Clone, PartialEq, Eq, Hash)]
748pub struct DynTraitType { 430pub struct GenericParamList {
749 pub(crate) syntax: SyntaxNode, 431 pub(crate) syntax: SyntaxNode,
750} 432}
751impl ast::TypeBoundsOwner for DynTraitType {} 433impl GenericParamList {
752impl DynTraitType { 434 pub fn l_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![<]) }
753 pub fn dyn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![dyn]) } 435 pub fn generic_params(&self) -> AstChildren<GenericParam> { support::children(&self.syntax) }
436 pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) }
754} 437}
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)] 438#[derive(Debug, Clone, PartialEq, Eq, Hash)]
763pub struct TupleExpr { 439pub struct WhereClause {
764 pub(crate) syntax: SyntaxNode, 440 pub(crate) syntax: SyntaxNode,
765} 441}
766impl ast::AttrsOwner for TupleExpr {} 442impl WhereClause {
767impl TupleExpr { 443 pub fn where_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![where]) }
768 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } 444 pub fn predicates(&self) -> AstChildren<WherePred> { support::children(&self.syntax) }
769 pub fn exprs(&self) -> AstChildren<Expr> { support::children(&self.syntax) }
770 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
771} 445}
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)] 446#[derive(Debug, Clone, PartialEq, Eq, Hash)]
782pub struct ArrayExpr { 447pub struct BlockExpr {
783 pub(crate) syntax: SyntaxNode, 448 pub(crate) syntax: SyntaxNode,
784} 449}
785impl ast::AttrsOwner for ArrayExpr {} 450impl ast::AttrsOwner for BlockExpr {}
786impl ArrayExpr { 451impl BlockExpr {
787 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } 452 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
788 pub fn exprs(&self) -> AstChildren<Expr> { support::children(&self.syntax) } 453 pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) }
789 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 454 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
790 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } 455 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
791} 456}
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)] 457#[derive(Debug, Clone, PartialEq, Eq, Hash)]
801pub struct ParenExpr { 458pub struct SelfParam {
802 pub(crate) syntax: SyntaxNode, 459 pub(crate) syntax: SyntaxNode,
803} 460}
804impl ast::AttrsOwner for ParenExpr {} 461impl ast::AttrsOwner for SelfParam {}
805impl ParenExpr { 462impl SelfParam {
806 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } 463 pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) }
807 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 464 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
808 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 465 support::token(&self.syntax, T![lifetime])
466 }
467 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
468 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) }
469 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
470 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
809} 471}
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)] 472#[derive(Debug, Clone, PartialEq, Eq, Hash)]
824pub struct PathExpr { 473pub struct Param {
825 pub(crate) syntax: SyntaxNode, 474 pub(crate) syntax: SyntaxNode,
826} 475}
827impl PathExpr { 476impl ast::AttrsOwner for Param {}
828 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } 477impl Param {
478 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
479 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
480 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
481 pub fn dotdotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![...]) }
829} 482}
830/// Anonymous callable object literal a.k.a. closure, lambda or functor. 483#[derive(Debug, Clone, PartialEq, Eq, Hash)]
831/// 484pub struct RecordFieldList {
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)]
842pub struct LambdaExpr {
843 pub(crate) syntax: SyntaxNode, 485 pub(crate) syntax: SyntaxNode,
844} 486}
845impl ast::AttrsOwner for LambdaExpr {} 487impl RecordFieldList {
846impl LambdaExpr { 488 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
847 pub fn static_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![static]) } 489 pub fn fields(&self) -> AstChildren<RecordField> { support::children(&self.syntax) }
848 pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) } 490 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
849 pub fn move_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![move]) }
850 pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) }
851 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) }
852 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) }
853} 491}
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)] 492#[derive(Debug, Clone, PartialEq, Eq, Hash)]
874pub struct IfExpr { 493pub struct TupleFieldList {
875 pub(crate) syntax: SyntaxNode, 494 pub(crate) syntax: SyntaxNode,
876} 495}
877impl ast::AttrsOwner for IfExpr {} 496impl TupleFieldList {
878impl IfExpr { 497 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
879 pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) } 498 pub fn fields(&self) -> AstChildren<TupleField> { support::children(&self.syntax) }
880 pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } 499 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
881} 500}
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)] 501#[derive(Debug, Clone, PartialEq, Eq, Hash)]
894pub struct LoopExpr { 502pub struct RecordField {
895 pub(crate) syntax: SyntaxNode, 503 pub(crate) syntax: SyntaxNode,
896} 504}
897impl ast::AttrsOwner for LoopExpr {} 505impl ast::AttrsOwner for RecordField {}
898impl ast::LoopBodyOwner for LoopExpr {} 506impl ast::NameOwner for RecordField {}
899impl LoopExpr { 507impl ast::VisibilityOwner for RecordField {}
900 pub fn loop_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![loop]) } 508impl RecordField {
509 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
510 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
901} 511}
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)] 512#[derive(Debug, Clone, PartialEq, Eq, Hash)]
917pub struct EffectExpr { 513pub struct TupleField {
918 pub(crate) syntax: SyntaxNode, 514 pub(crate) syntax: SyntaxNode,
919} 515}
920impl ast::AttrsOwner for EffectExpr {} 516impl ast::AttrsOwner for TupleField {}
921impl EffectExpr { 517impl ast::VisibilityOwner for TupleField {}
922 pub fn label(&self) -> Option<Label> { support::child(&self.syntax) } 518impl TupleField {
923 pub fn try_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![try]) } 519 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
924 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) }
925 pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) }
926 pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) }
927} 520}
928/// For loop expression.
929/// Note: record struct literals are not valid as iterable expression
930/// due to ambiguity.
931///
932/// ```
933/// ❰
934/// for i in (0..4) {
935/// dbg!(i);
936/// }
937/// ❱
938/// ```
939///
940/// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#iterator-loops)
941#[derive(Debug, Clone, PartialEq, Eq, Hash)] 521#[derive(Debug, Clone, PartialEq, Eq, Hash)]
942pub struct ForExpr { 522pub struct VariantList {
943 pub(crate) syntax: SyntaxNode, 523 pub(crate) syntax: SyntaxNode,
944} 524}
945impl ast::AttrsOwner for ForExpr {} 525impl VariantList {
946impl ast::LoopBodyOwner for ForExpr {} 526 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
947impl ForExpr { 527 pub fn variants(&self) -> AstChildren<Variant> { support::children(&self.syntax) }
948 pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) } 528 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
949 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
950 pub fn in_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![in]) }
951 pub fn iterable(&self) -> Option<Expr> { support::child(&self.syntax) }
952} 529}
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)] 530#[derive(Debug, Clone, PartialEq, Eq, Hash)]
970pub struct WhileExpr { 531pub struct Variant {
971 pub(crate) syntax: SyntaxNode, 532 pub(crate) syntax: SyntaxNode,
972} 533}
973impl ast::AttrsOwner for WhileExpr {} 534impl ast::AttrsOwner for Variant {}
974impl ast::LoopBodyOwner for WhileExpr {} 535impl ast::NameOwner for Variant {}
975impl WhileExpr { 536impl ast::VisibilityOwner for Variant {}
976 pub fn while_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![while]) } 537impl Variant {
977 pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } 538 pub fn field_list(&self) -> Option<FieldList> { support::child(&self.syntax) }
539 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
540 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
978} 541}
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)] 542#[derive(Debug, Clone, PartialEq, Eq, Hash)]
996pub struct ContinueExpr { 543pub struct AssocItemList {
997 pub(crate) syntax: SyntaxNode, 544 pub(crate) syntax: SyntaxNode,
998} 545}
999impl ast::AttrsOwner for ContinueExpr {} 546impl ast::AttrsOwner for AssocItemList {}
1000impl ContinueExpr { 547impl AssocItemList {
1001 pub fn continue_token(&self) -> Option<SyntaxToken> { 548 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
1002 support::token(&self.syntax, T![continue]) 549 pub fn assoc_items(&self) -> AstChildren<AssocItem> { support::children(&self.syntax) }
1003 } 550 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
1004 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
1005 support::token(&self.syntax, T![lifetime])
1006 }
1007} 551}
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)] 552#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1028pub struct BreakExpr { 553pub struct ExternItemList {
1029 pub(crate) syntax: SyntaxNode, 554 pub(crate) syntax: SyntaxNode,
1030} 555}
1031impl ast::AttrsOwner for BreakExpr {} 556impl ast::AttrsOwner for ExternItemList {}
1032impl BreakExpr { 557impl ExternItemList {
1033 pub fn break_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![break]) } 558 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
1034 pub fn lifetime_token(&self) -> Option<SyntaxToken> { 559 pub fn extern_items(&self) -> AstChildren<ExternItem> { support::children(&self.syntax) }
1035 support::token(&self.syntax, T![lifetime]) 560 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
1036 }
1037 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1038} 561}
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)] 562#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1054pub struct Label { 563pub struct ConstParam {
1055 pub(crate) syntax: SyntaxNode, 564 pub(crate) syntax: SyntaxNode,
1056} 565}
1057impl Label { 566impl ast::AttrsOwner for ConstParam {}
567impl ast::NameOwner for ConstParam {}
568impl ConstParam {
569 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
570 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
571 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
572 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
573 pub fn default_val(&self) -> Option<Expr> { support::child(&self.syntax) }
574}
575#[derive(Debug, Clone, PartialEq, Eq, Hash)]
576pub struct LifetimeParam {
577 pub(crate) syntax: SyntaxNode,
578}
579impl ast::AttrsOwner for LifetimeParam {}
580impl ast::TypeBoundsOwner for LifetimeParam {}
581impl LifetimeParam {
1058 pub fn lifetime_token(&self) -> Option<SyntaxToken> { 582 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
1059 support::token(&self.syntax, T![lifetime]) 583 support::token(&self.syntax, T![lifetime])
1060 } 584 }
1061} 585}
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)] 586#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1078pub struct BlockExpr { 587pub struct TypeParam {
1079 pub(crate) syntax: SyntaxNode, 588 pub(crate) syntax: SyntaxNode,
1080} 589}
1081impl ast::AttrsOwner for BlockExpr {} 590impl ast::AttrsOwner for TypeParam {}
1082impl ast::ModuleItemOwner for BlockExpr {} 591impl ast::NameOwner for TypeParam {}
1083impl BlockExpr { 592impl ast::TypeBoundsOwner for TypeParam {}
1084 pub fn label(&self) -> Option<Label> { support::child(&self.syntax) } 593impl TypeParam {
1085 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } 594 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
1086 pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) } 595 pub fn default_type(&self) -> Option<Type> { support::child(&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} 596}
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)] 597#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1102pub struct ReturnExpr { 598pub struct WherePred {
1103 pub(crate) syntax: SyntaxNode, 599 pub(crate) syntax: SyntaxNode,
1104} 600}
1105impl ast::AttrsOwner for ReturnExpr {} 601impl ast::TypeBoundsOwner for WherePred {}
1106impl ReturnExpr { 602impl WherePred {
1107 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 603 pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) }
604 pub fn generic_param_list(&self) -> Option<GenericParamList> { support::child(&self.syntax) }
605 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
606 support::token(&self.syntax, T![lifetime])
607 }
608 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
1108} 609}
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)] 610#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1120pub struct CallExpr { 611pub struct Literal {
1121 pub(crate) syntax: SyntaxNode, 612 pub(crate) syntax: SyntaxNode,
1122} 613}
1123impl ast::ArgListOwner for CallExpr {} 614impl ast::AttrsOwner for Literal {}
1124impl CallExpr { 615impl Literal {}
1125 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1126}
1127/// Method call expression.
1128///
1129/// ```
1130/// ❰ receiver_expr.method() ❱;
1131/// ❰ receiver_expr.method::<T>(42, true) ❱;
1132///
1133/// ❰ ❰ ❰ foo.bar() ❱ .baz() ❱ .bruh() ❱;
1134/// ```
1135///
1136/// [Reference](https://doc.rust-lang.org/reference/expressions/method-call-expr.html)
1137#[derive(Debug, Clone, PartialEq, Eq, Hash)] 616#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1138pub struct MethodCallExpr { 617pub struct ExprStmt {
1139 pub(crate) syntax: SyntaxNode, 618 pub(crate) syntax: SyntaxNode,
1140} 619}
1141impl ast::AttrsOwner for MethodCallExpr {} 620impl ast::AttrsOwner for ExprStmt {}
1142impl ast::ArgListOwner for MethodCallExpr {} 621impl ExprStmt {
1143impl MethodCallExpr {
1144 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 622 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1145 pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) } 623 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
1146 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
1147 pub fn type_arg_list(&self) -> Option<TypeArgList> { support::child(&self.syntax) }
1148} 624}
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)] 625#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1157pub struct IndexExpr { 626pub struct LetStmt {
1158 pub(crate) syntax: SyntaxNode, 627 pub(crate) syntax: SyntaxNode,
1159} 628}
1160impl ast::AttrsOwner for IndexExpr {} 629impl ast::AttrsOwner for LetStmt {}
1161impl IndexExpr { 630impl LetStmt {
1162 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } 631 pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) }
1163 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } 632 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
633 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
634 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
635 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
636 pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) }
637 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
1164} 638}
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)] 639#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1175pub struct FieldExpr { 640pub struct ArrayExpr {
1176 pub(crate) syntax: SyntaxNode, 641 pub(crate) syntax: SyntaxNode,
1177} 642}
1178impl ast::AttrsOwner for FieldExpr {} 643impl ast::AttrsOwner for ArrayExpr {}
1179impl FieldExpr { 644impl ArrayExpr {
645 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
646 pub fn exprs(&self) -> AstChildren<Expr> { support::children(&self.syntax) }
1180 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 647 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1181 pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) } 648 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
1182 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } 649 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
1183} 650}
1184/// Await operator call expression.
1185///
1186/// ```
1187/// ❰ expr.await ❱;
1188/// ```
1189///
1190/// [Reference](https://doc.rust-lang.org/reference/expressions/await-expr.html)
1191#[derive(Debug, Clone, PartialEq, Eq, Hash)] 651#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1192pub struct AwaitExpr { 652pub struct AwaitExpr {
1193 pub(crate) syntax: SyntaxNode, 653 pub(crate) syntax: SyntaxNode,
@@ -1198,1579 +658,739 @@ impl AwaitExpr {
1198 pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) } 658 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]) } 659 pub fn await_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![await]) }
1200} 660}
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)] 661#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1209pub struct TryExpr { 662pub struct BinExpr {
1210 pub(crate) syntax: SyntaxNode, 663 pub(crate) syntax: SyntaxNode,
1211} 664}
1212impl ast::AttrsOwner for TryExpr {} 665impl ast::AttrsOwner for BinExpr {}
1213impl TryExpr { 666impl BinExpr {}
1214 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1215 pub fn question_mark_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![?]) }
1216}
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)] 667#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1225pub struct CastExpr { 668pub struct BoxExpr {
1226 pub(crate) syntax: SyntaxNode, 669 pub(crate) syntax: SyntaxNode,
1227} 670}
1228impl ast::AttrsOwner for CastExpr {} 671impl ast::AttrsOwner for BoxExpr {}
1229impl CastExpr { 672impl BoxExpr {
673 pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) }
1230 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 674 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1231 pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) } 675}
1232 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
1233}
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)] 676#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1245pub struct RefExpr { 677pub struct BreakExpr {
1246 pub(crate) syntax: SyntaxNode, 678 pub(crate) syntax: SyntaxNode,
1247} 679}
1248impl ast::AttrsOwner for RefExpr {} 680impl ast::AttrsOwner for BreakExpr {}
1249impl RefExpr { 681impl BreakExpr {
1250 pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) } 682 pub fn break_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![break]) }
1251 pub fn raw_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![raw]) } 683 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
1252 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } 684 support::token(&self.syntax, T![lifetime])
1253 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } 685 }
1254 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 686 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1255} 687}
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)] 688#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1266pub struct PrefixExpr { 689pub struct CallExpr {
1267 pub(crate) syntax: SyntaxNode, 690 pub(crate) syntax: SyntaxNode,
1268} 691}
1269impl ast::AttrsOwner for PrefixExpr {} 692impl ast::AttrsOwner for CallExpr {}
1270impl PrefixExpr { 693impl ast::ArgListOwner for CallExpr {}
694impl CallExpr {
1271 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 695 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1272} 696}
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)] 697#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1281pub struct BoxExpr { 698pub struct CastExpr {
1282 pub(crate) syntax: SyntaxNode, 699 pub(crate) syntax: SyntaxNode,
1283} 700}
1284impl ast::AttrsOwner for BoxExpr {} 701impl ast::AttrsOwner for CastExpr {}
1285impl BoxExpr { 702impl CastExpr {
1286 pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) }
1287 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 703 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
704 pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) }
705 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
1288} 706}
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)] 707#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1302pub struct RangeExpr { 708pub struct ClosureExpr {
1303 pub(crate) syntax: SyntaxNode, 709 pub(crate) syntax: SyntaxNode,
1304} 710}
1305impl ast::AttrsOwner for RangeExpr {} 711impl ast::AttrsOwner for ClosureExpr {}
1306impl RangeExpr {} 712impl ClosureExpr {
1307/// Binary operator call. 713 pub fn static_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![static]) }
1308/// Includes all arithmetic, logic, bitwise and assignment operators. 714 pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) }
1309/// 715 pub fn move_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![move]) }
1310/// ``` 716 pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) }
1311/// ❰ 2 + ❰ 2 * 2 ❱ ❱; 717 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) }
1312/// ❰ ❰ true && false ❱ || true ❱; 718 pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) }
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)]
1317pub struct BinExpr {
1318 pub(crate) syntax: SyntaxNode,
1319} 719}
1320impl ast::AttrsOwner for BinExpr {}
1321impl 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)] 720#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1336pub struct Literal { 721pub struct ContinueExpr {
1337 pub(crate) syntax: SyntaxNode, 722 pub(crate) syntax: SyntaxNode,
1338} 723}
1339impl Literal {} 724impl ast::AttrsOwner for ContinueExpr {}
1340/// Match expression. 725impl ContinueExpr {
1341/// 726 pub fn continue_token(&self) -> Option<SyntaxToken> {
1342/// ``` 727 support::token(&self.syntax, T![continue])
1343/// ❰ 728 }
1344/// match expr { 729 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
1345/// Pat1 => {} 730 support::token(&self.syntax, T![lifetime])
1346/// Pat2(_) => 42, 731 }
1347/// } 732}
1348/// ❱
1349/// ```
1350///
1351/// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html)
1352#[derive(Debug, Clone, PartialEq, Eq, Hash)] 733#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1353pub struct MatchExpr { 734pub struct EffectExpr {
1354 pub(crate) syntax: SyntaxNode, 735 pub(crate) syntax: SyntaxNode,
1355} 736}
1356impl ast::AttrsOwner for MatchExpr {} 737impl ast::AttrsOwner for EffectExpr {}
1357impl MatchExpr { 738impl EffectExpr {
1358 pub fn match_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![match]) } 739 pub fn label(&self) -> Option<Label> { support::child(&self.syntax) }
1359 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 740 pub fn try_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![try]) }
1360 pub fn match_arm_list(&self) -> Option<MatchArmList> { support::child(&self.syntax) } 741 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) }
742 pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) }
743 pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) }
1361} 744}
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)] 745#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1377pub struct MatchArmList { 746pub struct FieldExpr {
1378 pub(crate) syntax: SyntaxNode, 747 pub(crate) syntax: SyntaxNode,
1379} 748}
1380impl ast::AttrsOwner for MatchArmList {} 749impl ast::AttrsOwner for FieldExpr {}
1381impl MatchArmList { 750impl FieldExpr {
1382 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } 751 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1383 pub fn arms(&self) -> AstChildren<MatchArm> { support::children(&self.syntax) } 752 pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) }
1384 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } 753 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
1385} 754}
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)] 755#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1397pub struct MatchArm { 756pub struct ForExpr {
1398 pub(crate) syntax: SyntaxNode, 757 pub(crate) syntax: SyntaxNode,
1399} 758}
1400impl ast::AttrsOwner for MatchArm {} 759impl ast::AttrsOwner for ForExpr {}
1401impl MatchArm { 760impl ast::LoopBodyOwner for ForExpr {}
761impl ForExpr {
762 pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) }
1402 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 763 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
1403 pub fn guard(&self) -> Option<MatchGuard> { support::child(&self.syntax) } 764 pub fn in_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![in]) }
1404 pub fn fat_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=>]) } 765 pub fn iterable(&self) -> Option<Expr> { support::child(&self.syntax) }
1405 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1406} 766}
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)] 767#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1417pub struct MatchGuard { 768pub struct IfExpr {
1418 pub(crate) syntax: SyntaxNode, 769 pub(crate) syntax: SyntaxNode,
1419} 770}
1420impl MatchGuard { 771impl ast::AttrsOwner for IfExpr {}
772impl IfExpr {
1421 pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) } 773 pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) }
1422 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 774 pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) }
775 pub fn else_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![else]) }
1423} 776}
1424/// Record literal expression. The same syntax is used for structs, 777#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1425/// unions and record enum variants. 778pub struct IndexExpr {
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)]
1440pub struct RecordLit {
1441 pub(crate) syntax: SyntaxNode, 779 pub(crate) syntax: SyntaxNode,
1442} 780}
1443impl RecordLit { 781impl ast::AttrsOwner for IndexExpr {}
1444 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } 782impl IndexExpr {
1445 pub fn record_field_list(&self) -> Option<RecordFieldList> { support::child(&self.syntax) } 783 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
784 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
1446} 785}
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)] 786#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1458pub struct RecordFieldList { 787pub struct LoopExpr {
1459 pub(crate) syntax: SyntaxNode, 788 pub(crate) syntax: SyntaxNode,
1460} 789}
1461impl RecordFieldList { 790impl ast::AttrsOwner for LoopExpr {}
1462 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } 791impl ast::LoopBodyOwner for LoopExpr {}
1463 pub fn fields(&self) -> AstChildren<RecordField> { support::children(&self.syntax) } 792impl LoopExpr {
1464 pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } 793 pub fn loop_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![loop]) }
1465 pub fn spread(&self) -> Option<Expr> { support::child(&self.syntax) }
1466 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
1467} 794}
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)] 795#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1478pub struct RecordField { 796pub struct MatchExpr {
1479 pub(crate) syntax: SyntaxNode, 797 pub(crate) syntax: SyntaxNode,
1480} 798}
1481impl ast::AttrsOwner for RecordField {} 799impl ast::AttrsOwner for MatchExpr {}
1482impl RecordField { 800impl MatchExpr {
1483 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } 801 pub fn match_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![match]) }
1484 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
1485 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 802 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
803 pub fn match_arm_list(&self) -> Option<MatchArmList> { support::child(&self.syntax) }
1486} 804}
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)] 805#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1495pub struct OrPat { 806pub struct MethodCallExpr {
1496 pub(crate) syntax: SyntaxNode, 807 pub(crate) syntax: SyntaxNode,
1497} 808}
1498impl OrPat { 809impl ast::AttrsOwner for MethodCallExpr {}
1499 pub fn pats(&self) -> AstChildren<Pat> { support::children(&self.syntax) } 810impl ast::ArgListOwner for MethodCallExpr {}
811impl MethodCallExpr {
812 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
813 pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) }
814 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
815 pub fn generic_arg_list(&self) -> Option<GenericArgList> { support::child(&self.syntax) }
1500} 816}
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)] 817#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1510pub struct ParenPat { 818pub struct ParenExpr {
1511 pub(crate) syntax: SyntaxNode, 819 pub(crate) syntax: SyntaxNode,
1512} 820}
1513impl ParenPat { 821impl ast::AttrsOwner for ParenExpr {}
822impl ParenExpr {
1514 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } 823 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
1515 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 824 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1516 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 825 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
1517} 826}
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)] 827#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1529pub struct RefPat { 828pub struct PathExpr {
1530 pub(crate) syntax: SyntaxNode, 829 pub(crate) syntax: SyntaxNode,
1531} 830}
1532impl RefPat { 831impl ast::AttrsOwner for PathExpr {}
1533 pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) } 832impl PathExpr {
1534 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } 833 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
1535 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
1536} 834}
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)] 835#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1545pub struct BoxPat { 836pub struct PrefixExpr {
1546 pub(crate) syntax: SyntaxNode,
1547}
1548impl BoxPat {
1549 pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) }
1550 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
1551}
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)]
1563pub struct BindPat {
1564 pub(crate) syntax: SyntaxNode, 837 pub(crate) syntax: SyntaxNode,
1565} 838}
1566impl ast::AttrsOwner for BindPat {} 839impl ast::AttrsOwner for PrefixExpr {}
1567impl ast::NameOwner for BindPat {} 840impl PrefixExpr {
1568impl BindPat { 841 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1569 pub fn ref_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ref]) }
1570 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
1571 pub fn at_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![@]) }
1572 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
1573} 842}
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)] 843#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1582pub struct PlaceholderPat { 844pub struct RangeExpr {
1583 pub(crate) syntax: SyntaxNode, 845 pub(crate) syntax: SyntaxNode,
1584} 846}
1585impl PlaceholderPat { 847impl ast::AttrsOwner for RangeExpr {}
1586 pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) } 848impl RangeExpr {}
1587} 849#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1588/// Rest-of-the record/tuple pattern. 850pub struct RecordExpr {
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)]
1599pub struct DotDotPat {
1600 pub(crate) syntax: SyntaxNode, 851 pub(crate) syntax: SyntaxNode,
1601} 852}
1602impl DotDotPat { 853impl RecordExpr {
1603 pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } 854 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
855 pub fn record_expr_field_list(&self) -> Option<RecordExprFieldList> {
856 support::child(&self.syntax)
857 }
1604} 858}
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)] 859#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1615pub struct PathPat { 860pub struct RefExpr {
1616 pub(crate) syntax: SyntaxNode, 861 pub(crate) syntax: SyntaxNode,
1617} 862}
1618impl PathPat { 863impl ast::AttrsOwner for RefExpr {}
1619 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } 864impl RefExpr {
865 pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) }
866 pub fn raw_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![raw]) }
867 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
868 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
869 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1620} 870}
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)] 871#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1629pub struct SlicePat { 872pub struct ReturnExpr {
1630 pub(crate) syntax: SyntaxNode, 873 pub(crate) syntax: SyntaxNode,
1631} 874}
1632impl SlicePat { 875impl ast::AttrsOwner for ReturnExpr {}
1633 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } 876impl ReturnExpr {
1634 pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } 877 pub fn return_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![return]) }
1635 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } 878 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1636} 879}
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)] 880#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1648pub struct RangePat { 881pub struct TryExpr {
1649 pub(crate) syntax: SyntaxNode, 882 pub(crate) syntax: SyntaxNode,
1650} 883}
1651impl RangePat {} 884impl ast::AttrsOwner for TryExpr {}
1652/// Literal pattern. 885impl TryExpr {
1653/// Includes only bool, number, char, and string literals. 886 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1654/// 887 pub fn question_mark_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![?]) }
1655/// ``` 888}
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)] 889#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1665pub struct LiteralPat { 890pub struct TupleExpr {
1666 pub(crate) syntax: SyntaxNode, 891 pub(crate) syntax: SyntaxNode,
1667} 892}
1668impl LiteralPat { 893impl ast::AttrsOwner for TupleExpr {}
1669 pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) } 894impl TupleExpr {
895 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
896 pub fn fields(&self) -> AstChildren<Expr> { support::children(&self.syntax) }
897 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
1670} 898}
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)] 899#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1679pub struct MacroPat { 900pub struct WhileExpr {
1680 pub(crate) syntax: SyntaxNode, 901 pub(crate) syntax: SyntaxNode,
1681} 902}
1682impl MacroPat { 903impl ast::AttrsOwner for WhileExpr {}
1683 pub fn macro_call(&self) -> Option<MacroCall> { support::child(&self.syntax) } 904impl ast::LoopBodyOwner for WhileExpr {}
905impl WhileExpr {
906 pub fn while_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![while]) }
907 pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) }
1684} 908}
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)] 909#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1693pub struct RecordPat { 910pub struct Label {
1694 pub(crate) syntax: SyntaxNode, 911 pub(crate) syntax: SyntaxNode,
1695} 912}
1696impl RecordPat { 913impl Label {
1697 pub fn record_field_pat_list(&self) -> Option<RecordFieldPatList> { 914 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
1698 support::child(&self.syntax) 915 support::token(&self.syntax, T![lifetime])
1699 } 916 }
1700 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
1701} 917}
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)] 918#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1710pub struct RecordFieldPatList { 919pub struct RecordExprFieldList {
1711 pub(crate) syntax: SyntaxNode, 920 pub(crate) syntax: SyntaxNode,
1712} 921}
1713impl RecordFieldPatList { 922impl ast::AttrsOwner for RecordExprFieldList {}
923impl RecordExprFieldList {
1714 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } 924 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
1715 pub fn pats(&self) -> AstChildren<RecordInnerPat> { support::children(&self.syntax) } 925 pub fn fields(&self) -> AstChildren<RecordExprField> { support::children(&self.syntax) }
1716 pub fn record_field_pats(&self) -> AstChildren<RecordFieldPat> {
1717 support::children(&self.syntax)
1718 }
1719 pub fn bind_pats(&self) -> AstChildren<BindPat> { support::children(&self.syntax) }
1720 pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } 926 pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) }
927 pub fn spread(&self) -> Option<Expr> { support::child(&self.syntax) }
1721 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } 928 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
1722} 929}
1723/// Record literal's field pattern. 930#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1724/// Note: record literal can also match tuple structs. 931pub struct RecordExprField {
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)]
1733pub struct RecordFieldPat {
1734 pub(crate) syntax: SyntaxNode, 932 pub(crate) syntax: SyntaxNode,
1735} 933}
1736impl ast::AttrsOwner for RecordFieldPat {} 934impl ast::AttrsOwner for RecordExprField {}
1737impl RecordFieldPat { 935impl RecordExprField {
1738 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } 936 pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) }
1739 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } 937 pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) }
1740 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 938 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1741} 939}
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)] 940#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1750pub struct TupleStructPat { 941pub struct ArgList {
1751 pub(crate) syntax: SyntaxNode, 942 pub(crate) syntax: SyntaxNode,
1752} 943}
1753impl TupleStructPat { 944impl ArgList {
1754 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
1755 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } 945 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
1756 pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } 946 pub fn args(&self) -> AstChildren<Expr> { support::children(&self.syntax) }
1757 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 947 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
1758} 948}
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)] 949#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1768pub struct TuplePat { 950pub struct Condition {
1769 pub(crate) syntax: SyntaxNode, 951 pub(crate) syntax: SyntaxNode,
1770} 952}
1771impl TuplePat { 953impl Condition {
1772 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } 954 pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) }
1773 pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } 955 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
1774 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 956 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
957 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1775} 958}
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)] 959#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1788pub struct Visibility { 960pub struct MatchArmList {
1789 pub(crate) syntax: SyntaxNode, 961 pub(crate) syntax: SyntaxNode,
1790} 962}
1791impl Visibility { 963impl ast::AttrsOwner for MatchArmList {}
1792 pub fn pub_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![pub]) } 964impl MatchArmList {
1793 pub fn super_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![super]) } 965 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
1794 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) } 966 pub fn arms(&self) -> AstChildren<MatchArm> { support::children(&self.syntax) }
1795 pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) } 967 pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
1796} 968}
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)] 969#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1821pub struct Name { 970pub struct MatchArm {
1822 pub(crate) syntax: SyntaxNode, 971 pub(crate) syntax: SyntaxNode,
1823} 972}
1824impl Name { 973impl ast::AttrsOwner for MatchArm {}
1825 pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) } 974impl MatchArm {
1826} 975 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
1827/// Reference to a name. 976 pub fn guard(&self) -> Option<MatchGuard> { support::child(&self.syntax) }
1828/// See the explanation on the difference between `Name` and `NameRef` 977 pub fn fat_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=>]) }
1829/// in `Name` ast node docs. 978 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1830/// 979 pub fn comma_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![,]) }
1831/// ```
1832/// let foo = ❰ bar ❱(❰ Baz(❰ bruh ❱) ❱;
1833/// ```
1834///
1835/// [Reference](https://doc.rust-lang.org/reference/identifiers.html)
1836#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1837pub struct NameRef {
1838 pub(crate) syntax: SyntaxNode,
1839} 980}
1840impl NameRef {}
1841/// Macro call.
1842/// Includes all of its attributes and doc comments.
1843///
1844/// ```
1845/// ❰
1846/// /// Docs
1847/// #[attr]
1848/// macro_rules! foo { // macro rules is also a macro call
1849/// ($bar: tt) => {}
1850/// }
1851/// ❱
1852///
1853/// // semicolon is a part of `MacroCall` when it is used in item positions
1854/// ❰ foo!(); ❱
1855///
1856/// fn main() {
1857/// ❰ foo!() ❱; // macro call in expression positions doesn't include the semi
1858/// }
1859/// ```
1860///
1861/// [Reference](https://doc.rust-lang.org/reference/macros.html)
1862#[derive(Debug, Clone, PartialEq, Eq, Hash)] 981#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1863pub struct MacroCall { 982pub struct MatchGuard {
1864 pub(crate) syntax: SyntaxNode, 983 pub(crate) syntax: SyntaxNode,
1865} 984}
1866impl ast::NameOwner for MacroCall {} 985impl MatchGuard {
1867impl ast::AttrsOwner for MacroCall {} 986 pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) }
1868impl ast::DocCommentsOwner for MacroCall {} 987 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1869impl MacroCall {
1870 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
1871 pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) }
1872 pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) }
1873 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
1874} 988}
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)] 989#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1888pub struct Attr { 990pub struct ArrayType {
1889 pub(crate) syntax: SyntaxNode, 991 pub(crate) syntax: SyntaxNode,
1890} 992}
1891impl Attr { 993impl ArrayType {
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!['[']) } 994 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
1895 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } 995 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
1896 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } 996 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
1897 pub fn input(&self) -> Option<AttrInput> { support::child(&self.syntax) } 997 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
1898 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } 998 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
1899} 999}
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)] 1000#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1909pub struct TokenTree { 1001pub struct DynTraitType {
1910 pub(crate) syntax: SyntaxNode,
1911}
1912impl 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)]
1927pub struct TypeParamList {
1928 pub(crate) syntax: SyntaxNode, 1002 pub(crate) syntax: SyntaxNode,
1929} 1003}
1930impl TypeParamList { 1004impl DynTraitType {
1931 pub fn l_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![<]) } 1005 pub fn dyn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![dyn]) }
1932 pub fn generic_params(&self) -> AstChildren<GenericParam> { support::children(&self.syntax) } 1006 pub fn type_bound_list(&self) -> Option<TypeBoundList> { support::child(&self.syntax) }
1933 pub fn type_params(&self) -> AstChildren<TypeParam> { support::children(&self.syntax) }
1934 pub fn lifetime_params(&self) -> AstChildren<LifetimeParam> { support::children(&self.syntax) }
1935 pub fn const_params(&self) -> AstChildren<ConstParam> { support::children(&self.syntax) }
1936 pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) }
1937} 1007}
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)] 1008#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1946pub struct TypeParam { 1009pub struct FnPtrType {
1947 pub(crate) syntax: SyntaxNode, 1010 pub(crate) syntax: SyntaxNode,
1948} 1011}
1949impl ast::NameOwner for TypeParam {} 1012impl FnPtrType {
1950impl ast::AttrsOwner for TypeParam {} 1013 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
1951impl ast::TypeBoundsOwner for TypeParam {} 1014 pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) }
1952impl TypeParam { 1015 pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) }
1953 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } 1016 pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) }
1954 pub fn default_type(&self) -> Option<TypeRef> { support::child(&self.syntax) } 1017 pub fn fn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![fn]) }
1018 pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) }
1019 pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) }
1955} 1020}
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)] 1021#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1963pub struct ConstParam { 1022pub struct ForType {
1964 pub(crate) syntax: SyntaxNode, 1023 pub(crate) syntax: SyntaxNode,
1965} 1024}
1966impl ast::NameOwner for ConstParam {} 1025impl ForType {
1967impl ast::AttrsOwner for ConstParam {} 1026 pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) }
1968impl ast::TypeAscriptionOwner for ConstParam {} 1027 pub fn generic_param_list(&self) -> Option<GenericParamList> { support::child(&self.syntax) }
1969impl ConstParam { 1028 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
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} 1029}
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)] 1030#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1981pub struct LifetimeParam { 1031pub struct ImplTraitType {
1982 pub(crate) syntax: SyntaxNode, 1032 pub(crate) syntax: SyntaxNode,
1983} 1033}
1984impl ast::AttrsOwner for LifetimeParam {} 1034impl ImplTraitType {
1985impl LifetimeParam { 1035 pub fn impl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![impl]) }
1986 pub fn lifetime_token(&self) -> Option<SyntaxToken> { 1036 pub fn type_bound_list(&self) -> Option<TypeBoundList> { support::child(&self.syntax) }
1987 support::token(&self.syntax, T![lifetime])
1988 }
1989}
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)]
2005pub struct TypeBound {
2006 pub(crate) syntax: SyntaxNode,
2007} 1037}
2008impl TypeBound {
2009 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
2010 support::token(&self.syntax, T![lifetime])
2011 }
2012 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) }
2014}
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)] 1038#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2031pub struct TypeBoundList { 1039pub struct InferType {
2032 pub(crate) syntax: SyntaxNode, 1040 pub(crate) syntax: SyntaxNode,
2033} 1041}
2034impl TypeBoundList { 1042impl InferType {
2035 pub fn bounds(&self) -> AstChildren<TypeBound> { support::children(&self.syntax) } 1043 pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) }
2036} 1044}
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)] 1045#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2050pub struct WherePred { 1046pub struct NeverType {
2051 pub(crate) syntax: SyntaxNode, 1047 pub(crate) syntax: SyntaxNode,
2052} 1048}
2053impl ast::TypeBoundsOwner for WherePred {} 1049impl NeverType {
2054impl WherePred { 1050 pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) }
2055 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) }
2057 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
2058 support::token(&self.syntax, T![lifetime])
2059 }
2060 pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) }
2061} 1051}
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)] 1052#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2071pub struct WhereClause { 1053pub struct ParenType {
2072 pub(crate) syntax: SyntaxNode, 1054 pub(crate) syntax: SyntaxNode,
2073} 1055}
2074impl WhereClause { 1056impl ParenType {
2075 pub fn where_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![where]) } 1057 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
2076 pub fn predicates(&self) -> AstChildren<WherePred> { support::children(&self.syntax) } 1058 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
2077} 1059 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
2078/// Abi declaration.
2079/// Note: the abi string is optional.
2080///
2081/// ```
2082/// ❰ extern "C" ❱ {
2083/// fn foo() {}
2084/// }
2085///
2086/// type Bar = ❰ extern ❱ fn() -> u32;
2087///
2088/// type Baz = ❰ extern r#"stdcall"# ❱ fn() -> bool;
2089/// ```
2090///
2091/// - [Extern blocks reference](https://doc.rust-lang.org/reference/items/external-blocks.html)
2092/// - [FFI function pointers reference](https://doc.rust-lang.org/reference/items/functions.html#functions)
2093#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2094pub struct Abi {
2095 pub(crate) syntax: SyntaxNode,
2096} 1060}
2097impl Abi {}
2098/// Expression statement.
2099///
2100/// ```
2101/// ❰ 42; ❱
2102/// ❰ foo(); ❱
2103/// ❰ (); ❱
2104/// ❰ {}; ❱
2105///
2106/// // constructions with trailing curly brace can omit the semicolon
2107/// // but only when there are satements immediately after them (this is important!)
2108/// ❰ if bool_cond { } ❱
2109/// ❰ loop {} ❱
2110/// ❰ somestatment; ❱
2111/// ```
2112///
2113/// [Reference](https://doc.rust-lang.org/reference/statements.html)
2114#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1061#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2115pub struct ExprStmt { 1062pub struct PtrType {
2116 pub(crate) syntax: SyntaxNode, 1063 pub(crate) syntax: SyntaxNode,
2117} 1064}
2118impl ast::AttrsOwner for ExprStmt {} 1065impl PtrType {
2119impl ExprStmt { 1066 pub fn star_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![*]) }
2120 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } 1067 pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) }
2121 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } 1068 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
1069 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
2122} 1070}
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)] 1071#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2134pub struct LetStmt { 1072pub struct RefType {
2135 pub(crate) syntax: SyntaxNode, 1073 pub(crate) syntax: SyntaxNode,
2136} 1074}
2137impl ast::AttrsOwner for LetStmt {} 1075impl RefType {
2138impl ast::TypeAscriptionOwner for LetStmt {} 1076 pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) }
2139impl LetStmt { 1077 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
2140 pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) } 1078 support::token(&self.syntax, T![lifetime])
2141 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 1079 }
2142 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } 1080 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
2143 pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) } 1081 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
2144 pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
2145} 1082}
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)] 1083#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2159pub struct Condition { 1084pub struct SliceType {
2160 pub(crate) syntax: SyntaxNode, 1085 pub(crate) syntax: SyntaxNode,
2161} 1086}
2162impl Condition { 1087impl SliceType {
2163 pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) } 1088 pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
2164 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 1089 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
2165 pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } 1090 pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
2166 pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
2167} 1091}
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)] 1092#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2181pub struct ParamList { 1093pub struct TupleType {
2182 pub(crate) syntax: SyntaxNode, 1094 pub(crate) syntax: SyntaxNode,
2183} 1095}
2184impl ParamList { 1096impl TupleType {
2185 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } 1097 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) } 1098 pub fn fields(&self) -> AstChildren<Type> { support::children(&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![')']) } 1099 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
2189} 1100}
2190/// Self parameter **declaration**.
2191///
2192/// ```
2193/// impl Bruh {
2194/// fn foo(❰ self ❱) {}
2195/// fn bar(❰ &self ❱) {}
2196/// fn baz(❰ &mut self ❱) {}
2197/// fn blah<'a>(❰ &'a self ❱) {}
2198/// fn blin(❰ self: Box<Self> ❱) {}
2199/// }
2200/// ```
2201///
2202/// [Reference](https://doc.rust-lang.org/reference/items/functions.html)
2203#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1101#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2204pub struct SelfParam { 1102pub struct TypeBound {
2205 pub(crate) syntax: SyntaxNode, 1103 pub(crate) syntax: SyntaxNode,
2206} 1104}
2207impl ast::TypeAscriptionOwner for SelfParam {} 1105impl TypeBound {
2208impl ast::AttrsOwner for SelfParam {}
2209impl 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> { 1106 pub fn lifetime_token(&self) -> Option<SyntaxToken> {
2213 support::token(&self.syntax, T![lifetime]) 1107 support::token(&self.syntax, T![lifetime])
2214 } 1108 }
2215 pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) } 1109 pub fn question_mark_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![?]) }
1110 pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
2216} 1111}
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)] 1112#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2229pub struct Param { 1113pub struct IdentPat {
2230 pub(crate) syntax: SyntaxNode, 1114 pub(crate) syntax: SyntaxNode,
2231} 1115}
2232impl ast::TypeAscriptionOwner for Param {} 1116impl ast::AttrsOwner for IdentPat {}
2233impl ast::AttrsOwner for Param {} 1117impl ast::NameOwner for IdentPat {}
2234impl Param { 1118impl IdentPat {
1119 pub fn ref_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ref]) }
1120 pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) }
1121 pub fn at_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![@]) }
2235 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } 1122 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
2236 pub fn dotdotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![...]) }
2237} 1123}
2238/// Use declaration. 1124#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2239/// 1125pub struct BoxPat {
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)]
2249pub struct UseItem {
2250 pub(crate) syntax: SyntaxNode, 1126 pub(crate) syntax: SyntaxNode,
2251} 1127}
2252impl ast::AttrsOwner for UseItem {} 1128impl BoxPat {
2253impl ast::VisibilityOwner for UseItem {} 1129 pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) }
2254impl UseItem { 1130 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
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} 1131}
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)] 1132#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2269pub struct UseTree { 1133pub struct RestPat {
2270 pub(crate) syntax: SyntaxNode, 1134 pub(crate) syntax: SyntaxNode,
2271} 1135}
2272impl UseTree { 1136impl RestPat {
2273 pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } 1137 pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) }
2274 pub fn star_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![*]) } 1138}
2275 pub fn use_tree_list(&self) -> Option<UseTreeList> { support::child(&self.syntax) } 1139#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2276 pub fn alias(&self) -> Option<Alias> { support::child(&self.syntax) } 1140pub struct LiteralPat {
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)]
2289pub struct Alias {
2290 pub(crate) syntax: SyntaxNode, 1141 pub(crate) syntax: SyntaxNode,
2291} 1142}
2292impl ast::NameOwner for Alias {} 1143impl LiteralPat {
2293impl Alias { 1144 pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) }
2294 pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) }
2295} 1145}
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)] 1146#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2305pub struct UseTreeList { 1147pub struct MacroPat {
2306 pub(crate) syntax: SyntaxNode, 1148 pub(crate) syntax: SyntaxNode,
2307} 1149}
2308impl UseTreeList { 1150impl MacroPat {
2309 pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } 1151 pub fn macro_call(&self) -> Option<MacroCall> { support::child(&self.syntax) }
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} 1152}
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)] 1153#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2322pub struct ExternCrateItem { 1154pub struct OrPat {
2323 pub(crate) syntax: SyntaxNode, 1155 pub(crate) syntax: SyntaxNode,
2324} 1156}
2325impl ast::AttrsOwner for ExternCrateItem {} 1157impl OrPat {
2326impl ast::VisibilityOwner for ExternCrateItem {} 1158 pub fn pats(&self) -> AstChildren<Pat> { support::children(&self.syntax) }
2327impl 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} 1159}
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)] 1160#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2341pub struct ArgList { 1161pub struct ParenPat {
2342 pub(crate) syntax: SyntaxNode, 1162 pub(crate) syntax: SyntaxNode,
2343} 1163}
2344impl ArgList { 1164impl ParenPat {
2345 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } 1165 pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) }
2346 pub fn args(&self) -> AstChildren<Expr> { support::children(&self.syntax) } 1166 pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) }
2347 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } 1167 pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) }
2348} 1168}
2349/// Path to a symbol. Includes single identifier names and elaborate paths with
2350/// generic parameters.