From 572f1c08b6ba43bdd57c5cb99f79a08ecd821c1c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 19:49:26 +0200 Subject: Minor gramamr reorder --- crates/ra_syntax/src/ast/generated/nodes.rs | 659 ++++++++++++++-------------- 1 file changed, 328 insertions(+), 331 deletions(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index 6ce9c4adc..66821a31c 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -6,6 +6,20 @@ use crate::{ SyntaxNode, SyntaxToken, T, }; #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct Name { + pub(crate) syntax: SyntaxNode, +} +impl Name { + pub fn ident_token(&self) -> Option { support::token(&self.syntax, T![ident]) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct NameRef { + pub(crate) syntax: SyntaxNode, +} +impl NameRef { + pub fn ident_token(&self) -> Option { support::token(&self.syntax, T![ident]) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Path { pub(crate) syntax: SyntaxNode, } @@ -33,13 +47,6 @@ impl PathSegment { pub fn r_angle_token(&self) -> Option { support::token(&self.syntax, T![>]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct NameRef { - pub(crate) syntax: SyntaxNode, -} -impl NameRef { - pub fn ident_token(&self) -> Option { support::token(&self.syntax, T![ident]) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct GenericArgList { pub(crate) syntax: SyntaxNode, } @@ -116,13 +123,16 @@ impl TypeBoundList { pub fn bounds(&self) -> AstChildren { support::children(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct SourceFile { +pub struct MacroCall { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for SourceFile {} -impl ast::ModuleItemOwner for SourceFile {} -impl SourceFile { - pub fn shebang_token(&self) -> Option { support::token(&self.syntax, T![shebang]) } +impl ast::AttrsOwner for MacroCall {} +impl ast::NameOwner for MacroCall {} +impl MacroCall { + pub fn path(&self) -> Option { support::child(&self.syntax) } + pub fn excl_token(&self) -> Option { support::token(&self.syntax, T![!]) } + pub fn token_tree(&self) -> Option { support::child(&self.syntax) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Attr { @@ -139,6 +149,41 @@ impl Attr { pub fn r_brack_token(&self) -> Option { support::token(&self.syntax, T![']']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct TokenTree { + pub(crate) syntax: SyntaxNode, +} +impl TokenTree { + pub fn l_paren_token(&self) -> Option { support::token(&self.syntax, T!['(']) } + pub fn r_paren_token(&self) -> Option { support::token(&self.syntax, T![')']) } + pub fn l_curly_token(&self) -> Option { support::token(&self.syntax, T!['{']) } + pub fn r_curly_token(&self) -> Option { support::token(&self.syntax, T!['}']) } + pub fn l_brack_token(&self) -> Option { support::token(&self.syntax, T!['[']) } + pub fn r_brack_token(&self) -> Option { support::token(&self.syntax, T![']']) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct MacroItems { + pub(crate) syntax: SyntaxNode, +} +impl ast::ModuleItemOwner for MacroItems {} +impl MacroItems {} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct MacroStmts { + pub(crate) syntax: SyntaxNode, +} +impl MacroStmts { + pub fn statements(&self) -> AstChildren { support::children(&self.syntax) } + pub fn expr(&self) -> Option { support::child(&self.syntax) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct SourceFile { + pub(crate) syntax: SyntaxNode, +} +impl ast::AttrsOwner for SourceFile {} +impl ast::ModuleItemOwner for SourceFile {} +impl SourceFile { + pub fn shebang_token(&self) -> Option { support::token(&self.syntax, T![shebang]) } +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Const { pub(crate) syntax: SyntaxNode, } @@ -228,18 +273,6 @@ impl Impl { pub fn assoc_item_list(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct MacroCall { - pub(crate) syntax: SyntaxNode, -} -impl ast::AttrsOwner for MacroCall {} -impl ast::NameOwner for MacroCall {} -impl MacroCall { - pub fn path(&self) -> Option { support::child(&self.syntax) } - pub fn excl_token(&self) -> Option { support::token(&self.syntax, T![!]) } - pub fn token_tree(&self) -> Option { support::child(&self.syntax) } - pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Module { pub(crate) syntax: SyntaxNode, } @@ -349,13 +382,6 @@ impl Visibility { pub fn r_paren_token(&self) -> Option { support::token(&self.syntax, T![')']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Name { - pub(crate) syntax: SyntaxNode, -} -impl Name { - pub fn ident_token(&self) -> Option { support::token(&self.syntax, T![ident]) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ItemList { pub(crate) syntax: SyntaxNode, } @@ -589,18 +615,6 @@ pub struct Literal { impl ast::AttrsOwner for Literal {} impl Literal {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct TokenTree { - pub(crate) syntax: SyntaxNode, -} -impl TokenTree { - pub fn l_paren_token(&self) -> Option { support::token(&self.syntax, T!['(']) } - pub fn r_paren_token(&self) -> Option { support::token(&self.syntax, T![')']) } - pub fn l_curly_token(&self) -> Option { support::token(&self.syntax, T!['{']) } - pub fn r_curly_token(&self) -> Option { support::token(&self.syntax, T!['}']) } - pub fn l_brack_token(&self) -> Option { support::token(&self.syntax, T!['[']) } - pub fn r_brack_token(&self) -> Option { support::token(&self.syntax, T![']']) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ExprStmt { pub(crate) syntax: SyntaxNode, } @@ -1097,28 +1111,15 @@ impl TypeBound { pub fn ty(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct OrPat { - pub(crate) syntax: SyntaxNode, -} -impl OrPat { - pub fn pats(&self) -> AstChildren { support::children(&self.syntax) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct ParenPat { - pub(crate) syntax: SyntaxNode, -} -impl ParenPat { - pub fn l_paren_token(&self) -> Option { support::token(&self.syntax, T!['(']) } - pub fn pat(&self) -> Option { support::child(&self.syntax) } - pub fn r_paren_token(&self) -> Option { support::token(&self.syntax, T![')']) } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct RefPat { +pub struct BindPat { pub(crate) syntax: SyntaxNode, } -impl RefPat { - pub fn amp_token(&self) -> Option { support::token(&self.syntax, T![&]) } +impl ast::AttrsOwner for BindPat {} +impl ast::NameOwner for BindPat {} +impl BindPat { + pub fn ref_token(&self) -> Option { support::token(&self.syntax, T![ref]) } pub fn mut_token(&self) -> Option { support::token(&self.syntax, T![mut]) } + pub fn at_token(&self) -> Option { support::token(&self.syntax, T![@]) } pub fn pat(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1130,69 +1131,61 @@ impl BoxPat { pub fn path(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct BindPat { +pub struct DotDotPat { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for BindPat {} -impl ast::NameOwner for BindPat {} -impl BindPat { - pub fn ref_token(&self) -> Option { support::token(&self.syntax, T![ref]) } - pub fn mut_token(&self) -> Option { support::token(&self.syntax, T![mut]) } - pub fn at_token(&self) -> Option { support::token(&self.syntax, T![@]) } - pub fn pat(&self) -> Option { support::child(&self.syntax) } +impl DotDotPat { + pub fn dotdot_token(&self) -> Option { support::token(&self.syntax, T![..]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct PlaceholderPat { +pub struct LiteralPat { pub(crate) syntax: SyntaxNode, } -impl PlaceholderPat { - pub fn underscore_token(&self) -> Option { support::token(&self.syntax, T![_]) } +impl LiteralPat { + pub fn literal(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct DotDotPat { +pub struct MacroPat { pub(crate) syntax: SyntaxNode, } -impl DotDotPat { - pub fn dotdot_token(&self) -> Option { support::token(&self.syntax, T![..]) } +impl MacroPat { + pub fn macro_call(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct PathPat { +pub struct OrPat { pub(crate) syntax: SyntaxNode, } -impl PathPat { - pub fn path(&self) -> Option { support::child(&self.syntax) } +impl OrPat { + pub fn pats(&self) -> AstChildren { support::children(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct SlicePat { +pub struct ParenPat { pub(crate) syntax: SyntaxNode, } -impl SlicePat { - pub fn l_brack_token(&self) -> Option { support::token(&self.syntax, T!['[']) } - pub fn args(&self) -> AstChildren { support::children(&self.syntax) } - pub fn r_brack_token(&self) -> Option { support::token(&self.syntax, T![']']) } +impl ParenPat { + pub fn l_paren_token(&self) -> Option { support::token(&self.syntax, T!['(']) } + pub fn pat(&self) -> Option { support::child(&self.syntax) } + pub fn r_paren_token(&self) -> Option { support::token(&self.syntax, T![')']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct RangePat { +pub struct PathPat { pub(crate) syntax: SyntaxNode, } -impl RangePat { - pub fn dotdot_token(&self) -> Option { support::token(&self.syntax, T![..]) } - pub fn dotdoteq_token(&self) -> Option { support::token(&self.syntax, T![..=]) } +impl PathPat { + pub fn path(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct LiteralPat { +pub struct PlaceholderPat { pub(crate) syntax: SyntaxNode, } -impl LiteralPat { - pub fn literal(&self) -> Option { support::child(&self.syntax) } +impl PlaceholderPat { + pub fn underscore_token(&self) -> Option { support::token(&self.syntax, T![_]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct MacroPat { +pub struct RangePat { pub(crate) syntax: SyntaxNode, } -impl MacroPat { - pub fn macro_call(&self) -> Option { support::child(&self.syntax) } -} +impl RangePat {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct RecordPat { pub(crate) syntax: SyntaxNode, @@ -1204,60 +1197,64 @@ impl RecordPat { } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct RecordFieldPatList { +pub struct RefPat { pub(crate) syntax: SyntaxNode, } -impl RecordFieldPatList { - pub fn l_curly_token(&self) -> Option { support::token(&self.syntax, T!['{']) } - pub fn record_field_pats(&self) -> AstChildren { - support::children(&self.syntax) - } - pub fn bind_pats(&self) -> AstChildren { support::children(&self.syntax) } - pub fn dotdot_token(&self) -> Option { support::token(&self.syntax, T![..]) } - pub fn r_curly_token(&self) -> Option { support::token(&self.syntax, T!['}']) } +impl RefPat { + pub fn amp_token(&self) -> Option { support::token(&self.syntax, T![&]) } + pub fn mut_token(&self) -> Option { support::token(&self.syntax, T![mut]) } + pub fn pat(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct RecordFieldPat { +pub struct SlicePat { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for RecordFieldPat {} -impl RecordFieldPat { - pub fn name_ref(&self) -> Option { support::child(&self.syntax) } - pub fn colon_token(&self) -> Option { support::token(&self.syntax, T![:]) } - pub fn pat(&self) -> Option { support::child(&self.syntax) } +impl SlicePat { + pub fn l_brack_token(&self) -> Option { support::token(&self.syntax, T!['[']) } + pub fn args(&self) -> AstChildren { support::children(&self.syntax) } + pub fn r_brack_token(&self) -> Option { support::token(&self.syntax, T![']']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct TupleStructPat { +pub struct TuplePat { pub(crate) syntax: SyntaxNode, } -impl TupleStructPat { - pub fn path(&self) -> Option { support::child(&self.syntax) } +impl TuplePat { pub fn l_paren_token(&self) -> Option { support::token(&self.syntax, T!['(']) } pub fn args(&self) -> AstChildren { support::children(&self.syntax) } pub fn r_paren_token(&self) -> Option { support::token(&self.syntax, T![')']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct TuplePat { +pub struct TupleStructPat { pub(crate) syntax: SyntaxNode, } -impl TuplePat { +impl TupleStructPat { + pub fn path(&self) -> Option { support::child(&self.syntax) } pub fn l_paren_token(&self) -> Option { support::token(&self.syntax, T!['(']) } pub fn args(&self) -> AstChildren { support::children(&self.syntax) } pub fn r_paren_token(&self) -> Option { support::token(&self.syntax, T![')']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct MacroItems { +pub struct RecordFieldPatList { pub(crate) syntax: SyntaxNode, } -impl ast::ModuleItemOwner for MacroItems {} -impl MacroItems {} +impl RecordFieldPatList { + pub fn l_curly_token(&self) -> Option { support::token(&self.syntax, T!['{']) } + pub fn record_field_pats(&self) -> AstChildren { + support::children(&self.syntax) + } + pub fn bind_pats(&self) -> AstChildren { support::children(&self.syntax) } + pub fn dotdot_token(&self) -> Option { support::token(&self.syntax, T![..]) } + pub fn r_curly_token(&self) -> Option { support::token(&self.syntax, T!['}']) } +} #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct MacroStmts { +pub struct RecordFieldPat { pub(crate) syntax: SyntaxNode, } -impl MacroStmts { - pub fn statements(&self) -> AstChildren { support::children(&self.syntax) } - pub fn expr(&self) -> Option { support::child(&self.syntax) } +impl ast::AttrsOwner for RecordFieldPat {} +impl RecordFieldPat { + pub fn name_ref(&self) -> Option { support::child(&self.syntax) } + pub fn colon_token(&self) -> Option { support::token(&self.syntax, T![:]) } + pub fn pat(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum GenericArg { @@ -1334,22 +1331,28 @@ pub enum Item { } impl ast::AttrsOwner for Item {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub enum Stmt { + ExprStmt(ExprStmt), + Item(Item), + LetStmt(LetStmt), +} +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum Pat { - OrPat(OrPat), - ParenPat(ParenPat), - RefPat(RefPat), - BoxPat(BoxPat), BindPat(BindPat), - PlaceholderPat(PlaceholderPat), + BoxPat(BoxPat), DotDotPat(DotDotPat), + LiteralPat(LiteralPat), + MacroPat(MacroPat), + OrPat(OrPat), + ParenPat(ParenPat), PathPat(PathPat), + PlaceholderPat(PlaceholderPat), + RangePat(RangePat), RecordPat(RecordPat), - TupleStructPat(TupleStructPat), - TuplePat(TuplePat), + RefPat(RefPat), SlicePat(SlicePat), - RangePat(RangePat), - LiteralPat(LiteralPat), - MacroPat(MacroPat), + TuplePat(TuplePat), + TupleStructPat(TupleStructPat), } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum FieldList { @@ -1390,14 +1393,19 @@ pub enum GenericParam { TypeParam(TypeParam), } impl ast::AttrsOwner for GenericParam {} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum Stmt { - ExprStmt(ExprStmt), - Item(Item), - LetStmt(LetStmt), +impl AstNode for Name { + fn can_cast(kind: SyntaxKind) -> bool { kind == NAME } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for Path { - fn can_cast(kind: SyntaxKind) -> bool { kind == PATH } +impl AstNode for NameRef { + fn can_cast(kind: SyntaxKind) -> bool { kind == NAME_REF } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1407,8 +1415,8 @@ impl AstNode for Path { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for PathSegment { - fn can_cast(kind: SyntaxKind) -> bool { kind == PATH_SEGMENT } +impl AstNode for Path { + fn can_cast(kind: SyntaxKind) -> bool { kind == PATH } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1418,8 +1426,8 @@ impl AstNode for PathSegment { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for NameRef { - fn can_cast(kind: SyntaxKind) -> bool { kind == NAME_REF } +impl AstNode for PathSegment { + fn can_cast(kind: SyntaxKind) -> bool { kind == PATH_SEGMENT } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1528,8 +1536,8 @@ impl AstNode for TypeBoundList { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for SourceFile { - fn can_cast(kind: SyntaxKind) -> bool { kind == SOURCE_FILE } +impl AstNode for MacroCall { + fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_CALL } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -1550,6 +1558,50 @@ impl AstNode for Attr { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } +impl AstNode for TokenTree { + fn can_cast(kind: SyntaxKind) -> bool { kind == TOKEN_TREE } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} +impl AstNode for MacroItems { + fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_ITEMS } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} +impl AstNode for MacroStmts { + fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_STMTS } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} +impl AstNode for SourceFile { + fn can_cast(kind: SyntaxKind) -> bool { kind == SOURCE_FILE } + fn cast(syntax: SyntaxNode) -> Option { + if Self::can_cast(syntax.kind()) { + Some(Self { syntax }) + } else { + None + } + } + fn syntax(&self) -> &SyntaxNode { &self.syntax } +} impl AstNode for Const { fn can_cast(kind: SyntaxKind) -> bool { kind == CONST } fn cast(syntax: SyntaxNode) -> Option { @@ -1616,17 +1668,6 @@ impl AstNode for Impl { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for MacroCall { - fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_CALL } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} impl AstNode for Module { fn can_cast(kind: SyntaxKind) -> bool { kind == MODULE } fn cast(syntax: SyntaxNode) -> Option { @@ -1715,17 +1756,6 @@ impl AstNode for Visibility { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for Name { - fn can_cast(kind: SyntaxKind) -> bool { kind == NAME } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} impl AstNode for ItemList { fn can_cast(kind: SyntaxKind) -> bool { kind == ITEM_LIST } fn cast(syntax: SyntaxNode) -> Option { @@ -1979,17 +2009,6 @@ impl AstNode for Literal { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for TokenTree { - fn can_cast(kind: SyntaxKind) -> bool { kind == TOKEN_TREE } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} impl AstNode for ExprStmt { fn can_cast(kind: SyntaxKind) -> bool { kind == EXPR_STMT } fn cast(syntax: SyntaxNode) -> Option { @@ -2529,30 +2548,8 @@ impl AstNode for TupleType { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for TypeBound { - fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_BOUND } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} -impl AstNode for OrPat { - fn can_cast(kind: SyntaxKind) -> bool { kind == OR_PAT } - fn cast(syntax: SyntaxNode) -> Option { - if Self::can_cast(syntax.kind()) { - Some(Self { syntax }) - } else { - None - } - } - fn syntax(&self) -> &SyntaxNode { &self.syntax } -} -impl AstNode for ParenPat { - fn can_cast(kind: SyntaxKind) -> bool { kind == PAREN_PAT } +impl AstNode for TypeBound { + fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_BOUND } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -2562,8 +2559,8 @@ impl AstNode for ParenPat { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for RefPat { - fn can_cast(kind: SyntaxKind) -> bool { kind == REF_PAT } +impl AstNode for BindPat { + fn can_cast(kind: SyntaxKind) -> bool { kind == BIND_PAT } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -2584,8 +2581,8 @@ impl AstNode for BoxPat { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for BindPat { - fn can_cast(kind: SyntaxKind) -> bool { kind == BIND_PAT } +impl AstNode for DotDotPat { + fn can_cast(kind: SyntaxKind) -> bool { kind == DOT_DOT_PAT } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -2595,8 +2592,8 @@ impl AstNode for BindPat { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for PlaceholderPat { - fn can_cast(kind: SyntaxKind) -> bool { kind == PLACEHOLDER_PAT } +impl AstNode for LiteralPat { + fn can_cast(kind: SyntaxKind) -> bool { kind == LITERAL_PAT } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -2606,8 +2603,8 @@ impl AstNode for PlaceholderPat { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for DotDotPat { - fn can_cast(kind: SyntaxKind) -> bool { kind == DOT_DOT_PAT } +impl AstNode for MacroPat { + fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_PAT } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -2617,8 +2614,8 @@ impl AstNode for DotDotPat { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for PathPat { - fn can_cast(kind: SyntaxKind) -> bool { kind == PATH_PAT } +impl AstNode for OrPat { + fn can_cast(kind: SyntaxKind) -> bool { kind == OR_PAT } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -2628,8 +2625,8 @@ impl AstNode for PathPat { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for SlicePat { - fn can_cast(kind: SyntaxKind) -> bool { kind == SLICE_PAT } +impl AstNode for ParenPat { + fn can_cast(kind: SyntaxKind) -> bool { kind == PAREN_PAT } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -2639,8 +2636,8 @@ impl AstNode for SlicePat { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for RangePat { - fn can_cast(kind: SyntaxKind) -> bool { kind == RANGE_PAT } +impl AstNode for PathPat { + fn can_cast(kind: SyntaxKind) -> bool { kind == PATH_PAT } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -2650,8 +2647,8 @@ impl AstNode for RangePat { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for LiteralPat { - fn can_cast(kind: SyntaxKind) -> bool { kind == LITERAL_PAT } +impl AstNode for PlaceholderPat { + fn can_cast(kind: SyntaxKind) -> bool { kind == PLACEHOLDER_PAT } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -2661,8 +2658,8 @@ impl AstNode for LiteralPat { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for MacroPat { - fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_PAT } +impl AstNode for RangePat { + fn can_cast(kind: SyntaxKind) -> bool { kind == RANGE_PAT } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -2683,8 +2680,8 @@ impl AstNode for RecordPat { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for RecordFieldPatList { - fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_PAT_LIST } +impl AstNode for RefPat { + fn can_cast(kind: SyntaxKind) -> bool { kind == REF_PAT } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -2694,8 +2691,8 @@ impl AstNode for RecordFieldPatList { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for RecordFieldPat { - fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_PAT } +impl AstNode for SlicePat { + fn can_cast(kind: SyntaxKind) -> bool { kind == SLICE_PAT } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -2705,8 +2702,8 @@ impl AstNode for RecordFieldPat { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for TupleStructPat { - fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_STRUCT_PAT } +impl AstNode for TuplePat { + fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_PAT } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -2716,8 +2713,8 @@ impl AstNode for TupleStructPat { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for TuplePat { - fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_PAT } +impl AstNode for TupleStructPat { + fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_STRUCT_PAT } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -2727,8 +2724,8 @@ impl AstNode for TuplePat { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for MacroItems { - fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_ITEMS } +impl AstNode for RecordFieldPatList { + fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_PAT_LIST } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -2738,8 +2735,8 @@ impl AstNode for MacroItems { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for MacroStmts { - fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_STMTS } +impl AstNode for RecordFieldPat { + fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_PAT } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -3133,98 +3130,107 @@ impl AstNode for Item { } } } -impl From for Pat { - fn from(node: OrPat) -> Pat { Pat::OrPat(node) } -} -impl From for Pat { - fn from(node: ParenPat) -> Pat { Pat::ParenPat(node) } +impl From for Stmt { + fn from(node: ExprStmt) -> Stmt { Stmt::ExprStmt(node) } } -impl From for Pat { - fn from(node: RefPat) -> Pat { Pat::RefPat(node) } +impl From for Stmt { + fn from(node: Item) -> Stmt { Stmt::Item(node) } } -impl From for Pat { - fn from(node: BoxPat) -> Pat { Pat::BoxPat(node) } +impl From for Stmt { + fn from(node: LetStmt) -> Stmt { Stmt::LetStmt(node) } } impl From for Pat { fn from(node: BindPat) -> Pat { Pat::BindPat(node) } } -impl From for Pat { - fn from(node: PlaceholderPat) -> Pat { Pat::PlaceholderPat(node) } +impl From for Pat { + fn from(node: BoxPat) -> Pat { Pat::BoxPat(node) } } impl From for Pat { fn from(node: DotDotPat) -> Pat { Pat::DotDotPat(node) } } +impl From for Pat { + fn from(node: LiteralPat) -> Pat { Pat::LiteralPat(node) } +} +impl From for Pat { + fn from(node: MacroPat) -> Pat { Pat::MacroPat(node) } +} +impl From for Pat { + fn from(node: OrPat) -> Pat { Pat::OrPat(node) } +} +impl From for Pat { + fn from(node: ParenPat) -> Pat { Pat::ParenPat(node) } +} impl From for Pat { fn from(node: PathPat) -> Pat { Pat::PathPat(node) } } +impl From for Pat { + fn from(node: PlaceholderPat) -> Pat { Pat::PlaceholderPat(node) } +} +impl From for Pat { + fn from(node: RangePat) -> Pat { Pat::RangePat(node) } +} impl From for Pat { fn from(node: RecordPat) -> Pat { Pat::RecordPat(node) } } -impl From for Pat { - fn from(node: TupleStructPat) -> Pat { Pat::TupleStructPat(node) } -} -impl From for Pat { - fn from(node: TuplePat) -> Pat { Pat::TuplePat(node) } +impl From for Pat { + fn from(node: RefPat) -> Pat { Pat::RefPat(node) } } impl From for Pat { fn from(node: SlicePat) -> Pat { Pat::SlicePat(node) } } -impl From for Pat { - fn from(node: RangePat) -> Pat { Pat::RangePat(node) } -} -impl From for Pat { - fn from(node: LiteralPat) -> Pat { Pat::LiteralPat(node) } +impl From for Pat { + fn from(node: TuplePat) -> Pat { Pat::TuplePat(node) } } -impl From for Pat { - fn from(node: MacroPat) -> Pat { Pat::MacroPat(node) } +impl From for Pat { + fn from(node: TupleStructPat) -> Pat { Pat::TupleStructPat(node) } } impl AstNode for Pat { fn can_cast(kind: SyntaxKind) -> bool { match kind { - OR_PAT | PAREN_PAT | REF_PAT | BOX_PAT | BIND_PAT | PLACEHOLDER_PAT | DOT_DOT_PAT - | PATH_PAT | RECORD_PAT | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT - | LITERAL_PAT | MACRO_PAT => true, + BIND_PAT | BOX_PAT | DOT_DOT_PAT | LITERAL_PAT | MACRO_PAT | OR_PAT | PAREN_PAT + | PATH_PAT | PLACEHOLDER_PAT | RANGE_PAT | RECORD_PAT | REF_PAT | SLICE_PAT + | TUPLE_PAT | TUPLE_STRUCT_PAT => true, _ => false, } } fn cast(syntax: SyntaxNode) -> Option { let res = match syntax.kind() { - OR_PAT => Pat::OrPat(OrPat { syntax }), - PAREN_PAT => Pat::ParenPat(ParenPat { syntax }), - REF_PAT => Pat::RefPat(RefPat { syntax }), - BOX_PAT => Pat::BoxPat(BoxPat { syntax }), BIND_PAT => Pat::BindPat(BindPat { syntax }), - PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }), + BOX_PAT => Pat::BoxPat(BoxPat { syntax }), DOT_DOT_PAT => Pat::DotDotPat(DotDotPat { syntax }), + LITERAL_PAT => Pat::LiteralPat(LiteralPat { syntax }), + MACRO_PAT => Pat::MacroPat(MacroPat { syntax }), + OR_PAT => Pat::OrPat(OrPat { syntax }), + PAREN_PAT => Pat::ParenPat(ParenPat { syntax }), PATH_PAT => Pat::PathPat(PathPat { syntax }), + PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }), + RANGE_PAT => Pat::RangePat(RangePat { syntax }), RECORD_PAT => Pat::RecordPat(RecordPat { syntax }), - TUPLE_STRUCT_PAT => Pat::TupleStructPat(TupleStructPat { syntax }), - TUPLE_PAT => Pat::TuplePat(TuplePat { syntax }), + REF_PAT => Pat::RefPat(RefPat { syntax }), SLICE_PAT => Pat::SlicePat(SlicePat { syntax }), - RANGE_PAT => Pat::RangePat(RangePat { syntax }), - LITERAL_PAT => Pat::LiteralPat(LiteralPat { syntax }), - MACRO_PAT => Pat::MacroPat(MacroPat { syntax }), + TUPLE_PAT => Pat::TuplePat(TuplePat { syntax }), + TUPLE_STRUCT_PAT => Pat::TupleStructPat(TupleStructPat { syntax }), _ => return None, }; Some(res) } fn syntax(&self) -> &SyntaxNode { match self { - Pat::OrPat(it) => &it.syntax, - Pat::ParenPat(it) => &it.syntax, - Pat::RefPat(it) => &it.syntax, - Pat::BoxPat(it) => &it.syntax, Pat::BindPat(it) => &it.syntax, - Pat::PlaceholderPat(it) => &it.syntax, + Pat::BoxPat(it) => &it.syntax, Pat::DotDotPat(it) => &it.syntax, + Pat::LiteralPat(it) => &it.syntax, + Pat::MacroPat(it) => &it.syntax, + Pat::OrPat(it) => &it.syntax, + Pat::ParenPat(it) => &it.syntax, Pat::PathPat(it) => &it.syntax, + Pat::PlaceholderPat(it) => &it.syntax, + Pat::RangePat(it) => &it.syntax, Pat::RecordPat(it) => &it.syntax, - Pat::TupleStructPat(it) => &it.syntax, - Pat::TuplePat(it) => &it.syntax, + Pat::RefPat(it) => &it.syntax, Pat::SlicePat(it) => &it.syntax, - Pat::RangePat(it) => &it.syntax, - Pat::LiteralPat(it) => &it.syntax, - Pat::MacroPat(it) => &it.syntax, + Pat::TuplePat(it) => &it.syntax, + Pat::TupleStructPat(it) => &it.syntax, } } } @@ -3393,15 +3399,6 @@ impl AstNode for GenericParam { } } } -impl From for Stmt { - fn from(node: ExprStmt) -> Stmt { Stmt::ExprStmt(node) } -} -impl From for Stmt { - fn from(node: Item) -> Stmt { Stmt::Item(node) } -} -impl From for Stmt { - fn from(node: LetStmt) -> Stmt { Stmt::LetStmt(node) } -} impl std::fmt::Display for GenericArg { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -3422,6 +3419,11 @@ impl std::fmt::Display for Item { std::fmt::Display::fmt(self.syntax(), f) } } +impl std::fmt::Display for Stmt { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} impl std::fmt::Display for Pat { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -3452,22 +3454,22 @@ impl std::fmt::Display for GenericParam { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for Stmt { +impl std::fmt::Display for Name { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for Path { +impl std::fmt::Display for NameRef { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for PathSegment { +impl std::fmt::Display for Path { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for NameRef { +impl std::fmt::Display for PathSegment { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -3517,7 +3519,7 @@ impl std::fmt::Display for TypeBoundList { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for SourceFile { +impl std::fmt::Display for MacroCall { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -3527,6 +3529,26 @@ impl std::fmt::Display for Attr { std::fmt::Display::fmt(self.syntax(), f) } } +impl std::fmt::Display for TokenTree { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for MacroItems { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for MacroStmts { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} +impl std::fmt::Display for SourceFile { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(self.syntax(), f) + } +} impl std::fmt::Display for Const { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -3557,11 +3579,6 @@ impl std::fmt::Display for Impl { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for MacroCall { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} impl std::fmt::Display for Module { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -3602,11 +3619,6 @@ impl std::fmt::Display for Visibility { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for Name { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} impl std::fmt::Display for ItemList { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -3722,11 +3734,6 @@ impl std::fmt::Display for Literal { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for TokenTree { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} impl std::fmt::Display for ExprStmt { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) @@ -3977,37 +3984,37 @@ impl std::fmt::Display for TypeBound { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for OrPat { +impl std::fmt::Display for BindPat { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for ParenPat { +impl std::fmt::Display for BoxPat { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for RefPat { +impl std::fmt::Display for DotDotPat { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for BoxPat { +impl std::fmt::Display for LiteralPat { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for BindPat { +impl std::fmt::Display for MacroPat { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for PlaceholderPat { +impl std::fmt::Display for OrPat { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for DotDotPat { +impl std::fmt::Display for ParenPat { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -4017,7 +4024,7 @@ impl std::fmt::Display for PathPat { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for SlicePat { +impl std::fmt::Display for PlaceholderPat { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } @@ -4027,47 +4034,37 @@ impl std::fmt::Display for RangePat { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for LiteralPat { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} -impl std::fmt::Display for MacroPat { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} impl std::fmt::Display for RecordPat { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for RecordFieldPatList { +impl std::fmt::Display for RefPat { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for RecordFieldPat { +impl std::fmt::Display for SlicePat { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for TupleStructPat { +impl std::fmt::Display for TuplePat { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for TuplePat { +impl std::fmt::Display for TupleStructPat { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for MacroItems { +impl std::fmt::Display for RecordFieldPatList { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for MacroStmts { +impl std::fmt::Display for RecordFieldPat { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } -- cgit v1.2.3 From 14cb96ec0e6be3b99bfe4ea373c058dcbd2a4f79 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 19:54:16 +0200 Subject: Allign RecordPat with RecordExpr --- crates/ra_syntax/src/ast/generated/nodes.rs | 29 +++++++++++++---------------- crates/ra_syntax/src/ast/node_ext.rs | 2 +- 2 files changed, 14 insertions(+), 17 deletions(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index 66821a31c..7708ae806 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -1192,7 +1192,7 @@ pub struct RecordPat { } impl RecordPat { pub fn path(&self) -> Option { support::child(&self.syntax) } - pub fn record_field_pat_list(&self) -> Option { + pub fn record_pat_field_list(&self) -> Option { support::child(&self.syntax) } } @@ -1234,24 +1234,21 @@ impl TupleStructPat { pub fn r_paren_token(&self) -> Option { support::token(&self.syntax, T![')']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct RecordFieldPatList { +pub struct RecordPatFieldList { pub(crate) syntax: SyntaxNode, } -impl RecordFieldPatList { +impl RecordPatFieldList { pub fn l_curly_token(&self) -> Option { support::token(&self.syntax, T!['{']) } - pub fn record_field_pats(&self) -> AstChildren { - support::children(&self.syntax) - } - pub fn bind_pats(&self) -> AstChildren { support::children(&self.syntax) } + pub fn fields(&self) -> AstChildren { support::children(&self.syntax) } pub fn dotdot_token(&self) -> Option { support::token(&self.syntax, T![..]) } pub fn r_curly_token(&self) -> Option { support::token(&self.syntax, T!['}']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct RecordFieldPat { +pub struct RecordPatField { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for RecordFieldPat {} -impl RecordFieldPat { +impl ast::AttrsOwner for RecordPatField {} +impl RecordPatField { pub fn name_ref(&self) -> Option { support::child(&self.syntax) } pub fn colon_token(&self) -> Option { support::token(&self.syntax, T![:]) } pub fn pat(&self) -> Option { support::child(&self.syntax) } @@ -2724,8 +2721,8 @@ impl AstNode for TupleStructPat { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for RecordFieldPatList { - fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_PAT_LIST } +impl AstNode for RecordPatFieldList { + fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_PAT_FIELD_LIST } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -2735,8 +2732,8 @@ impl AstNode for RecordFieldPatList { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for RecordFieldPat { - fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_PAT } +impl AstNode for RecordPatField { + fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_PAT_FIELD } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -4059,12 +4056,12 @@ impl std::fmt::Display for TupleStructPat { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for RecordFieldPatList { +impl std::fmt::Display for RecordPatFieldList { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for RecordFieldPat { +impl std::fmt::Display for RecordPatField { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } diff --git a/crates/ra_syntax/src/ast/node_ext.rs b/crates/ra_syntax/src/ast/node_ext.rs index 69726fb93..2cfdac225 100644 --- a/crates/ra_syntax/src/ast/node_ext.rs +++ b/crates/ra_syntax/src/ast/node_ext.rs @@ -227,7 +227,7 @@ impl fmt::Display for NameOrNameRef { } } -impl ast::RecordFieldPat { +impl ast::RecordPatField { /// Deals with field init shorthand pub fn field_name(&self) -> Option { if let Some(name_ref) = self.name_ref() { -- cgit v1.2.3 From d7f75db90d99216c13000681ff2c4a887451c4b2 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 20:04:40 +0200 Subject: Reorder --- crates/ra_syntax/src/ast/generated/nodes.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index 7708ae806..713aebcfa 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -1128,7 +1128,7 @@ pub struct BoxPat { } impl BoxPat { pub fn box_token(&self) -> Option { support::token(&self.syntax, T![box]) } - pub fn path(&self) -> Option { support::child(&self.syntax) } + pub fn pat(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct DotDotPat { -- cgit v1.2.3 From 6791eb9685375da94556bb910ea71f78b08be5ec Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 20:07:21 +0200 Subject: Rename PalceholderPat -> WildcardPat --- crates/ra_syntax/src/ast/edit.rs | 2 +- crates/ra_syntax/src/ast/generated/nodes.rs | 22 +++++++++++----------- crates/ra_syntax/src/ast/make.rs | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs index 04746ef8f..667a9294f 100644 --- a/crates/ra_syntax/src/ast/edit.rs +++ b/crates/ra_syntax/src/ast/edit.rs @@ -390,7 +390,7 @@ impl ast::MatchArmList { #[must_use] pub fn remove_placeholder(&self) -> ast::MatchArmList { let placeholder = - self.arms().find(|arm| matches!(arm.pat(), Some(ast::Pat::PlaceholderPat(_)))); + self.arms().find(|arm| matches!(arm.pat(), Some(ast::Pat::WildcardPat(_)))); if let Some(placeholder) = placeholder { self.remove_arm(&placeholder) } else { diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index 713aebcfa..f6b3fa6ef 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -1175,10 +1175,10 @@ impl PathPat { pub fn path(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct PlaceholderPat { +pub struct WildcardPat { pub(crate) syntax: SyntaxNode, } -impl PlaceholderPat { +impl WildcardPat { pub fn underscore_token(&self) -> Option { support::token(&self.syntax, T![_]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1343,7 +1343,7 @@ pub enum Pat { OrPat(OrPat), ParenPat(ParenPat), PathPat(PathPat), - PlaceholderPat(PlaceholderPat), + WildcardPat(WildcardPat), RangePat(RangePat), RecordPat(RecordPat), RefPat(RefPat), @@ -2644,8 +2644,8 @@ impl AstNode for PathPat { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for PlaceholderPat { - fn can_cast(kind: SyntaxKind) -> bool { kind == PLACEHOLDER_PAT } +impl AstNode for WildcardPat { + fn can_cast(kind: SyntaxKind) -> bool { kind == WILDCARD_PAT } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -3160,8 +3160,8 @@ impl From for Pat { impl From for Pat { fn from(node: PathPat) -> Pat { Pat::PathPat(node) } } -impl From for Pat { - fn from(node: PlaceholderPat) -> Pat { Pat::PlaceholderPat(node) } +impl From for Pat { + fn from(node: WildcardPat) -> Pat { Pat::WildcardPat(node) } } impl From for Pat { fn from(node: RangePat) -> Pat { Pat::RangePat(node) } @@ -3185,7 +3185,7 @@ impl AstNode for Pat { fn can_cast(kind: SyntaxKind) -> bool { match kind { BIND_PAT | BOX_PAT | DOT_DOT_PAT | LITERAL_PAT | MACRO_PAT | OR_PAT | PAREN_PAT - | PATH_PAT | PLACEHOLDER_PAT | RANGE_PAT | RECORD_PAT | REF_PAT | SLICE_PAT + | PATH_PAT | WILDCARD_PAT | RANGE_PAT | RECORD_PAT | REF_PAT | SLICE_PAT | TUPLE_PAT | TUPLE_STRUCT_PAT => true, _ => false, } @@ -3200,7 +3200,7 @@ impl AstNode for Pat { OR_PAT => Pat::OrPat(OrPat { syntax }), PAREN_PAT => Pat::ParenPat(ParenPat { syntax }), PATH_PAT => Pat::PathPat(PathPat { syntax }), - PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }), + WILDCARD_PAT => Pat::WildcardPat(WildcardPat { syntax }), RANGE_PAT => Pat::RangePat(RangePat { syntax }), RECORD_PAT => Pat::RecordPat(RecordPat { syntax }), REF_PAT => Pat::RefPat(RefPat { syntax }), @@ -3221,7 +3221,7 @@ impl AstNode for Pat { Pat::OrPat(it) => &it.syntax, Pat::ParenPat(it) => &it.syntax, Pat::PathPat(it) => &it.syntax, - Pat::PlaceholderPat(it) => &it.syntax, + Pat::WildcardPat(it) => &it.syntax, Pat::RangePat(it) => &it.syntax, Pat::RecordPat(it) => &it.syntax, Pat::RefPat(it) => &it.syntax, @@ -4021,7 +4021,7 @@ impl std::fmt::Display for PathPat { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for PlaceholderPat { +impl std::fmt::Display for WildcardPat { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 3d4fed64c..efb2cb4a3 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs @@ -156,10 +156,10 @@ pub fn bind_pat(name: ast::Name) -> ast::BindPat { } } -pub fn placeholder_pat() -> ast::PlaceholderPat { +pub fn placeholder_pat() -> ast::WildcardPat { return from_text("_"); - fn from_text(text: &str) -> ast::PlaceholderPat { + fn from_text(text: &str) -> ast::WildcardPat { ast_from_text(&format!("fn f({}: ())", text)) } } -- cgit v1.2.3 From 98181087984157e27faba0b969e384f3c62c39d5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 31 Jul 2020 20:09:09 +0200 Subject: Rename BindPat -> IdentPat --- crates/ra_syntax/src/ast/generated/nodes.rs | 26 +++++++++++++------------- crates/ra_syntax/src/ast/make.rs | 4 ++-- crates/ra_syntax/src/ast/node_ext.rs | 6 +++--- 3 files changed, 18 insertions(+), 18 deletions(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index f6b3fa6ef..231a0f727 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -1111,12 +1111,12 @@ impl TypeBound { pub fn ty(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct BindPat { +pub struct IdentPat { pub(crate) syntax: SyntaxNode, } -impl ast::AttrsOwner for BindPat {} -impl ast::NameOwner for BindPat {} -impl BindPat { +impl ast::AttrsOwner for IdentPat {} +impl ast::NameOwner for IdentPat {} +impl IdentPat { pub fn ref_token(&self) -> Option { support::token(&self.syntax, T![ref]) } pub fn mut_token(&self) -> Option { support::token(&self.syntax, T![mut]) } pub fn at_token(&self) -> Option { support::token(&self.syntax, T![@]) } @@ -1335,7 +1335,7 @@ pub enum Stmt { } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum Pat { - BindPat(BindPat), + IdentPat(IdentPat), BoxPat(BoxPat), DotDotPat(DotDotPat), LiteralPat(LiteralPat), @@ -2556,8 +2556,8 @@ impl AstNode for TypeBound { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl AstNode for BindPat { - fn can_cast(kind: SyntaxKind) -> bool { kind == BIND_PAT } +impl AstNode for IdentPat { + fn can_cast(kind: SyntaxKind) -> bool { kind == IDENT_PAT } fn cast(syntax: SyntaxNode) -> Option { if Self::can_cast(syntax.kind()) { Some(Self { syntax }) @@ -3136,8 +3136,8 @@ impl From for Stmt { impl From for Stmt { fn from(node: LetStmt) -> Stmt { Stmt::LetStmt(node) } } -impl From for Pat { - fn from(node: BindPat) -> Pat { Pat::BindPat(node) } +impl From for Pat { + fn from(node: IdentPat) -> Pat { Pat::IdentPat(node) } } impl From for Pat { fn from(node: BoxPat) -> Pat { Pat::BoxPat(node) } @@ -3184,7 +3184,7 @@ impl From for Pat { impl AstNode for Pat { fn can_cast(kind: SyntaxKind) -> bool { match kind { - BIND_PAT | BOX_PAT | DOT_DOT_PAT | LITERAL_PAT | MACRO_PAT | OR_PAT | PAREN_PAT + IDENT_PAT | BOX_PAT | DOT_DOT_PAT | LITERAL_PAT | MACRO_PAT | OR_PAT | PAREN_PAT | PATH_PAT | WILDCARD_PAT | RANGE_PAT | RECORD_PAT | REF_PAT | SLICE_PAT | TUPLE_PAT | TUPLE_STRUCT_PAT => true, _ => false, @@ -3192,7 +3192,7 @@ impl AstNode for Pat { } fn cast(syntax: SyntaxNode) -> Option { let res = match syntax.kind() { - BIND_PAT => Pat::BindPat(BindPat { syntax }), + IDENT_PAT => Pat::IdentPat(IdentPat { syntax }), BOX_PAT => Pat::BoxPat(BoxPat { syntax }), DOT_DOT_PAT => Pat::DotDotPat(DotDotPat { syntax }), LITERAL_PAT => Pat::LiteralPat(LiteralPat { syntax }), @@ -3213,7 +3213,7 @@ impl AstNode for Pat { } fn syntax(&self) -> &SyntaxNode { match self { - Pat::BindPat(it) => &it.syntax, + Pat::IdentPat(it) => &it.syntax, Pat::BoxPat(it) => &it.syntax, Pat::DotDotPat(it) => &it.syntax, Pat::LiteralPat(it) => &it.syntax, @@ -3981,7 +3981,7 @@ impl std::fmt::Display for TypeBound { std::fmt::Display::fmt(self.syntax(), f) } } -impl std::fmt::Display for BindPat { +impl std::fmt::Display for IdentPat { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Display::fmt(self.syntax(), f) } diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index efb2cb4a3..673777015 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs @@ -148,10 +148,10 @@ pub fn condition(expr: ast::Expr, pattern: Option) -> ast::Condition { } } -pub fn bind_pat(name: ast::Name) -> ast::BindPat { +pub fn bind_pat(name: ast::Name) -> ast::IdentPat { return from_text(name.text()); - fn from_text(text: &str) -> ast::BindPat { + fn from_text(text: &str) -> ast::IdentPat { ast_from_text(&format!("fn f({}: ())", text)) } } diff --git a/crates/ra_syntax/src/ast/node_ext.rs b/crates/ra_syntax/src/ast/node_ext.rs index 2cfdac225..4b4a72375 100644 --- a/crates/ra_syntax/src/ast/node_ext.rs +++ b/crates/ra_syntax/src/ast/node_ext.rs @@ -233,7 +233,7 @@ impl ast::RecordPatField { if let Some(name_ref) = self.name_ref() { return Some(NameOrNameRef::NameRef(name_ref)); } - if let Some(ast::Pat::BindPat(pat)) = self.pat() { + if let Some(ast::Pat::IdentPat(pat)) = self.pat() { let name = pat.name()?; return Some(NameOrNameRef::Name(name)); } @@ -294,13 +294,13 @@ impl ast::SlicePat { let prefix = args .peeking_take_while(|p| match p { ast::Pat::DotDotPat(_) => false, - ast::Pat::BindPat(bp) => match bp.pat() { + ast::Pat::IdentPat(bp) => match bp.pat() { Some(ast::Pat::DotDotPat(_)) => false, _ => true, }, ast::Pat::RefPat(rp) => match rp.pat() { Some(ast::Pat::DotDotPat(_)) => false, - Some(ast::Pat::BindPat(bp)) => match bp.pat() { + Some(ast::Pat::IdentPat(bp)) => match bp.pat() { Some(ast::Pat::DotDotPat(_)) => false, _ => true, }, -- cgit v1.2.3