diff options
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r-- | crates/ra_syntax/src/ast/edit.rs | 78 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/expr_extensions.rs | 33 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/extensions.rs | 8 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/generated/nodes.rs | 1625 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/make.rs | 55 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/tokens.rs | 10 |
6 files changed, 1545 insertions, 264 deletions
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs index 26e4576ff..29eb3fcb9 100644 --- a/crates/ra_syntax/src/ast/edit.rs +++ b/crates/ra_syntax/src/ast/edit.rs | |||
@@ -1,7 +1,10 @@ | |||
1 | //! This module contains functions for editing syntax trees. As the trees are | 1 | //! This module contains functions for editing syntax trees. As the trees are |
2 | //! immutable, all function here return a fresh copy of the tree, instead of | 2 | //! immutable, all function here return a fresh copy of the tree, instead of |
3 | //! doing an in-place modification. | 3 | //! doing an in-place modification. |
4 | use std::{iter, ops::RangeInclusive}; | 4 | use std::{ |
5 | fmt, iter, | ||
6 | ops::{self, RangeInclusive}, | ||
7 | }; | ||
5 | 8 | ||
6 | use arrayvec::ArrayVec; | 9 | use arrayvec::ArrayVec; |
7 | 10 | ||
@@ -28,7 +31,7 @@ impl ast::BinExpr { | |||
28 | 31 | ||
29 | impl ast::FnDef { | 32 | impl ast::FnDef { |
30 | #[must_use] | 33 | #[must_use] |
31 | pub fn with_body(&self, body: ast::Block) -> ast::FnDef { | 34 | pub fn with_body(&self, body: ast::BlockExpr) -> ast::FnDef { |
32 | let mut to_insert: ArrayVec<[SyntaxElement; 2]> = ArrayVec::new(); | 35 | let mut to_insert: ArrayVec<[SyntaxElement; 2]> = ArrayVec::new(); |
33 | 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() { |
34 | old_body.syntax().clone().into() | 37 | old_body.syntax().clone().into() |
@@ -79,7 +82,7 @@ where | |||
79 | 82 | ||
80 | impl ast::ItemList { | 83 | impl ast::ItemList { |
81 | #[must_use] | 84 | #[must_use] |
82 | pub fn append_items(&self, items: impl IntoIterator<Item = ast::ImplItem>) -> ast::ItemList { | 85 | pub fn append_items(&self, items: impl IntoIterator<Item = ast::AssocItem>) -> ast::ItemList { |
83 | let mut res = self.clone(); | 86 | let mut res = self.clone(); |
84 | if !self.syntax().text().contains_char('\n') { | 87 | if !self.syntax().text().contains_char('\n') { |
85 | res = make_multiline(res); | 88 | res = make_multiline(res); |
@@ -89,8 +92,8 @@ impl ast::ItemList { | |||
89 | } | 92 | } |
90 | 93 | ||
91 | #[must_use] | 94 | #[must_use] |
92 | pub fn append_item(&self, item: ast::ImplItem) -> ast::ItemList { | 95 | pub fn append_item(&self, item: ast::AssocItem) -> ast::ItemList { |
93 | let (indent, position) = match self.impl_items().last() { | 96 | let (indent, position) = match self.assoc_items().last() { |
94 | Some(it) => ( | 97 | Some(it) => ( |
95 | leading_indent(it.syntax()).unwrap_or_default().to_string(), | 98 | leading_indent(it.syntax()).unwrap_or_default().to_string(), |
96 | InsertPosition::After(it.syntax().clone().into()), | 99 | InsertPosition::After(it.syntax().clone().into()), |
@@ -437,6 +440,28 @@ impl From<u8> for IndentLevel { | |||
437 | } | 440 | } |
438 | } | 441 | } |
439 | 442 | ||
443 | impl fmt::Display for IndentLevel { | ||
444 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
445 | let spaces = " "; | ||
446 | let buf; | ||
447 | let len = self.0 as usize * 4; | ||
448 | let indent = if len <= spaces.len() { | ||
449 | &spaces[..len] | ||
450 | } else { | ||
451 | buf = iter::repeat(' ').take(len).collect::<String>(); | ||
452 | &buf | ||
453 | }; | ||
454 | fmt::Display::fmt(indent, f) | ||
455 | } | ||
456 | } | ||
457 | |||
458 | impl ops::Add<u8> for IndentLevel { | ||
459 | type Output = IndentLevel; | ||
460 | fn add(self, rhs: u8) -> IndentLevel { | ||
461 | IndentLevel(self.0 + rhs) | ||
462 | } | ||
463 | } | ||
464 | |||
440 | impl IndentLevel { | 465 | impl IndentLevel { |
441 | pub fn from_node(node: &SyntaxNode) -> IndentLevel { | 466 | pub fn from_node(node: &SyntaxNode) -> IndentLevel { |
442 | let first_token = match node.first_token() { | 467 | let first_token = match node.first_token() { |
@@ -453,11 +478,15 @@ impl IndentLevel { | |||
453 | IndentLevel(0) | 478 | IndentLevel(0) |
454 | } | 479 | } |
455 | 480 | ||
456 | pub fn increase_indent<N: AstNode>(self, node: N) -> N { | 481 | /// XXX: this intentionally doesn't change the indent of the very first token. |
457 | N::cast(self._increase_indent(node.syntax().clone())).unwrap() | 482 | /// Ie, in something like |
458 | } | 483 | /// ``` |
459 | 484 | /// fn foo() { | |
460 | fn _increase_indent(self, node: SyntaxNode) -> SyntaxNode { | 485 | /// 92 |
486 | /// } | ||
487 | /// ``` | ||
488 | /// if you indent the block, the `{` token would stay put. | ||
489 | fn increase_indent(self, node: SyntaxNode) -> SyntaxNode { | ||
461 | let mut rewriter = SyntaxRewriter::default(); | 490 | let mut rewriter = SyntaxRewriter::default(); |
462 | node.descendants_with_tokens() | 491 | node.descendants_with_tokens() |
463 | .filter_map(|el| el.into_token()) | 492 | .filter_map(|el| el.into_token()) |
@@ -467,22 +496,13 @@ impl IndentLevel { | |||
467 | text.contains('\n') | 496 | text.contains('\n') |
468 | }) | 497 | }) |
469 | .for_each(|ws| { | 498 | .for_each(|ws| { |
470 | let new_ws = make::tokens::whitespace(&format!( | 499 | let new_ws = make::tokens::whitespace(&format!("{}{}", ws.syntax(), self,)); |
471 | "{}{:width$}", | ||
472 | ws.syntax().text(), | ||
473 | "", | ||
474 | width = self.0 as usize * 4 | ||
475 | )); | ||
476 | rewriter.replace(ws.syntax(), &new_ws) | 500 | rewriter.replace(ws.syntax(), &new_ws) |
477 | }); | 501 | }); |
478 | rewriter.rewrite(&node) | 502 | rewriter.rewrite(&node) |
479 | } | 503 | } |
480 | 504 | ||
481 | pub fn decrease_indent<N: AstNode>(self, node: N) -> N { | 505 | fn decrease_indent(self, node: SyntaxNode) -> SyntaxNode { |
482 | N::cast(self._decrease_indent(node.syntax().clone())).unwrap() | ||
483 | } | ||
484 | |||
485 | fn _decrease_indent(self, node: SyntaxNode) -> SyntaxNode { | ||
486 | let mut rewriter = SyntaxRewriter::default(); | 506 | let mut rewriter = SyntaxRewriter::default(); |
487 | node.descendants_with_tokens() | 507 | node.descendants_with_tokens() |
488 | .filter_map(|el| el.into_token()) | 508 | .filter_map(|el| el.into_token()) |
@@ -493,7 +513,7 @@ impl IndentLevel { | |||
493 | }) | 513 | }) |
494 | .for_each(|ws| { | 514 | .for_each(|ws| { |
495 | let new_ws = make::tokens::whitespace( | 515 | let new_ws = make::tokens::whitespace( |
496 | &ws.syntax().text().replace(&format!("\n{:1$}", "", self.0 as usize * 4), "\n"), | 516 | &ws.syntax().text().replace(&format!("\n{}", self), "\n"), |
497 | ); | 517 | ); |
498 | rewriter.replace(ws.syntax(), &new_ws) | 518 | rewriter.replace(ws.syntax(), &new_ws) |
499 | }); | 519 | }); |
@@ -521,7 +541,7 @@ fn prev_tokens(token: SyntaxToken) -> impl Iterator<Item = SyntaxToken> { | |||
521 | iter::successors(Some(token), |token| token.prev_token()) | 541 | iter::successors(Some(token), |token| token.prev_token()) |
522 | } | 542 | } |
523 | 543 | ||
524 | pub trait AstNodeEdit: AstNode + Sized { | 544 | pub trait AstNodeEdit: AstNode + Clone + Sized { |
525 | #[must_use] | 545 | #[must_use] |
526 | fn insert_children( | 546 | fn insert_children( |
527 | &self, | 547 | &self, |
@@ -558,9 +578,17 @@ pub trait AstNodeEdit: AstNode + Sized { | |||
558 | } | 578 | } |
559 | rewriter.rewrite_ast(self) | 579 | rewriter.rewrite_ast(self) |
560 | } | 580 | } |
581 | #[must_use] | ||
582 | fn indent(&self, indent: IndentLevel) -> Self { | ||
583 | Self::cast(indent.increase_indent(self.syntax().clone())).unwrap() | ||
584 | } | ||
585 | #[must_use] | ||
586 | fn dedent(&self, indent: IndentLevel) -> Self { | ||
587 | Self::cast(indent.decrease_indent(self.syntax().clone())).unwrap() | ||
588 | } | ||
561 | } | 589 | } |
562 | 590 | ||
563 | impl<N: AstNode> AstNodeEdit for N {} | 591 | impl<N: AstNode + Clone> AstNodeEdit for N {} |
564 | 592 | ||
565 | fn single_node(element: impl Into<SyntaxElement>) -> RangeInclusive<SyntaxElement> { | 593 | fn single_node(element: impl Into<SyntaxElement>) -> RangeInclusive<SyntaxElement> { |
566 | let element = element.into(); | 594 | let element = element.into(); |
@@ -580,7 +608,7 @@ fn test_increase_indent() { | |||
580 | _ => (), | 608 | _ => (), |
581 | }" | 609 | }" |
582 | ); | 610 | ); |
583 | let indented = IndentLevel(2).increase_indent(arm_list); | 611 | let indented = arm_list.indent(IndentLevel(2)); |
584 | assert_eq!( | 612 | assert_eq!( |
585 | indented.syntax().to_string(), | 613 | indented.syntax().to_string(), |
586 | "{ | 614 | "{ |
diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs index 352c0d2c5..7771d6759 100644 --- a/crates/ra_syntax/src/ast/expr_extensions.rs +++ b/crates/ra_syntax/src/ast/expr_extensions.rs | |||
@@ -16,7 +16,7 @@ impl ast::Expr { | |||
16 | | ast::Expr::WhileExpr(_) | 16 | | ast::Expr::WhileExpr(_) |
17 | | ast::Expr::BlockExpr(_) | 17 | | ast::Expr::BlockExpr(_) |
18 | | ast::Expr::MatchExpr(_) | 18 | | ast::Expr::MatchExpr(_) |
19 | | ast::Expr::TryExpr(_) => true, | 19 | | ast::Expr::EffectExpr(_) => true, |
20 | _ => false, | 20 | _ => false, |
21 | } | 21 | } |
22 | } | 22 | } |
@@ -43,7 +43,7 @@ impl ast::IfExpr { | |||
43 | Some(res) | 43 | Some(res) |
44 | } | 44 | } |
45 | 45 | ||
46 | fn blocks(&self) -> AstChildren<ast::BlockExpr> { | 46 | pub fn blocks(&self) -> AstChildren<ast::BlockExpr> { |
47 | support::children(self.syntax()) | 47 | support::children(self.syntax()) |
48 | } | 48 | } |
49 | } | 49 | } |
@@ -359,22 +359,34 @@ impl ast::Literal { | |||
359 | } | 359 | } |
360 | } | 360 | } |
361 | 361 | ||
362 | pub enum BlockModifier { | 362 | #[derive(Debug, Clone, PartialEq, Eq)] |
363 | pub enum Effect { | ||
363 | Async(SyntaxToken), | 364 | Async(SyntaxToken), |
364 | Unsafe(SyntaxToken), | 365 | Unsafe(SyntaxToken), |
366 | Try(SyntaxToken), | ||
367 | // Very much not an effect, but we stuff it into this node anyway | ||
368 | Label(ast::Label), | ||
365 | } | 369 | } |
366 | 370 | ||
367 | impl ast::BlockExpr { | 371 | impl ast::EffectExpr { |
368 | pub fn modifier(&self) -> Option<BlockModifier> { | 372 | pub fn effect(&self) -> Effect { |
369 | if let Some(token) = self.async_token() { | 373 | if let Some(token) = self.async_token() { |
370 | return Some(BlockModifier::Async(token)); | 374 | return Effect::Async(token); |
371 | } | 375 | } |
372 | if let Some(token) = self.unsafe_token() { | 376 | if let Some(token) = self.unsafe_token() { |
373 | return Some(BlockModifier::Unsafe(token)); | 377 | return Effect::Unsafe(token); |
378 | } | ||
379 | if let Some(token) = self.try_token() { | ||
380 | return Effect::Try(token); | ||
381 | } | ||
382 | if let Some(label) = self.label() { | ||
383 | return Effect::Label(label); | ||
374 | } | 384 | } |
375 | None | 385 | unreachable!("ast::EffectExpr without Effect") |
376 | } | 386 | } |
387 | } | ||
377 | 388 | ||
389 | impl ast::BlockExpr { | ||
378 | /// false if the block is an intrinsic part of the syntax and can't be | 390 | /// false if the block is an intrinsic part of the syntax and can't be |
379 | /// replaced with arbitrary expression. | 391 | /// replaced with arbitrary expression. |
380 | /// | 392 | /// |
@@ -383,15 +395,12 @@ impl ast::BlockExpr { | |||
383 | /// const FOO: () = { stand_alone }; | 395 | /// const FOO: () = { stand_alone }; |
384 | /// ``` | 396 | /// ``` |
385 | pub fn is_standalone(&self) -> bool { | 397 | pub fn is_standalone(&self) -> bool { |
386 | if self.modifier().is_some() { | ||
387 | return false; | ||
388 | } | ||
389 | let parent = match self.syntax().parent() { | 398 | let parent = match self.syntax().parent() { |
390 | Some(it) => it, | 399 | Some(it) => it, |
391 | None => return true, | 400 | None => return true, |
392 | }; | 401 | }; |
393 | match parent.kind() { | 402 | match parent.kind() { |
394 | FN_DEF | IF_EXPR | WHILE_EXPR | LOOP_EXPR => false, | 403 | FN_DEF | IF_EXPR | WHILE_EXPR | LOOP_EXPR | EFFECT_EXPR => false, |
395 | _ => true, | 404 | _ => true, |
396 | } | 405 | } |
397 | } | 406 | } |
diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index f2ea5088e..98c38d009 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs | |||
@@ -407,7 +407,7 @@ impl ast::Visibility { | |||
407 | } else if self.super_token().is_some() { | 407 | } else if self.super_token().is_some() { |
408 | VisibilityKind::PubSuper | 408 | VisibilityKind::PubSuper |
409 | } else if self.self_token().is_some() { | 409 | } else if self.self_token().is_some() { |
410 | VisibilityKind::PubSuper | 410 | VisibilityKind::PubSelf |
411 | } else { | 411 | } else { |
412 | VisibilityKind::Pub | 412 | VisibilityKind::Pub |
413 | } | 413 | } |
@@ -423,6 +423,10 @@ impl ast::MacroCall { | |||
423 | None | 423 | None |
424 | } | 424 | } |
425 | } | 425 | } |
426 | |||
427 | pub fn is_bang(&self) -> bool { | ||
428 | self.is_macro_rules().is_none() | ||
429 | } | ||
426 | } | 430 | } |
427 | 431 | ||
428 | impl ast::LifetimeParam { | 432 | impl ast::LifetimeParam { |
@@ -463,7 +467,7 @@ impl ast::TokenTree { | |||
463 | 467 | ||
464 | pub fn right_delimiter_token(&self) -> Option<SyntaxToken> { | 468 | pub fn right_delimiter_token(&self) -> Option<SyntaxToken> { |
465 | self.syntax().last_child_or_token()?.into_token().filter(|it| match it.kind() { | 469 | self.syntax().last_child_or_token()?.into_token().filter(|it| match it.kind() { |
466 | T!['{'] | T!['('] | T!['['] => true, | 470 | T!['}'] | T![')'] | T![']'] => true, |
467 | _ => false, | 471 | _ => false, |
468 | }) | 472 | }) |
469 | } | 473 | } |
diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index 81260680f..cb430ca01 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs | |||
@@ -5,17 +5,41 @@ use crate::{ | |||
5 | SyntaxKind::{self, *}, | 5 | SyntaxKind::{self, *}, |
6 | SyntaxNode, SyntaxToken, T, | 6 | SyntaxNode, SyntaxToken, T, |
7 | }; | 7 | }; |
8 | 8 | /// The entire Rust source file. Includes all top-level inner attributes and module items. | |
9 | /// | ||
10 | /// [Reference](https://doc.rust-lang.org/reference/crates-and-source-files.html) | ||
9 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 11 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
10 | pub struct SourceFile { | 12 | pub struct SourceFile { |
11 | pub(crate) syntax: SyntaxNode, | 13 | pub(crate) syntax: SyntaxNode, |
12 | } | 14 | } |
13 | impl ast::ModuleItemOwner for SourceFile {} | 15 | impl ast::ModuleItemOwner for SourceFile {} |
14 | impl ast::AttrsOwner for SourceFile {} | 16 | impl ast::AttrsOwner for SourceFile {} |
17 | impl ast::DocCommentsOwner for SourceFile {} | ||
15 | impl SourceFile { | 18 | impl SourceFile { |
16 | pub fn modules(&self) -> AstChildren<Module> { support::children(&self.syntax) } | 19 | pub fn modules(&self) -> AstChildren<Module> { support::children(&self.syntax) } |
17 | } | 20 | } |
18 | 21 | /// Function definition either with body or not. | |
22 | /// Includes all of its attributes and doc comments. | ||
23 | /// | ||
24 | /// ``` | ||
25 | /// ❰ | ||
26 | /// /// Docs | ||
27 | /// #[attr] | ||
28 | /// pub extern "C" fn foo<T>(#[attr] Patern {p}: Pattern) -> u32 | ||
29 | /// where | ||
30 | /// T: Debug | ||
31 | /// { | ||
32 | /// 42 | ||
33 | /// } | ||
34 | /// ❱ | ||
35 | /// | ||
36 | /// extern "C" { | ||
37 | /// ❰ fn fn_decl(also_variadic_ffi: u32, ...) -> u32; ❱ | ||
38 | /// } | ||
39 | /// ``` | ||
40 | /// | ||
41 | /// - [Reference](https://doc.rust-lang.org/reference/items/functions.html) | ||
42 | /// - [Nomicon](https://doc.rust-lang.org/nomicon/ffi.html#variadic-functions) | ||
19 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 43 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
20 | pub struct FnDef { | 44 | pub struct FnDef { |
21 | pub(crate) syntax: SyntaxNode, | 45 | pub(crate) syntax: SyntaxNode, |
@@ -37,7 +61,13 @@ impl FnDef { | |||
37 | pub fn body(&self) -> Option<BlockExpr> { support::child(&self.syntax) } | 61 | pub fn body(&self) -> Option<BlockExpr> { support::child(&self.syntax) } |
38 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 62 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
39 | } | 63 | } |
40 | 64 | /// Return type annotation. | |
65 | /// | ||
66 | /// ``` | ||
67 | /// fn foo(a: u32) ❰ -> Option<u32> ❱ { Some(a) } | ||
68 | /// ``` | ||
69 | /// | ||
70 | /// [Reference](https://doc.rust-lang.org/reference/items/functions.html) | ||
41 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 71 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
42 | pub struct RetType { | 72 | pub struct RetType { |
43 | pub(crate) syntax: SyntaxNode, | 73 | pub(crate) syntax: SyntaxNode, |
@@ -46,7 +76,26 @@ impl RetType { | |||
46 | pub fn thin_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![->]) } | 76 | pub fn thin_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![->]) } |
47 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 77 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
48 | } | 78 | } |
49 | 79 | /// Struct definition. | |
80 | /// Includes all of its attributes and doc comments. | ||
81 | /// | ||
82 | /// ``` | ||
83 | /// ❰ | ||
84 | /// /// Docs | ||
85 | /// #[attr] | ||
86 | /// struct Foo<T> where T: Debug { | ||
87 | /// /// Docs | ||
88 | /// #[attr] | ||
89 | /// pub a: u32, | ||
90 | /// b: T, | ||
91 | /// } | ||
92 | /// ❱ | ||
93 | /// | ||
94 | /// ❰ struct Foo; ❱ | ||
95 | /// ❰ struct Foo<T>(#[attr] T) where T: Debug; ❱ | ||
96 | /// ``` | ||
97 | /// | ||
98 | /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) | ||
50 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 99 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
51 | pub struct StructDef { | 100 | pub struct StructDef { |
52 | pub(crate) syntax: SyntaxNode, | 101 | pub(crate) syntax: SyntaxNode, |
@@ -61,7 +110,23 @@ impl StructDef { | |||
61 | pub fn field_def_list(&self) -> Option<FieldDefList> { support::child(&self.syntax) } | 110 | pub fn field_def_list(&self) -> Option<FieldDefList> { support::child(&self.syntax) } |
62 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 111 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
63 | } | 112 | } |
64 | 113 | /// Union definition. | |
114 | /// Includes all of its attributes and doc comments. | ||
115 | /// | ||
116 | /// ``` | ||
117 | /// ❰ | ||
118 | /// /// Docs | ||
119 | /// #[attr] | ||
120 | /// pub union Foo<T> where T: Debug { | ||
121 | /// /// Docs | ||
122 | /// #[attr] | ||
123 | /// a: T, | ||
124 | /// b: u32, | ||
125 | /// } | ||
126 | /// ❱ | ||
127 | /// ``` | ||
128 | /// | ||
129 | /// [Reference](https://doc.rust-lang.org/reference/items/unions.html) | ||
65 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 130 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
66 | pub struct UnionDef { | 131 | pub struct UnionDef { |
67 | pub(crate) syntax: SyntaxNode, | 132 | pub(crate) syntax: SyntaxNode, |
@@ -77,7 +142,19 @@ impl UnionDef { | |||
77 | support::child(&self.syntax) | 142 | support::child(&self.syntax) |
78 | } | 143 | } |
79 | } | 144 | } |
80 | 145 | /// Record field definition list including enclosing curly braces. | |
146 | /// | ||
147 | /// ``` | ||
148 | /// struct Foo // same for union | ||
149 | /// ❰ | ||
150 | /// { | ||
151 | /// a: u32, | ||
152 | /// b: bool, | ||
153 | /// } | ||
154 | /// ❱ | ||
155 | /// ``` | ||
156 | /// | ||
157 | /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) | ||
81 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 158 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
82 | pub struct RecordFieldDefList { | 159 | pub struct RecordFieldDefList { |
83 | pub(crate) syntax: SyntaxNode, | 160 | pub(crate) syntax: SyntaxNode, |
@@ -87,7 +164,22 @@ impl RecordFieldDefList { | |||
87 | pub fn fields(&self) -> AstChildren<RecordFieldDef> { support::children(&self.syntax) } | 164 | pub fn fields(&self) -> AstChildren<RecordFieldDef> { support::children(&self.syntax) } |
88 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 165 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
89 | } | 166 | } |
90 | 167 | /// Record field definition including its attributes and doc comments. | |
168 | /// | ||
169 | /// ` `` | ||
170 | /// same for union | ||
171 | /// struct Foo { | ||
172 | /// ❰ | ||
173 | /// /// Docs | ||
174 | /// #[attr] | ||
175 | /// pub a: u32 | ||
176 | /// ❱ | ||
177 | /// | ||
178 | /// ❰ b: bool ❱ | ||
179 | /// } | ||
180 | /// ``` | ||
181 | /// | ||
182 | /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) | ||
91 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 183 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
92 | pub struct RecordFieldDef { | 184 | pub struct RecordFieldDef { |
93 | pub(crate) syntax: SyntaxNode, | 185 | pub(crate) syntax: SyntaxNode, |
@@ -98,7 +190,13 @@ impl ast::AttrsOwner for RecordFieldDef {} | |||
98 | impl ast::DocCommentsOwner for RecordFieldDef {} | 190 | impl ast::DocCommentsOwner for RecordFieldDef {} |
99 | impl ast::TypeAscriptionOwner for RecordFieldDef {} | 191 | impl ast::TypeAscriptionOwner for RecordFieldDef {} |
100 | impl RecordFieldDef {} | 192 | impl RecordFieldDef {} |
101 | 193 | /// Tuple field definition list including enclosing parens. | |
194 | /// | ||
195 | /// ``` | ||
196 | /// struct Foo ❰ (u32, String, Vec<u32>) ❱; | ||
197 | /// ``` | ||
198 | /// | ||
199 | /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) | ||
102 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 200 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
103 | pub struct TupleFieldDefList { | 201 | pub struct TupleFieldDefList { |
104 | pub(crate) syntax: SyntaxNode, | 202 | pub(crate) syntax: SyntaxNode, |
@@ -108,7 +206,13 @@ impl TupleFieldDefList { | |||
108 | pub fn fields(&self) -> AstChildren<TupleFieldDef> { support::children(&self.syntax) } | 206 | pub fn fields(&self) -> AstChildren<TupleFieldDef> { support::children(&self.syntax) } |
109 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 207 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
110 | } | 208 | } |
111 | 209 | /// Tuple field definition including its attributes. | |
210 | /// | ||
211 | /// ``` | ||
212 | /// struct Foo(❰ #[attr] u32 ❱); | ||
213 | /// ``` | ||
214 | /// | ||
215 | /// [Reference](https://doc.rust-lang.org/reference/items/structs.html) | ||
112 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 216 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
113 | pub struct TupleFieldDef { | 217 | pub struct TupleFieldDef { |
114 | pub(crate) syntax: SyntaxNode, | 218 | pub(crate) syntax: SyntaxNode, |
@@ -118,7 +222,29 @@ impl ast::AttrsOwner for TupleFieldDef {} | |||
118 | impl TupleFieldDef { | 222 | impl TupleFieldDef { |
119 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 223 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
120 | } | 224 | } |
121 | 225 | /// Enum definition. | |
226 | /// Includes all of its attributes and doc comments. | ||
227 | /// | ||
228 | /// ``` | ||
229 | /// ❰ | ||
230 | /// /// Docs | ||
231 | /// #[attr] | ||
232 | /// pub enum Foo<T> where T: Debug { | ||
233 | /// /// Docs | ||
234 | /// #[attr] | ||
235 | /// Bar, | ||
236 | /// Baz(#[attr] u32), | ||
237 | /// Bruh { | ||
238 | /// a: u32, | ||
239 | /// /// Docs | ||
240 | /// #[attr] | ||
241 | /// b: T, | ||
242 | /// } | ||
243 | /// } | ||
244 | /// ❱ | ||
245 | /// ``` | ||
246 | /// | ||
247 | /// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html) | ||
122 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 248 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
123 | pub struct EnumDef { | 249 | pub struct EnumDef { |
124 | pub(crate) syntax: SyntaxNode, | 250 | pub(crate) syntax: SyntaxNode, |
@@ -132,7 +258,22 @@ impl EnumDef { | |||
132 | pub fn enum_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![enum]) } | 258 | pub fn enum_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![enum]) } |
133 | pub fn variant_list(&self) -> Option<EnumVariantList> { support::child(&self.syntax) } | 259 | pub fn variant_list(&self) -> Option<EnumVariantList> { support::child(&self.syntax) } |
134 | } | 260 | } |
135 | 261 | /// Enum variant definition list including enclosing curly braces. | |
262 | /// | ||
263 | /// ``` | ||
264 | /// enum Foo | ||
265 | /// ❰ | ||
266 | /// { | ||
267 | /// Bar, | ||
268 | /// Baz(u32), | ||
269 | /// Bruh { | ||
270 | /// a: u32 | ||
271 | /// } | ||
272 | /// } | ||
273 | /// ❱ | ||
274 | /// ``` | ||
275 | /// | ||
276 | /// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html) | ||
136 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 277 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
137 | pub struct EnumVariantList { | 278 | pub struct EnumVariantList { |
138 | pub(crate) syntax: SyntaxNode, | 279 | pub(crate) syntax: SyntaxNode, |
@@ -142,7 +283,21 @@ impl EnumVariantList { | |||
142 | pub fn variants(&self) -> AstChildren<EnumVariant> { support::children(&self.syntax) } | 283 | pub fn variants(&self) -> AstChildren<EnumVariant> { support::children(&self.syntax) } |
143 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 284 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
144 | } | 285 | } |
145 | 286 | /// Enum variant definition including its attributes and discriminant value definition. | |
287 | /// | ||
288 | /// ``` | ||
289 | /// enum Foo { | ||
290 | /// ❰ | ||
291 | /// /// Docs | ||
292 | /// #[attr] | ||
293 | /// Bar | ||
294 | /// ❱ | ||
295 | /// | ||
296 | /// // same for tuple and record variants | ||
297 | /// } | ||
298 | /// ``` | ||
299 | /// | ||
300 | /// [Reference](https://doc.rust-lang.org/reference/items/enumerations.html) | ||
146 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 301 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
147 | pub struct EnumVariant { | 302 | pub struct EnumVariant { |
148 | pub(crate) syntax: SyntaxNode, | 303 | pub(crate) syntax: SyntaxNode, |
@@ -156,7 +311,20 @@ impl EnumVariant { | |||
156 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | 311 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } |
157 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 312 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
158 | } | 313 | } |
159 | 314 | /// Trait definition. | |
315 | /// Includes all of its attributes and doc comments. | ||
316 | /// | ||
317 | /// ``` | ||
318 | /// ❰ | ||
319 | /// /// Docs | ||
320 | /// #[attr] | ||
321 | /// pub unsafe trait Foo<T>: Debug where T: Debug { | ||
322 | /// // ... | ||
323 | /// } | ||
324 | /// ❱ | ||
325 | /// ``` | ||
326 | /// | ||
327 | /// [Reference](https://doc.rust-lang.org/reference/items/traits.html) | ||
160 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 328 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
161 | pub struct TraitDef { | 329 | pub struct TraitDef { |
162 | pub(crate) syntax: SyntaxNode, | 330 | pub(crate) syntax: SyntaxNode, |
@@ -173,7 +341,27 @@ impl TraitDef { | |||
173 | pub fn trait_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![trait]) } | 341 | pub fn trait_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![trait]) } |
174 | pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } | 342 | pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } |
175 | } | 343 | } |
176 | 344 | /// Module definition either with body or not. | |
345 | /// Includes all of its inner and outer attributes, module items, doc comments. | ||
346 | /// | ||
347 | /// ``` | ||
348 | /// ❰ | ||
349 | /// /// Docs | ||
350 | /// #[attr] | ||
351 | /// pub mod foo; | ||
352 | /// ❱ | ||
353 | /// | ||
354 | /// ❰ | ||
355 | /// /// Docs | ||
356 | /// #[attr] | ||
357 | /// pub mod bar { | ||
358 | /// //! Inner docs | ||
359 | /// #![inner_attr] | ||
360 | /// } | ||
361 | /// ❱ | ||
362 | /// ``` | ||
363 | /// | ||
364 | /// [Reference](https://doc.rust-lang.org/reference/items/modules.html) | ||
177 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 365 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
178 | pub struct Module { | 366 | pub struct Module { |
179 | pub(crate) syntax: SyntaxNode, | 367 | pub(crate) syntax: SyntaxNode, |
@@ -187,7 +375,28 @@ impl Module { | |||
187 | pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } | 375 | pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } |
188 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 376 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
189 | } | 377 | } |
190 | 378 | /// Item defintion list. | |
379 | /// This is used for both top-level items and impl block items. | ||
380 | /// | ||
381 | /// ``` | ||
382 | /// ❰ | ||
383 | /// fn foo {} | ||
384 | /// struct Bar; | ||
385 | /// enum Baz; | ||
386 | /// trait Bruh; | ||
387 | /// const BRUUH: u32 = 42; | ||
388 | /// ❱ | ||
389 | /// | ||
390 | /// impl Foo | ||
391 | /// ❰ | ||
392 | /// { | ||
393 | /// fn bar() {} | ||
394 | /// const BAZ: u32 = 42; | ||
395 | /// } | ||
396 | /// ❱ | ||
397 | /// ``` | ||
398 | /// | ||
399 | /// [Reference](https://doc.rust-lang.org/reference/items.html) | ||
191 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 400 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
192 | pub struct ItemList { | 401 | pub struct ItemList { |
193 | pub(crate) syntax: SyntaxNode, | 402 | pub(crate) syntax: SyntaxNode, |
@@ -195,10 +404,21 @@ pub struct ItemList { | |||
195 | impl ast::ModuleItemOwner for ItemList {} | 404 | impl ast::ModuleItemOwner for ItemList {} |
196 | impl ItemList { | 405 | impl ItemList { |
197 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | 406 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } |
198 | pub fn impl_items(&self) -> AstChildren<ImplItem> { support::children(&self.syntax) } | 407 | pub fn assoc_items(&self) -> AstChildren<AssocItem> { support::children(&self.syntax) } |
199 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 408 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
200 | } | 409 | } |
201 | 410 | /// Constant variable definition. | |
411 | /// Includes all of its attributes and doc comments. | ||
412 | /// | ||
413 | /// ``` | ||
414 | /// ❰ | ||
415 | /// /// Docs | ||
416 | /// #[attr] | ||
417 | /// pub const FOO: u32 = 42; | ||
418 | /// ❱ | ||
419 | /// ``` | ||
420 | /// | ||
421 | /// [Reference](https://doc.rust-lang.org/reference/items/constant-items.html) | ||
202 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 422 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
203 | pub struct ConstDef { | 423 | pub struct ConstDef { |
204 | pub(crate) syntax: SyntaxNode, | 424 | pub(crate) syntax: SyntaxNode, |
@@ -216,7 +436,18 @@ impl ConstDef { | |||
216 | pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } | 436 | pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } |
217 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 437 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
218 | } | 438 | } |
219 | 439 | /// Static variable definition. | |
440 | /// Includes all of its attributes and doc comments. | ||
441 | /// | ||
442 | /// ``` | ||
443 | /// ❰ | ||
444 | /// /// Docs | ||
445 | /// #[attr] | ||
446 | /// pub static mut FOO: u32 = 42; | ||
447 | /// ❱ | ||
448 | /// ``` | ||
449 | /// | ||
450 | /// [Reference](https://doc.rust-lang.org/reference/items/static-items.html) | ||
220 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 451 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
221 | pub struct StaticDef { | 452 | pub struct StaticDef { |
222 | pub(crate) syntax: SyntaxNode, | 453 | pub(crate) syntax: SyntaxNode, |
@@ -234,7 +465,24 @@ impl StaticDef { | |||
234 | pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } | 465 | pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } |
235 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 466 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
236 | } | 467 | } |
237 | 468 | /// Type alias definition. | |
469 | /// Includes associated type clauses with type bounds. | ||
470 | /// | ||
471 | /// ``` | ||
472 | /// ❰ | ||
473 | /// /// Docs | ||
474 | /// #[attr] | ||
475 | /// pub type Foo<T> where T: Debug = T; | ||
476 | /// ❱ | ||
477 | /// | ||
478 | /// trait Bar { | ||
479 | /// ❰ type Baz: Debug; ❱ | ||
480 | /// ❰ type Bruh = String; ❱ | ||
481 | /// ❰ type Bruuh: Debug = u32; ❱ | ||
482 | /// } | ||
483 | /// ``` | ||
484 | /// | ||
485 | /// [Reference](https://doc.rust-lang.org/reference/items/type-aliases.html) | ||
238 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 486 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
239 | pub struct TypeAliasDef { | 487 | pub struct TypeAliasDef { |
240 | pub(crate) syntax: SyntaxNode, | 488 | pub(crate) syntax: SyntaxNode, |
@@ -252,13 +500,27 @@ impl TypeAliasDef { | |||
252 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 500 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
253 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 501 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
254 | } | 502 | } |
255 | 503 | /// Inherent and trait impl definition. | |
504 | /// Includes all of its inner and outer attributes. | ||
505 | /// | ||
506 | /// ``` | ||
507 | /// ❰ | ||
508 | /// #[attr] | ||
509 | /// unsafe impl<T> const !Foo for Bar where T: Debug { | ||
510 | /// #![inner_attr] | ||
511 | /// // ... | ||
512 | /// } | ||
513 | /// ❱ | ||
514 | /// ``` | ||
515 | /// | ||
516 | /// [Reference](https://doc.rust-lang.org/reference/items/implementations.html) | ||
256 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 517 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
257 | pub struct ImplDef { | 518 | pub struct ImplDef { |
258 | pub(crate) syntax: SyntaxNode, | 519 | pub(crate) syntax: SyntaxNode, |
259 | } | 520 | } |
260 | impl ast::TypeParamsOwner for ImplDef {} | 521 | impl ast::TypeParamsOwner for ImplDef {} |
261 | impl ast::AttrsOwner for ImplDef {} | 522 | impl ast::AttrsOwner for ImplDef {} |
523 | impl ast::DocCommentsOwner for ImplDef {} | ||
262 | impl ImplDef { | 524 | impl ImplDef { |
263 | pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) } | 525 | pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) } |
264 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } | 526 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } |
@@ -268,7 +530,16 @@ impl ImplDef { | |||
268 | pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) } | 530 | pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) } |
269 | pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } | 531 | pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } |
270 | } | 532 | } |
271 | 533 | /// Parenthesized type reference. | |
534 | /// Note: parens are only used for grouping, this is not a tuple type. | ||
535 | /// | ||
536 | /// ``` | ||
537 | /// // This is effectively just `u32`. | ||
538 | /// // Single-item tuple must be defined with a trailing comma: `(u32,)` | ||
539 | /// type Foo = ❰ (u32) ❱; | ||
540 | /// | ||
541 | /// let bar: &'static ❰ (dyn Debug) ❱ = "bruh"; | ||
542 | /// ``` | ||
272 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 543 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
273 | pub struct ParenType { | 544 | pub struct ParenType { |
274 | pub(crate) syntax: SyntaxNode, | 545 | pub(crate) syntax: SyntaxNode, |
@@ -278,7 +549,13 @@ impl ParenType { | |||
278 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 549 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
279 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 550 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
280 | } | 551 | } |
281 | 552 | /// Unnamed tuple type. | |
553 | /// | ||
554 | /// ``` | ||
555 | /// let foo: ❰ (u32, bool) ❱ = (42, true); | ||
556 | /// ``` | ||
557 | /// | ||
558 | /// [Reference](https://doc.rust-lang.org/reference/types/tuple.html) | ||
282 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 559 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
283 | pub struct TupleType { | 560 | pub struct TupleType { |
284 | pub(crate) syntax: SyntaxNode, | 561 | pub(crate) syntax: SyntaxNode, |
@@ -288,7 +565,17 @@ impl TupleType { | |||
288 | pub fn fields(&self) -> AstChildren<TypeRef> { support::children(&self.syntax) } | 565 | pub fn fields(&self) -> AstChildren<TypeRef> { support::children(&self.syntax) } |
289 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 566 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
290 | } | 567 | } |
291 | 568 | /// The never type (i.e. the exclamation point). | |
569 | /// | ||
570 | /// ``` | ||
571 | /// type T = ❰ ! ❱; | ||
572 | /// | ||
573 | /// fn no_return() -> ❰ ! ❱ { | ||
574 | /// loop {} | ||
575 | /// } | ||
576 | /// ``` | ||
577 | /// | ||
578 | /// [Reference](https://doc.rust-lang.org/reference/types/never.html) | ||
292 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 579 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
293 | pub struct NeverType { | 580 | pub struct NeverType { |
294 | pub(crate) syntax: SyntaxNode, | 581 | pub(crate) syntax: SyntaxNode, |
@@ -296,7 +583,17 @@ pub struct NeverType { | |||
296 | impl NeverType { | 583 | impl NeverType { |
297 | pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) } | 584 | pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) } |
298 | } | 585 | } |
299 | 586 | /// Path to a type. | |
587 | /// Includes single identifier type names and elaborate paths with | ||
588 | /// generic parameters. | ||
589 | /// | ||
590 | /// ``` | ||
591 | /// type Foo = ❰ String ❱; | ||
592 | /// type Bar = ❰ std::vec::Vec<T> ❱; | ||
593 | /// type Baz = ❰ ::bruh::<Bruuh as Iterator>::Item ❱; | ||
594 | /// ``` | ||
595 | /// | ||
596 | /// [Reference](https://doc.rust-lang.org/reference/paths.html) | ||
300 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 597 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
301 | pub struct PathType { | 598 | pub struct PathType { |
302 | pub(crate) syntax: SyntaxNode, | 599 | pub(crate) syntax: SyntaxNode, |
@@ -304,7 +601,14 @@ pub struct PathType { | |||
304 | impl PathType { | 601 | impl PathType { |
305 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | 602 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } |
306 | } | 603 | } |
307 | 604 | /// Raw pointer type. | |
605 | /// | ||
606 | /// ``` | ||
607 | /// type Foo = ❰ *const u32 ❱; | ||
608 | /// type Bar = ❰ *mut u32 ❱; | ||
609 | /// ``` | ||
610 | /// | ||
611 | /// [Reference](https://doc.rust-lang.org/reference/types/pointer.html#raw-pointers-const-and-mut) | ||
308 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 612 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
309 | pub struct PointerType { | 613 | pub struct PointerType { |
310 | pub(crate) syntax: SyntaxNode, | 614 | pub(crate) syntax: SyntaxNode, |
@@ -315,7 +619,13 @@ impl PointerType { | |||
315 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } | 619 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } |
316 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 620 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
317 | } | 621 | } |
318 | 622 | /// Array type. | |
623 | /// | ||
624 | /// ``` | ||
625 | /// type Foo = ❰ [u32; 24 - 3] ❱; | ||
626 | /// ``` | ||
627 | /// | ||
628 | /// [Reference](https://doc.rust-lang.org/reference/types/array.html) | ||
319 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 629 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
320 | pub struct ArrayType { | 630 | pub struct ArrayType { |
321 | pub(crate) syntax: SyntaxNode, | 631 | pub(crate) syntax: SyntaxNode, |
@@ -327,7 +637,13 @@ impl ArrayType { | |||
327 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 637 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
328 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | 638 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } |
329 | } | 639 | } |
330 | 640 | /// Slice type. | |
641 | /// | ||
642 | /// ``` | ||
643 | /// type Foo = ❰ [u8] ❱; | ||
644 | /// ``` | ||
645 | /// | ||
646 | /// [Reference](https://doc.rust-lang.org/reference/types/slice.html) | ||
331 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 647 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
332 | pub struct SliceType { | 648 | pub struct SliceType { |
333 | pub(crate) syntax: SyntaxNode, | 649 | pub(crate) syntax: SyntaxNode, |
@@ -337,7 +653,13 @@ impl SliceType { | |||
337 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 653 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
338 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | 654 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } |
339 | } | 655 | } |
340 | 656 | /// Reference type. | |
657 | /// | ||
658 | /// ``` | ||
659 | /// type Foo = ❰ &'static str ❱; | ||
660 | /// ``` | ||
661 | /// | ||
662 | /// [Reference](https://doc.rust-lang.org/reference/types/pointer.html) | ||
341 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 663 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
342 | pub struct ReferenceType { | 664 | pub struct ReferenceType { |
343 | pub(crate) syntax: SyntaxNode, | 665 | pub(crate) syntax: SyntaxNode, |
@@ -350,7 +672,13 @@ impl ReferenceType { | |||
350 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } | 672 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } |
351 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 673 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
352 | } | 674 | } |
353 | 675 | /// Placeholder type (i.e. the underscore). | |
676 | /// | ||
677 | /// ``` | ||
678 | /// let foo: ❰ _ ❱ = 42_u32; | ||
679 | /// ``` | ||
680 | /// | ||
681 | /// [Reference](https://doc.rust-lang.org/reference/types/inferred.html) | ||
354 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 682 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
355 | pub struct PlaceholderType { | 683 | pub struct PlaceholderType { |
356 | pub(crate) syntax: SyntaxNode, | 684 | pub(crate) syntax: SyntaxNode, |
@@ -358,7 +686,15 @@ pub struct PlaceholderType { | |||
358 | impl PlaceholderType { | 686 | impl PlaceholderType { |
359 | pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) } | 687 | pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) } |
360 | } | 688 | } |
361 | 689 | /// Function pointer type (not to be confused with `Fn*` family of traits). | |
690 | /// | ||
691 | /// ``` | ||
692 | /// type Foo = ❰ async fn(#[attr] u32, named: bool) -> u32 ❱; | ||
693 | /// | ||
694 | /// type Bar = ❰ extern "C" fn(variadic: u32, #[attr] ...) ❱; | ||
695 | /// ``` | ||
696 | /// | ||
697 | /// [Reference](https://doc.rust-lang.org/reference/types/function-pointer.html) | ||
362 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 698 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
363 | pub struct FnPointerType { | 699 | pub struct FnPointerType { |
364 | pub(crate) syntax: SyntaxNode, | 700 | pub(crate) syntax: SyntaxNode, |
@@ -370,7 +706,13 @@ impl FnPointerType { | |||
370 | pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) } | 706 | pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) } |
371 | pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } | 707 | pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } |
372 | } | 708 | } |
373 | 709 | /// Higher order type. | |
710 | /// | ||
711 | /// ``` | ||
712 | /// type Foo = ❰ for<'a> fn(&'a str) ❱; | ||
713 | /// ``` | ||
714 | /// | ||
715 | /// [Reference](https://doc.rust-lang.org/nomicon/hrtb.html) | ||
374 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 716 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
375 | pub struct ForType { | 717 | pub struct ForType { |
376 | pub(crate) syntax: SyntaxNode, | 718 | pub(crate) syntax: SyntaxNode, |
@@ -380,7 +722,13 @@ impl ForType { | |||
380 | pub fn type_param_list(&self) -> Option<TypeParamList> { support::child(&self.syntax) } | 722 | pub fn type_param_list(&self) -> Option<TypeParamList> { support::child(&self.syntax) } |
381 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 723 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
382 | } | 724 | } |
383 | 725 | /// Opaque `impl Trait` type. | |
726 | /// | ||
727 | /// ``` | ||
728 | /// fn foo(bar: ❰ impl Debug + Eq ❱) {} | ||
729 | /// ``` | ||
730 | /// | ||
731 | /// [Reference](https://doc.rust-lang.org/reference/types/impl-trait.html) | ||
384 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 732 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
385 | pub struct ImplTraitType { | 733 | pub struct ImplTraitType { |
386 | pub(crate) syntax: SyntaxNode, | 734 | pub(crate) syntax: SyntaxNode, |
@@ -389,7 +737,13 @@ impl ast::TypeBoundsOwner for ImplTraitType {} | |||
389 | impl ImplTraitType { | 737 | impl ImplTraitType { |
390 | pub fn impl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![impl]) } | 738 | pub fn impl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![impl]) } |
391 | } | 739 | } |
392 | 740 | /// Trait object type. | |
741 | /// | ||
742 | /// ``` | ||
743 | /// type Foo = ❰ dyn Debug ❱; | ||
744 | /// ``` | ||
745 | /// | ||
746 | /// [Reference](https://doc.rust-lang.org/reference/types/trait-object.html) | ||
393 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 747 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
394 | pub struct DynTraitType { | 748 | pub struct DynTraitType { |
395 | pub(crate) syntax: SyntaxNode, | 749 | pub(crate) syntax: SyntaxNode, |
@@ -398,7 +752,13 @@ impl ast::TypeBoundsOwner for DynTraitType {} | |||
398 | impl DynTraitType { | 752 | impl DynTraitType { |
399 | pub fn dyn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![dyn]) } | 753 | pub fn dyn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![dyn]) } |
400 | } | 754 | } |
401 | 755 | /// Tuple literal. | |
756 | /// | ||
757 | /// ``` | ||
758 | /// ❰ (42, true) ❱; | ||
759 | /// ``` | ||
760 | /// | ||
761 | /// [Reference](https://doc.rust-lang.org/reference/expressions/tuple-expr.html) | ||
402 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 762 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
403 | pub struct TupleExpr { | 763 | pub struct TupleExpr { |
404 | pub(crate) syntax: SyntaxNode, | 764 | pub(crate) syntax: SyntaxNode, |
@@ -409,7 +769,15 @@ impl TupleExpr { | |||
409 | pub fn exprs(&self) -> AstChildren<Expr> { support::children(&self.syntax) } | 769 | pub fn exprs(&self) -> AstChildren<Expr> { support::children(&self.syntax) } |
410 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 770 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
411 | } | 771 | } |
412 | 772 | /// Array literal. | |
773 | /// | ||
774 | /// ``` | ||
775 | /// ❰ [#![inner_attr] true, false, true] ❱; | ||
776 | /// | ||
777 | /// ❰ ["baz"; 24] ❱; | ||
778 | /// ``` | ||
779 | /// | ||
780 | /// [Reference](https://doc.rust-lang.org/reference/expressions/array-expr.html) | ||
413 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 781 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
414 | pub struct ArrayExpr { | 782 | pub struct ArrayExpr { |
415 | pub(crate) syntax: SyntaxNode, | 783 | pub(crate) syntax: SyntaxNode, |
@@ -421,7 +789,14 @@ impl ArrayExpr { | |||
421 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 789 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
422 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | 790 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } |
423 | } | 791 | } |
424 | 792 | /// Parenthesized expression. | |
793 | /// Note: parens are only used for grouping, this is not a tuple literal. | ||
794 | /// | ||
795 | /// ``` | ||
796 | /// ❰ (#![inner_attr] 2 + 2) ❱ * 2; | ||
797 | /// ``` | ||
798 | /// | ||
799 | /// [Reference](https://doc.rust-lang.org/reference/expressions/grouped-expr.html) | ||
425 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 800 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
426 | pub struct ParenExpr { | 801 | pub struct ParenExpr { |
427 | pub(crate) syntax: SyntaxNode, | 802 | pub(crate) syntax: SyntaxNode, |
@@ -432,7 +807,19 @@ impl ParenExpr { | |||
432 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 807 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
433 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 808 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
434 | } | 809 | } |
435 | 810 | /// Path to a symbol in expression context. | |
811 | /// Includes single identifier variable names and elaborate paths with | ||
812 | /// generic parameters. | ||
813 | /// | ||
814 | /// ``` | ||
815 | /// ❰ Some::<i32> ❱; | ||
816 | /// ❰ foo ❱ + 42; | ||
817 | /// ❰ Vec::<i32>::push ❱; | ||
818 | /// ❰ <[i32]>::reverse ❱; | ||
819 | /// ❰ <String as std::borrow::Borrow<str>>::borrow ❱; | ||
820 | /// ``` | ||
821 | /// | ||
822 | /// [Reference](https://doc.rust-lang.org/reference/expressions/path-expr.html) | ||
436 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 823 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
437 | pub struct PathExpr { | 824 | pub struct PathExpr { |
438 | pub(crate) syntax: SyntaxNode, | 825 | pub(crate) syntax: SyntaxNode, |
@@ -440,7 +827,17 @@ pub struct PathExpr { | |||
440 | impl PathExpr { | 827 | impl PathExpr { |
441 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | 828 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } |
442 | } | 829 | } |
443 | 830 | /// Anonymous callable object literal a.k.a. closure, lambda or functor. | |
831 | /// | ||
832 | /// ``` | ||
833 | /// ❰ || 42 ❱; | ||
834 | /// ❰ |a: u32| val + 1 ❱; | ||
835 | /// ❰ async |#[attr] Pattern(_): Pattern| { bar } ❱; | ||
836 | /// ❰ move || baz ❱; | ||
837 | /// ❰ || -> u32 { closure_with_ret_type_annotation_requires_block_expr } ❱ | ||
838 | /// ``` | ||
839 | /// | ||
840 | /// [Reference](https://doc.rust-lang.org/reference/expressions/closure-expr.html) | ||
444 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 841 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
445 | pub struct LambdaExpr { | 842 | pub struct LambdaExpr { |
446 | pub(crate) syntax: SyntaxNode, | 843 | pub(crate) syntax: SyntaxNode, |
@@ -454,7 +851,25 @@ impl LambdaExpr { | |||
454 | pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } | 851 | pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } |
455 | pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } | 852 | pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } |
456 | } | 853 | } |
457 | 854 | /// If expression. Includes both regular `if` and `if let` forms. | |
855 | /// Beware that `else if` is a special case syntax sugar, because in general | ||
856 | /// there has to be block expression after `else`. | ||
857 | /// | ||
858 | /// ``` | ||
859 | /// ❰ if bool_cond { 42 } ❱ | ||
860 | /// ❰ if bool_cond { 42 } else { 24 } ❱ | ||
861 | /// ❰ if bool_cond { 42 } else if bool_cond2 { 42 } ❱ | ||
862 | /// | ||
863 | /// ❰ | ||
864 | /// if let Pattern(foo) = bar { | ||
865 | /// foo | ||
866 | /// } else { | ||
867 | /// panic!(); | ||
868 | /// } | ||
869 | /// ❱ | ||
870 | /// ``` | ||
871 | /// | ||
872 | /// [Reference](https://doc.rust-lang.org/reference/expressions/if-expr.html) | ||
458 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 873 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
459 | pub struct IfExpr { | 874 | pub struct IfExpr { |
460 | pub(crate) syntax: SyntaxNode, | 875 | pub(crate) syntax: SyntaxNode, |
@@ -464,7 +879,17 @@ impl IfExpr { | |||
464 | pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) } | 879 | pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) } |
465 | pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } | 880 | pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } |
466 | } | 881 | } |
467 | 882 | /// Unconditional loop expression. | |
883 | /// | ||
884 | /// ``` | ||
885 | /// ❰ | ||
886 | /// loop { | ||
887 | /// // yeah, it's that simple... | ||
888 | /// } | ||
889 | /// ❱ | ||
890 | /// ``` | ||
891 | /// | ||
892 | /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html) | ||
468 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 893 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
469 | pub struct LoopExpr { | 894 | pub struct LoopExpr { |
470 | pub(crate) syntax: SyntaxNode, | 895 | pub(crate) syntax: SyntaxNode, |
@@ -474,7 +899,45 @@ impl ast::LoopBodyOwner for LoopExpr {} | |||
474 | impl LoopExpr { | 899 | impl LoopExpr { |
475 | pub fn loop_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![loop]) } | 900 | pub fn loop_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![loop]) } |
476 | } | 901 | } |
477 | 902 | /// Block expression with an optional prefix (label, try ketword, | |
903 | /// unsafe keyword, async keyword...). | ||
904 | /// | ||
905 | /// ``` | ||
906 | /// ❰ | ||
907 | /// 'label: try { | ||
908 | /// None? | ||
909 | /// } | ||
910 | /// ❱ | ||
911 | /// ``` | ||
912 | /// | ||
913 | /// - [try block](https://doc.rust-lang.org/unstable-book/language-features/try-blocks.html) | ||
914 | /// - [unsafe block](https://doc.rust-lang.org/reference/expressions/block-expr.html#unsafe-blocks) | ||
915 | /// - [async block](https://doc.rust-lang.org/reference/expressions/block-expr.html#async-blocks) | ||
916 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
917 | pub struct EffectExpr { | ||
918 | pub(crate) syntax: SyntaxNode, | ||
919 | } | ||
920 | impl ast::AttrsOwner for EffectExpr {} | ||
921 | impl EffectExpr { | ||
922 | pub fn label(&self) -> Option<Label> { support::child(&self.syntax) } | ||
923 | pub fn try_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![try]) } | ||
924 | pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) } | ||
925 | pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) } | ||
926 | pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) } | ||
927 | } | ||
928 | /// For loop expression. | ||
929 | /// Note: record struct literals are not valid as iterable expression | ||
930 | /// due to ambiguity. | ||
931 | /// | ||
932 | /// ``` | ||
933 | /// ❰ | ||
934 | /// for i in (0..4) { | ||
935 | /// dbg!(i); | ||
936 | /// } | ||
937 | /// ❱ | ||
938 | /// ``` | ||
939 | /// | ||
940 | /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#iterator-loops) | ||
478 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 941 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
479 | pub struct ForExpr { | 942 | pub struct ForExpr { |
480 | pub(crate) syntax: SyntaxNode, | 943 | pub(crate) syntax: SyntaxNode, |
@@ -487,7 +950,22 @@ impl ForExpr { | |||
487 | pub fn in_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![in]) } | 950 | pub fn in_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![in]) } |
488 | pub fn iterable(&self) -> Option<Expr> { support::child(&self.syntax) } | 951 | pub fn iterable(&self) -> Option<Expr> { support::child(&self.syntax) } |
489 | } | 952 | } |
490 | 953 | /// While loop expression. Includes both regular `while` and `while let` forms. | |
954 | /// | ||
955 | /// ``` | ||
956 | /// ❰ | ||
957 | /// while bool_cond { | ||
958 | /// 42; | ||
959 | /// } | ||
960 | /// ❱ | ||
961 | /// ❰ | ||
962 | /// while let Pattern(foo) = bar { | ||
963 | /// bar += 1; | ||
964 | /// } | ||
965 | /// ❱ | ||
966 | /// ``` | ||
967 | /// | ||
968 | /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-loops) | ||
491 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 969 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
492 | pub struct WhileExpr { | 970 | pub struct WhileExpr { |
493 | pub(crate) syntax: SyntaxNode, | 971 | pub(crate) syntax: SyntaxNode, |
@@ -498,7 +976,22 @@ impl WhileExpr { | |||
498 | pub fn while_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![while]) } | 976 | pub fn while_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![while]) } |
499 | pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } | 977 | pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } |
500 | } | 978 | } |
501 | 979 | /// Continue expression. | |
980 | /// | ||
981 | /// ``` | ||
982 | /// while bool_cond { | ||
983 | /// ❰ continue ❱; | ||
984 | /// } | ||
985 | /// | ||
986 | /// 'outer: loop { | ||
987 | /// loop { | ||
988 | /// ❰ continue 'outer ❱; | ||
989 | /// } | ||
990 | /// } | ||
991 | /// | ||
992 | /// ``` | ||
993 | /// | ||
994 | /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#continue-expressions) | ||
502 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 995 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
503 | pub struct ContinueExpr { | 996 | pub struct ContinueExpr { |
504 | pub(crate) syntax: SyntaxNode, | 997 | pub(crate) syntax: SyntaxNode, |
@@ -512,7 +1005,25 @@ impl ContinueExpr { | |||
512 | support::token(&self.syntax, T![lifetime]) | 1005 | support::token(&self.syntax, T![lifetime]) |
513 | } | 1006 | } |
514 | } | 1007 | } |
515 | 1008 | /// Break expression. | |
1009 | /// | ||
1010 | /// ``` | ||
1011 | /// while bool_cond { | ||
1012 | /// ❰ break ❱; | ||
1013 | /// } | ||
1014 | /// 'outer: loop { | ||
1015 | /// for foo in bar { | ||
1016 | /// ❰ break 'outer ❱; | ||
1017 | /// } | ||
1018 | /// } | ||
1019 | /// 'outer: loop { | ||
1020 | /// loop { | ||
1021 | /// ❰ break 'outer 42 ❱; | ||
1022 | /// } | ||
1023 | /// } | ||
1024 | /// ``` | ||
1025 | /// | ||
1026 | /// [Refernce](https://doc.rust-lang.org/reference/expressions/loop-expr.html#break-expressions) | ||
516 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1027 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
517 | pub struct BreakExpr { | 1028 | pub struct BreakExpr { |
518 | pub(crate) syntax: SyntaxNode, | 1029 | pub(crate) syntax: SyntaxNode, |
@@ -525,7 +1036,20 @@ impl BreakExpr { | |||
525 | } | 1036 | } |
526 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 1037 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
527 | } | 1038 | } |
528 | 1039 | /// Label. | |
1040 | /// | ||
1041 | /// ``` | ||
1042 | /// ❰ 'outer: ❱ loop {} | ||
1043 | /// | ||
1044 | /// let foo = ❰ 'bar: ❱ loop {} | ||
1045 | /// | ||
1046 | /// ❰ 'baz: ❱ { | ||
1047 | /// break 'baz; | ||
1048 | /// } | ||
1049 | /// ``` | ||
1050 | /// | ||
1051 | /// [Reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html?highlight=label#loop-labels) | ||
1052 | /// [Labels for blocks RFC](https://github.com/rust-lang/rfcs/blob/master/text/2046-label-break-value.md) | ||
529 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1053 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
530 | pub struct Label { | 1054 | pub struct Label { |
531 | pub(crate) syntax: SyntaxNode, | 1055 | pub(crate) syntax: SyntaxNode, |
@@ -535,19 +1059,45 @@ impl Label { | |||
535 | support::token(&self.syntax, T![lifetime]) | 1059 | support::token(&self.syntax, T![lifetime]) |
536 | } | 1060 | } |
537 | } | 1061 | } |
538 | 1062 | /// Block expression. Includes unsafe blocks and block labels. | |
1063 | /// | ||
1064 | /// ``` | ||
1065 | /// let foo = ❰ | ||
1066 | /// { | ||
1067 | /// #![inner_attr] | ||
1068 | /// ❰ { } ❱ | ||
1069 | /// | ||
1070 | /// ❰ 'label: { break 'label } ❱ | ||
1071 | /// } | ||
1072 | /// ❱; | ||
1073 | /// ``` | ||
1074 | /// | ||
1075 | /// [Reference](https://doc.rust-lang.org/reference/expressions/block-expr.html) | ||
1076 | /// [Labels for blocks RFC](https://github.com/rust-lang/rfcs/blob/master/text/2046-label-break-value.md) | ||
539 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1077 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
540 | pub struct BlockExpr { | 1078 | pub struct BlockExpr { |
541 | pub(crate) syntax: SyntaxNode, | 1079 | pub(crate) syntax: SyntaxNode, |
542 | } | 1080 | } |
543 | impl ast::AttrsOwner for BlockExpr {} | 1081 | impl ast::AttrsOwner for BlockExpr {} |
1082 | impl ast::ModuleItemOwner for BlockExpr {} | ||
544 | impl BlockExpr { | 1083 | impl BlockExpr { |
545 | pub fn label(&self) -> Option<Label> { support::child(&self.syntax) } | 1084 | pub fn label(&self) -> Option<Label> { support::child(&self.syntax) } |
546 | pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) } | 1085 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } |
547 | pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) } | 1086 | pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) } |
548 | pub fn block(&self) -> Option<Block> { 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!['}']) } | ||
549 | } | 1089 | } |
550 | 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) | ||
551 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1101 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
552 | pub struct ReturnExpr { | 1102 | pub struct ReturnExpr { |
553 | pub(crate) syntax: SyntaxNode, | 1103 | pub(crate) syntax: SyntaxNode, |
@@ -556,7 +1106,16 @@ impl ast::AttrsOwner for ReturnExpr {} | |||
556 | impl ReturnExpr { | 1106 | impl ReturnExpr { |
557 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 1107 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
558 | } | 1108 | } |
559 | 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) | ||
560 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1119 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
561 | pub struct CallExpr { | 1120 | pub struct CallExpr { |
562 | pub(crate) syntax: SyntaxNode, | 1121 | pub(crate) syntax: SyntaxNode, |
@@ -565,7 +1124,16 @@ impl ast::ArgListOwner for CallExpr {} | |||
565 | impl CallExpr { | 1124 | impl CallExpr { |
566 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 1125 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
567 | } | 1126 | } |
568 | 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) | ||
569 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1137 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
570 | pub struct MethodCallExpr { | 1138 | pub struct MethodCallExpr { |
571 | pub(crate) syntax: SyntaxNode, | 1139 | pub(crate) syntax: SyntaxNode, |
@@ -578,7 +1146,13 @@ impl MethodCallExpr { | |||
578 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } | 1146 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } |
579 | pub fn type_arg_list(&self) -> Option<TypeArgList> { support::child(&self.syntax) } | 1147 | pub fn type_arg_list(&self) -> Option<TypeArgList> { support::child(&self.syntax) } |
580 | } | 1148 | } |
581 | 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) | ||
582 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1156 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
583 | pub struct IndexExpr { | 1157 | pub struct IndexExpr { |
584 | pub(crate) syntax: SyntaxNode, | 1158 | pub(crate) syntax: SyntaxNode, |
@@ -588,7 +1162,15 @@ impl IndexExpr { | |||
588 | pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } | 1162 | pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } |
589 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | 1163 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } |
590 | } | 1164 | } |
591 | 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) | ||
592 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1174 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
593 | pub struct FieldExpr { | 1175 | pub struct FieldExpr { |
594 | pub(crate) syntax: SyntaxNode, | 1176 | pub(crate) syntax: SyntaxNode, |
@@ -599,7 +1181,13 @@ impl FieldExpr { | |||
599 | pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) } | 1181 | pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) } |
600 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } | 1182 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } |
601 | } | 1183 | } |
602 | 1184 | /// Await operator call expression. | |
1185 | /// | ||
1186 | /// ``` | ||
1187 | /// ❰ expr.await ❱; | ||
1188 | /// ``` | ||
1189 | /// | ||
1190 | /// [Reference](https://doc.rust-lang.org/reference/expressions/await-expr.html) | ||
603 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1191 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
604 | pub struct AwaitExpr { | 1192 | pub struct AwaitExpr { |
605 | pub(crate) syntax: SyntaxNode, | 1193 | pub(crate) syntax: SyntaxNode, |
@@ -610,17 +1198,29 @@ impl AwaitExpr { | |||
610 | pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) } | 1198 | pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) } |
611 | pub fn await_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![await]) } | 1199 | pub fn await_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![await]) } |
612 | } | 1200 | } |
613 | 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) | ||
614 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1208 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
615 | pub struct TryExpr { | 1209 | pub struct TryExpr { |
616 | pub(crate) syntax: SyntaxNode, | 1210 | pub(crate) syntax: SyntaxNode, |
617 | } | 1211 | } |
618 | impl ast::AttrsOwner for TryExpr {} | 1212 | impl ast::AttrsOwner for TryExpr {} |
619 | impl TryExpr { | 1213 | impl TryExpr { |
620 | pub fn try_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![try]) } | ||
621 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 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![?]) } | ||
622 | } | 1216 | } |
623 | 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) | ||
624 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1224 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
625 | pub struct CastExpr { | 1225 | pub struct CastExpr { |
626 | pub(crate) syntax: SyntaxNode, | 1226 | pub(crate) syntax: SyntaxNode, |
@@ -631,7 +1231,16 @@ impl CastExpr { | |||
631 | pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) } | 1231 | pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) } |
632 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 1232 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
633 | } | 1233 | } |
634 | 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) | ||
635 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1244 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
636 | pub struct RefExpr { | 1245 | pub struct RefExpr { |
637 | pub(crate) syntax: SyntaxNode, | 1246 | pub(crate) syntax: SyntaxNode, |
@@ -641,9 +1250,18 @@ impl RefExpr { | |||
641 | pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) } | 1250 | pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) } |
642 | pub fn raw_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![raw]) } | 1251 | pub fn raw_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![raw]) } |
643 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } | 1252 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } |
1253 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } | ||
644 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 1254 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
645 | } | 1255 | } |
646 | 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) | ||
647 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1265 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
648 | pub struct PrefixExpr { | 1266 | pub struct PrefixExpr { |
649 | pub(crate) syntax: SyntaxNode, | 1267 | pub(crate) syntax: SyntaxNode, |
@@ -652,7 +1270,13 @@ impl ast::AttrsOwner for PrefixExpr {} | |||
652 | impl PrefixExpr { | 1270 | impl PrefixExpr { |
653 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 1271 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
654 | } | 1272 | } |
655 | 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) | ||
656 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1280 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
657 | pub struct BoxExpr { | 1281 | pub struct BoxExpr { |
658 | pub(crate) syntax: SyntaxNode, | 1282 | pub(crate) syntax: SyntaxNode, |
@@ -662,27 +1286,69 @@ impl BoxExpr { | |||
662 | pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) } | 1286 | pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) } |
663 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 1287 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
664 | } | 1288 | } |
665 | 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) | ||
666 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1301 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
667 | pub struct RangeExpr { | 1302 | pub struct RangeExpr { |
668 | pub(crate) syntax: SyntaxNode, | 1303 | pub(crate) syntax: SyntaxNode, |
669 | } | 1304 | } |
670 | impl ast::AttrsOwner for RangeExpr {} | 1305 | impl ast::AttrsOwner for RangeExpr {} |
671 | impl RangeExpr {} | 1306 | impl RangeExpr {} |
672 | 1307 | /// Binary operator call. | |
1308 | /// Includes all arithmetic, logic, bitwise and assignment operators. | ||
1309 | /// | ||
1310 | /// ``` | ||
1311 | /// ❰ 2 + ❰ 2 * 2 ❱ ❱; | ||
1312 | /// ❰ ❰ true && false ❱ || true ❱; | ||
1313 | /// ``` | ||
1314 | /// | ||
1315 | /// [Reference](https://doc.rust-lang.org/reference/expressions/operator-expr.html#arithmetic-and-logical-binary-operators) | ||
673 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1316 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
674 | pub struct BinExpr { | 1317 | pub struct BinExpr { |
675 | pub(crate) syntax: SyntaxNode, | 1318 | pub(crate) syntax: SyntaxNode, |
676 | } | 1319 | } |
677 | impl ast::AttrsOwner for BinExpr {} | 1320 | impl ast::AttrsOwner for BinExpr {} |
678 | impl BinExpr {} | 1321 | impl BinExpr {} |
679 | 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) | ||
680 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1335 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
681 | pub struct Literal { | 1336 | pub struct Literal { |
682 | pub(crate) syntax: SyntaxNode, | 1337 | pub(crate) syntax: SyntaxNode, |
683 | } | 1338 | } |
684 | impl Literal {} | 1339 | impl Literal {} |
685 | 1340 | /// Match expression. | |
1341 | /// | ||
1342 | /// ``` | ||
1343 | /// ❰ | ||
1344 | /// match expr { | ||
1345 | /// Pat1 => {} | ||
1346 | /// Pat2(_) => 42, | ||
1347 | /// } | ||
1348 | /// ❱ | ||
1349 | /// ``` | ||
1350 | /// | ||
1351 | /// [Reference](https://doc.rust-lang.org/reference/expressions/match-expr.html) | ||
686 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1352 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
687 | pub struct MatchExpr { | 1353 | pub struct MatchExpr { |
688 | pub(crate) syntax: SyntaxNode, | 1354 | pub(crate) syntax: SyntaxNode, |
@@ -693,7 +1359,20 @@ impl MatchExpr { | |||
693 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 1359 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
694 | pub fn match_arm_list(&self) -> Option<MatchArmList> { support::child(&self.syntax) } | 1360 | pub fn match_arm_list(&self) -> Option<MatchArmList> { support::child(&self.syntax) } |
695 | } | 1361 | } |
696 | 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) | ||
697 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1376 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
698 | pub struct MatchArmList { | 1377 | pub struct MatchArmList { |
699 | pub(crate) syntax: SyntaxNode, | 1378 | pub(crate) syntax: SyntaxNode, |
@@ -704,7 +1383,16 @@ impl MatchArmList { | |||
704 | pub fn arms(&self) -> AstChildren<MatchArm> { support::children(&self.syntax) } | 1383 | pub fn arms(&self) -> AstChildren<MatchArm> { support::children(&self.syntax) } |
705 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 1384 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
706 | } | 1385 | } |
707 | 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) | ||
708 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1396 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
709 | pub struct MatchArm { | 1397 | pub struct MatchArm { |
710 | pub(crate) syntax: SyntaxNode, | 1398 | pub(crate) syntax: SyntaxNode, |
@@ -716,7 +1404,15 @@ impl MatchArm { | |||
716 | pub fn fat_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=>]) } | 1404 | pub fn fat_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=>]) } |
717 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 1405 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
718 | } | 1406 | } |
719 | 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) | ||
720 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1416 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
721 | pub struct MatchGuard { | 1417 | pub struct MatchGuard { |
722 | pub(crate) syntax: SyntaxNode, | 1418 | pub(crate) syntax: SyntaxNode, |
@@ -725,7 +1421,21 @@ impl MatchGuard { | |||
725 | pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) } | 1421 | pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) } |
726 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 1422 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
727 | } | 1423 | } |
728 | 1424 | /// Record literal expression. The same syntax is used for structs, | |
1425 | /// unions and record enum variants. | ||
1426 | /// | ||
1427 | /// ``` | ||
1428 | /// ❰ | ||
1429 | /// foo::Bar { | ||
1430 | /// #![inner_attr] | ||
1431 | /// baz: 42, | ||
1432 | /// bruh: true, | ||
1433 | /// ..spread | ||
1434 | /// } | ||
1435 | /// ❱ | ||
1436 | /// ``` | ||
1437 | /// | ||
1438 | /// [Reference](https://doc.rust-lang.org/reference/expressions/struct-expr.html) | ||
729 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1439 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
730 | pub struct RecordLit { | 1440 | pub struct RecordLit { |
731 | pub(crate) syntax: SyntaxNode, | 1441 | pub(crate) syntax: SyntaxNode, |
@@ -734,7 +1444,16 @@ impl RecordLit { | |||
734 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | 1444 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } |
735 | pub fn record_field_list(&self) -> Option<RecordFieldList> { support::child(&self.syntax) } | 1445 | pub fn record_field_list(&self) -> Option<RecordFieldList> { support::child(&self.syntax) } |
736 | } | 1446 | } |
737 | 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) | ||
738 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1457 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
739 | pub struct RecordFieldList { | 1458 | pub struct RecordFieldList { |
740 | pub(crate) syntax: SyntaxNode, | 1459 | pub(crate) syntax: SyntaxNode, |
@@ -746,7 +1465,15 @@ impl RecordFieldList { | |||
746 | pub fn spread(&self) -> Option<Expr> { support::child(&self.syntax) } | 1465 | pub fn spread(&self) -> Option<Expr> { support::child(&self.syntax) } |
747 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 1466 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
748 | } | 1467 | } |
749 | 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) | ||
750 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1477 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
751 | pub struct RecordField { | 1478 | pub struct RecordField { |
752 | pub(crate) syntax: SyntaxNode, | 1479 | pub(crate) syntax: SyntaxNode, |
@@ -757,7 +1484,13 @@ impl RecordField { | |||
757 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } | 1484 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } |
758 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 1485 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
759 | } | 1486 | } |
760 | 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) | ||
761 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1494 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
762 | pub struct OrPat { | 1495 | pub struct OrPat { |
763 | pub(crate) syntax: SyntaxNode, | 1496 | pub(crate) syntax: SyntaxNode, |
@@ -765,7 +1498,14 @@ pub struct OrPat { | |||
765 | impl OrPat { | 1498 | impl OrPat { |
766 | pub fn pats(&self) -> AstChildren<Pat> { support::children(&self.syntax) } | 1499 | pub fn pats(&self) -> AstChildren<Pat> { support::children(&self.syntax) } |
767 | } | 1500 | } |
768 | 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 | ||
769 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1509 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
770 | pub struct ParenPat { | 1510 | pub struct ParenPat { |
771 | pub(crate) syntax: SyntaxNode, | 1511 | pub(crate) syntax: SyntaxNode, |
@@ -775,7 +1515,16 @@ impl ParenPat { | |||
775 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | 1515 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } |
776 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 1516 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
777 | } | 1517 | } |
778 | 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) | ||
779 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1528 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
780 | pub struct RefPat { | 1529 | pub struct RefPat { |
781 | pub(crate) syntax: SyntaxNode, | 1530 | pub(crate) syntax: SyntaxNode, |
@@ -785,7 +1534,13 @@ impl RefPat { | |||
785 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } | 1534 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } |
786 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | 1535 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } |
787 | } | 1536 | } |
788 | 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) | ||
789 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1544 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
790 | pub struct BoxPat { | 1545 | pub struct BoxPat { |
791 | pub(crate) syntax: SyntaxNode, | 1546 | pub(crate) syntax: SyntaxNode, |
@@ -794,7 +1549,16 @@ impl BoxPat { | |||
794 | pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) } | 1549 | pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) } |
795 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | 1550 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } |
796 | } | 1551 | } |
797 | 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) | ||
798 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1562 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
799 | pub struct BindPat { | 1563 | pub struct BindPat { |
800 | pub(crate) syntax: SyntaxNode, | 1564 | pub(crate) syntax: SyntaxNode, |
@@ -807,7 +1571,13 @@ impl BindPat { | |||
807 | pub fn at_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![@]) } | 1571 | pub fn at_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![@]) } |
808 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | 1572 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } |
809 | } | 1573 | } |
810 | 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) | ||
811 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1581 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
812 | pub struct PlaceholderPat { | 1582 | pub struct PlaceholderPat { |
813 | pub(crate) syntax: SyntaxNode, | 1583 | pub(crate) syntax: SyntaxNode, |
@@ -815,7 +1585,16 @@ pub struct PlaceholderPat { | |||
815 | impl PlaceholderPat { | 1585 | impl PlaceholderPat { |
816 | pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) } | 1586 | pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) } |
817 | } | 1587 | } |
818 | 1588 | /// Rest-of-the record/tuple pattern. | |
1589 | /// Note: this is not the unbonded range pattern (even more: it doesn't exist). | ||
1590 | /// | ||
1591 | /// ``` | ||
1592 | /// let Foo { bar, ❰ .. ❱ } = baz; | ||
1593 | /// let (❰ .. ❱, bruh) = (42, 24, 42); | ||
1594 | /// let Bruuh(❰ .. ❱) = bruuuh; | ||
1595 | /// ``` | ||
1596 | /// | ||
1597 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns) | ||
819 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1598 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
820 | pub struct DotDotPat { | 1599 | pub struct DotDotPat { |
821 | pub(crate) syntax: SyntaxNode, | 1600 | pub(crate) syntax: SyntaxNode, |
@@ -823,7 +1602,15 @@ pub struct DotDotPat { | |||
823 | impl DotDotPat { | 1602 | impl DotDotPat { |
824 | pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } | 1603 | pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } |
825 | } | 1604 | } |
826 | 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) | ||
827 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1614 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
828 | pub struct PathPat { | 1615 | pub struct PathPat { |
829 | pub(crate) syntax: SyntaxNode, | 1616 | pub(crate) syntax: SyntaxNode, |
@@ -831,7 +1618,13 @@ pub struct PathPat { | |||
831 | impl PathPat { | 1618 | impl PathPat { |
832 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | 1619 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } |
833 | } | 1620 | } |
834 | 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) | ||
835 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1628 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
836 | pub struct SlicePat { | 1629 | pub struct SlicePat { |
837 | pub(crate) syntax: SyntaxNode, | 1630 | pub(crate) syntax: SyntaxNode, |
@@ -841,13 +1634,33 @@ impl SlicePat { | |||
841 | pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } | 1634 | pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } |
842 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | 1635 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } |
843 | } | 1636 | } |
844 | 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) | ||
845 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1647 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
846 | pub struct RangePat { | 1648 | pub struct RangePat { |
847 | pub(crate) syntax: SyntaxNode, | 1649 | pub(crate) syntax: SyntaxNode, |
848 | } | 1650 | } |
849 | impl RangePat {} | 1651 | impl RangePat {} |
850 | 1652 | /// Literal pattern. | |
1653 | /// Includes only bool, number, char, and string literals. | ||
1654 | /// | ||
1655 | /// ``` | ||
1656 | /// match foo { | ||
1657 | /// Number(❰ 42 ❱) => {} | ||
1658 | /// String(❰ "42" ❱) => {} | ||
1659 | /// Bool(❰ true ❱) => {} | ||
1660 | /// } | ||
1661 | /// ``` | ||
1662 | /// | ||
1663 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#literal-patterns) | ||
851 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1664 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
852 | pub struct LiteralPat { | 1665 | pub struct LiteralPat { |
853 | pub(crate) syntax: SyntaxNode, | 1666 | pub(crate) syntax: SyntaxNode, |
@@ -855,7 +1668,13 @@ pub struct LiteralPat { | |||
855 | impl LiteralPat { | 1668 | impl LiteralPat { |
856 | pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) } | 1669 | pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) } |
857 | } | 1670 | } |
858 | 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) | ||
859 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1678 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
860 | pub struct MacroPat { | 1679 | pub struct MacroPat { |
861 | pub(crate) syntax: SyntaxNode, | 1680 | pub(crate) syntax: SyntaxNode, |
@@ -863,7 +1682,13 @@ pub struct MacroPat { | |||
863 | impl MacroPat { | 1682 | impl MacroPat { |
864 | pub fn macro_call(&self) -> Option<MacroCall> { support::child(&self.syntax) } | 1683 | pub fn macro_call(&self) -> Option<MacroCall> { support::child(&self.syntax) } |
865 | } | 1684 | } |
866 | 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) | ||
867 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1692 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
868 | pub struct RecordPat { | 1693 | pub struct RecordPat { |
869 | pub(crate) syntax: SyntaxNode, | 1694 | pub(crate) syntax: SyntaxNode, |
@@ -874,7 +1699,13 @@ impl RecordPat { | |||
874 | } | 1699 | } |
875 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | 1700 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } |
876 | } | 1701 | } |
877 | 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) | ||
878 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1709 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
879 | pub struct RecordFieldPatList { | 1710 | pub struct RecordFieldPatList { |
880 | pub(crate) syntax: SyntaxNode, | 1711 | pub(crate) syntax: SyntaxNode, |
@@ -889,7 +1720,15 @@ impl RecordFieldPatList { | |||
889 | pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } | 1720 | pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } |
890 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 1721 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
891 | } | 1722 | } |
892 | 1723 | /// Record literal's field pattern. | |
1724 | /// Note: record literal can also match tuple structs. | ||
1725 | /// | ||
1726 | /// ``` | ||
1727 | /// let Foo { ❰ bar: _ ❱ } = baz; | ||
1728 | /// let TupleStruct { ❰ 0: _ ❱ } = bruh; | ||
1729 | /// ``` | ||
1730 | /// | ||
1731 | /// [Reference](https://doc.rust-lang.org/reference/patterns.html#struct-patterns) | ||
893 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1732 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
894 | pub struct RecordFieldPat { | 1733 | pub struct RecordFieldPat { |
895 | pub(crate) syntax: SyntaxNode, | 1734 | pub(crate) syntax: SyntaxNode, |
@@ -900,7 +1739,13 @@ impl RecordFieldPat { | |||
900 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } | 1739 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } |
901 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | 1740 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } |
902 | } | 1741 | } |
903 | 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) | ||
904 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1749 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
905 | pub struct TupleStructPat { | 1750 | pub struct TupleStructPat { |
906 | pub(crate) syntax: SyntaxNode, | 1751 | pub(crate) syntax: SyntaxNode, |
@@ -911,7 +1756,14 @@ impl TupleStructPat { | |||
911 | pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } | 1756 | pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } |
912 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 1757 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
913 | } | 1758 | } |
914 | 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) | ||
915 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1767 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
916 | pub struct TuplePat { | 1768 | pub struct TuplePat { |
917 | pub(crate) syntax: SyntaxNode, | 1769 | pub(crate) syntax: SyntaxNode, |
@@ -921,7 +1773,17 @@ impl TuplePat { | |||
921 | pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } | 1773 | pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } |
922 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 1774 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
923 | } | 1775 | } |
924 | 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) | ||
925 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1787 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
926 | pub struct Visibility { | 1788 | pub struct Visibility { |
927 | pub(crate) syntax: SyntaxNode, | 1789 | pub(crate) syntax: SyntaxNode, |
@@ -932,7 +1794,29 @@ impl Visibility { | |||
932 | pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) } | 1794 | pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) } |
933 | pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) } | 1795 | pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) } |
934 | } | 1796 | } |
935 | 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) | ||
936 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1820 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
937 | pub struct Name { | 1821 | pub struct Name { |
938 | pub(crate) syntax: SyntaxNode, | 1822 | pub(crate) syntax: SyntaxNode, |
@@ -940,13 +1824,41 @@ pub struct Name { | |||
940 | impl Name { | 1824 | impl Name { |
941 | pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) } | 1825 | pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) } |
942 | } | 1826 | } |
943 | 1827 | /// Reference to a name. | |
1828 | /// See the explanation on the difference between `Name` and `NameRef` | ||
1829 | /// in `Name` ast node docs. | ||
1830 | /// | ||
1831 | /// ``` | ||
1832 | /// let foo = ❰ bar ❱(❰ Baz(❰ bruh ❱) ❱; | ||
1833 | /// ``` | ||
1834 | /// | ||
1835 | /// [Reference](https://doc.rust-lang.org/reference/identifiers.html) | ||
944 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1836 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
945 | pub struct NameRef { | 1837 | pub struct NameRef { |
946 | pub(crate) syntax: SyntaxNode, | 1838 | pub(crate) syntax: SyntaxNode, |
947 | } | 1839 | } |
948 | impl NameRef {} | 1840 | impl NameRef {} |
949 | 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) | ||
950 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1862 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
951 | pub struct MacroCall { | 1863 | pub struct MacroCall { |
952 | pub(crate) syntax: SyntaxNode, | 1864 | pub(crate) syntax: SyntaxNode, |
@@ -960,7 +1872,18 @@ impl MacroCall { | |||
960 | pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) } | 1872 | pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) } |
961 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 1873 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
962 | } | 1874 | } |
963 | 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) | ||
964 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1887 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
965 | pub struct Attr { | 1888 | pub struct Attr { |
966 | pub(crate) syntax: SyntaxNode, | 1889 | pub(crate) syntax: SyntaxNode, |
@@ -974,13 +1897,32 @@ impl Attr { | |||
974 | pub fn input(&self) -> Option<AttrInput> { support::child(&self.syntax) } | 1897 | pub fn input(&self) -> Option<AttrInput> { support::child(&self.syntax) } |
975 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | 1898 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } |
976 | } | 1899 | } |
977 | 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) | ||
978 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1908 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
979 | pub struct TokenTree { | 1909 | pub struct TokenTree { |
980 | pub(crate) syntax: SyntaxNode, | 1910 | pub(crate) syntax: SyntaxNode, |
981 | } | 1911 | } |
982 | impl TokenTree {} | 1912 | impl TokenTree {} |
983 | 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) | ||
984 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1926 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
985 | pub struct TypeParamList { | 1927 | pub struct TypeParamList { |
986 | pub(crate) syntax: SyntaxNode, | 1928 | pub(crate) syntax: SyntaxNode, |
@@ -993,7 +1935,13 @@ impl TypeParamList { | |||
993 | pub fn const_params(&self) -> AstChildren<ConstParam> { support::children(&self.syntax) } | 1935 | pub fn const_params(&self) -> AstChildren<ConstParam> { support::children(&self.syntax) } |
994 | pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) } | 1936 | pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) } |
995 | } | 1937 | } |
996 | 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) | ||
997 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1945 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
998 | pub struct TypeParam { | 1946 | pub struct TypeParam { |
999 | pub(crate) syntax: SyntaxNode, | 1947 | pub(crate) syntax: SyntaxNode, |
@@ -1005,7 +1953,12 @@ impl TypeParam { | |||
1005 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | 1953 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } |
1006 | pub fn default_type(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 1954 | pub fn default_type(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
1007 | } | 1955 | } |
1008 | 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) | ||
1009 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1962 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1010 | pub struct ConstParam { | 1963 | pub struct ConstParam { |
1011 | pub(crate) syntax: SyntaxNode, | 1964 | pub(crate) syntax: SyntaxNode, |
@@ -1017,7 +1970,13 @@ impl ConstParam { | |||
1017 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | 1970 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } |
1018 | pub fn default_val(&self) -> Option<Expr> { support::child(&self.syntax) } | 1971 | pub fn default_val(&self) -> Option<Expr> { support::child(&self.syntax) } |
1019 | } | 1972 | } |
1020 | 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) | ||
1021 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 1980 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1022 | pub struct LifetimeParam { | 1981 | pub struct LifetimeParam { |
1023 | pub(crate) syntax: SyntaxNode, | 1982 | pub(crate) syntax: SyntaxNode, |
@@ -1028,7 +1987,20 @@ impl LifetimeParam { | |||
1028 | support::token(&self.syntax, T![lifetime]) | 1987 | support::token(&self.syntax, T![lifetime]) |
1029 | } | 1988 | } |
1030 | } | 1989 | } |
1031 | 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) | ||
1032 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2004 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1033 | pub struct TypeBound { | 2005 | pub struct TypeBound { |
1034 | pub(crate) syntax: SyntaxNode, | 2006 | pub(crate) syntax: SyntaxNode, |
@@ -1040,7 +2012,21 @@ impl TypeBound { | |||
1040 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } | 2012 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } |
1041 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 2013 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
1042 | } | 2014 | } |
1043 | 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) | ||
1044 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2030 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1045 | pub struct TypeBoundList { | 2031 | pub struct TypeBoundList { |
1046 | pub(crate) syntax: SyntaxNode, | 2032 | pub(crate) syntax: SyntaxNode, |
@@ -1048,7 +2034,18 @@ pub struct TypeBoundList { | |||
1048 | impl TypeBoundList { | 2034 | impl TypeBoundList { |
1049 | pub fn bounds(&self) -> AstChildren<TypeBound> { support::children(&self.syntax) } | 2035 | pub fn bounds(&self) -> AstChildren<TypeBound> { support::children(&self.syntax) } |
1050 | } | 2036 | } |
1051 | 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) | ||
1052 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2049 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1053 | pub struct WherePred { | 2050 | pub struct WherePred { |
1054 | pub(crate) syntax: SyntaxNode, | 2051 | pub(crate) syntax: SyntaxNode, |
@@ -1060,7 +2057,14 @@ impl WherePred { | |||
1060 | } | 2057 | } |
1061 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 2058 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
1062 | } | 2059 | } |
1063 | 2060 | /// Where clause. | |
2061 | /// | ||
2062 | /// ``` | ||
2063 | /// trait Foo<'a, T> ❰ where 'a: 'static, T: Debug ❱ {} | ||
2064 | /// | ||
2065 | /// ``` | ||
2066 | /// | ||
2067 | /// [Reference](https://doc.rust-lang.org/reference/items/generics.html#where-clauses) | ||
1064 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2068 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1065 | pub struct WhereClause { | 2069 | pub struct WhereClause { |
1066 | pub(crate) syntax: SyntaxNode, | 2070 | pub(crate) syntax: SyntaxNode, |
@@ -1069,13 +2073,42 @@ impl WhereClause { | |||
1069 | pub fn where_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![where]) } | 2073 | pub fn where_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![where]) } |
1070 | pub fn predicates(&self) -> AstChildren<WherePred> { support::children(&self.syntax) } | 2074 | pub fn predicates(&self) -> AstChildren<WherePred> { support::children(&self.syntax) } |
1071 | } | 2075 | } |
1072 | 2076 | /// Abi declaration. | |
2077 | /// Note: the abi string is optional. | ||
2078 | /// | ||
2079 | /// ``` | ||
2080 | /// ❰ extern "C" ❱ { | ||
2081 | /// fn foo() {} | ||
2082 | /// } | ||
2083 | /// | ||
2084 | /// type Bar = ❰ extern ❱ fn() -> u32; | ||
2085 | /// | ||
2086 | /// type Baz = ❰ extern r#"stdcall"# ❱ fn() -> bool; | ||
2087 | /// ``` | ||
2088 | /// | ||
2089 | /// - [Extern blocks reference](https://doc.rust-lang.org/reference/items/external-blocks.html) | ||
2090 | /// - [FFI function pointers reference](https://doc.rust-lang.org/reference/items/functions.html#functions) | ||
1073 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2091 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1074 | pub struct Abi { | 2092 | pub struct Abi { |
1075 | pub(crate) syntax: SyntaxNode, | 2093 | pub(crate) syntax: SyntaxNode, |
1076 | } | 2094 | } |
1077 | impl Abi {} | 2095 | impl Abi {} |
1078 | 2096 | /// Expression statement. | |
2097 | /// | ||
2098 | /// ``` | ||
2099 | /// ❰ 42; ❱ | ||
2100 | /// ❰ foo(); ❱ | ||
2101 | /// ❰ (); ❱ | ||
2102 | /// ❰ {}; ❱ | ||
2103 | /// | ||
2104 | /// // constructions with trailing curly brace can omit the semicolon | ||
2105 | /// // but only when there are satements immediately after them (this is important!) | ||
2106 | /// ❰ if bool_cond { } ❱ | ||
2107 | /// ❰ loop {} ❱ | ||
2108 | /// ❰ somestatment; ❱ | ||
2109 | /// ``` | ||
2110 | /// | ||
2111 | /// [Reference](https://doc.rust-lang.org/reference/statements.html) | ||
1079 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2112 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1080 | pub struct ExprStmt { | 2113 | pub struct ExprStmt { |
1081 | pub(crate) syntax: SyntaxNode, | 2114 | pub(crate) syntax: SyntaxNode, |
@@ -1085,7 +2118,16 @@ impl ExprStmt { | |||
1085 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 2118 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1086 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 2119 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
1087 | } | 2120 | } |
1088 | 2121 | /// Let statement. | |
2122 | /// | ||
2123 | /// ``` | ||
2124 | /// ❰ #[attr] let foo; ❱ | ||
2125 | /// ❰ let bar: u64; ❱ | ||
2126 | /// ❰ let baz = 42; ❱ | ||
2127 | /// ❰ let bruh: bool = true; ❱ | ||
2128 | /// ``` | ||
2129 | /// | ||
2130 | /// [Reference](https://doc.rust-lang.org/reference/statements.html#let-statements) | ||
1089 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2131 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1090 | pub struct LetStmt { | 2132 | pub struct LetStmt { |
1091 | pub(crate) syntax: SyntaxNode, | 2133 | pub(crate) syntax: SyntaxNode, |
@@ -1099,7 +2141,18 @@ impl LetStmt { | |||
1099 | pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) } | 2141 | pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) } |
1100 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | 2142 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } |
1101 | } | 2143 | } |
1102 | 2144 | /// Condition of `if` or `while` expression. | |
2145 | /// | ||
2146 | /// ``` | ||
2147 | /// if ❰ true ❱ {} | ||
2148 | /// if ❰ let Pat(foo) = bar ❱ {} | ||
2149 | /// | ||
2150 | /// while ❰ true ❱ {} | ||
2151 | /// while ❰ let Pat(baz) = bruh ❱ {} | ||
2152 | /// ``` | ||
2153 | /// | ||
2154 | /// [If expression reference](https://doc.rust-lang.org/reference/expressions/if-expr.html) | ||
2155 | /// [While expression reference](https://doc.rust-lang.org/reference/expressions/loop-expr.html#predicate-loops) | ||
1103 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2156 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1104 | pub struct Condition { | 2157 | pub struct Condition { |
1105 | pub(crate) syntax: SyntaxNode, | 2158 | pub(crate) syntax: SyntaxNode, |
@@ -1110,20 +2163,18 @@ impl Condition { | |||
1110 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | 2163 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } |
1111 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 2164 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1112 | } | 2165 | } |
1113 | 2166 | /// Parameter list **declaration**. | |
1114 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2167 | /// |
1115 | pub struct Block { | 2168 | /// ``` |
1116 | pub(crate) syntax: SyntaxNode, | 2169 | /// fn foo❰ (a: u32, b: bool) ❱ -> u32 {} |
1117 | } | 2170 | /// let bar = ❰ |a, b| ❱ {}; |
1118 | impl ast::AttrsOwner for Block {} | 2171 | /// |
1119 | impl ast::ModuleItemOwner for Block {} | 2172 | /// impl Baz { |
1120 | impl Block { | 2173 | /// fn bruh❰ (&self, a: u32) ❱ {} |
1121 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | 2174 | /// } |
1122 | pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) } | 2175 | /// ``` |
1123 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 2176 | /// |
1124 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 2177 | /// [Reference](https://doc.rust-lang.org/reference/items/functions.html)ocs to codegen script |
1125 | } | ||
1126 | |||
1127 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2178 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1128 | pub struct ParamList { | 2179 | pub struct ParamList { |
1129 | pub(crate) syntax: SyntaxNode, | 2180 | pub(crate) syntax: SyntaxNode, |
@@ -1134,7 +2185,19 @@ impl ParamList { | |||
1134 | pub fn params(&self) -> AstChildren<Param> { support::children(&self.syntax) } | 2185 | pub fn params(&self) -> AstChildren<Param> { support::children(&self.syntax) } |
1135 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 2186 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
1136 | } | 2187 | } |
1137 | 2188 | /// Self parameter **declaration**. | |
2189 | /// | ||
2190 | /// ``` | ||
2191 | /// impl Bruh { | ||
2192 | /// fn foo(❰ self ❱) {} | ||
2193 | /// fn bar(❰ &self ❱) {} | ||
2194 | /// fn baz(❰ &mut self ❱) {} | ||
2195 | /// fn blah<'a>(❰ &'a self ❱) {} | ||
2196 | /// fn blin(❰ self: Box<Self> ❱) {} | ||
2197 | /// } | ||
2198 | /// ``` | ||
2199 | /// | ||
2200 | /// [Reference](https://doc.rust-lang.org/reference/items/functions.html) | ||
1138 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2201 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1139 | pub struct SelfParam { | 2202 | pub struct SelfParam { |
1140 | pub(crate) syntax: SyntaxNode, | 2203 | pub(crate) syntax: SyntaxNode, |
@@ -1149,7 +2212,17 @@ impl SelfParam { | |||
1149 | } | 2212 | } |
1150 | pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) } | 2213 | pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) } |
1151 | } | 2214 | } |
1152 | 2215 | /// Parameter **declaration**. | |
2216 | /// | ||
2217 | /// ``` | ||
2218 | /// fn foo(❰ #[attr] Pat(bar): Pat(u32) ❱, ❰ #[attr] _: bool ❱) {} | ||
2219 | /// | ||
2220 | /// extern "C" { | ||
2221 | /// fn bar(❰ baz: u32 ❱, ❰ ... ❱) -> u32; | ||
2222 | /// } | ||
2223 | /// ``` | ||
2224 | /// | ||
2225 | /// [Reference](https://doc.rust-lang.org/reference/items/functions.html) | ||
1153 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2226 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1154 | pub struct Param { | 2227 | pub struct Param { |
1155 | pub(crate) syntax: SyntaxNode, | 2228 | pub(crate) syntax: SyntaxNode, |
@@ -1160,7 +2233,16 @@ impl Param { | |||
1160 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | 2233 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } |
1161 | pub fn dotdotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![...]) } | 2234 | pub fn dotdotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![...]) } |
1162 | } | 2235 | } |
1163 | 2236 | /// Use declaration. | |
2237 | /// | ||
2238 | /// ``` | ||
2239 | /// ❰ #[attr] pub use foo; ❱ | ||
2240 | /// ❰ use bar as baz; ❱ | ||
2241 | /// ❰ use bruh::{self, bruuh}; ❱ | ||
2242 | /// ❰ use { blin::blen, blah::* }; | ||
2243 | /// ``` | ||
2244 | /// | ||
2245 | /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html) | ||
1164 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2246 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1165 | pub struct UseItem { | 2247 | pub struct UseItem { |
1166 | pub(crate) syntax: SyntaxNode, | 2248 | pub(crate) syntax: SyntaxNode, |
@@ -1171,7 +2253,16 @@ impl UseItem { | |||
1171 | pub fn use_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![use]) } | 2253 | pub fn use_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![use]) } |
1172 | pub fn use_tree(&self) -> Option<UseTree> { support::child(&self.syntax) } | 2254 | pub fn use_tree(&self) -> Option<UseTree> { support::child(&self.syntax) } |
1173 | } | 2255 | } |
1174 | 2256 | /// Use tree. | |
2257 | /// | ||
2258 | /// ``` | ||
2259 | /// pub use ❰ foo::❰ * ❱ ❱; | ||
2260 | /// use ❰ bar as baz ❱; | ||
2261 | /// use ❰ bruh::bruuh::{ ❰ self ❱, ❰ blin ❱ } ❱; | ||
2262 | /// use ❰ { ❰ blin::blen ❱ } ❱ | ||
2263 | /// ``` | ||
2264 | /// | ||
2265 | /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html) | ||
1175 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2266 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1176 | pub struct UseTree { | 2267 | pub struct UseTree { |
1177 | pub(crate) syntax: SyntaxNode, | 2268 | pub(crate) syntax: SyntaxNode, |
@@ -1182,7 +2273,16 @@ impl UseTree { | |||
1182 | pub fn use_tree_list(&self) -> Option<UseTreeList> { support::child(&self.syntax) } | 2273 | pub fn use_tree_list(&self) -> Option<UseTreeList> { support::child(&self.syntax) } |
1183 | pub fn alias(&self) -> Option<Alias> { support::child(&self.syntax) } | 2274 | pub fn alias(&self) -> Option<Alias> { support::child(&self.syntax) } |
1184 | } | 2275 | } |
1185 | 2276 | /// Item alias. | |
2277 | /// Note: this is not the type alias. | ||
2278 | /// | ||
2279 | /// ``` | ||
2280 | /// use foo ❰ as bar ❱; | ||
2281 | /// use baz::{bruh ❰ as _ ❱}; | ||
2282 | /// extern crate bruuh ❰ as blin ❱; | ||
2283 | /// ``` | ||
2284 | /// | ||
2285 | /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html) | ||
1186 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2286 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1187 | pub struct Alias { | 2287 | pub struct Alias { |
1188 | pub(crate) syntax: SyntaxNode, | 2288 | pub(crate) syntax: SyntaxNode, |
@@ -1191,7 +2291,14 @@ impl ast::NameOwner for Alias {} | |||
1191 | impl Alias { | 2291 | impl Alias { |
1192 | pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) } | 2292 | pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) } |
1193 | } | 2293 | } |
1194 | 2294 | /// Sublist of use trees. | |
2295 | /// | ||
2296 | /// ``` | ||
2297 | /// use bruh::bruuh::❰ { ❰ self ❱, ❰ blin ❱ } ❱; | ||
2298 | /// use ❰ { blin::blen::❰ {} ❱ } ❱ | ||
2299 | /// ``` | ||
2300 | /// | ||
2301 | /// [Reference](https://doc.rust-lang.org/reference/items/use-declarations.html) | ||
1195 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2302 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1196 | pub struct UseTreeList { | 2303 | pub struct UseTreeList { |
1197 | pub(crate) syntax: SyntaxNode, | 2304 | pub(crate) syntax: SyntaxNode, |
@@ -1201,7 +2308,14 @@ impl UseTreeList { | |||
1201 | pub fn use_trees(&self) -> AstChildren<UseTree> { support::children(&self.syntax) } | 2308 | pub fn use_trees(&self) -> AstChildren<UseTree> { support::children(&self.syntax) } |
1202 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 2309 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
1203 | } | 2310 | } |
1204 | 2311 | /// Extern crate item. | |
2312 | /// | ||
2313 | /// ``` | ||
2314 | /// ❰ #[attr] pub extern crate foo; ❱ | ||
2315 | /// ❰ extern crate self as bar; ❱ | ||
2316 | /// ``` | ||
2317 | /// | ||
2318 | /// [Reference](https://doc.rust-lang.org/reference/items/extern-crates.html) | ||
1205 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2319 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1206 | pub struct ExternCrateItem { | 2320 | pub struct ExternCrateItem { |
1207 | pub(crate) syntax: SyntaxNode, | 2321 | pub(crate) syntax: SyntaxNode, |
@@ -1214,7 +2328,13 @@ impl ExternCrateItem { | |||
1214 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } | 2328 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } |
1215 | pub fn alias(&self) -> Option<Alias> { support::child(&self.syntax) } | 2329 | pub fn alias(&self) -> Option<Alias> { support::child(&self.syntax) } |
1216 | } | 2330 | } |
1217 | 2331 | /// Call site arguments list. | |
2332 | /// | ||
2333 | /// ``` | ||
2334 | /// foo::<T, U>❰ (42, true) ❱; | ||
2335 | /// ``` | ||
2336 | /// | ||
2337 | /// [Reference](https://doc.rust-lang.org/reference/expressions/call-expr.html) | ||
1218 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2338 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1219 | pub struct ArgList { | 2339 | pub struct ArgList { |
1220 | pub(crate) syntax: SyntaxNode, | 2340 | pub(crate) syntax: SyntaxNode, |
@@ -1224,16 +2344,41 @@ impl ArgList { | |||
1224 | pub fn args(&self) -> AstChildren<Expr> { support::children(&self.syntax) } | 2344 | pub fn args(&self) -> AstChildren<Expr> { support::children(&self.syntax) } |
1225 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | 2345 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } |
1226 | } | 2346 | } |
1227 | 2347 | /// Path to a symbol. Includes single identifier names and elaborate paths with | |
2348 | /// generic parameters. | ||
2349 | /// | ||
2350 | /// ``` | ||
2351 | /// (0..10).❰ ❰ collect ❱ ::<Vec<_>> ❱(); | ||
2352 | /// ❰ ❰ ❰ Vec ❱ ::<u8> ❱ ::with_capacity ❱(1024); | ||
2353 | /// ❰ ❰ <❰ Foo ❱ as ❰ ❰ bar ❱ ::Bar ❱> ❱ ::baz ❱(); | ||
2354 | /// ❰ ❰ <❰ bruh ❱> ❱ ::bruuh ❱(); | ||
2355 | /// ``` | ||
2356 | /// | ||
2357 | /// [Reference](https://doc.rust-lang.org/reference/paths.html) | ||
1228 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2358 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1229 | pub struct Path { | 2359 | pub struct Path { |
1230 | pub(crate) syntax: SyntaxNode, | 2360 | pub(crate) syntax: SyntaxNode, |
1231 | } | 2361 | } |
1232 | impl Path { | 2362 | impl Path { |
1233 | pub fn segment(&self) -> Option<PathSegment> { support::child(&self.syntax) } | 2363 | pub fn segment(&self) -> Option<PathSegment> { support::child(&self.syntax) } |
2364 | pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) } | ||
1234 | pub fn qualifier(&self) -> Option<Path> { support::child(&self.syntax) } | 2365 | pub fn qualifier(&self) -> Option<Path> { support::child(&self.syntax) } |
1235 | } | 2366 | } |
1236 | 2367 | /// Segment of the path to a symbol. | |
2368 | /// Only path segment of an absolute path holds the `::` token, | ||
2369 | /// all other `::` tokens that connect path segments reside under `Path` itself.` | ||
2370 | /// | ||
2371 | /// ``` | ||
2372 | /// (0..10).❰ collect ❱ :: ❰ <Vec<_>> ❱(); | ||
2373 | /// ❰ Vec ❱ :: ❰ <u8> ❱ :: ❰ with_capacity ❱(1024); | ||
2374 | /// ❰ <❰ Foo ❱ as ❰ bar ❱ :: ❰ Bar ❱> ❱ :: ❰ baz ❱(); | ||
2375 | /// ❰ <❰ bruh ❱> ❱ :: ❰ bruuh ❱(); | ||
2376 | /// | ||
2377 | /// // Note that only in this case `::` token is inlcuded: | ||
2378 | /// ❰ ::foo ❱; | ||
2379 | /// ``` | ||
2380 | /// | ||
2381 | /// [Reference](https://doc.rust-lang.org/reference/paths.html) | ||
1237 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2382 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1238 | pub struct PathSegment { | 2383 | pub struct PathSegment { |
1239 | pub(crate) syntax: SyntaxNode, | 2384 | pub(crate) syntax: SyntaxNode, |
@@ -1241,6 +2386,8 @@ pub struct PathSegment { | |||
1241 | impl PathSegment { | 2386 | impl PathSegment { |
1242 | pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) } | 2387 | pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) } |
1243 | pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) } | 2388 | pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) } |
2389 | pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) } | ||
2390 | pub fn super_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![super]) } | ||
1244 | pub fn l_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![<]) } | 2391 | pub fn l_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![<]) } |
1245 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } | 2392 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } |
1246 | pub fn type_arg_list(&self) -> Option<TypeArgList> { support::child(&self.syntax) } | 2393 | pub fn type_arg_list(&self) -> Option<TypeArgList> { support::child(&self.syntax) } |
@@ -1249,7 +2396,15 @@ impl PathSegment { | |||
1249 | pub fn path_type(&self) -> Option<PathType> { support::child(&self.syntax) } | 2396 | pub fn path_type(&self) -> Option<PathType> { support::child(&self.syntax) } |
1250 | pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) } | 2397 | pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) } |
1251 | } | 2398 | } |
1252 | 2399 | /// List of type arguments that are passed at generic instantiation site. | |
2400 | /// | ||
2401 | /// ``` | ||
2402 | /// type _ = Foo ❰ ::<'a, u64, Item = Bar, 42, {true}> ❱::Bar; | ||
2403 | /// | ||
2404 | /// Vec❰ ::<bool> ❱::(); | ||
2405 | /// ``` | ||
2406 | /// | ||
2407 | /// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions) | ||
1253 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2408 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1254 | pub struct TypeArgList { | 2409 | pub struct TypeArgList { |
1255 | pub(crate) syntax: SyntaxNode, | 2410 | pub(crate) syntax: SyntaxNode, |
@@ -1264,7 +2419,13 @@ impl TypeArgList { | |||
1264 | pub fn const_args(&self) -> AstChildren<ConstArg> { support::children(&self.syntax) } | 2419 | pub fn const_args(&self) -> AstChildren<ConstArg> { support::children(&self.syntax) } |
1265 | pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) } | 2420 | pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) } |
1266 | } | 2421 | } |
1267 | 2422 | /// Type argument that is passed at generic instantiation site. | |
2423 | /// | ||
2424 | /// ``` | ||
2425 | /// type _ = Foo::<'a, ❰ u64 ❱, ❰ bool ❱, Item = Bar, 42>::Baz; | ||
2426 | /// ``` | ||
2427 | /// | ||
2428 | /// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions) | ||
1268 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2429 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1269 | pub struct TypeArg { | 2430 | pub struct TypeArg { |
1270 | pub(crate) syntax: SyntaxNode, | 2431 | pub(crate) syntax: SyntaxNode, |
@@ -1272,7 +2433,13 @@ pub struct TypeArg { | |||
1272 | impl TypeArg { | 2433 | impl TypeArg { |
1273 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 2434 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
1274 | } | 2435 | } |
1275 | 2436 | /// Associated type argument that is passed at generic instantiation site. | |
2437 | /// ``` | ||
2438 | /// type Foo = Bar::<'a, u64, bool, ❰ Item = Baz ❱, 42>::Bruh; | ||
2439 | /// | ||
2440 | /// trait Bruh<T>: Iterator<❰ Item: Debug ❱> {} | ||
2441 | /// ``` | ||
2442 | /// | ||
1276 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2443 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1277 | pub struct AssocTypeArg { | 2444 | pub struct AssocTypeArg { |
1278 | pub(crate) syntax: SyntaxNode, | 2445 | pub(crate) syntax: SyntaxNode, |
@@ -1283,7 +2450,15 @@ impl AssocTypeArg { | |||
1283 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | 2450 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } |
1284 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | 2451 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } |
1285 | } | 2452 | } |
1286 | 2453 | /// Lifetime argument that is passed at generic instantiation site. | |
2454 | /// | ||
2455 | /// ``` | ||
2456 | /// fn foo<'a>(s: &'a str) { | ||
2457 | /// bar::<❰ 'a ❱>(s); | ||
2458 | /// } | ||
2459 | /// ``` | ||
2460 | /// | ||
2461 | /// [Reference](https://doc.rust-lang.org/reference/paths.html#paths-in-expressions) | ||
1287 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2462 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1288 | pub struct LifetimeArg { | 2463 | pub struct LifetimeArg { |
1289 | pub(crate) syntax: SyntaxNode, | 2464 | pub(crate) syntax: SyntaxNode, |
@@ -1293,24 +2468,41 @@ impl LifetimeArg { | |||
1293 | support::token(&self.syntax, T![lifetime]) | 2468 | support::token(&self.syntax, T![lifetime]) |
1294 | } | 2469 | } |
1295 | } | 2470 | } |
1296 | 2471 | /// Constant value argument that is passed at generic instantiation site. | |
2472 | /// | ||
2473 | /// ``` | ||
2474 | /// foo::<u32, ❰ { true } ❱>(); | ||
2475 | /// | ||
2476 | /// bar::<❰ { 2 + 2} ❱>(); | ||
2477 | /// ``` | ||
2478 | /// | ||
2479 | /// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/2000-const-generics.md#declaring-a-const-parameter) | ||
1297 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2480 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1298 | pub struct ConstArg { | 2481 | pub struct ConstArg { |
1299 | pub(crate) syntax: SyntaxNode, | 2482 | pub(crate) syntax: SyntaxNode, |
1300 | } | 2483 | } |
1301 | impl ConstArg { | 2484 | impl ConstArg { |
1302 | pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) } | 2485 | pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) } |
1303 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | ||
1304 | pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) } | 2486 | pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) } |
1305 | } | 2487 | } |
1306 | 2488 | /// FIXME: (@edwin0cheng) Remove it to use ItemList instead | |
2489 | /// https://github.com/rust-analyzer/rust-analyzer/pull/4083#discussion_r422666243 | ||
2490 | /// | ||
2491 | /// [Reference](https://doc.rust-lang.org/reference/macros.html) | ||
1307 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2492 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1308 | pub struct MacroItems { | 2493 | pub struct MacroItems { |
1309 | pub(crate) syntax: SyntaxNode, | 2494 | pub(crate) syntax: SyntaxNode, |
1310 | } | 2495 | } |
1311 | impl ast::ModuleItemOwner for MacroItems {} | 2496 | impl ast::ModuleItemOwner for MacroItems {} |
1312 | impl MacroItems {} | 2497 | impl MacroItems {} |
1313 | 2498 | /// FIXME: (@edwin0cheng) add some documentation here. As per the writing | |
2499 | /// of this comment this ast node is not used. | ||
2500 | /// | ||
2501 | /// ``` | ||
2502 | /// // FIXME: example here | ||
2503 | /// ``` | ||
2504 | /// | ||
2505 | /// [Reference](https://doc.rust-lang.org/reference/macros.html) | ||
1314 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2506 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1315 | pub struct MacroStmts { | 2507 | pub struct MacroStmts { |
1316 | pub(crate) syntax: SyntaxNode, | 2508 | pub(crate) syntax: SyntaxNode, |
@@ -1319,7 +2511,18 @@ impl MacroStmts { | |||
1319 | pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) } | 2511 | pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) } |
1320 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | 2512 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } |
1321 | } | 2513 | } |
1322 | 2514 | /// List of items in an extern block. | |
2515 | /// | ||
2516 | /// ``` | ||
2517 | /// extern "C" ❰ | ||
2518 | /// { | ||
2519 | /// fn foo(); | ||
2520 | /// static var: u32; | ||
2521 | /// } | ||
2522 | /// ❱ | ||
2523 | /// ``` | ||
2524 | /// | ||
2525 | /// [Reference](https://doc.rust-lang.org/reference/items/external-blocks.html) | ||
1323 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2526 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1324 | pub struct ExternItemList { | 2527 | pub struct ExternItemList { |
1325 | pub(crate) syntax: SyntaxNode, | 2528 | pub(crate) syntax: SyntaxNode, |
@@ -1330,7 +2533,18 @@ impl ExternItemList { | |||
1330 | pub fn extern_items(&self) -> AstChildren<ExternItem> { support::children(&self.syntax) } | 2533 | pub fn extern_items(&self) -> AstChildren<ExternItem> { support::children(&self.syntax) } |
1331 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | 2534 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } |
1332 | } | 2535 | } |
1333 | 2536 | /// Extern block. | |
2537 | /// | ||
2538 | /// ``` | ||
2539 | /// ❰ | ||
2540 | /// extern "C" { | ||
2541 | /// fn foo(); | ||
2542 | /// } | ||
2543 | /// ❱ | ||
2544 | /// | ||
2545 | /// ``` | ||
2546 | /// | ||
2547 | /// [Reference](https://doc.rust-lang.org/reference/items/external-blocks.html) | ||
1334 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2548 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1335 | pub struct ExternBlock { | 2549 | pub struct ExternBlock { |
1336 | pub(crate) syntax: SyntaxNode, | 2550 | pub(crate) syntax: SyntaxNode, |
@@ -1339,7 +2553,15 @@ impl ExternBlock { | |||
1339 | pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) } | 2553 | pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) } |
1340 | pub fn extern_item_list(&self) -> Option<ExternItemList> { support::child(&self.syntax) } | 2554 | pub fn extern_item_list(&self) -> Option<ExternItemList> { support::child(&self.syntax) } |
1341 | } | 2555 | } |
1342 | 2556 | /// Meta item in an attribute. | |
2557 | /// | ||
2558 | /// ``` | ||
2559 | /// #[❰ bar::baz = "42" ❱] | ||
2560 | /// #[❰ bruh(bruuh("true")) ❱] | ||
2561 | /// struct Foo; | ||
2562 | /// ``` | ||
2563 | /// | ||
2564 | /// [Reference](https://doc.rust-lang.org/reference/attributes.html?highlight=meta,item#meta-item-attribute-syntax) | ||
1343 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2565 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1344 | pub struct MetaItem { | 2566 | pub struct MetaItem { |
1345 | pub(crate) syntax: SyntaxNode, | 2567 | pub(crate) syntax: SyntaxNode, |
@@ -1350,7 +2572,15 @@ impl MetaItem { | |||
1350 | pub fn attr_input(&self) -> Option<AttrInput> { support::child(&self.syntax) } | 2572 | pub fn attr_input(&self) -> Option<AttrInput> { support::child(&self.syntax) } |
1351 | pub fn nested_meta_items(&self) -> AstChildren<MetaItem> { support::children(&self.syntax) } | 2573 | pub fn nested_meta_items(&self) -> AstChildren<MetaItem> { support::children(&self.syntax) } |
1352 | } | 2574 | } |
1353 | 2575 | /// Macro 2.0 definition. | |
2576 | /// Their syntax is still WIP by rustc team... | ||
2577 | /// ``` | ||
2578 | /// ❰ | ||
2579 | /// macro foo { } | ||
2580 | /// ❱ | ||
2581 | /// ``` | ||
2582 | /// | ||
2583 | /// [RFC](https://github.com/rust-lang/rfcs/blob/master/text/1584-macros.md) | ||
1354 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2584 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1355 | pub struct MacroDef { | 2585 | pub struct MacroDef { |
1356 | pub(crate) syntax: SyntaxNode, | 2586 | pub(crate) syntax: SyntaxNode, |
@@ -1359,7 +2589,7 @@ impl MacroDef { | |||
1359 | pub fn name(&self) -> Option<Name> { support::child(&self.syntax) } | 2589 | pub fn name(&self) -> Option<Name> { support::child(&self.syntax) } |
1360 | pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) } | 2590 | pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) } |
1361 | } | 2591 | } |
1362 | 2592 | /// Any kind of nominal type definition. | |
1363 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2593 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1364 | pub enum NominalDef { | 2594 | pub enum NominalDef { |
1365 | StructDef(StructDef), | 2595 | StructDef(StructDef), |
@@ -1369,14 +2599,14 @@ pub enum NominalDef { | |||
1369 | impl ast::NameOwner for NominalDef {} | 2599 | impl ast::NameOwner for NominalDef {} |
1370 | impl ast::TypeParamsOwner for NominalDef {} | 2600 | impl ast::TypeParamsOwner for NominalDef {} |
1371 | impl ast::AttrsOwner for NominalDef {} | 2601 | impl ast::AttrsOwner for NominalDef {} |
1372 | 2602 | /// Any kind of **declared** generic parameter | |
1373 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2603 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1374 | pub enum GenericParam { | 2604 | pub enum GenericParam { |
1375 | LifetimeParam(LifetimeParam), | 2605 | LifetimeParam(LifetimeParam), |
1376 | TypeParam(TypeParam), | 2606 | TypeParam(TypeParam), |
1377 | ConstParam(ConstParam), | 2607 | ConstParam(ConstParam), |
1378 | } | 2608 | } |
1379 | 2609 | /// Any kind of generic argument passed at instantiation site | |
1380 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2610 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1381 | pub enum GenericArg { | 2611 | pub enum GenericArg { |
1382 | LifetimeArg(LifetimeArg), | 2612 | LifetimeArg(LifetimeArg), |
@@ -1384,7 +2614,7 @@ pub enum GenericArg { | |||
1384 | ConstArg(ConstArg), | 2614 | ConstArg(ConstArg), |
1385 | AssocTypeArg(AssocTypeArg), | 2615 | AssocTypeArg(AssocTypeArg), |
1386 | } | 2616 | } |
1387 | 2617 | /// Any kind of construct valid in type context | |
1388 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2618 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1389 | pub enum TypeRef { | 2619 | pub enum TypeRef { |
1390 | ParenType(ParenType), | 2620 | ParenType(ParenType), |
@@ -1401,7 +2631,7 @@ pub enum TypeRef { | |||
1401 | ImplTraitType(ImplTraitType), | 2631 | ImplTraitType(ImplTraitType), |
1402 | DynTraitType(DynTraitType), | 2632 | DynTraitType(DynTraitType), |
1403 | } | 2633 | } |
1404 | 2634 | /// Any kind of top-level item that may appear in a module | |
1405 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2635 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1406 | pub enum ModuleItem { | 2636 | pub enum ModuleItem { |
1407 | StructDef(StructDef), | 2637 | StructDef(StructDef), |
@@ -1422,16 +2652,20 @@ pub enum ModuleItem { | |||
1422 | impl ast::NameOwner for ModuleItem {} | 2652 | impl ast::NameOwner for ModuleItem {} |
1423 | impl ast::AttrsOwner for ModuleItem {} | 2653 | impl ast::AttrsOwner for ModuleItem {} |
1424 | impl ast::VisibilityOwner for ModuleItem {} | 2654 | impl ast::VisibilityOwner for ModuleItem {} |
1425 | 2655 | /// Any kind of item that may appear in an impl block | |
2656 | /// | ||
2657 | /// // FIXME: impl blocks can also contain MacroCall | ||
1426 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2658 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1427 | pub enum ImplItem { | 2659 | pub enum AssocItem { |
1428 | FnDef(FnDef), | 2660 | FnDef(FnDef), |
1429 | TypeAliasDef(TypeAliasDef), | 2661 | TypeAliasDef(TypeAliasDef), |
1430 | ConstDef(ConstDef), | 2662 | ConstDef(ConstDef), |
1431 | } | 2663 | } |
1432 | impl ast::NameOwner for ImplItem {} | 2664 | impl ast::NameOwner for AssocItem {} |
1433 | impl ast::AttrsOwner for ImplItem {} | 2665 | impl ast::AttrsOwner for AssocItem {} |
1434 | 2666 | /// Any kind of item that may appear in an extern block | |
2667 | /// | ||
2668 | /// // FIXME: extern blocks can also contain MacroCall | ||
1435 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2669 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1436 | pub enum ExternItem { | 2670 | pub enum ExternItem { |
1437 | FnDef(FnDef), | 2671 | FnDef(FnDef), |
@@ -1440,7 +2674,7 @@ pub enum ExternItem { | |||
1440 | impl ast::NameOwner for ExternItem {} | 2674 | impl ast::NameOwner for ExternItem {} |
1441 | impl ast::AttrsOwner for ExternItem {} | 2675 | impl ast::AttrsOwner for ExternItem {} |
1442 | impl ast::VisibilityOwner for ExternItem {} | 2676 | impl ast::VisibilityOwner for ExternItem {} |
1443 | 2677 | /// Any kind of expression | |
1444 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2678 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1445 | pub enum Expr { | 2679 | pub enum Expr { |
1446 | TupleExpr(TupleExpr), | 2680 | TupleExpr(TupleExpr), |
@@ -1465,6 +2699,7 @@ pub enum Expr { | |||
1465 | FieldExpr(FieldExpr), | 2699 | FieldExpr(FieldExpr), |
1466 | AwaitExpr(AwaitExpr), | 2700 | AwaitExpr(AwaitExpr), |
1467 | TryExpr(TryExpr), | 2701 | TryExpr(TryExpr), |
2702 | EffectExpr(EffectExpr), | ||
1468 | CastExpr(CastExpr), | 2703 | CastExpr(CastExpr), |
1469 | RefExpr(RefExpr), | 2704 | RefExpr(RefExpr), |
1470 | PrefixExpr(PrefixExpr), | 2705 | PrefixExpr(PrefixExpr), |
@@ -1475,7 +2710,7 @@ pub enum Expr { | |||
1475 | BoxExpr(BoxExpr), | 2710 | BoxExpr(BoxExpr), |
1476 | } | 2711 | } |
1477 | impl ast::AttrsOwner for Expr {} | 2712 | impl ast::AttrsOwner for Expr {} |
1478 | 2713 | /// Any kind of pattern | |
1479 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2714 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1480 | pub enum Pat { | 2715 | pub enum Pat { |
1481 | OrPat(OrPat), | 2716 | OrPat(OrPat), |
@@ -1494,25 +2729,28 @@ pub enum Pat { | |||
1494 | LiteralPat(LiteralPat), | 2729 | LiteralPat(LiteralPat), |
1495 | MacroPat(MacroPat), | 2730 | MacroPat(MacroPat), |
1496 | } | 2731 | } |
1497 | 2732 | /// Any kind of pattern that appears directly inside of the curly | |
2733 | /// braces of a record pattern | ||
1498 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2734 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1499 | pub enum RecordInnerPat { | 2735 | pub enum RecordInnerPat { |
1500 | RecordFieldPat(RecordFieldPat), | 2736 | RecordFieldPat(RecordFieldPat), |
1501 | BindPat(BindPat), | 2737 | BindPat(BindPat), |
1502 | } | 2738 | } |
1503 | 2739 | /// Any kind of input to an attribute | |
1504 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2740 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1505 | pub enum AttrInput { | 2741 | pub enum AttrInput { |
1506 | Literal(Literal), | 2742 | Literal(Literal), |
1507 | TokenTree(TokenTree), | 2743 | TokenTree(TokenTree), |
1508 | } | 2744 | } |
1509 | 2745 | /// Any kind of statement | |
2746 | /// Note: there are no empty statements, these are just represented as | ||
2747 | /// bare semicolons without a dedicated statement ast node. | ||
1510 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2748 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1511 | pub enum Stmt { | 2749 | pub enum Stmt { |
1512 | LetStmt(LetStmt), | 2750 | LetStmt(LetStmt), |
1513 | ExprStmt(ExprStmt), | 2751 | ExprStmt(ExprStmt), |
1514 | } | 2752 | } |
1515 | 2753 | /// Any kind of fields list (record or tuple field lists) | |
1516 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2754 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
1517 | pub enum FieldDefList { | 2755 | pub enum FieldDefList { |
1518 | RecordFieldDefList(RecordFieldDefList), | 2756 | RecordFieldDefList(RecordFieldDefList), |
@@ -1947,6 +3185,17 @@ impl AstNode for LoopExpr { | |||
1947 | } | 3185 | } |
1948 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 3186 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
1949 | } | 3187 | } |
3188 | impl AstNode for EffectExpr { | ||
3189 | fn can_cast(kind: SyntaxKind) -> bool { kind == EFFECT_EXPR } | ||
3190 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
3191 | if Self::can_cast(syntax.kind()) { | ||
3192 | Some(Self { syntax }) | ||
3193 | } else { | ||
3194 | None | ||
3195 | } | ||
3196 | } | ||
3197 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
3198 | } | ||
1950 | impl AstNode for ForExpr { | 3199 | impl AstNode for ForExpr { |
1951 | fn can_cast(kind: SyntaxKind) -> bool { kind == FOR_EXPR } | 3200 | fn can_cast(kind: SyntaxKind) -> bool { kind == FOR_EXPR } |
1952 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3201 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
@@ -2629,17 +3878,6 @@ impl AstNode for Condition { | |||
2629 | } | 3878 | } |
2630 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | 3879 | fn syntax(&self) -> &SyntaxNode { &self.syntax } |
2631 | } | 3880 | } |
2632 | impl AstNode for Block { | ||
2633 | fn can_cast(kind: SyntaxKind) -> bool { kind == BLOCK } | ||
2634 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2635 | if Self::can_cast(syntax.kind()) { | ||
2636 | Some(Self { syntax }) | ||
2637 | } else { | ||
2638 | None | ||
2639 | } | ||
2640 | } | ||
2641 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2642 | } | ||
2643 | impl AstNode for ParamList { | 3881 | impl AstNode for ParamList { |
2644 | fn can_cast(kind: SyntaxKind) -> bool { kind == PARAM_LIST } | 3882 | fn can_cast(kind: SyntaxKind) -> bool { kind == PARAM_LIST } |
2645 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 3883 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
@@ -3161,16 +4399,16 @@ impl AstNode for ModuleItem { | |||
3161 | } | 4399 | } |
3162 | } | 4400 | } |
3163 | } | 4401 | } |
3164 | impl From<FnDef> for ImplItem { | 4402 | impl From<FnDef> for AssocItem { |
3165 | fn from(node: FnDef) -> ImplItem { ImplItem::FnDef(node) } | 4403 | fn from(node: FnDef) -> AssocItem { AssocItem::FnDef(node) } |
3166 | } | 4404 | } |
3167 | impl From<TypeAliasDef> for ImplItem { | 4405 | impl From<TypeAliasDef> for AssocItem { |
3168 | fn from(node: TypeAliasDef) -> ImplItem { ImplItem::TypeAliasDef(node) } | 4406 | fn from(node: TypeAliasDef) -> AssocItem { AssocItem::TypeAliasDef(node) } |
3169 | } | 4407 | } |
3170 | impl From<ConstDef> for ImplItem { | 4408 | impl From<ConstDef> for AssocItem { |
3171 | fn from(node: ConstDef) -> ImplItem { ImplItem::ConstDef(node) } | 4409 | fn from(node: ConstDef) -> AssocItem { AssocItem::ConstDef(node) } |
3172 | } | 4410 | } |
3173 | impl AstNode for ImplItem { | 4411 | impl AstNode for AssocItem { |
3174 | fn can_cast(kind: SyntaxKind) -> bool { | 4412 | fn can_cast(kind: SyntaxKind) -> bool { |
3175 | match kind { | 4413 | match kind { |
3176 | FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true, | 4414 | FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true, |
@@ -3179,18 +4417,18 @@ impl AstNode for ImplItem { | |||
3179 | } | 4417 | } |
3180 | fn cast(syntax: SyntaxNode) -> Option<Self> { | 4418 | fn cast(syntax: SyntaxNode) -> Option<Self> { |
3181 | let res = match syntax.kind() { | 4419 | let res = match syntax.kind() { |
3182 | FN_DEF => ImplItem::FnDef(FnDef { syntax }), | 4420 | FN_DEF => AssocItem::FnDef(FnDef { syntax }), |
3183 | TYPE_ALIAS_DEF => ImplItem::TypeAliasDef(TypeAliasDef { syntax }), | 4421 | TYPE_ALIAS_DEF => AssocItem::TypeAliasDef(TypeAliasDef { syntax }), |
3184 | CONST_DEF => ImplItem::ConstDef(ConstDef { syntax }), | 4422 | CONST_DEF => AssocItem::ConstDef(ConstDef { syntax }), |
3185 | _ => return None, | 4423 | _ => return None, |
3186 | }; | 4424 | }; |
3187 | Some(res) | 4425 | Some(res) |
3188 | } | 4426 | } |
3189 | fn syntax(&self) -> &SyntaxNode { | 4427 | fn syntax(&self) -> &SyntaxNode { |
3190 | match self { | 4428 | match self { |
3191 | ImplItem::FnDef(it) => &it.syntax, | 4429 | AssocItem::FnDef(it) => &it.syntax, |
3192 | ImplItem::TypeAliasDef(it) => &it.syntax, | 4430 | AssocItem::TypeAliasDef(it) => &it.syntax, |
3193 | ImplItem::ConstDef(it) => &it.syntax, | 4431 | AssocItem::ConstDef(it) => &it.syntax, |
3194 | } | 4432 | } |
3195 | } | 4433 | } |
3196 | } | 4434 | } |
@@ -3288,6 +4526,9 @@ impl From<AwaitExpr> for Expr { | |||
3288 | impl From<TryExpr> for Expr { | 4526 | impl From<TryExpr> for Expr { |
3289 | fn from(node: TryExpr) -> Expr { Expr::TryExpr(node) } | 4527 | fn from(node: TryExpr) -> Expr { Expr::TryExpr(node) } |
3290 | } | 4528 | } |
4529 | impl From<EffectExpr> for Expr { | ||
4530 | fn from(node: EffectExpr) -> Expr { Expr::EffectExpr(node) } | ||
4531 | } | ||
3291 | impl From<CastExpr> for Expr { | 4532 | impl From<CastExpr> for Expr { |
3292 | fn from(node: CastExpr) -> Expr { Expr::CastExpr(node) } | 4533 | fn from(node: CastExpr) -> Expr { Expr::CastExpr(node) } |
3293 | } | 4534 | } |
@@ -3318,8 +4559,10 @@ impl AstNode for Expr { | |||
3318 | TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR | 4559 | TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR |
3319 | | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL | 4560 | | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL |
3320 | | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | RECORD_LIT | CALL_EXPR | INDEX_EXPR | 4561 | | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | RECORD_LIT | CALL_EXPR | INDEX_EXPR |
3321 | | METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | CAST_EXPR | REF_EXPR | 4562 | | METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | EFFECT_EXPR | CAST_EXPR |
3322 | | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL | BOX_EXPR => true, | 4563 | | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL | BOX_EXPR => { |
4564 | true | ||
4565 | } | ||
3323 | _ => false, | 4566 | _ => false, |
3324 | } | 4567 | } |
3325 | } | 4568 | } |
@@ -3347,6 +4590,7 @@ impl AstNode for Expr { | |||
3347 | FIELD_EXPR => Expr::FieldExpr(FieldExpr { syntax }), | 4590 | FIELD_EXPR => Expr::FieldExpr(FieldExpr { syntax }), |
3348 | AWAIT_EXPR => Expr::AwaitExpr(AwaitExpr { syntax }), | 4591 | AWAIT_EXPR => Expr::AwaitExpr(AwaitExpr { syntax }), |
3349 | TRY_EXPR => Expr::TryExpr(TryExpr { syntax }), | 4592 | TRY_EXPR => Expr::TryExpr(TryExpr { syntax }), |
4593 | EFFECT_EXPR => Expr::EffectExpr(EffectExpr { syntax }), | ||
3350 | CAST_EXPR => Expr::CastExpr(CastExpr { syntax }), | 4594 | CAST_EXPR => Expr::CastExpr(CastExpr { syntax }), |
3351 | REF_EXPR => Expr::RefExpr(RefExpr { syntax }), | 4595 | REF_EXPR => Expr::RefExpr(RefExpr { syntax }), |
3352 | PREFIX_EXPR => Expr::PrefixExpr(PrefixExpr { syntax }), | 4596 | PREFIX_EXPR => Expr::PrefixExpr(PrefixExpr { syntax }), |
@@ -3383,6 +4627,7 @@ impl AstNode for Expr { | |||
3383 | Expr::FieldExpr(it) => &it.syntax, | 4627 | Expr::FieldExpr(it) => &it.syntax, |
3384 | Expr::AwaitExpr(it) => &it.syntax, | 4628 | Expr::AwaitExpr(it) => &it.syntax, |
3385 | Expr::TryExpr(it) => &it.syntax, | 4629 | Expr::TryExpr(it) => &it.syntax, |
4630 | Expr::EffectExpr(it) => &it.syntax, | ||
3386 | Expr::CastExpr(it) => &it.syntax, | 4631 | Expr::CastExpr(it) => &it.syntax, |
3387 | Expr::RefExpr(it) => &it.syntax, | 4632 | Expr::RefExpr(it) => &it.syntax, |
3388 | Expr::PrefixExpr(it) => &it.syntax, | 4633 | Expr::PrefixExpr(it) => &it.syntax, |
@@ -3628,7 +4873,7 @@ impl std::fmt::Display for ModuleItem { | |||
3628 | std::fmt::Display::fmt(self.syntax(), f) | 4873 | std::fmt::Display::fmt(self.syntax(), f) |
3629 | } | 4874 | } |
3630 | } | 4875 | } |
3631 | impl std::fmt::Display for ImplItem { | 4876 | impl std::fmt::Display for AssocItem { |
3632 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | 4877 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
3633 | std::fmt::Display::fmt(self.syntax(), f) | 4878 | std::fmt::Display::fmt(self.syntax(), f) |
3634 | } | 4879 | } |
@@ -3863,6 +5108,11 @@ impl std::fmt::Display for LoopExpr { | |||
3863 | std::fmt::Display::fmt(self.syntax(), f) | 5108 | std::fmt::Display::fmt(self.syntax(), f) |
3864 | } | 5109 | } |
3865 | } | 5110 | } |
5111 | impl std::fmt::Display for EffectExpr { | ||
5112 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
5113 | std::fmt::Display::fmt(self.syntax(), f) | ||
5114 | } | ||
5115 | } | ||
3866 | impl std::fmt::Display for ForExpr { | 5116 | impl std::fmt::Display for ForExpr { |
3867 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | 5117 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
3868 | std::fmt::Display::fmt(self.syntax(), f) | 5118 | std::fmt::Display::fmt(self.syntax(), f) |
@@ -4173,11 +5423,6 @@ impl std::fmt::Display for Condition { | |||
4173 | std::fmt::Display::fmt(self.syntax(), f) | 5423 | std::fmt::Display::fmt(self.syntax(), f) |
4174 | } | 5424 | } |
4175 | } | 5425 | } |
4176 | impl std::fmt::Display for Block { | ||
4177 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
4178 | std::fmt::Display::fmt(self.syntax(), f) | ||
4179 | } | ||
4180 | } | ||
4181 | impl std::fmt::Display for ParamList { | 5426 | impl std::fmt::Display for ParamList { |
4182 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | 5427 | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
4183 | std::fmt::Display::fmt(self.syntax(), f) | 5428 | std::fmt::Display::fmt(self.syntax(), f) |
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 492088353..da0eb0926 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs | |||
@@ -1,5 +1,9 @@ | |||
1 | //! This module contains free-standing functions for creating AST fragments out | 1 | //! This module contains free-standing functions for creating AST fragments out |
2 | //! of smaller pieces. | 2 | //! of smaller pieces. |
3 | //! | ||
4 | //! Note that all functions here intended to be stupid constructors, which just | ||
5 | //! assemble a finish node from immediate children. If you want to do something | ||
6 | //! smarter than that, it probably doesn't belong in this module. | ||
3 | use itertools::Itertools; | 7 | use itertools::Itertools; |
4 | use stdx::format_to; | 8 | use stdx::format_to; |
5 | 9 | ||
@@ -13,6 +17,10 @@ pub fn name_ref(text: &str) -> ast::NameRef { | |||
13 | ast_from_text(&format!("fn f() {{ {}; }}", text)) | 17 | ast_from_text(&format!("fn f() {{ {}; }}", text)) |
14 | } | 18 | } |
15 | 19 | ||
20 | pub fn type_ref(text: &str) -> ast::TypeRef { | ||
21 | ast_from_text(&format!("impl {} for D {{}};", text)) | ||
22 | } | ||
23 | |||
16 | pub fn path_segment(name_ref: ast::NameRef) -> ast::PathSegment { | 24 | pub fn path_segment(name_ref: ast::NameRef) -> ast::PathSegment { |
17 | ast_from_text(&format!("use {};", name_ref)) | 25 | ast_from_text(&format!("use {};", name_ref)) |
18 | } | 26 | } |
@@ -82,14 +90,6 @@ pub fn block_expr( | |||
82 | ast_from_text(&format!("fn f() {}", buf)) | 90 | ast_from_text(&format!("fn f() {}", buf)) |
83 | } | 91 | } |
84 | 92 | ||
85 | pub fn block_from_expr(e: ast::Expr) -> ast::Block { | ||
86 | return from_text(&format!("{{ {} }}", e)); | ||
87 | |||
88 | fn from_text(text: &str) -> ast::Block { | ||
89 | ast_from_text(&format!("fn f() {}", text)) | ||
90 | } | ||
91 | } | ||
92 | |||
93 | pub fn expr_unit() -> ast::Expr { | 93 | pub fn expr_unit() -> ast::Expr { |
94 | expr_from_text("()") | 94 | expr_from_text("()") |
95 | } | 95 | } |
@@ -99,6 +99,9 @@ pub fn expr_empty_block() -> ast::Expr { | |||
99 | pub fn expr_unimplemented() -> ast::Expr { | 99 | pub fn expr_unimplemented() -> ast::Expr { |
100 | expr_from_text("unimplemented!()") | 100 | expr_from_text("unimplemented!()") |
101 | } | 101 | } |
102 | pub fn expr_unreachable() -> ast::Expr { | ||
103 | expr_from_text("unreachable!()") | ||
104 | } | ||
102 | pub fn expr_todo() -> ast::Expr { | 105 | pub fn expr_todo() -> ast::Expr { |
103 | expr_from_text("todo!()") | 106 | expr_from_text("todo!()") |
104 | } | 107 | } |
@@ -268,10 +271,6 @@ pub fn token(kind: SyntaxKind) -> SyntaxToken { | |||
268 | .unwrap_or_else(|| panic!("unhandled token: {:?}", kind)) | 271 | .unwrap_or_else(|| panic!("unhandled token: {:?}", kind)) |
269 | } | 272 | } |
270 | 273 | ||
271 | pub fn unreachable_macro_call() -> ast::MacroCall { | ||
272 | ast_from_text(&format!("unreachable!()")) | ||
273 | } | ||
274 | |||
275 | pub fn param(name: String, ty: String) -> ast::Param { | 274 | pub fn param(name: String, ty: String) -> ast::Param { |
276 | ast_from_text(&format!("fn f({}: {}) {{ }}", name, ty)) | 275 | ast_from_text(&format!("fn f({}: {}) {{ }}", name, ty)) |
277 | } | 276 | } |
@@ -281,7 +280,12 @@ pub fn param_list(pats: impl IntoIterator<Item = ast::Param>) -> ast::ParamList | |||
281 | ast_from_text(&format!("fn f({}) {{ }}", args)) | 280 | ast_from_text(&format!("fn f({}) {{ }}", args)) |
282 | } | 281 | } |
283 | 282 | ||
283 | pub fn visibility_pub_crate() -> ast::Visibility { | ||
284 | ast_from_text("pub(crate) struct S") | ||
285 | } | ||
286 | |||
284 | pub fn fn_def( | 287 | pub fn fn_def( |
288 | visibility: Option<ast::Visibility>, | ||
285 | fn_name: ast::Name, | 289 | fn_name: ast::Name, |
286 | type_params: Option<ast::TypeParamList>, | 290 | type_params: Option<ast::TypeParamList>, |
287 | params: ast::ParamList, | 291 | params: ast::ParamList, |
@@ -289,26 +293,21 @@ pub fn fn_def( | |||
289 | ) -> ast::FnDef { | 293 | ) -> ast::FnDef { |
290 | let type_params = | 294 | let type_params = |
291 | if let Some(type_params) = type_params { format!("<{}>", type_params) } else { "".into() }; | 295 | if let Some(type_params) = type_params { format!("<{}>", type_params) } else { "".into() }; |
292 | ast_from_text(&format!("fn {}{}{} {}", fn_name, type_params, params, body)) | 296 | let visibility = match visibility { |
293 | } | 297 | None => String::new(), |
294 | 298 | Some(it) => format!("{} ", it), | |
295 | pub fn add_leading_newlines(amount_of_newlines: usize, t: impl AstNode) -> ast::SourceFile { | 299 | }; |
296 | let newlines = "\n".repeat(amount_of_newlines); | 300 | ast_from_text(&format!("{}fn {}{}{} {}", visibility, fn_name, type_params, params, body)) |
297 | ast_from_text(&format!("{}{}", newlines, t.syntax())) | ||
298 | } | ||
299 | |||
300 | pub fn add_trailing_newlines(amount_of_newlines: usize, t: impl AstNode) -> ast::SourceFile { | ||
301 | let newlines = "\n".repeat(amount_of_newlines); | ||
302 | ast_from_text(&format!("{}{}", t.syntax(), newlines)) | ||
303 | } | ||
304 | |||
305 | pub fn add_pub_crate_modifier(fn_def: ast::FnDef) -> ast::FnDef { | ||
306 | ast_from_text(&format!("pub(crate) {}", fn_def)) | ||
307 | } | 301 | } |
308 | 302 | ||
309 | fn ast_from_text<N: AstNode>(text: &str) -> N { | 303 | fn ast_from_text<N: AstNode>(text: &str) -> N { |
310 | let parse = SourceFile::parse(text); | 304 | let parse = SourceFile::parse(text); |
311 | let node = parse.tree().syntax().descendants().find_map(N::cast).unwrap(); | 305 | let node = match parse.tree().syntax().descendants().find_map(N::cast) { |
306 | Some(it) => it, | ||
307 | None => { | ||
308 | panic!("Failed to make ast node `{}` from text {}", std::any::type_name::<N>(), text) | ||
309 | } | ||
310 | }; | ||
312 | let node = node.syntax().clone(); | 311 | let node = node.syntax().clone(); |
313 | let node = unroot(node); | 312 | let node = unroot(node); |
314 | let node = N::cast(node).unwrap(); | 313 | let node = N::cast(node).unwrap(); |
diff --git a/crates/ra_syntax/src/ast/tokens.rs b/crates/ra_syntax/src/ast/tokens.rs index 74906d8a6..04b0a4480 100644 --- a/crates/ra_syntax/src/ast/tokens.rs +++ b/crates/ra_syntax/src/ast/tokens.rs | |||
@@ -6,6 +6,7 @@ use crate::{ | |||
6 | ast::{AstToken, Comment, RawString, String, Whitespace}, | 6 | ast::{AstToken, Comment, RawString, String, Whitespace}, |
7 | TextRange, TextSize, | 7 | TextRange, TextSize, |
8 | }; | 8 | }; |
9 | use rustc_lexer::unescape::{unescape_literal, Mode}; | ||
9 | 10 | ||
10 | impl Comment { | 11 | impl Comment { |
11 | pub fn kind(&self) -> CommentKind { | 12 | pub fn kind(&self) -> CommentKind { |
@@ -147,7 +148,7 @@ impl HasStringValue for String { | |||
147 | 148 | ||
148 | let mut buf = std::string::String::with_capacity(text.len()); | 149 | let mut buf = std::string::String::with_capacity(text.len()); |
149 | let mut has_error = false; | 150 | let mut has_error = false; |
150 | rustc_lexer::unescape::unescape_str(text, &mut |_, unescaped_char| match unescaped_char { | 151 | unescape_literal(text, Mode::Str, &mut |_, unescaped_char| match unescaped_char { |
151 | Ok(c) => buf.push(c), | 152 | Ok(c) => buf.push(c), |
152 | Err(_) => has_error = true, | 153 | Err(_) => has_error = true, |
153 | }); | 154 | }); |
@@ -417,14 +418,9 @@ pub trait HasFormatSpecifier: AstToken { | |||
417 | 418 | ||
418 | let mut cloned = chars.clone().take(2); | 419 | let mut cloned = chars.clone().take(2); |
419 | let first = cloned.next().and_then(|next| next.1.as_ref().ok()).copied(); | 420 | let first = cloned.next().and_then(|next| next.1.as_ref().ok()).copied(); |
420 | let second = cloned.next().and_then(|next| next.1.as_ref().ok()).copied(); | ||
421 | if first != Some('}') { | 421 | if first != Some('}') { |
422 | continue; | 422 | continue; |
423 | } | 423 | } |
424 | if second == Some('}') { | ||
425 | // Escaped format end specifier, `}}` | ||
426 | continue; | ||
427 | } | ||
428 | skip_char_and_emit(&mut chars, FormatSpecifier::Close, &mut callback); | 424 | skip_char_and_emit(&mut chars, FormatSpecifier::Close, &mut callback); |
429 | } | 425 | } |
430 | _ => { | 426 | _ => { |
@@ -498,7 +494,7 @@ impl HasFormatSpecifier for String { | |||
498 | let offset = self.text_range_between_quotes()?.start() - self.syntax().text_range().start(); | 494 | let offset = self.text_range_between_quotes()?.start() - self.syntax().text_range().start(); |
499 | 495 | ||
500 | let mut res = Vec::with_capacity(text.len()); | 496 | let mut res = Vec::with_capacity(text.len()); |
501 | rustc_lexer::unescape::unescape_str(text, &mut |range, unescaped_char| { | 497 | unescape_literal(text, Mode::Str, &mut |range, unescaped_char| { |
502 | res.push(( | 498 | res.push(( |
503 | TextRange::new(range.start.try_into().unwrap(), range.end.try_into().unwrap()) | 499 | TextRange::new(range.start.try_into().unwrap(), range.end.try_into().unwrap()) |
504 | + offset, | 500 | + offset, |