mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-17 15:23:26 +03:00
use new quote-generated ast
This commit is contained in:
+1408
-1188
@@ -1,25 +1,14 @@
|
||||
// This file is automatically generated based on the file `./generated.rs.tera` when `cargo gen-syntax` is run
|
||||
// Do not edit manually
|
||||
|
||||
//! This module contains auto-generated Rust AST. Like `SyntaxNode`s, AST nodes
|
||||
//! are generic over ownership: `X<'a>` things are `Copy` references, `XNode`
|
||||
//! are Arc-based. You can switch between the two variants using `.owned` and
|
||||
//! `.borrowed` functions. Most of the code works with borowed mode, and only
|
||||
//! this mode has all AST accessors.
|
||||
|
||||
#![cfg_attr(rustfmt, rustfmt_skip)]
|
||||
// Generated file, do not edit by hand, see `crate/ra_tools/src/codegen`
|
||||
|
||||
use crate::{
|
||||
SyntaxNode, SyntaxKind::{self, *},
|
||||
ast::{self, AstNode},
|
||||
ast::{self, AstChildren, AstNode},
|
||||
SyntaxKind::{self, *},
|
||||
SyntaxNode,
|
||||
};
|
||||
|
||||
// Alias
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Alias {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for Alias {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -28,21 +17,22 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(Alias { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::NameOwner for Alias {}
|
||||
impl Alias {}
|
||||
|
||||
// ArgList
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ArgList {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for ArgList {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -51,24 +41,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(ArgList { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ArgList {
|
||||
pub fn args(&self) -> impl Iterator<Item = Expr> {
|
||||
super::children(self)
|
||||
pub fn args(&self) -> AstChildren<Expr> {
|
||||
AstChildren::new(&self.syntax)
|
||||
}
|
||||
}
|
||||
|
||||
// ArrayExpr
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ArrayExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for ArrayExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -77,24 +68,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(ArrayExpr { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ArrayExpr {
|
||||
pub fn exprs(&self) -> impl Iterator<Item = Expr> {
|
||||
super::children(self)
|
||||
pub fn exprs(&self) -> AstChildren<Expr> {
|
||||
AstChildren::new(&self.syntax)
|
||||
}
|
||||
}
|
||||
|
||||
// ArrayType
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ArrayType {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for ArrayType {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -103,28 +95,28 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(ArrayType { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ArrayType {
|
||||
pub fn type_ref(&self) -> Option<TypeRef> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
|
||||
pub fn expr(&self) -> Option<Expr> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// AssocTypeArg
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct AssocTypeArg {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for AssocTypeArg {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -133,28 +125,28 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(AssocTypeArg { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl AssocTypeArg {
|
||||
pub fn name_ref(&self) -> Option<NameRef> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
|
||||
pub fn type_ref(&self) -> Option<TypeRef> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// Attr
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Attr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for Attr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -163,24 +155,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(Attr { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl Attr {
|
||||
pub fn value(&self) -> Option<TokenTree> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// AwaitExpr
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct AwaitExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for AwaitExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -189,24 +182,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(AwaitExpr { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl AwaitExpr {
|
||||
pub fn expr(&self) -> Option<Expr> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// BinExpr
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct BinExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for BinExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -215,20 +209,21 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(BinExpr { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl BinExpr {}
|
||||
|
||||
// BindPat
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct BindPat {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for BindPat {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -237,25 +232,26 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(BindPat { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::NameOwner for BindPat {}
|
||||
impl BindPat {
|
||||
pub fn pat(&self) -> Option<Pat> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// Block
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Block {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for Block {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -264,29 +260,29 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(Block { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::AttrsOwner for Block {}
|
||||
impl Block {
|
||||
pub fn statements(&self) -> impl Iterator<Item = Stmt> {
|
||||
super::children(self)
|
||||
pub fn statements(&self) -> AstChildren<Stmt> {
|
||||
AstChildren::new(&self.syntax)
|
||||
}
|
||||
|
||||
pub fn expr(&self) -> Option<Expr> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// BlockExpr
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct BlockExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for BlockExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -295,24 +291,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(BlockExpr { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl BlockExpr {
|
||||
pub fn block(&self) -> Option<Block> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// BreakExpr
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct BreakExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for BreakExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -321,24 +318,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(BreakExpr { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl BreakExpr {
|
||||
pub fn expr(&self) -> Option<Expr> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// CallExpr
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct CallExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for CallExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -347,25 +345,26 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(CallExpr { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::ArgListOwner for CallExpr {}
|
||||
impl CallExpr {
|
||||
pub fn expr(&self) -> Option<Expr> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// CastExpr
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct CastExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for CastExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -374,28 +373,28 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(CastExpr { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl CastExpr {
|
||||
pub fn expr(&self) -> Option<Expr> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
|
||||
pub fn type_ref(&self) -> Option<TypeRef> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// Condition
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Condition {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for Condition {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -404,28 +403,28 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(Condition { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl Condition {
|
||||
pub fn pat(&self) -> Option<Pat> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
|
||||
pub fn expr(&self) -> Option<Expr> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// ConstDef
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ConstDef {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for ConstDef {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -434,12 +433,16 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(ConstDef { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::VisibilityOwner for ConstDef {}
|
||||
impl ast::NameOwner for ConstDef {}
|
||||
impl ast::TypeParamsOwner for ConstDef {}
|
||||
@@ -448,16 +451,13 @@ impl ast::DocCommentsOwner for ConstDef {}
|
||||
impl ast::TypeAscriptionOwner for ConstDef {}
|
||||
impl ConstDef {
|
||||
pub fn body(&self) -> Option<Expr> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// ContinueExpr
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ContinueExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for ContinueExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -466,20 +466,21 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(ContinueExpr { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ContinueExpr {}
|
||||
|
||||
// DynTraitType
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct DynTraitType {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for DynTraitType {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -488,21 +489,22 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(DynTraitType { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::TypeBoundsOwner for DynTraitType {}
|
||||
impl DynTraitType {}
|
||||
|
||||
// EnumDef
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct EnumDef {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for EnumDef {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -511,12 +513,16 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(EnumDef { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::VisibilityOwner for EnumDef {}
|
||||
impl ast::NameOwner for EnumDef {}
|
||||
impl ast::TypeParamsOwner for EnumDef {}
|
||||
@@ -524,16 +530,13 @@ impl ast::AttrsOwner for EnumDef {}
|
||||
impl ast::DocCommentsOwner for EnumDef {}
|
||||
impl EnumDef {
|
||||
pub fn variant_list(&self) -> Option<EnumVariantList> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// EnumVariant
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct EnumVariant {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for EnumVariant {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -542,27 +545,28 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(EnumVariant { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::NameOwner for EnumVariant {}
|
||||
impl ast::DocCommentsOwner for EnumVariant {}
|
||||
impl ast::AttrsOwner for EnumVariant {}
|
||||
impl EnumVariant {
|
||||
pub fn expr(&self) -> Option<Expr> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// EnumVariantList
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct EnumVariantList {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for EnumVariantList {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -571,39 +575,49 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(EnumVariantList { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl EnumVariantList {
|
||||
pub fn variants(&self) -> impl Iterator<Item = EnumVariant> {
|
||||
super::children(self)
|
||||
pub fn variants(&self) -> AstChildren<EnumVariant> {
|
||||
AstChildren::new(&self.syntax)
|
||||
}
|
||||
}
|
||||
|
||||
// Expr
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Expr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for Expr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
| TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | STRUCT_LIT | CALL_EXPR | INDEX_EXPR | METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | TRY_BLOCK_EXPR | CAST_EXPR | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL => true,
|
||||
TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR
|
||||
| LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL
|
||||
| BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | STRUCT_LIT | CALL_EXPR | INDEX_EXPR
|
||||
| METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | TRY_BLOCK_EXPR
|
||||
| CAST_EXPR | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL => {
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(Expr { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum ExprKind {
|
||||
TupleExpr(TupleExpr),
|
||||
ArrayExpr(ArrayExpr),
|
||||
@@ -637,141 +651,198 @@ pub enum ExprKind {
|
||||
MacroCall(MacroCall),
|
||||
}
|
||||
impl From<TupleExpr> for Expr {
|
||||
fn from(n: TupleExpr) -> Expr { Expr { syntax: n.syntax } }
|
||||
fn from(node: TupleExpr) -> Expr {
|
||||
Expr { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<ArrayExpr> for Expr {
|
||||
fn from(n: ArrayExpr) -> Expr { Expr { syntax: n.syntax } }
|
||||
fn from(node: ArrayExpr) -> Expr {
|
||||
Expr { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<ParenExpr> for Expr {
|
||||
fn from(n: ParenExpr) -> Expr { Expr { syntax: n.syntax } }
|
||||
fn from(node: ParenExpr) -> Expr {
|
||||
Expr { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<PathExpr> for Expr {
|
||||
fn from(n: PathExpr) -> Expr { Expr { syntax: n.syntax } }
|
||||
fn from(node: PathExpr) -> Expr {
|
||||
Expr { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<LambdaExpr> for Expr {
|
||||
fn from(n: LambdaExpr) -> Expr { Expr { syntax: n.syntax } }
|
||||
fn from(node: LambdaExpr) -> Expr {
|
||||
Expr { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<IfExpr> for Expr {
|
||||
fn from(n: IfExpr) -> Expr { Expr { syntax: n.syntax } }
|
||||
fn from(node: IfExpr) -> Expr {
|
||||
Expr { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<LoopExpr> for Expr {
|
||||
fn from(n: LoopExpr) -> Expr { Expr { syntax: n.syntax } }
|
||||
fn from(node: LoopExpr) -> Expr {
|
||||
Expr { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<ForExpr> for Expr {
|
||||
fn from(n: ForExpr) -> Expr { Expr { syntax: n.syntax } }
|
||||
fn from(node: ForExpr) -> Expr {
|
||||
Expr { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<WhileExpr> for Expr {
|
||||
fn from(n: WhileExpr) -> Expr { Expr { syntax: n.syntax } }
|
||||
fn from(node: WhileExpr) -> Expr {
|
||||
Expr { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<ContinueExpr> for Expr {
|
||||
fn from(n: ContinueExpr) -> Expr { Expr { syntax: n.syntax } }
|
||||
fn from(node: ContinueExpr) -> Expr {
|
||||
Expr { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<BreakExpr> for Expr {
|
||||
fn from(n: BreakExpr) -> Expr { Expr { syntax: n.syntax } }
|
||||
fn from(node: BreakExpr) -> Expr {
|
||||
Expr { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<Label> for Expr {
|
||||
fn from(n: Label) -> Expr { Expr { syntax: n.syntax } }
|
||||
fn from(node: Label) -> Expr {
|
||||
Expr { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<BlockExpr> for Expr {
|
||||
fn from(n: BlockExpr) -> Expr { Expr { syntax: n.syntax } }
|
||||
fn from(node: BlockExpr) -> Expr {
|
||||
Expr { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<ReturnExpr> for Expr {
|
||||
fn from(n: ReturnExpr) -> Expr { Expr { syntax: n.syntax } }
|
||||
fn from(node: ReturnExpr) -> Expr {
|
||||
Expr { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<MatchExpr> for Expr {
|
||||
fn from(n: MatchExpr) -> Expr { Expr { syntax: n.syntax } }
|
||||
fn from(node: MatchExpr) -> Expr {
|
||||
Expr { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<StructLit> for Expr {
|
||||
fn from(n: StructLit) -> Expr { Expr { syntax: n.syntax } }
|
||||
fn from(node: StructLit) -> Expr {
|
||||
Expr { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<CallExpr> for Expr {
|
||||
fn from(n: CallExpr) -> Expr { Expr { syntax: n.syntax } }
|
||||
fn from(node: CallExpr) -> Expr {
|
||||
Expr { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<IndexExpr> for Expr {
|
||||
fn from(n: IndexExpr) -> Expr { Expr { syntax: n.syntax } }
|
||||
fn from(node: IndexExpr) -> Expr {
|
||||
Expr { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<MethodCallExpr> for Expr {
|
||||
fn from(n: MethodCallExpr) -> Expr { Expr { syntax: n.syntax } }
|
||||
fn from(node: MethodCallExpr) -> Expr {
|
||||
Expr { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<FieldExpr> for Expr {
|
||||
fn from(n: FieldExpr) -> Expr { Expr { syntax: n.syntax } }
|
||||
fn from(node: FieldExpr) -> Expr {
|
||||
Expr { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<AwaitExpr> for Expr {
|
||||
fn from(n: AwaitExpr) -> Expr { Expr { syntax: n.syntax } }
|
||||
fn from(node: AwaitExpr) -> Expr {
|
||||
Expr { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<TryExpr> for Expr {
|
||||
fn from(n: TryExpr) -> Expr { Expr { syntax: n.syntax } }
|
||||
fn from(node: TryExpr) -> Expr {
|
||||
Expr { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<TryBlockExpr> for Expr {
|
||||
fn from(n: TryBlockExpr) -> Expr { Expr { syntax: n.syntax } }
|
||||
fn from(node: TryBlockExpr) -> Expr {
|
||||
Expr { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<CastExpr> for Expr {
|
||||
fn from(n: CastExpr) -> Expr { Expr { syntax: n.syntax } }
|
||||
fn from(node: CastExpr) -> Expr {
|
||||
Expr { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<RefExpr> for Expr {
|
||||
fn from(n: RefExpr) -> Expr { Expr { syntax: n.syntax } }
|
||||
fn from(node: RefExpr) -> Expr {
|
||||
Expr { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<PrefixExpr> for Expr {
|
||||
fn from(n: PrefixExpr) -> Expr { Expr { syntax: n.syntax } }
|
||||
fn from(node: PrefixExpr) -> Expr {
|
||||
Expr { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<RangeExpr> for Expr {
|
||||
fn from(n: RangeExpr) -> Expr { Expr { syntax: n.syntax } }
|
||||
fn from(node: RangeExpr) -> Expr {
|
||||
Expr { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<BinExpr> for Expr {
|
||||
fn from(n: BinExpr) -> Expr { Expr { syntax: n.syntax } }
|
||||
fn from(node: BinExpr) -> Expr {
|
||||
Expr { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<Literal> for Expr {
|
||||
fn from(n: Literal) -> Expr { Expr { syntax: n.syntax } }
|
||||
fn from(node: Literal) -> Expr {
|
||||
Expr { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<MacroCall> for Expr {
|
||||
fn from(n: MacroCall) -> Expr { Expr { syntax: n.syntax } }
|
||||
fn from(node: MacroCall) -> Expr {
|
||||
Expr { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl Expr {
|
||||
pub fn kind(&self) -> ExprKind {
|
||||
match self.syntax.kind() {
|
||||
TUPLE_EXPR => ExprKind::TupleExpr(TupleExpr::cast(self.syntax.clone()).unwrap()),
|
||||
ARRAY_EXPR => ExprKind::ArrayExpr(ArrayExpr::cast(self.syntax.clone()).unwrap()),
|
||||
PAREN_EXPR => ExprKind::ParenExpr(ParenExpr::cast(self.syntax.clone()).unwrap()),
|
||||
PATH_EXPR => ExprKind::PathExpr(PathExpr::cast(self.syntax.clone()).unwrap()),
|
||||
LAMBDA_EXPR => ExprKind::LambdaExpr(LambdaExpr::cast(self.syntax.clone()).unwrap()),
|
||||
IF_EXPR => ExprKind::IfExpr(IfExpr::cast(self.syntax.clone()).unwrap()),
|
||||
LOOP_EXPR => ExprKind::LoopExpr(LoopExpr::cast(self.syntax.clone()).unwrap()),
|
||||
FOR_EXPR => ExprKind::ForExpr(ForExpr::cast(self.syntax.clone()).unwrap()),
|
||||
WHILE_EXPR => ExprKind::WhileExpr(WhileExpr::cast(self.syntax.clone()).unwrap()),
|
||||
CONTINUE_EXPR => ExprKind::ContinueExpr(ContinueExpr::cast(self.syntax.clone()).unwrap()),
|
||||
BREAK_EXPR => ExprKind::BreakExpr(BreakExpr::cast(self.syntax.clone()).unwrap()),
|
||||
LABEL => ExprKind::Label(Label::cast(self.syntax.clone()).unwrap()),
|
||||
BLOCK_EXPR => ExprKind::BlockExpr(BlockExpr::cast(self.syntax.clone()).unwrap()),
|
||||
RETURN_EXPR => ExprKind::ReturnExpr(ReturnExpr::cast(self.syntax.clone()).unwrap()),
|
||||
MATCH_EXPR => ExprKind::MatchExpr(MatchExpr::cast(self.syntax.clone()).unwrap()),
|
||||
STRUCT_LIT => ExprKind::StructLit(StructLit::cast(self.syntax.clone()).unwrap()),
|
||||
CALL_EXPR => ExprKind::CallExpr(CallExpr::cast(self.syntax.clone()).unwrap()),
|
||||
INDEX_EXPR => ExprKind::IndexExpr(IndexExpr::cast(self.syntax.clone()).unwrap()),
|
||||
METHOD_CALL_EXPR => ExprKind::MethodCallExpr(MethodCallExpr::cast(self.syntax.clone()).unwrap()),
|
||||
FIELD_EXPR => ExprKind::FieldExpr(FieldExpr::cast(self.syntax.clone()).unwrap()),
|
||||
AWAIT_EXPR => ExprKind::AwaitExpr(AwaitExpr::cast(self.syntax.clone()).unwrap()),
|
||||
TRY_EXPR => ExprKind::TryExpr(TryExpr::cast(self.syntax.clone()).unwrap()),
|
||||
TRY_BLOCK_EXPR => ExprKind::TryBlockExpr(TryBlockExpr::cast(self.syntax.clone()).unwrap()),
|
||||
CAST_EXPR => ExprKind::CastExpr(CastExpr::cast(self.syntax.clone()).unwrap()),
|
||||
REF_EXPR => ExprKind::RefExpr(RefExpr::cast(self.syntax.clone()).unwrap()),
|
||||
PREFIX_EXPR => ExprKind::PrefixExpr(PrefixExpr::cast(self.syntax.clone()).unwrap()),
|
||||
RANGE_EXPR => ExprKind::RangeExpr(RangeExpr::cast(self.syntax.clone()).unwrap()),
|
||||
BIN_EXPR => ExprKind::BinExpr(BinExpr::cast(self.syntax.clone()).unwrap()),
|
||||
LITERAL => ExprKind::Literal(Literal::cast(self.syntax.clone()).unwrap()),
|
||||
MACRO_CALL => ExprKind::MacroCall(MacroCall::cast(self.syntax.clone()).unwrap()),
|
||||
let syntax = self.syntax.clone();
|
||||
match syntax.kind() {
|
||||
TUPLE_EXPR => ExprKind::TupleExpr(TupleExpr { syntax }),
|
||||
ARRAY_EXPR => ExprKind::ArrayExpr(ArrayExpr { syntax }),
|
||||
PAREN_EXPR => ExprKind::ParenExpr(ParenExpr { syntax }),
|
||||
PATH_EXPR => ExprKind::PathExpr(PathExpr { syntax }),
|
||||
LAMBDA_EXPR => ExprKind::LambdaExpr(LambdaExpr { syntax }),
|
||||
IF_EXPR => ExprKind::IfExpr(IfExpr { syntax }),
|
||||
LOOP_EXPR => ExprKind::LoopExpr(LoopExpr { syntax }),
|
||||
FOR_EXPR => ExprKind::ForExpr(ForExpr { syntax }),
|
||||
WHILE_EXPR => ExprKind::WhileExpr(WhileExpr { syntax }),
|
||||
CONTINUE_EXPR => ExprKind::ContinueExpr(ContinueExpr { syntax }),
|
||||
BREAK_EXPR => ExprKind::BreakExpr(BreakExpr { syntax }),
|
||||
LABEL => ExprKind::Label(Label { syntax }),
|
||||
BLOCK_EXPR => ExprKind::BlockExpr(BlockExpr { syntax }),
|
||||
RETURN_EXPR => ExprKind::ReturnExpr(ReturnExpr { syntax }),
|
||||
MATCH_EXPR => ExprKind::MatchExpr(MatchExpr { syntax }),
|
||||
STRUCT_LIT => ExprKind::StructLit(StructLit { syntax }),
|
||||
CALL_EXPR => ExprKind::CallExpr(CallExpr { syntax }),
|
||||
INDEX_EXPR => ExprKind::IndexExpr(IndexExpr { syntax }),
|
||||
METHOD_CALL_EXPR => ExprKind::MethodCallExpr(MethodCallExpr { syntax }),
|
||||
FIELD_EXPR => ExprKind::FieldExpr(FieldExpr { syntax }),
|
||||
AWAIT_EXPR => ExprKind::AwaitExpr(AwaitExpr { syntax }),
|
||||
TRY_EXPR => ExprKind::TryExpr(TryExpr { syntax }),
|
||||
TRY_BLOCK_EXPR => ExprKind::TryBlockExpr(TryBlockExpr { syntax }),
|
||||
CAST_EXPR => ExprKind::CastExpr(CastExpr { syntax }),
|
||||
REF_EXPR => ExprKind::RefExpr(RefExpr { syntax }),
|
||||
PREFIX_EXPR => ExprKind::PrefixExpr(PrefixExpr { syntax }),
|
||||
RANGE_EXPR => ExprKind::RangeExpr(RangeExpr { syntax }),
|
||||
BIN_EXPR => ExprKind::BinExpr(BinExpr { syntax }),
|
||||
LITERAL => ExprKind::Literal(Literal { syntax }),
|
||||
MACRO_CALL => ExprKind::MacroCall(MacroCall { syntax }),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Expr {}
|
||||
|
||||
// ExprStmt
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ExprStmt {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for ExprStmt {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -780,24 +851,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(ExprStmt { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ExprStmt {
|
||||
pub fn expr(&self) -> Option<Expr> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// ExternCrateItem
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ExternCrateItem {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for ExternCrateItem {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -806,28 +878,28 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(ExternCrateItem { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ExternCrateItem {
|
||||
pub fn name_ref(&self) -> Option<NameRef> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
|
||||
pub fn alias(&self) -> Option<Alias> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// FieldExpr
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct FieldExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for FieldExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -836,28 +908,28 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(FieldExpr { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl FieldExpr {
|
||||
pub fn expr(&self) -> Option<Expr> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
|
||||
pub fn name_ref(&self) -> Option<NameRef> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// FieldPat
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct FieldPat {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for FieldPat {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -866,25 +938,26 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(FieldPat { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::NameOwner for FieldPat {}
|
||||
impl FieldPat {
|
||||
pub fn pat(&self) -> Option<Pat> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// FieldPatList
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct FieldPatList {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for FieldPatList {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -893,28 +966,28 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(FieldPatList { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl FieldPatList {
|
||||
pub fn field_pats(&self) -> impl Iterator<Item = FieldPat> {
|
||||
super::children(self)
|
||||
pub fn field_pats(&self) -> AstChildren<FieldPat> {
|
||||
AstChildren::new(&self.syntax)
|
||||
}
|
||||
|
||||
pub fn bind_pats(&self) -> impl Iterator<Item = BindPat> {
|
||||
super::children(self)
|
||||
pub fn bind_pats(&self) -> AstChildren<BindPat> {
|
||||
AstChildren::new(&self.syntax)
|
||||
}
|
||||
}
|
||||
|
||||
// FnDef
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct FnDef {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for FnDef {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -923,12 +996,16 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(FnDef { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::VisibilityOwner for FnDef {}
|
||||
impl ast::NameOwner for FnDef {}
|
||||
impl ast::TypeParamsOwner for FnDef {}
|
||||
@@ -936,24 +1013,19 @@ impl ast::AttrsOwner for FnDef {}
|
||||
impl ast::DocCommentsOwner for FnDef {}
|
||||
impl FnDef {
|
||||
pub fn param_list(&self) -> Option<ParamList> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
|
||||
pub fn body(&self) -> Option<Block> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
|
||||
pub fn ret_type(&self) -> Option<RetType> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// FnPointerType
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct FnPointerType {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for FnPointerType {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -962,28 +1034,28 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(FnPointerType { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl FnPointerType {
|
||||
pub fn param_list(&self) -> Option<ParamList> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
|
||||
pub fn ret_type(&self) -> Option<RetType> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// ForExpr
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ForExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for ForExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -992,29 +1064,29 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(ForExpr { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::LoopBodyOwner for ForExpr {}
|
||||
impl ForExpr {
|
||||
pub fn pat(&self) -> Option<Pat> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
|
||||
pub fn iterable(&self) -> Option<Expr> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// ForType
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ForType {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for ForType {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -1023,24 +1095,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(ForType { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ForType {
|
||||
pub fn type_ref(&self) -> Option<TypeRef> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// IfExpr
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct IfExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for IfExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -1049,24 +1122,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(IfExpr { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl IfExpr {
|
||||
pub fn condition(&self) -> Option<Condition> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// ImplBlock
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ImplBlock {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for ImplBlock {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -1075,74 +1149,81 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(ImplBlock { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::TypeParamsOwner for ImplBlock {}
|
||||
impl ast::AttrsOwner for ImplBlock {}
|
||||
impl ImplBlock {
|
||||
pub fn item_list(&self) -> Option<ItemList> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// ImplItem
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ImplItem {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for ImplItem {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
| FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true,
|
||||
FN_DEF | TYPE_ALIAS_DEF | CONST_DEF => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(ImplItem { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum ImplItemKind {
|
||||
FnDef(FnDef),
|
||||
TypeAliasDef(TypeAliasDef),
|
||||
ConstDef(ConstDef),
|
||||
}
|
||||
impl From<FnDef> for ImplItem {
|
||||
fn from(n: FnDef) -> ImplItem { ImplItem { syntax: n.syntax } }
|
||||
fn from(node: FnDef) -> ImplItem {
|
||||
ImplItem { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<TypeAliasDef> for ImplItem {
|
||||
fn from(n: TypeAliasDef) -> ImplItem { ImplItem { syntax: n.syntax } }
|
||||
fn from(node: TypeAliasDef) -> ImplItem {
|
||||
ImplItem { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<ConstDef> for ImplItem {
|
||||
fn from(n: ConstDef) -> ImplItem { ImplItem { syntax: n.syntax } }
|
||||
fn from(node: ConstDef) -> ImplItem {
|
||||
ImplItem { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl ImplItem {
|
||||
pub fn kind(&self) -> ImplItemKind {
|
||||
match self.syntax.kind() {
|
||||
FN_DEF => ImplItemKind::FnDef(FnDef::cast(self.syntax.clone()).unwrap()),
|
||||
TYPE_ALIAS_DEF => ImplItemKind::TypeAliasDef(TypeAliasDef::cast(self.syntax.clone()).unwrap()),
|
||||
CONST_DEF => ImplItemKind::ConstDef(ConstDef::cast(self.syntax.clone()).unwrap()),
|
||||
let syntax = self.syntax.clone();
|
||||
match syntax.kind() {
|
||||
FN_DEF => ImplItemKind::FnDef(FnDef { syntax }),
|
||||
TYPE_ALIAS_DEF => ImplItemKind::TypeAliasDef(TypeAliasDef { syntax }),
|
||||
CONST_DEF => ImplItemKind::ConstDef(ConstDef { syntax }),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ImplItem {}
|
||||
|
||||
// ImplTraitType
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ImplTraitType {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for ImplTraitType {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -1151,21 +1232,22 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(ImplTraitType { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::TypeBoundsOwner for ImplTraitType {}
|
||||
impl ImplTraitType {}
|
||||
|
||||
// IndexExpr
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct IndexExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for IndexExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -1174,20 +1256,21 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(IndexExpr { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl IndexExpr {}
|
||||
|
||||
// ItemList
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ItemList {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for ItemList {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -1196,26 +1279,27 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(ItemList { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::FnDefOwner for ItemList {}
|
||||
impl ast::ModuleItemOwner for ItemList {}
|
||||
impl ItemList {
|
||||
pub fn impl_items(&self) -> impl Iterator<Item = ImplItem> {
|
||||
super::children(self)
|
||||
pub fn impl_items(&self) -> AstChildren<ImplItem> {
|
||||
AstChildren::new(&self.syntax)
|
||||
}
|
||||
}
|
||||
|
||||
// Label
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Label {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for Label {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -1224,20 +1308,21 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(Label { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl Label {}
|
||||
|
||||
// LambdaExpr
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct LambdaExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for LambdaExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -1246,28 +1331,28 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(LambdaExpr { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl LambdaExpr {
|
||||
pub fn param_list(&self) -> Option<ParamList> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
|
||||
pub fn body(&self) -> Option<Expr> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// LetStmt
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct LetStmt {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for LetStmt {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -1276,29 +1361,29 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(LetStmt { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::TypeAscriptionOwner for LetStmt {}
|
||||
impl LetStmt {
|
||||
pub fn pat(&self) -> Option<Pat> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
|
||||
pub fn initializer(&self) -> Option<Expr> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// LifetimeArg
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct LifetimeArg {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for LifetimeArg {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -1307,20 +1392,21 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(LifetimeArg { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl LifetimeArg {}
|
||||
|
||||
// LifetimeParam
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct LifetimeParam {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for LifetimeParam {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -1329,21 +1415,22 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(LifetimeParam { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::AttrsOwner for LifetimeParam {}
|
||||
impl LifetimeParam {}
|
||||
|
||||
// Literal
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Literal {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for Literal {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -1352,20 +1439,21 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(Literal { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl Literal {}
|
||||
|
||||
// LiteralPat
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct LiteralPat {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for LiteralPat {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -1374,24 +1462,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(LiteralPat { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl LiteralPat {
|
||||
pub fn literal(&self) -> Option<Literal> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// LoopExpr
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct LoopExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for LoopExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -1400,21 +1489,22 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(LoopExpr { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::LoopBodyOwner for LoopExpr {}
|
||||
impl LoopExpr {}
|
||||
|
||||
// MacroCall
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct MacroCall {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for MacroCall {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -1423,31 +1513,31 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(MacroCall { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::NameOwner for MacroCall {}
|
||||
impl ast::AttrsOwner for MacroCall {}
|
||||
impl ast::DocCommentsOwner for MacroCall {}
|
||||
impl MacroCall {
|
||||
pub fn token_tree(&self) -> Option<TokenTree> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
|
||||
pub fn path(&self) -> Option<Path> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// MacroItems
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct MacroItems {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for MacroItems {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -1456,22 +1546,23 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(MacroItems { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::ModuleItemOwner for MacroItems {}
|
||||
impl ast::FnDefOwner for MacroItems {}
|
||||
impl MacroItems {}
|
||||
|
||||
// MacroStmts
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct MacroStmts {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for MacroStmts {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -1480,28 +1571,28 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(MacroStmts { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl MacroStmts {
|
||||
pub fn statements(&self) -> impl Iterator<Item = Stmt> {
|
||||
super::children(self)
|
||||
pub fn statements(&self) -> AstChildren<Stmt> {
|
||||
AstChildren::new(&self.syntax)
|
||||
}
|
||||
|
||||
pub fn expr(&self) -> Option<Expr> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// MatchArm
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct MatchArm {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for MatchArm {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -1510,33 +1601,32 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(MatchArm { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::AttrsOwner for MatchArm {}
|
||||
impl MatchArm {
|
||||
pub fn pats(&self) -> impl Iterator<Item = Pat> {
|
||||
super::children(self)
|
||||
pub fn pats(&self) -> AstChildren<Pat> {
|
||||
AstChildren::new(&self.syntax)
|
||||
}
|
||||
|
||||
pub fn guard(&self) -> Option<MatchGuard> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
|
||||
pub fn expr(&self) -> Option<Expr> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// MatchArmList
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct MatchArmList {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for MatchArmList {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -1545,25 +1635,26 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(MatchArmList { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::AttrsOwner for MatchArmList {}
|
||||
impl MatchArmList {
|
||||
pub fn arms(&self) -> impl Iterator<Item = MatchArm> {
|
||||
super::children(self)
|
||||
pub fn arms(&self) -> AstChildren<MatchArm> {
|
||||
AstChildren::new(&self.syntax)
|
||||
}
|
||||
}
|
||||
|
||||
// MatchExpr
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct MatchExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for MatchExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -1572,28 +1663,28 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(MatchExpr { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl MatchExpr {
|
||||
pub fn expr(&self) -> Option<Expr> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
|
||||
pub fn match_arm_list(&self) -> Option<MatchArmList> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// MatchGuard
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct MatchGuard {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for MatchGuard {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -1602,24 +1693,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(MatchGuard { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl MatchGuard {
|
||||
pub fn expr(&self) -> Option<Expr> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// MethodCallExpr
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct MethodCallExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for MethodCallExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -1628,33 +1720,32 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(MethodCallExpr { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::ArgListOwner for MethodCallExpr {}
|
||||
impl MethodCallExpr {
|
||||
pub fn expr(&self) -> Option<Expr> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
|
||||
pub fn name_ref(&self) -> Option<NameRef> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
|
||||
pub fn type_arg_list(&self) -> Option<TypeArgList> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// Module
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Module {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for Module {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -1663,43 +1754,48 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(Module { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::VisibilityOwner for Module {}
|
||||
impl ast::NameOwner for Module {}
|
||||
impl ast::AttrsOwner for Module {}
|
||||
impl ast::DocCommentsOwner for Module {}
|
||||
impl Module {
|
||||
pub fn item_list(&self) -> Option<ItemList> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// ModuleItem
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ModuleItem {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for ModuleItem {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
| STRUCT_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_BLOCK | USE_ITEM | EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE => true,
|
||||
STRUCT_DEF | ENUM_DEF | FN_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | IMPL_BLOCK | USE_ITEM
|
||||
| EXTERN_CRATE_ITEM | CONST_DEF | STATIC_DEF | MODULE => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(ModuleItem { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum ModuleItemKind {
|
||||
StructDef(StructDef),
|
||||
EnumDef(EnumDef),
|
||||
@@ -1714,65 +1810,84 @@ pub enum ModuleItemKind {
|
||||
Module(Module),
|
||||
}
|
||||
impl From<StructDef> for ModuleItem {
|
||||
fn from(n: StructDef) -> ModuleItem { ModuleItem { syntax: n.syntax } }
|
||||
fn from(node: StructDef) -> ModuleItem {
|
||||
ModuleItem { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<EnumDef> for ModuleItem {
|
||||
fn from(n: EnumDef) -> ModuleItem { ModuleItem { syntax: n.syntax } }
|
||||
fn from(node: EnumDef) -> ModuleItem {
|
||||
ModuleItem { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<FnDef> for ModuleItem {
|
||||
fn from(n: FnDef) -> ModuleItem { ModuleItem { syntax: n.syntax } }
|
||||
fn from(node: FnDef) -> ModuleItem {
|
||||
ModuleItem { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<TraitDef> for ModuleItem {
|
||||
fn from(n: TraitDef) -> ModuleItem { ModuleItem { syntax: n.syntax } }
|
||||
fn from(node: TraitDef) -> ModuleItem {
|
||||
ModuleItem { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<TypeAliasDef> for ModuleItem {
|
||||
fn from(n: TypeAliasDef) -> ModuleItem { ModuleItem { syntax: n.syntax } }
|
||||
fn from(node: TypeAliasDef) -> ModuleItem {
|
||||
ModuleItem { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<ImplBlock> for ModuleItem {
|
||||
fn from(n: ImplBlock) -> ModuleItem { ModuleItem { syntax: n.syntax } }
|
||||
fn from(node: ImplBlock) -> ModuleItem {
|
||||
ModuleItem { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<UseItem> for ModuleItem {
|
||||
fn from(n: UseItem) -> ModuleItem { ModuleItem { syntax: n.syntax } }
|
||||
fn from(node: UseItem) -> ModuleItem {
|
||||
ModuleItem { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<ExternCrateItem> for ModuleItem {
|
||||
fn from(n: ExternCrateItem) -> ModuleItem { ModuleItem { syntax: n.syntax } }
|
||||
fn from(node: ExternCrateItem) -> ModuleItem {
|
||||
ModuleItem { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<ConstDef> for ModuleItem {
|
||||
fn from(n: ConstDef) -> ModuleItem { ModuleItem { syntax: n.syntax } }
|
||||
fn from(node: ConstDef) -> ModuleItem {
|
||||
ModuleItem { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<StaticDef> for ModuleItem {
|
||||
fn from(n: StaticDef) -> ModuleItem { ModuleItem { syntax: n.syntax } }
|
||||
fn from(node: StaticDef) -> ModuleItem {
|
||||
ModuleItem { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<Module> for ModuleItem {
|
||||
fn from(n: Module) -> ModuleItem { ModuleItem { syntax: n.syntax } }
|
||||
fn from(node: Module) -> ModuleItem {
|
||||
ModuleItem { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl ModuleItem {
|
||||
pub fn kind(&self) -> ModuleItemKind {
|
||||
match self.syntax.kind() {
|
||||
STRUCT_DEF => ModuleItemKind::StructDef(StructDef::cast(self.syntax.clone()).unwrap()),
|
||||
ENUM_DEF => ModuleItemKind::EnumDef(EnumDef::cast(self.syntax.clone()).unwrap()),
|
||||
FN_DEF => ModuleItemKind::FnDef(FnDef::cast(self.syntax.clone()).unwrap()),
|
||||
TRAIT_DEF => ModuleItemKind::TraitDef(TraitDef::cast(self.syntax.clone()).unwrap()),
|
||||
TYPE_ALIAS_DEF => ModuleItemKind::TypeAliasDef(TypeAliasDef::cast(self.syntax.clone()).unwrap()),
|
||||
IMPL_BLOCK => ModuleItemKind::ImplBlock(ImplBlock::cast(self.syntax.clone()).unwrap()),
|
||||
USE_ITEM => ModuleItemKind::UseItem(UseItem::cast(self.syntax.clone()).unwrap()),
|
||||
EXTERN_CRATE_ITEM => ModuleItemKind::ExternCrateItem(ExternCrateItem::cast(self.syntax.clone()).unwrap()),
|
||||
CONST_DEF => ModuleItemKind::ConstDef(ConstDef::cast(self.syntax.clone()).unwrap()),
|
||||
STATIC_DEF => ModuleItemKind::StaticDef(StaticDef::cast(self.syntax.clone()).unwrap()),
|
||||
MODULE => ModuleItemKind::Module(Module::cast(self.syntax.clone()).unwrap()),
|
||||
let syntax = self.syntax.clone();
|
||||
match syntax.kind() {
|
||||
STRUCT_DEF => ModuleItemKind::StructDef(StructDef { syntax }),
|
||||
ENUM_DEF => ModuleItemKind::EnumDef(EnumDef { syntax }),
|
||||
FN_DEF => ModuleItemKind::FnDef(FnDef { syntax }),
|
||||
TRAIT_DEF => ModuleItemKind::TraitDef(TraitDef { syntax }),
|
||||
TYPE_ALIAS_DEF => ModuleItemKind::TypeAliasDef(TypeAliasDef { syntax }),
|
||||
IMPL_BLOCK => ModuleItemKind::ImplBlock(ImplBlock { syntax }),
|
||||
USE_ITEM => ModuleItemKind::UseItem(UseItem { syntax }),
|
||||
EXTERN_CRATE_ITEM => ModuleItemKind::ExternCrateItem(ExternCrateItem { syntax }),
|
||||
CONST_DEF => ModuleItemKind::ConstDef(ConstDef { syntax }),
|
||||
STATIC_DEF => ModuleItemKind::StaticDef(StaticDef { syntax }),
|
||||
MODULE => ModuleItemKind::Module(Module { syntax }),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ModuleItem {}
|
||||
|
||||
// Name
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Name {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for Name {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -1781,20 +1896,21 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(Name { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl Name {}
|
||||
|
||||
// NameRef
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct NameRef {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for NameRef {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -1803,20 +1919,21 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(NameRef { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl NameRef {}
|
||||
|
||||
// NamedField
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct NamedField {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for NamedField {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -1825,28 +1942,28 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(NamedField { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl NamedField {
|
||||
pub fn name_ref(&self) -> Option<NameRef> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
|
||||
pub fn expr(&self) -> Option<Expr> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// NamedFieldDef
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct NamedFieldDef {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for NamedFieldDef {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -1855,25 +1972,26 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(NamedFieldDef { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::VisibilityOwner for NamedFieldDef {}
|
||||
impl ast::NameOwner for NamedFieldDef {}
|
||||
impl ast::AttrsOwner for NamedFieldDef {}
|
||||
impl ast::DocCommentsOwner for NamedFieldDef {}
|
||||
impl ast::TypeAscriptionOwner for NamedFieldDef {}
|
||||
impl NamedFieldDef {}
|
||||
|
||||
// NamedFieldDefList
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct NamedFieldDefList {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for NamedFieldDefList {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -1882,24 +2000,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(NamedFieldDefList { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl NamedFieldDefList {
|
||||
pub fn fields(&self) -> impl Iterator<Item = NamedFieldDef> {
|
||||
super::children(self)
|
||||
pub fn fields(&self) -> AstChildren<NamedFieldDef> {
|
||||
AstChildren::new(&self.syntax)
|
||||
}
|
||||
}
|
||||
|
||||
// NamedFieldList
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct NamedFieldList {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for NamedFieldList {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -1908,28 +2027,28 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(NamedFieldList { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl NamedFieldList {
|
||||
pub fn fields(&self) -> impl Iterator<Item = NamedField> {
|
||||
super::children(self)
|
||||
pub fn fields(&self) -> AstChildren<NamedField> {
|
||||
AstChildren::new(&self.syntax)
|
||||
}
|
||||
|
||||
pub fn spread(&self) -> Option<Expr> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// NeverType
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct NeverType {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for NeverType {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -1938,66 +2057,71 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(NeverType { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl NeverType {}
|
||||
|
||||
// NominalDef
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct NominalDef {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for NominalDef {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
| STRUCT_DEF | ENUM_DEF => true,
|
||||
STRUCT_DEF | ENUM_DEF => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(NominalDef { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum NominalDefKind {
|
||||
StructDef(StructDef),
|
||||
EnumDef(EnumDef),
|
||||
}
|
||||
impl From<StructDef> for NominalDef {
|
||||
fn from(n: StructDef) -> NominalDef { NominalDef { syntax: n.syntax } }
|
||||
fn from(node: StructDef) -> NominalDef {
|
||||
NominalDef { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<EnumDef> for NominalDef {
|
||||
fn from(n: EnumDef) -> NominalDef { NominalDef { syntax: n.syntax } }
|
||||
fn from(node: EnumDef) -> NominalDef {
|
||||
NominalDef { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl NominalDef {
|
||||
pub fn kind(&self) -> NominalDefKind {
|
||||
match self.syntax.kind() {
|
||||
STRUCT_DEF => NominalDefKind::StructDef(StructDef::cast(self.syntax.clone()).unwrap()),
|
||||
ENUM_DEF => NominalDefKind::EnumDef(EnumDef::cast(self.syntax.clone()).unwrap()),
|
||||
let syntax = self.syntax.clone();
|
||||
match syntax.kind() {
|
||||
STRUCT_DEF => NominalDefKind::StructDef(StructDef { syntax }),
|
||||
ENUM_DEF => NominalDefKind::EnumDef(EnumDef { syntax }),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::NameOwner for NominalDef {}
|
||||
impl ast::TypeParamsOwner for NominalDef {}
|
||||
impl ast::AttrsOwner for NominalDef {}
|
||||
impl NominalDef {}
|
||||
|
||||
// Param
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Param {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for Param {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2006,26 +2130,27 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(Param { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::TypeAscriptionOwner for Param {}
|
||||
impl ast::AttrsOwner for Param {}
|
||||
impl Param {
|
||||
pub fn pat(&self) -> Option<Pat> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// ParamList
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ParamList {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for ParamList {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2034,28 +2159,28 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(ParamList { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ParamList {
|
||||
pub fn params(&self) -> impl Iterator<Item = Param> {
|
||||
super::children(self)
|
||||
pub fn params(&self) -> AstChildren<Param> {
|
||||
AstChildren::new(&self.syntax)
|
||||
}
|
||||
|
||||
pub fn self_param(&self) -> Option<SelfParam> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// ParenExpr
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ParenExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for ParenExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2064,24 +2189,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(ParenExpr { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ParenExpr {
|
||||
pub fn expr(&self) -> Option<Expr> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// ParenType
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ParenType {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for ParenType {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2090,39 +2216,44 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(ParenType { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ParenType {
|
||||
pub fn type_ref(&self) -> Option<TypeRef> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// Pat
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Pat {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for Pat {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
| REF_PAT | BIND_PAT | PLACEHOLDER_PAT | PATH_PAT | STRUCT_PAT | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => true,
|
||||
REF_PAT | BIND_PAT | PLACEHOLDER_PAT | PATH_PAT | STRUCT_PAT | TUPLE_STRUCT_PAT
|
||||
| TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(Pat { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum PatKind {
|
||||
RefPat(RefPat),
|
||||
BindPat(BindPat),
|
||||
@@ -2136,61 +2267,78 @@ pub enum PatKind {
|
||||
LiteralPat(LiteralPat),
|
||||
}
|
||||
impl From<RefPat> for Pat {
|
||||
fn from(n: RefPat) -> Pat { Pat { syntax: n.syntax } }
|
||||
fn from(node: RefPat) -> Pat {
|
||||
Pat { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<BindPat> for Pat {
|
||||
fn from(n: BindPat) -> Pat { Pat { syntax: n.syntax } }
|
||||
fn from(node: BindPat) -> Pat {
|
||||
Pat { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<PlaceholderPat> for Pat {
|
||||
fn from(n: PlaceholderPat) -> Pat { Pat { syntax: n.syntax } }
|
||||
fn from(node: PlaceholderPat) -> Pat {
|
||||
Pat { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<PathPat> for Pat {
|
||||
fn from(n: PathPat) -> Pat { Pat { syntax: n.syntax } }
|
||||
fn from(node: PathPat) -> Pat {
|
||||
Pat { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<StructPat> for Pat {
|
||||
fn from(n: StructPat) -> Pat { Pat { syntax: n.syntax } }
|
||||
fn from(node: StructPat) -> Pat {
|
||||
Pat { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<TupleStructPat> for Pat {
|
||||
fn from(n: TupleStructPat) -> Pat { Pat { syntax: n.syntax } }
|
||||
fn from(node: TupleStructPat) -> Pat {
|
||||
Pat { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<TuplePat> for Pat {
|
||||
fn from(n: TuplePat) -> Pat { Pat { syntax: n.syntax } }
|
||||
fn from(node: TuplePat) -> Pat {
|
||||
Pat { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<SlicePat> for Pat {
|
||||
fn from(n: SlicePat) -> Pat { Pat { syntax: n.syntax } }
|
||||
fn from(node: SlicePat) -> Pat {
|
||||
Pat { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<RangePat> for Pat {
|
||||
fn from(n: RangePat) -> Pat { Pat { syntax: n.syntax } }
|
||||
fn from(node: RangePat) -> Pat {
|
||||
Pat { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<LiteralPat> for Pat {
|
||||
fn from(n: LiteralPat) -> Pat { Pat { syntax: n.syntax } }
|
||||
fn from(node: LiteralPat) -> Pat {
|
||||
Pat { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl Pat {
|
||||
pub fn kind(&self) -> PatKind {
|
||||
match self.syntax.kind() {
|
||||
REF_PAT => PatKind::RefPat(RefPat::cast(self.syntax.clone()).unwrap()),
|
||||
BIND_PAT => PatKind::BindPat(BindPat::cast(self.syntax.clone()).unwrap()),
|
||||
PLACEHOLDER_PAT => PatKind::PlaceholderPat(PlaceholderPat::cast(self.syntax.clone()).unwrap()),
|
||||
PATH_PAT => PatKind::PathPat(PathPat::cast(self.syntax.clone()).unwrap()),
|
||||
STRUCT_PAT => PatKind::StructPat(StructPat::cast(self.syntax.clone()).unwrap()),
|
||||
TUPLE_STRUCT_PAT => PatKind::TupleStructPat(TupleStructPat::cast(self.syntax.clone()).unwrap()),
|
||||
TUPLE_PAT => PatKind::TuplePat(TuplePat::cast(self.syntax.clone()).unwrap()),
|
||||
SLICE_PAT => PatKind::SlicePat(SlicePat::cast(self.syntax.clone()).unwrap()),
|
||||
RANGE_PAT => PatKind::RangePat(RangePat::cast(self.syntax.clone()).unwrap()),
|
||||
LITERAL_PAT => PatKind::LiteralPat(LiteralPat::cast(self.syntax.clone()).unwrap()),
|
||||
let syntax = self.syntax.clone();
|
||||
match syntax.kind() {
|
||||
REF_PAT => PatKind::RefPat(RefPat { syntax }),
|
||||
BIND_PAT => PatKind::BindPat(BindPat { syntax }),
|
||||
PLACEHOLDER_PAT => PatKind::PlaceholderPat(PlaceholderPat { syntax }),
|
||||
PATH_PAT => PatKind::PathPat(PathPat { syntax }),
|
||||
STRUCT_PAT => PatKind::StructPat(StructPat { syntax }),
|
||||
TUPLE_STRUCT_PAT => PatKind::TupleStructPat(TupleStructPat { syntax }),
|
||||
TUPLE_PAT => PatKind::TuplePat(TuplePat { syntax }),
|
||||
SLICE_PAT => PatKind::SlicePat(SlicePat { syntax }),
|
||||
RANGE_PAT => PatKind::RangePat(RangePat { syntax }),
|
||||
LITERAL_PAT => PatKind::LiteralPat(LiteralPat { syntax }),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Pat {}
|
||||
|
||||
// Path
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Path {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for Path {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2199,28 +2347,28 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(Path { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl Path {
|
||||
pub fn segment(&self) -> Option<PathSegment> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
|
||||
pub fn qualifier(&self) -> Option<Path> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// PathExpr
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct PathExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for PathExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2229,24 +2377,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(PathExpr { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl PathExpr {
|
||||
pub fn path(&self) -> Option<Path> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// PathPat
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct PathPat {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for PathPat {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2255,24 +2404,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(PathPat { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl PathPat {
|
||||
pub fn path(&self) -> Option<Path> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// PathSegment
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct PathSegment {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for PathSegment {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2281,28 +2431,28 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(PathSegment { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl PathSegment {
|
||||
pub fn name_ref(&self) -> Option<NameRef> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
|
||||
pub fn type_arg_list(&self) -> Option<TypeArgList> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// PathType
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct PathType {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for PathType {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2311,24 +2461,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(PathType { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl PathType {
|
||||
pub fn path(&self) -> Option<Path> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// PlaceholderPat
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct PlaceholderPat {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for PlaceholderPat {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2337,20 +2488,21 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(PlaceholderPat { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl PlaceholderPat {}
|
||||
|
||||
// PlaceholderType
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct PlaceholderType {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for PlaceholderType {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2359,20 +2511,21 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(PlaceholderType { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl PlaceholderType {}
|
||||
|
||||
// PointerType
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct PointerType {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for PointerType {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2381,24 +2534,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(PointerType { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl PointerType {
|
||||
pub fn type_ref(&self) -> Option<TypeRef> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// PosFieldDef
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct PosFieldDef {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for PosFieldDef {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2407,26 +2561,27 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(PosFieldDef { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::VisibilityOwner for PosFieldDef {}
|
||||
impl ast::AttrsOwner for PosFieldDef {}
|
||||
impl PosFieldDef {
|
||||
pub fn type_ref(&self) -> Option<TypeRef> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// PosFieldDefList
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct PosFieldDefList {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for PosFieldDefList {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2435,24 +2590,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(PosFieldDefList { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl PosFieldDefList {
|
||||
pub fn fields(&self) -> impl Iterator<Item = PosFieldDef> {
|
||||
super::children(self)
|
||||
pub fn fields(&self) -> AstChildren<PosFieldDef> {
|
||||
AstChildren::new(&self.syntax)
|
||||
}
|
||||
}
|
||||
|
||||
// PrefixExpr
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct PrefixExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for PrefixExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2461,24 +2617,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(PrefixExpr { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl PrefixExpr {
|
||||
pub fn expr(&self) -> Option<Expr> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// RangeExpr
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct RangeExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for RangeExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2487,20 +2644,21 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(RangeExpr { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl RangeExpr {}
|
||||
|
||||
// RangePat
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct RangePat {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for RangePat {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2509,20 +2667,21 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(RangePat { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl RangePat {}
|
||||
|
||||
// RefExpr
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct RefExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for RefExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2531,24 +2690,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(RefExpr { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl RefExpr {
|
||||
pub fn expr(&self) -> Option<Expr> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// RefPat
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct RefPat {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for RefPat {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2557,24 +2717,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(RefPat { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl RefPat {
|
||||
pub fn pat(&self) -> Option<Pat> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// ReferenceType
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ReferenceType {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for ReferenceType {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2583,24 +2744,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(ReferenceType { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ReferenceType {
|
||||
pub fn type_ref(&self) -> Option<TypeRef> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// RetType
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct RetType {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for RetType {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2609,24 +2771,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(RetType { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl RetType {
|
||||
pub fn type_ref(&self) -> Option<TypeRef> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// ReturnExpr
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ReturnExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for ReturnExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2635,24 +2798,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(ReturnExpr { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ReturnExpr {
|
||||
pub fn expr(&self) -> Option<Expr> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// SelfParam
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct SelfParam {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for SelfParam {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2661,22 +2825,23 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(SelfParam { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::TypeAscriptionOwner for SelfParam {}
|
||||
impl ast::AttrsOwner for SelfParam {}
|
||||
impl SelfParam {}
|
||||
|
||||
// SlicePat
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct SlicePat {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for SlicePat {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2685,20 +2850,21 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(SlicePat { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl SlicePat {}
|
||||
|
||||
// SliceType
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct SliceType {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for SliceType {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2707,24 +2873,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(SliceType { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl SliceType {
|
||||
pub fn type_ref(&self) -> Option<TypeRef> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// SourceFile
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct SourceFile {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for SourceFile {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2733,26 +2900,27 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(SourceFile { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::ModuleItemOwner for SourceFile {}
|
||||
impl ast::FnDefOwner for SourceFile {}
|
||||
impl SourceFile {
|
||||
pub fn modules(&self) -> impl Iterator<Item = Module> {
|
||||
super::children(self)
|
||||
pub fn modules(&self) -> AstChildren<Module> {
|
||||
AstChildren::new(&self.syntax)
|
||||
}
|
||||
}
|
||||
|
||||
// StaticDef
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct StaticDef {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for StaticDef {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2761,12 +2929,16 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(StaticDef { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::VisibilityOwner for StaticDef {}
|
||||
impl ast::NameOwner for StaticDef {}
|
||||
impl ast::TypeParamsOwner for StaticDef {}
|
||||
@@ -2775,59 +2947,60 @@ impl ast::DocCommentsOwner for StaticDef {}
|
||||
impl ast::TypeAscriptionOwner for StaticDef {}
|
||||
impl StaticDef {
|
||||
pub fn body(&self) -> Option<Expr> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// Stmt
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Stmt {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for Stmt {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
| EXPR_STMT | LET_STMT => true,
|
||||
EXPR_STMT | LET_STMT => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(Stmt { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum StmtKind {
|
||||
ExprStmt(ExprStmt),
|
||||
LetStmt(LetStmt),
|
||||
}
|
||||
impl From<ExprStmt> for Stmt {
|
||||
fn from(n: ExprStmt) -> Stmt { Stmt { syntax: n.syntax } }
|
||||
fn from(node: ExprStmt) -> Stmt {
|
||||
Stmt { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<LetStmt> for Stmt {
|
||||
fn from(n: LetStmt) -> Stmt { Stmt { syntax: n.syntax } }
|
||||
fn from(node: LetStmt) -> Stmt {
|
||||
Stmt { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl Stmt {
|
||||
pub fn kind(&self) -> StmtKind {
|
||||
match self.syntax.kind() {
|
||||
EXPR_STMT => StmtKind::ExprStmt(ExprStmt::cast(self.syntax.clone()).unwrap()),
|
||||
LET_STMT => StmtKind::LetStmt(LetStmt::cast(self.syntax.clone()).unwrap()),
|
||||
let syntax = self.syntax.clone();
|
||||
match syntax.kind() {
|
||||
EXPR_STMT => StmtKind::ExprStmt(ExprStmt { syntax }),
|
||||
LET_STMT => StmtKind::LetStmt(LetStmt { syntax }),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Stmt {}
|
||||
|
||||
// StructDef
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct StructDef {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for StructDef {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2836,25 +3009,26 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(StructDef { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::VisibilityOwner for StructDef {}
|
||||
impl ast::NameOwner for StructDef {}
|
||||
impl ast::TypeParamsOwner for StructDef {}
|
||||
impl ast::AttrsOwner for StructDef {}
|
||||
impl ast::DocCommentsOwner for StructDef {}
|
||||
impl StructDef {}
|
||||
|
||||
// StructLit
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct StructLit {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for StructLit {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2863,28 +3037,28 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(StructLit { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl StructLit {
|
||||
pub fn path(&self) -> Option<Path> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
|
||||
pub fn named_field_list(&self) -> Option<NamedFieldList> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// StructPat
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct StructPat {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for StructPat {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2893,28 +3067,28 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(StructPat { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl StructPat {
|
||||
pub fn field_pat_list(&self) -> Option<FieldPatList> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
|
||||
pub fn path(&self) -> Option<Path> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// TokenTree
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct TokenTree {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for TokenTree {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2923,20 +3097,21 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(TokenTree { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl TokenTree {}
|
||||
|
||||
// TraitDef
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct TraitDef {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for TraitDef {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2945,12 +3120,16 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(TraitDef { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::VisibilityOwner for TraitDef {}
|
||||
impl ast::NameOwner for TraitDef {}
|
||||
impl ast::AttrsOwner for TraitDef {}
|
||||
@@ -2959,16 +3138,13 @@ impl ast::TypeParamsOwner for TraitDef {}
|
||||
impl ast::TypeBoundsOwner for TraitDef {}
|
||||
impl TraitDef {
|
||||
pub fn item_list(&self) -> Option<ItemList> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// TryBlockExpr
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct TryBlockExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for TryBlockExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -2977,21 +3153,22 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(TryBlockExpr { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::TryBlockBodyOwner for TryBlockExpr {}
|
||||
impl TryBlockExpr {}
|
||||
|
||||
// TryExpr
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct TryExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for TryExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -3000,24 +3177,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(TryExpr { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl TryExpr {
|
||||
pub fn expr(&self) -> Option<Expr> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// TupleExpr
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct TupleExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for TupleExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -3026,24 +3204,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(TupleExpr { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl TupleExpr {
|
||||
pub fn exprs(&self) -> impl Iterator<Item = Expr> {
|
||||
super::children(self)
|
||||
pub fn exprs(&self) -> AstChildren<Expr> {
|
||||
AstChildren::new(&self.syntax)
|
||||
}
|
||||
}
|
||||
|
||||
// TuplePat
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct TuplePat {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for TuplePat {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -3052,24 +3231,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(TuplePat { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl TuplePat {
|
||||
pub fn args(&self) -> impl Iterator<Item = Pat> {
|
||||
super::children(self)
|
||||
pub fn args(&self) -> AstChildren<Pat> {
|
||||
AstChildren::new(&self.syntax)
|
||||
}
|
||||
}
|
||||
|
||||
// TupleStructPat
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct TupleStructPat {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for TupleStructPat {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -3078,28 +3258,28 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(TupleStructPat { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl TupleStructPat {
|
||||
pub fn args(&self) -> impl Iterator<Item = Pat> {
|
||||
super::children(self)
|
||||
pub fn args(&self) -> AstChildren<Pat> {
|
||||
AstChildren::new(&self.syntax)
|
||||
}
|
||||
|
||||
pub fn path(&self) -> Option<Path> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// TupleType
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct TupleType {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for TupleType {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -3108,24 +3288,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(TupleType { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl TupleType {
|
||||
pub fn fields(&self) -> impl Iterator<Item = TypeRef> {
|
||||
super::children(self)
|
||||
pub fn fields(&self) -> AstChildren<TypeRef> {
|
||||
AstChildren::new(&self.syntax)
|
||||
}
|
||||
}
|
||||
|
||||
// TypeAliasDef
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct TypeAliasDef {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for TypeAliasDef {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -3134,12 +3315,16 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(TypeAliasDef { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::VisibilityOwner for TypeAliasDef {}
|
||||
impl ast::NameOwner for TypeAliasDef {}
|
||||
impl ast::TypeParamsOwner for TypeAliasDef {}
|
||||
@@ -3148,16 +3333,13 @@ impl ast::DocCommentsOwner for TypeAliasDef {}
|
||||
impl ast::TypeBoundsOwner for TypeAliasDef {}
|
||||
impl TypeAliasDef {
|
||||
pub fn type_ref(&self) -> Option<TypeRef> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// TypeArg
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct TypeArg {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for TypeArg {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -3166,24 +3348,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(TypeArg { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl TypeArg {
|
||||
pub fn type_ref(&self) -> Option<TypeRef> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// TypeArgList
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct TypeArgList {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for TypeArgList {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -3192,32 +3375,31 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(TypeArgList { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl TypeArgList {
|
||||
pub fn type_args(&self) -> impl Iterator<Item = TypeArg> {
|
||||
super::children(self)
|
||||
pub fn type_args(&self) -> AstChildren<TypeArg> {
|
||||
AstChildren::new(&self.syntax)
|
||||
}
|
||||
|
||||
pub fn lifetime_args(&self) -> impl Iterator<Item = LifetimeArg> {
|
||||
super::children(self)
|
||||
pub fn lifetime_args(&self) -> AstChildren<LifetimeArg> {
|
||||
AstChildren::new(&self.syntax)
|
||||
}
|
||||
|
||||
pub fn assoc_type_args(&self) -> impl Iterator<Item = AssocTypeArg> {
|
||||
super::children(self)
|
||||
pub fn assoc_type_args(&self) -> AstChildren<AssocTypeArg> {
|
||||
AstChildren::new(&self.syntax)
|
||||
}
|
||||
}
|
||||
|
||||
// TypeBound
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct TypeBound {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for TypeBound {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -3226,24 +3408,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(TypeBound { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl TypeBound {
|
||||
pub fn type_ref(&self) -> Option<TypeRef> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// TypeBoundList
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct TypeBoundList {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for TypeBoundList {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -3252,24 +3435,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(TypeBoundList { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl TypeBoundList {
|
||||
pub fn bounds(&self) -> impl Iterator<Item = TypeBound> {
|
||||
super::children(self)
|
||||
pub fn bounds(&self) -> AstChildren<TypeBound> {
|
||||
AstChildren::new(&self.syntax)
|
||||
}
|
||||
}
|
||||
|
||||
// TypeParam
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct TypeParam {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for TypeParam {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -3278,24 +3462,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(TypeParam { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::NameOwner for TypeParam {}
|
||||
impl ast::AttrsOwner for TypeParam {}
|
||||
impl ast::TypeBoundsOwner for TypeParam {}
|
||||
impl ast::DefaultTypeParamOwner for TypeParam {}
|
||||
impl TypeParam {}
|
||||
|
||||
// TypeParamList
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct TypeParamList {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for TypeParamList {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -3304,43 +3489,48 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(TypeParamList { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl TypeParamList {
|
||||
pub fn type_params(&self) -> impl Iterator<Item = TypeParam> {
|
||||
super::children(self)
|
||||
pub fn type_params(&self) -> AstChildren<TypeParam> {
|
||||
AstChildren::new(&self.syntax)
|
||||
}
|
||||
|
||||
pub fn lifetime_params(&self) -> impl Iterator<Item = LifetimeParam> {
|
||||
super::children(self)
|
||||
pub fn lifetime_params(&self) -> AstChildren<LifetimeParam> {
|
||||
AstChildren::new(&self.syntax)
|
||||
}
|
||||
}
|
||||
|
||||
// TypeRef
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct TypeRef {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for TypeRef {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
| PAREN_TYPE | TUPLE_TYPE | NEVER_TYPE | PATH_TYPE | POINTER_TYPE | ARRAY_TYPE | SLICE_TYPE | REFERENCE_TYPE | PLACEHOLDER_TYPE | FN_POINTER_TYPE | FOR_TYPE | IMPL_TRAIT_TYPE | DYN_TRAIT_TYPE => true,
|
||||
PAREN_TYPE | TUPLE_TYPE | NEVER_TYPE | PATH_TYPE | POINTER_TYPE | ARRAY_TYPE
|
||||
| SLICE_TYPE | REFERENCE_TYPE | PLACEHOLDER_TYPE | FN_POINTER_TYPE | FOR_TYPE
|
||||
| IMPL_TRAIT_TYPE | DYN_TRAIT_TYPE => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(TypeRef { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum TypeRefKind {
|
||||
ParenType(ParenType),
|
||||
TupleType(TupleType),
|
||||
@@ -3357,73 +3547,96 @@ pub enum TypeRefKind {
|
||||
DynTraitType(DynTraitType),
|
||||
}
|
||||
impl From<ParenType> for TypeRef {
|
||||
fn from(n: ParenType) -> TypeRef { TypeRef { syntax: n.syntax } }
|
||||
fn from(node: ParenType) -> TypeRef {
|
||||
TypeRef { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<TupleType> for TypeRef {
|
||||
fn from(n: TupleType) -> TypeRef { TypeRef { syntax: n.syntax } }
|
||||
fn from(node: TupleType) -> TypeRef {
|
||||
TypeRef { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<NeverType> for TypeRef {
|
||||
fn from(n: NeverType) -> TypeRef { TypeRef { syntax: n.syntax } }
|
||||
fn from(node: NeverType) -> TypeRef {
|
||||
TypeRef { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<PathType> for TypeRef {
|
||||
fn from(n: PathType) -> TypeRef { TypeRef { syntax: n.syntax } }
|
||||
fn from(node: PathType) -> TypeRef {
|
||||
TypeRef { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<PointerType> for TypeRef {
|
||||
fn from(n: PointerType) -> TypeRef { TypeRef { syntax: n.syntax } }
|
||||
fn from(node: PointerType) -> TypeRef {
|
||||
TypeRef { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<ArrayType> for TypeRef {
|
||||
fn from(n: ArrayType) -> TypeRef { TypeRef { syntax: n.syntax } }
|
||||
fn from(node: ArrayType) -> TypeRef {
|
||||
TypeRef { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<SliceType> for TypeRef {
|
||||
fn from(n: SliceType) -> TypeRef { TypeRef { syntax: n.syntax } }
|
||||
fn from(node: SliceType) -> TypeRef {
|
||||
TypeRef { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<ReferenceType> for TypeRef {
|
||||
fn from(n: ReferenceType) -> TypeRef { TypeRef { syntax: n.syntax } }
|
||||
fn from(node: ReferenceType) -> TypeRef {
|
||||
TypeRef { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<PlaceholderType> for TypeRef {
|
||||
fn from(n: PlaceholderType) -> TypeRef { TypeRef { syntax: n.syntax } }
|
||||
fn from(node: PlaceholderType) -> TypeRef {
|
||||
TypeRef { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<FnPointerType> for TypeRef {
|
||||
fn from(n: FnPointerType) -> TypeRef { TypeRef { syntax: n.syntax } }
|
||||
fn from(node: FnPointerType) -> TypeRef {
|
||||
TypeRef { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<ForType> for TypeRef {
|
||||
fn from(n: ForType) -> TypeRef { TypeRef { syntax: n.syntax } }
|
||||
fn from(node: ForType) -> TypeRef {
|
||||
TypeRef { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<ImplTraitType> for TypeRef {
|
||||
fn from(n: ImplTraitType) -> TypeRef { TypeRef { syntax: n.syntax } }
|
||||
fn from(node: ImplTraitType) -> TypeRef {
|
||||
TypeRef { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl From<DynTraitType> for TypeRef {
|
||||
fn from(n: DynTraitType) -> TypeRef { TypeRef { syntax: n.syntax } }
|
||||
fn from(node: DynTraitType) -> TypeRef {
|
||||
TypeRef { syntax: node.syntax }
|
||||
}
|
||||
}
|
||||
impl TypeRef {
|
||||
pub fn kind(&self) -> TypeRefKind {
|
||||
match self.syntax.kind() {
|
||||
PAREN_TYPE => TypeRefKind::ParenType(ParenType::cast(self.syntax.clone()).unwrap()),
|
||||
TUPLE_TYPE => TypeRefKind::TupleType(TupleType::cast(self.syntax.clone()).unwrap()),
|
||||
NEVER_TYPE => TypeRefKind::NeverType(NeverType::cast(self.syntax.clone()).unwrap()),
|
||||
PATH_TYPE => TypeRefKind::PathType(PathType::cast(self.syntax.clone()).unwrap()),
|
||||
POINTER_TYPE => TypeRefKind::PointerType(PointerType::cast(self.syntax.clone()).unwrap()),
|
||||
ARRAY_TYPE => TypeRefKind::ArrayType(ArrayType::cast(self.syntax.clone()).unwrap()),
|
||||
SLICE_TYPE => TypeRefKind::SliceType(SliceType::cast(self.syntax.clone()).unwrap()),
|
||||
REFERENCE_TYPE => TypeRefKind::ReferenceType(ReferenceType::cast(self.syntax.clone()).unwrap()),
|
||||
PLACEHOLDER_TYPE => TypeRefKind::PlaceholderType(PlaceholderType::cast(self.syntax.clone()).unwrap()),
|
||||
FN_POINTER_TYPE => TypeRefKind::FnPointerType(FnPointerType::cast(self.syntax.clone()).unwrap()),
|
||||
FOR_TYPE => TypeRefKind::ForType(ForType::cast(self.syntax.clone()).unwrap()),
|
||||
IMPL_TRAIT_TYPE => TypeRefKind::ImplTraitType(ImplTraitType::cast(self.syntax.clone()).unwrap()),
|
||||
DYN_TRAIT_TYPE => TypeRefKind::DynTraitType(DynTraitType::cast(self.syntax.clone()).unwrap()),
|
||||
let syntax = self.syntax.clone();
|
||||
match syntax.kind() {
|
||||
PAREN_TYPE => TypeRefKind::ParenType(ParenType { syntax }),
|
||||
TUPLE_TYPE => TypeRefKind::TupleType(TupleType { syntax }),
|
||||
NEVER_TYPE => TypeRefKind::NeverType(NeverType { syntax }),
|
||||
PATH_TYPE => TypeRefKind::PathType(PathType { syntax }),
|
||||
POINTER_TYPE => TypeRefKind::PointerType(PointerType { syntax }),
|
||||
ARRAY_TYPE => TypeRefKind::ArrayType(ArrayType { syntax }),
|
||||
SLICE_TYPE => TypeRefKind::SliceType(SliceType { syntax }),
|
||||
REFERENCE_TYPE => TypeRefKind::ReferenceType(ReferenceType { syntax }),
|
||||
PLACEHOLDER_TYPE => TypeRefKind::PlaceholderType(PlaceholderType { syntax }),
|
||||
FN_POINTER_TYPE => TypeRefKind::FnPointerType(FnPointerType { syntax }),
|
||||
FOR_TYPE => TypeRefKind::ForType(ForType { syntax }),
|
||||
IMPL_TRAIT_TYPE => TypeRefKind::ImplTraitType(ImplTraitType { syntax }),
|
||||
DYN_TRAIT_TYPE => TypeRefKind::DynTraitType(DynTraitType { syntax }),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TypeRef {}
|
||||
|
||||
// UseItem
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct UseItem {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for UseItem {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -3432,25 +3645,26 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(UseItem { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::AttrsOwner for UseItem {}
|
||||
impl UseItem {
|
||||
pub fn use_tree(&self) -> Option<UseTree> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// UseTree
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct UseTree {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for UseTree {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -3459,32 +3673,31 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(UseTree { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl UseTree {
|
||||
pub fn path(&self) -> Option<Path> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
|
||||
pub fn use_tree_list(&self) -> Option<UseTreeList> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
|
||||
pub fn alias(&self) -> Option<Alias> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// UseTreeList
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct UseTreeList {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for UseTreeList {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -3493,24 +3706,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(UseTreeList { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl UseTreeList {
|
||||
pub fn use_trees(&self) -> impl Iterator<Item = UseTree> {
|
||||
super::children(self)
|
||||
pub fn use_trees(&self) -> AstChildren<UseTree> {
|
||||
AstChildren::new(&self.syntax)
|
||||
}
|
||||
}
|
||||
|
||||
// Visibility
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Visibility {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for Visibility {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -3519,20 +3733,21 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(Visibility { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl Visibility {}
|
||||
|
||||
// WhereClause
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct WhereClause {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for WhereClause {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -3541,24 +3756,25 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(WhereClause { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl WhereClause {
|
||||
pub fn predicates(&self) -> impl Iterator<Item = WherePred> {
|
||||
super::children(self)
|
||||
pub fn predicates(&self) -> AstChildren<WherePred> {
|
||||
AstChildren::new(&self.syntax)
|
||||
}
|
||||
}
|
||||
|
||||
// WherePred
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct WherePred {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for WherePred {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -3567,25 +3783,26 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(WherePred { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::TypeBoundsOwner for WherePred {}
|
||||
impl WherePred {
|
||||
pub fn type_ref(&self) -> Option<TypeRef> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
// WhileExpr
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct WhileExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for WhileExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
@@ -3594,16 +3811,19 @@ fn can_cast(kind: SyntaxKind) -> bool {
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(WhileExpr { syntax }) } else { None }
|
||||
if Self::can_cast(syntax.kind()) {
|
||||
Some(Self { syntax })
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode {
|
||||
&self.syntax
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl ast::LoopBodyOwner for WhileExpr {}
|
||||
impl WhileExpr {
|
||||
pub fn condition(&self) -> Option<Condition> {
|
||||
super::child_opt(self)
|
||||
AstChildren::new(&self.syntax).next()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
{# THIS File is not automatically generated:
|
||||
the below applies to the result of this template
|
||||
#}// This file is automatically generated based on the file `./generated.rs.tera` when `cargo gen-syntax` is run
|
||||
// Do not edit manually
|
||||
|
||||
//! This module contains auto-generated Rust AST. Like `SyntaxNode`s, AST nodes
|
||||
//! are generic over ownership: `X<'a>` things are `Copy` references, `XNode`
|
||||
//! are Arc-based. You can switch between the two variants using `.owned` and
|
||||
//! `.borrowed` functions. Most of the code works with borowed mode, and only
|
||||
//! this mode has all AST accessors.
|
||||
|
||||
#![cfg_attr(rustfmt, rustfmt_skip)]
|
||||
|
||||
use crate::{
|
||||
SyntaxNode, SyntaxKind::{self, *},
|
||||
ast::{self, AstNode},
|
||||
};
|
||||
{% for node, methods in ast %}
|
||||
// {{ node }}
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct {{ node }} {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for {{ node }} {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
{%- if methods.enum %}
|
||||
{% for kind in methods.enum %} | {{ kind | SCREAM }} {%- endfor -%}
|
||||
{% else %}
|
||||
{{ node | SCREAM }}
|
||||
{%- endif %} => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some({{ node }} { syntax }) } else { None }
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
{% if methods.enum %}
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum {{ node }}Kind {
|
||||
{%- for kind in methods.enum %}
|
||||
{{ kind }}({{ kind }}),
|
||||
{%- endfor %}
|
||||
}
|
||||
|
||||
{%- for kind in methods.enum %}
|
||||
impl From<{{ kind }}> for {{ node }} {
|
||||
fn from(n: {{ kind }}) -> {{ node }} { {{ node }} { syntax: n.syntax } }
|
||||
}
|
||||
{%- endfor %}
|
||||
impl {{ node }} {
|
||||
pub fn kind(&self) -> {{ node }}Kind {
|
||||
match self.syntax.kind() {
|
||||
{%- for kind in methods.enum %}
|
||||
{{ kind | SCREAM }} => {{ node }}Kind::{{ kind }}({{ kind }}::cast(self.syntax.clone()).unwrap()),
|
||||
{%- endfor %}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
{% endif %}
|
||||
{% if methods.traits -%}
|
||||
|
||||
{%- for t in methods.traits -%}
|
||||
impl ast::{{ t }} for {{ node }} {}
|
||||
{% endfor -%}
|
||||
|
||||
{%- endif -%}
|
||||
|
||||
impl {{ node }} {
|
||||
{%- if methods.collections -%}
|
||||
{%- for m in methods.collections -%}
|
||||
{%- set method_name = m.0 -%}
|
||||
{%- set ChildName = m.1 %}
|
||||
pub fn {{ method_name }}(&self) -> impl Iterator<Item = {{ ChildName }}> {
|
||||
super::children(self)
|
||||
}
|
||||
{% endfor -%}
|
||||
{%- endif -%}
|
||||
|
||||
{%- if methods.options -%}
|
||||
{%- for m in methods.options -%}
|
||||
|
||||
{%- if m is string -%}
|
||||
{%- set method_name = m | snake -%}
|
||||
{%- set ChildName = m %}
|
||||
{%- else -%}
|
||||
{%- set method_name = m.0 -%}
|
||||
{%- set ChildName = m.1 %}
|
||||
{%- endif %}
|
||||
pub fn {{ method_name }}(&self) -> Option<{{ ChildName }}> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
{% endfor -%}
|
||||
{%- endif -%}
|
||||
}
|
||||
{% endfor %}
|
||||
@@ -154,7 +154,8 @@ fn reformat(text: impl std::fmt::Display) -> Result<String> {
|
||||
write!(rustfmt.stdin.take().unwrap(), "{}", text)?;
|
||||
let output = rustfmt.wait_with_output()?;
|
||||
let stdout = String::from_utf8(output.stdout)?;
|
||||
Ok(stdout)
|
||||
let preamble = "Generated file, do not edit by hand, see `crate/ra_tools/src/codegen`";
|
||||
Ok(format!("// {}\n\n{}", preamble, stdout))
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
|
||||
Reference in New Issue
Block a user