From d685a9b564fe524865cda5713c527aaeb1ca6b1d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 1 Nov 2018 13:41:04 +0300 Subject: Use From to get an owned AST --- crates/ra_syntax/src/ast/generated.rs | 1089 ++++++++++++++++++---------- crates/ra_syntax/src/ast/generated.rs.tera | 11 +- 2 files changed, 700 insertions(+), 400 deletions(-) (limited to 'crates/ra_syntax/src/ast') diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index b6a15dbdc..f77795d05 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -15,14 +15,17 @@ use crate::{ pub struct ArgListNode(SyntaxNode); impl ArgListNode { - pub fn new(ast: ArgList) -> ArgListNode { - let syntax = ast.syntax().owned(); - ArgListNode(syntax) - } pub fn ast(&self) -> ArgList { ArgList::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for ArgListNode { + fn from(ast: ArgList<'a>) -> ArgListNode { + let syntax = ast.syntax().owned(); + ArgListNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct ArgList<'a> { syntax: SyntaxNodeRef<'a>, @@ -50,14 +53,17 @@ impl<'a> ArgList<'a> { pub struct ArrayExprNode(SyntaxNode); impl ArrayExprNode { - pub fn new(ast: ArrayExpr) -> ArrayExprNode { - let syntax = ast.syntax().owned(); - ArrayExprNode(syntax) - } pub fn ast(&self) -> ArrayExpr { ArrayExpr::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for ArrayExprNode { + fn from(ast: ArrayExpr<'a>) -> ArrayExprNode { + let syntax = ast.syntax().owned(); + ArrayExprNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct ArrayExpr<'a> { syntax: SyntaxNodeRef<'a>, @@ -81,14 +87,17 @@ impl<'a> ArrayExpr<'a> {} pub struct ArrayTypeNode(SyntaxNode); impl ArrayTypeNode { - pub fn new(ast: ArrayType) -> ArrayTypeNode { - let syntax = ast.syntax().owned(); - ArrayTypeNode(syntax) - } pub fn ast(&self) -> ArrayType { ArrayType::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for ArrayTypeNode { + fn from(ast: ArrayType<'a>) -> ArrayTypeNode { + let syntax = ast.syntax().owned(); + ArrayTypeNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct ArrayType<'a> { syntax: SyntaxNodeRef<'a>, @@ -112,14 +121,17 @@ impl<'a> ArrayType<'a> {} pub struct AttrNode(SyntaxNode); impl AttrNode { - pub fn new(ast: Attr) -> AttrNode { - let syntax = ast.syntax().owned(); - AttrNode(syntax) - } pub fn ast(&self) -> Attr { Attr::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for AttrNode { + fn from(ast: Attr<'a>) -> AttrNode { + let syntax = ast.syntax().owned(); + AttrNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct Attr<'a> { syntax: SyntaxNodeRef<'a>, @@ -147,14 +159,17 @@ impl<'a> Attr<'a> { pub struct BinExprNode(SyntaxNode); impl BinExprNode { - pub fn new(ast: BinExpr) -> BinExprNode { - let syntax = ast.syntax().owned(); - BinExprNode(syntax) - } pub fn ast(&self) -> BinExpr { BinExpr::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for BinExprNode { + fn from(ast: BinExpr<'a>) -> BinExprNode { + let syntax = ast.syntax().owned(); + BinExprNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct BinExpr<'a> { syntax: SyntaxNodeRef<'a>, @@ -178,14 +193,17 @@ impl<'a> BinExpr<'a> {} pub struct BindPatNode(SyntaxNode); impl BindPatNode { - pub fn new(ast: BindPat) -> BindPatNode { - let syntax = ast.syntax().owned(); - BindPatNode(syntax) - } pub fn ast(&self) -> BindPat { BindPat::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for BindPatNode { + fn from(ast: BindPat<'a>) -> BindPatNode { + let syntax = ast.syntax().owned(); + BindPatNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct BindPat<'a> { syntax: SyntaxNodeRef<'a>, @@ -210,14 +228,17 @@ impl<'a> BindPat<'a> {} pub struct BlockNode(SyntaxNode); impl BlockNode { - pub fn new(ast: Block) -> BlockNode { - let syntax = ast.syntax().owned(); - BlockNode(syntax) - } pub fn ast(&self) -> Block { Block::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for BlockNode { + fn from(ast: Block<'a>) -> BlockNode { + let syntax = ast.syntax().owned(); + BlockNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct Block<'a> { syntax: SyntaxNodeRef<'a>, @@ -249,14 +270,17 @@ impl<'a> Block<'a> { pub struct BlockExprNode(SyntaxNode); impl BlockExprNode { - pub fn new(ast: BlockExpr) -> BlockExprNode { - let syntax = ast.syntax().owned(); - BlockExprNode(syntax) - } pub fn ast(&self) -> BlockExpr { BlockExpr::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for BlockExprNode { + fn from(ast: BlockExpr<'a>) -> BlockExprNode { + let syntax = ast.syntax().owned(); + BlockExprNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct BlockExpr<'a> { syntax: SyntaxNodeRef<'a>, @@ -284,14 +308,17 @@ impl<'a> BlockExpr<'a> { pub struct BreakExprNode(SyntaxNode); impl BreakExprNode { - pub fn new(ast: BreakExpr) -> BreakExprNode { - let syntax = ast.syntax().owned(); - BreakExprNode(syntax) - } pub fn ast(&self) -> BreakExpr { BreakExpr::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for BreakExprNode { + fn from(ast: BreakExpr<'a>) -> BreakExprNode { + let syntax = ast.syntax().owned(); + BreakExprNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct BreakExpr<'a> { syntax: SyntaxNodeRef<'a>, @@ -315,14 +342,17 @@ impl<'a> BreakExpr<'a> {} pub struct CallExprNode(SyntaxNode); impl CallExprNode { - pub fn new(ast: CallExpr) -> CallExprNode { - let syntax = ast.syntax().owned(); - CallExprNode(syntax) - } pub fn ast(&self) -> CallExpr { CallExpr::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for CallExprNode { + fn from(ast: CallExpr<'a>) -> CallExprNode { + let syntax = ast.syntax().owned(); + CallExprNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct CallExpr<'a> { syntax: SyntaxNodeRef<'a>, @@ -351,14 +381,17 @@ impl<'a> CallExpr<'a> { pub struct CastExprNode(SyntaxNode); impl CastExprNode { - pub fn new(ast: CastExpr) -> CastExprNode { - let syntax = ast.syntax().owned(); - CastExprNode(syntax) - } pub fn ast(&self) -> CastExpr { CastExpr::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for CastExprNode { + fn from(ast: CastExpr<'a>) -> CastExprNode { + let syntax = ast.syntax().owned(); + CastExprNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct CastExpr<'a> { syntax: SyntaxNodeRef<'a>, @@ -382,14 +415,17 @@ impl<'a> CastExpr<'a> {} pub struct CommentNode(SyntaxNode); impl CommentNode { - pub fn new(ast: Comment) -> CommentNode { - let syntax = ast.syntax().owned(); - CommentNode(syntax) - } pub fn ast(&self) -> Comment { Comment::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for CommentNode { + fn from(ast: Comment<'a>) -> CommentNode { + let syntax = ast.syntax().owned(); + CommentNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct Comment<'a> { syntax: SyntaxNodeRef<'a>, @@ -413,14 +449,17 @@ impl<'a> Comment<'a> {} pub struct ConditionNode(SyntaxNode); impl ConditionNode { - pub fn new(ast: Condition) -> ConditionNode { - let syntax = ast.syntax().owned(); - ConditionNode(syntax) - } pub fn ast(&self) -> Condition { Condition::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for ConditionNode { + fn from(ast: Condition<'a>) -> ConditionNode { + let syntax = ast.syntax().owned(); + ConditionNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct Condition<'a> { syntax: SyntaxNodeRef<'a>, @@ -452,14 +491,17 @@ impl<'a> Condition<'a> { pub struct ConstDefNode(SyntaxNode); impl ConstDefNode { - pub fn new(ast: ConstDef) -> ConstDefNode { - let syntax = ast.syntax().owned(); - ConstDefNode(syntax) - } pub fn ast(&self) -> ConstDef { ConstDef::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for ConstDefNode { + fn from(ast: ConstDef<'a>) -> ConstDefNode { + let syntax = ast.syntax().owned(); + ConstDefNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct ConstDef<'a> { syntax: SyntaxNodeRef<'a>, @@ -486,14 +528,17 @@ impl<'a> ConstDef<'a> {} pub struct ContinueExprNode(SyntaxNode); impl ContinueExprNode { - pub fn new(ast: ContinueExpr) -> ContinueExprNode { - let syntax = ast.syntax().owned(); - ContinueExprNode(syntax) - } pub fn ast(&self) -> ContinueExpr { ContinueExpr::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for ContinueExprNode { + fn from(ast: ContinueExpr<'a>) -> ContinueExprNode { + let syntax = ast.syntax().owned(); + ContinueExprNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct ContinueExpr<'a> { syntax: SyntaxNodeRef<'a>, @@ -517,14 +562,17 @@ impl<'a> ContinueExpr<'a> {} pub struct DynTraitTypeNode(SyntaxNode); impl DynTraitTypeNode { - pub fn new(ast: DynTraitType) -> DynTraitTypeNode { - let syntax = ast.syntax().owned(); - DynTraitTypeNode(syntax) - } pub fn ast(&self) -> DynTraitType { DynTraitType::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for DynTraitTypeNode { + fn from(ast: DynTraitType<'a>) -> DynTraitTypeNode { + let syntax = ast.syntax().owned(); + DynTraitTypeNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct DynTraitType<'a> { syntax: SyntaxNodeRef<'a>, @@ -548,14 +596,17 @@ impl<'a> DynTraitType<'a> {} pub struct EnumDefNode(SyntaxNode); impl EnumDefNode { - pub fn new(ast: EnumDef) -> EnumDefNode { - let syntax = ast.syntax().owned(); - EnumDefNode(syntax) - } pub fn ast(&self) -> EnumDef { EnumDef::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for EnumDefNode { + fn from(ast: EnumDef<'a>) -> EnumDefNode { + let syntax = ast.syntax().owned(); + EnumDefNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct EnumDef<'a> { syntax: SyntaxNodeRef<'a>, @@ -582,14 +633,17 @@ impl<'a> EnumDef<'a> {} pub struct ExprNode(SyntaxNode); impl ExprNode { - pub fn new(ast: Expr) -> ExprNode { - let syntax = ast.syntax().owned(); - ExprNode(syntax) - } pub fn ast(&self) -> Expr { Expr::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for ExprNode { + fn from(ast: Expr<'a>) -> ExprNode { + let syntax = ast.syntax().owned(); + ExprNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub enum Expr<'a> { TupleExpr(TupleExpr<'a>), @@ -710,14 +764,17 @@ impl<'a> Expr<'a> {} pub struct ExprStmtNode(SyntaxNode); impl ExprStmtNode { - pub fn new(ast: ExprStmt) -> ExprStmtNode { - let syntax = ast.syntax().owned(); - ExprStmtNode(syntax) - } pub fn ast(&self) -> ExprStmt { ExprStmt::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for ExprStmtNode { + fn from(ast: ExprStmt<'a>) -> ExprStmtNode { + let syntax = ast.syntax().owned(); + ExprStmtNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct ExprStmt<'a> { syntax: SyntaxNodeRef<'a>, @@ -745,14 +802,17 @@ impl<'a> ExprStmt<'a> { pub struct ExternCrateItemNode(SyntaxNode); impl ExternCrateItemNode { - pub fn new(ast: ExternCrateItem) -> ExternCrateItemNode { - let syntax = ast.syntax().owned(); - ExternCrateItemNode(syntax) - } pub fn ast(&self) -> ExternCrateItem { ExternCrateItem::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for ExternCrateItemNode { + fn from(ast: ExternCrateItem<'a>) -> ExternCrateItemNode { + let syntax = ast.syntax().owned(); + ExternCrateItemNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct ExternCrateItem<'a> { syntax: SyntaxNodeRef<'a>, @@ -776,14 +836,17 @@ impl<'a> ExternCrateItem<'a> {} pub struct FieldExprNode(SyntaxNode); impl FieldExprNode { - pub fn new(ast: FieldExpr) -> FieldExprNode { - let syntax = ast.syntax().owned(); - FieldExprNode(syntax) - } pub fn ast(&self) -> FieldExpr { FieldExpr::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for FieldExprNode { + fn from(ast: FieldExpr<'a>) -> FieldExprNode { + let syntax = ast.syntax().owned(); + FieldExprNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct FieldExpr<'a> { syntax: SyntaxNodeRef<'a>, @@ -807,14 +870,17 @@ impl<'a> FieldExpr<'a> {} pub struct FieldPatListNode(SyntaxNode); impl FieldPatListNode { - pub fn new(ast: FieldPatList) -> FieldPatListNode { - let syntax = ast.syntax().owned(); - FieldPatListNode(syntax) - } pub fn ast(&self) -> FieldPatList { FieldPatList::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for FieldPatListNode { + fn from(ast: FieldPatList<'a>) -> FieldPatListNode { + let syntax = ast.syntax().owned(); + FieldPatListNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct FieldPatList<'a> { syntax: SyntaxNodeRef<'a>, @@ -838,14 +904,17 @@ impl<'a> FieldPatList<'a> {} pub struct FnDefNode(SyntaxNode); impl FnDefNode { - pub fn new(ast: FnDef) -> FnDefNode { - let syntax = ast.syntax().owned(); - FnDefNode(syntax) - } pub fn ast(&self) -> FnDef { FnDef::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for FnDefNode { + fn from(ast: FnDef<'a>) -> FnDefNode { + let syntax = ast.syntax().owned(); + FnDefNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct FnDef<'a> { syntax: SyntaxNodeRef<'a>, @@ -885,14 +954,17 @@ impl<'a> FnDef<'a> { pub struct FnPointerTypeNode(SyntaxNode); impl FnPointerTypeNode { - pub fn new(ast: FnPointerType) -> FnPointerTypeNode { - let syntax = ast.syntax().owned(); - FnPointerTypeNode(syntax) - } pub fn ast(&self) -> FnPointerType { FnPointerType::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for FnPointerTypeNode { + fn from(ast: FnPointerType<'a>) -> FnPointerTypeNode { + let syntax = ast.syntax().owned(); + FnPointerTypeNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct FnPointerType<'a> { syntax: SyntaxNodeRef<'a>, @@ -916,14 +988,17 @@ impl<'a> FnPointerType<'a> {} pub struct ForExprNode(SyntaxNode); impl ForExprNode { - pub fn new(ast: ForExpr) -> ForExprNode { - let syntax = ast.syntax().owned(); - ForExprNode(syntax) - } pub fn ast(&self) -> ForExpr { ForExpr::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for ForExprNode { + fn from(ast: ForExpr<'a>) -> ForExprNode { + let syntax = ast.syntax().owned(); + ForExprNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct ForExpr<'a> { syntax: SyntaxNodeRef<'a>, @@ -956,14 +1031,17 @@ impl<'a> ForExpr<'a> { pub struct ForTypeNode(SyntaxNode); impl ForTypeNode { - pub fn new(ast: ForType) -> ForTypeNode { - let syntax = ast.syntax().owned(); - ForTypeNode(syntax) - } pub fn ast(&self) -> ForType { ForType::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for ForTypeNode { + fn from(ast: ForType<'a>) -> ForTypeNode { + let syntax = ast.syntax().owned(); + ForTypeNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct ForType<'a> { syntax: SyntaxNodeRef<'a>, @@ -987,14 +1065,17 @@ impl<'a> ForType<'a> {} pub struct IfExprNode(SyntaxNode); impl IfExprNode { - pub fn new(ast: IfExpr) -> IfExprNode { - let syntax = ast.syntax().owned(); - IfExprNode(syntax) - } pub fn ast(&self) -> IfExpr { IfExpr::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for IfExprNode { + fn from(ast: IfExpr<'a>) -> IfExprNode { + let syntax = ast.syntax().owned(); + IfExprNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct IfExpr<'a> { syntax: SyntaxNodeRef<'a>, @@ -1022,14 +1103,17 @@ impl<'a> IfExpr<'a> { pub struct ImplItemNode(SyntaxNode); impl ImplItemNode { - pub fn new(ast: ImplItem) -> ImplItemNode { - let syntax = ast.syntax().owned(); - ImplItemNode(syntax) - } pub fn ast(&self) -> ImplItem { ImplItem::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for ImplItemNode { + fn from(ast: ImplItem<'a>) -> ImplItemNode { + let syntax = ast.syntax().owned(); + ImplItemNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct ImplItem<'a> { syntax: SyntaxNodeRef<'a>, @@ -1053,14 +1137,17 @@ impl<'a> ImplItem<'a> {} pub struct ImplTraitTypeNode(SyntaxNode); impl ImplTraitTypeNode { - pub fn new(ast: ImplTraitType) -> ImplTraitTypeNode { - let syntax = ast.syntax().owned(); - ImplTraitTypeNode(syntax) - } pub fn ast(&self) -> ImplTraitType { ImplTraitType::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for ImplTraitTypeNode { + fn from(ast: ImplTraitType<'a>) -> ImplTraitTypeNode { + let syntax = ast.syntax().owned(); + ImplTraitTypeNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct ImplTraitType<'a> { syntax: SyntaxNodeRef<'a>, @@ -1084,14 +1171,17 @@ impl<'a> ImplTraitType<'a> {} pub struct IndexExprNode(SyntaxNode); impl IndexExprNode { - pub fn new(ast: IndexExpr) -> IndexExprNode { - let syntax = ast.syntax().owned(); - IndexExprNode(syntax) - } pub fn ast(&self) -> IndexExpr { IndexExpr::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for IndexExprNode { + fn from(ast: IndexExpr<'a>) -> IndexExprNode { + let syntax = ast.syntax().owned(); + IndexExprNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct IndexExpr<'a> { syntax: SyntaxNodeRef<'a>, @@ -1115,14 +1205,17 @@ impl<'a> IndexExpr<'a> {} pub struct ItemListNode(SyntaxNode); impl ItemListNode { - pub fn new(ast: ItemList) -> ItemListNode { - let syntax = ast.syntax().owned(); - ItemListNode(syntax) - } pub fn ast(&self) -> ItemList { ItemList::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for ItemListNode { + fn from(ast: ItemList<'a>) -> ItemListNode { + let syntax = ast.syntax().owned(); + ItemListNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct ItemList<'a> { syntax: SyntaxNodeRef<'a>, @@ -1148,14 +1241,17 @@ impl<'a> ItemList<'a> {} pub struct LabelNode(SyntaxNode); impl LabelNode { - pub fn new(ast: Label) -> LabelNode { - let syntax = ast.syntax().owned(); - LabelNode(syntax) - } pub fn ast(&self) -> Label { Label::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for LabelNode { + fn from(ast: Label<'a>) -> LabelNode { + let syntax = ast.syntax().owned(); + LabelNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct Label<'a> { syntax: SyntaxNodeRef<'a>, @@ -1179,14 +1275,17 @@ impl<'a> Label<'a> {} pub struct LambdaExprNode(SyntaxNode); impl LambdaExprNode { - pub fn new(ast: LambdaExpr) -> LambdaExprNode { - let syntax = ast.syntax().owned(); - LambdaExprNode(syntax) - } pub fn ast(&self) -> LambdaExpr { LambdaExpr::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for LambdaExprNode { + fn from(ast: LambdaExpr<'a>) -> LambdaExprNode { + let syntax = ast.syntax().owned(); + LambdaExprNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct LambdaExpr<'a> { syntax: SyntaxNodeRef<'a>, @@ -1218,14 +1317,17 @@ impl<'a> LambdaExpr<'a> { pub struct LetStmtNode(SyntaxNode); impl LetStmtNode { - pub fn new(ast: LetStmt) -> LetStmtNode { - let syntax = ast.syntax().owned(); - LetStmtNode(syntax) - } pub fn ast(&self) -> LetStmt { LetStmt::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for LetStmtNode { + fn from(ast: LetStmt<'a>) -> LetStmtNode { + let syntax = ast.syntax().owned(); + LetStmtNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct LetStmt<'a> { syntax: SyntaxNodeRef<'a>, @@ -1257,14 +1359,17 @@ impl<'a> LetStmt<'a> { pub struct LifetimeNode(SyntaxNode); impl LifetimeNode { - pub fn new(ast: Lifetime) -> LifetimeNode { - let syntax = ast.syntax().owned(); - LifetimeNode(syntax) - } pub fn ast(&self) -> Lifetime { Lifetime::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for LifetimeNode { + fn from(ast: Lifetime<'a>) -> LifetimeNode { + let syntax = ast.syntax().owned(); + LifetimeNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct Lifetime<'a> { syntax: SyntaxNodeRef<'a>, @@ -1288,14 +1393,17 @@ impl<'a> Lifetime<'a> {} pub struct LifetimeParamNode(SyntaxNode); impl LifetimeParamNode { - pub fn new(ast: LifetimeParam) -> LifetimeParamNode { - let syntax = ast.syntax().owned(); - LifetimeParamNode(syntax) - } pub fn ast(&self) -> LifetimeParam { LifetimeParam::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for LifetimeParamNode { + fn from(ast: LifetimeParam<'a>) -> LifetimeParamNode { + let syntax = ast.syntax().owned(); + LifetimeParamNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct LifetimeParam<'a> { syntax: SyntaxNodeRef<'a>, @@ -1323,14 +1431,17 @@ impl<'a> LifetimeParam<'a> { pub struct LiteralNode(SyntaxNode); impl LiteralNode { - pub fn new(ast: Literal) -> LiteralNode { - let syntax = ast.syntax().owned(); - LiteralNode(syntax) - } pub fn ast(&self) -> Literal { Literal::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for LiteralNode { + fn from(ast: Literal<'a>) -> LiteralNode { + let syntax = ast.syntax().owned(); + LiteralNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct Literal<'a> { syntax: SyntaxNodeRef<'a>, @@ -1354,14 +1465,17 @@ impl<'a> Literal<'a> {} pub struct LoopExprNode(SyntaxNode); impl LoopExprNode { - pub fn new(ast: LoopExpr) -> LoopExprNode { - let syntax = ast.syntax().owned(); - LoopExprNode(syntax) - } pub fn ast(&self) -> LoopExpr { LoopExpr::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for LoopExprNode { + fn from(ast: LoopExpr<'a>) -> LoopExprNode { + let syntax = ast.syntax().owned(); + LoopExprNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct LoopExpr<'a> { syntax: SyntaxNodeRef<'a>, @@ -1386,14 +1500,17 @@ impl<'a> LoopExpr<'a> {} pub struct MatchArmNode(SyntaxNode); impl MatchArmNode { - pub fn new(ast: MatchArm) -> MatchArmNode { - let syntax = ast.syntax().owned(); - MatchArmNode(syntax) - } pub fn ast(&self) -> MatchArm { MatchArm::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for MatchArmNode { + fn from(ast: MatchArm<'a>) -> MatchArmNode { + let syntax = ast.syntax().owned(); + MatchArmNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct MatchArm<'a> { syntax: SyntaxNodeRef<'a>, @@ -1429,14 +1546,17 @@ impl<'a> MatchArm<'a> { pub struct MatchArmListNode(SyntaxNode); impl MatchArmListNode { - pub fn new(ast: MatchArmList) -> MatchArmListNode { - let syntax = ast.syntax().owned(); - MatchArmListNode(syntax) - } pub fn ast(&self) -> MatchArmList { MatchArmList::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for MatchArmListNode { + fn from(ast: MatchArmList<'a>) -> MatchArmListNode { + let syntax = ast.syntax().owned(); + MatchArmListNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct MatchArmList<'a> { syntax: SyntaxNodeRef<'a>, @@ -1464,14 +1584,17 @@ impl<'a> MatchArmList<'a> { pub struct MatchExprNode(SyntaxNode); impl MatchExprNode { - pub fn new(ast: MatchExpr) -> MatchExprNode { - let syntax = ast.syntax().owned(); - MatchExprNode(syntax) - } pub fn ast(&self) -> MatchExpr { MatchExpr::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for MatchExprNode { + fn from(ast: MatchExpr<'a>) -> MatchExprNode { + let syntax = ast.syntax().owned(); + MatchExprNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct MatchExpr<'a> { syntax: SyntaxNodeRef<'a>, @@ -1503,14 +1626,17 @@ impl<'a> MatchExpr<'a> { pub struct MatchGuardNode(SyntaxNode); impl MatchGuardNode { - pub fn new(ast: MatchGuard) -> MatchGuardNode { - let syntax = ast.syntax().owned(); - MatchGuardNode(syntax) - } pub fn ast(&self) -> MatchGuard { MatchGuard::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for MatchGuardNode { + fn from(ast: MatchGuard<'a>) -> MatchGuardNode { + let syntax = ast.syntax().owned(); + MatchGuardNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct MatchGuard<'a> { syntax: SyntaxNodeRef<'a>, @@ -1534,14 +1660,17 @@ impl<'a> MatchGuard<'a> {} pub struct MethodCallExprNode(SyntaxNode); impl MethodCallExprNode { - pub fn new(ast: MethodCallExpr) -> MethodCallExprNode { - let syntax = ast.syntax().owned(); - MethodCallExprNode(syntax) - } pub fn ast(&self) -> MethodCallExpr { MethodCallExpr::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for MethodCallExprNode { + fn from(ast: MethodCallExpr<'a>) -> MethodCallExprNode { + let syntax = ast.syntax().owned(); + MethodCallExprNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct MethodCallExpr<'a> { syntax: SyntaxNodeRef<'a>, @@ -1570,14 +1699,17 @@ impl<'a> MethodCallExpr<'a> { pub struct ModuleNode(SyntaxNode); impl ModuleNode { - pub fn new(ast: Module) -> ModuleNode { - let syntax = ast.syntax().owned(); - ModuleNode(syntax) - } pub fn ast(&self) -> Module { Module::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for ModuleNode { + fn from(ast: Module<'a>) -> ModuleNode { + let syntax = ast.syntax().owned(); + ModuleNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct Module<'a> { syntax: SyntaxNodeRef<'a>, @@ -1607,14 +1739,17 @@ impl<'a> Module<'a> { pub struct ModuleItemNode(SyntaxNode); impl ModuleItemNode { - pub fn new(ast: ModuleItem) -> ModuleItemNode { - let syntax = ast.syntax().owned(); - ModuleItemNode(syntax) - } pub fn ast(&self) -> ModuleItem { ModuleItem::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for ModuleItemNode { + fn from(ast: ModuleItem<'a>) -> ModuleItemNode { + let syntax = ast.syntax().owned(); + ModuleItemNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub enum ModuleItem<'a> { StructDef(StructDef<'a>), @@ -1672,14 +1807,17 @@ impl<'a> ModuleItem<'a> {} pub struct NameNode(SyntaxNode); impl NameNode { - pub fn new(ast: Name) -> NameNode { - let syntax = ast.syntax().owned(); - NameNode(syntax) - } pub fn ast(&self) -> Name { Name::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for NameNode { + fn from(ast: Name<'a>) -> NameNode { + let syntax = ast.syntax().owned(); + NameNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct Name<'a> { syntax: SyntaxNodeRef<'a>, @@ -1703,14 +1841,17 @@ impl<'a> Name<'a> {} pub struct NameRefNode(SyntaxNode); impl NameRefNode { - pub fn new(ast: NameRef) -> NameRefNode { - let syntax = ast.syntax().owned(); - NameRefNode(syntax) - } pub fn ast(&self) -> NameRef { NameRef::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for NameRefNode { + fn from(ast: NameRef<'a>) -> NameRefNode { + let syntax = ast.syntax().owned(); + NameRefNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct NameRef<'a> { syntax: SyntaxNodeRef<'a>, @@ -1734,14 +1875,17 @@ impl<'a> NameRef<'a> {} pub struct NamedFieldNode(SyntaxNode); impl NamedFieldNode { - pub fn new(ast: NamedField) -> NamedFieldNode { - let syntax = ast.syntax().owned(); - NamedFieldNode(syntax) - } pub fn ast(&self) -> NamedField { NamedField::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for NamedFieldNode { + fn from(ast: NamedField<'a>) -> NamedFieldNode { + let syntax = ast.syntax().owned(); + NamedFieldNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct NamedField<'a> { syntax: SyntaxNodeRef<'a>, @@ -1765,14 +1909,17 @@ impl<'a> NamedField<'a> {} pub struct NamedFieldDefNode(SyntaxNode); impl NamedFieldDefNode { - pub fn new(ast: NamedFieldDef) -> NamedFieldDefNode { - let syntax = ast.syntax().owned(); - NamedFieldDefNode(syntax) - } pub fn ast(&self) -> NamedFieldDef { NamedFieldDef::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for NamedFieldDefNode { + fn from(ast: NamedFieldDef<'a>) -> NamedFieldDefNode { + let syntax = ast.syntax().owned(); + NamedFieldDefNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct NamedFieldDef<'a> { syntax: SyntaxNodeRef<'a>, @@ -1798,14 +1945,17 @@ impl<'a> NamedFieldDef<'a> {} pub struct NamedFieldListNode(SyntaxNode); impl NamedFieldListNode { - pub fn new(ast: NamedFieldList) -> NamedFieldListNode { - let syntax = ast.syntax().owned(); - NamedFieldListNode(syntax) - } pub fn ast(&self) -> NamedFieldList { NamedFieldList::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for NamedFieldListNode { + fn from(ast: NamedFieldList<'a>) -> NamedFieldListNode { + let syntax = ast.syntax().owned(); + NamedFieldListNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct NamedFieldList<'a> { syntax: SyntaxNodeRef<'a>, @@ -1829,14 +1979,17 @@ impl<'a> NamedFieldList<'a> {} pub struct NeverTypeNode(SyntaxNode); impl NeverTypeNode { - pub fn new(ast: NeverType) -> NeverTypeNode { - let syntax = ast.syntax().owned(); - NeverTypeNode(syntax) - } pub fn ast(&self) -> NeverType { NeverType::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for NeverTypeNode { + fn from(ast: NeverType<'a>) -> NeverTypeNode { + let syntax = ast.syntax().owned(); + NeverTypeNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct NeverType<'a> { syntax: SyntaxNodeRef<'a>, @@ -1860,14 +2013,17 @@ impl<'a> NeverType<'a> {} pub struct NominalDefNode(SyntaxNode); impl NominalDefNode { - pub fn new(ast: NominalDef) -> NominalDefNode { - let syntax = ast.syntax().owned(); - NominalDefNode(syntax) - } pub fn ast(&self) -> NominalDef { NominalDef::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for NominalDefNode { + fn from(ast: NominalDef<'a>) -> NominalDefNode { + let syntax = ast.syntax().owned(); + NominalDefNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub enum NominalDef<'a> { StructDef(StructDef<'a>), @@ -1901,14 +2057,17 @@ impl<'a> NominalDef<'a> {} pub struct ParamNode(SyntaxNode); impl ParamNode { - pub fn new(ast: Param) -> ParamNode { - let syntax = ast.syntax().owned(); - ParamNode(syntax) - } pub fn ast(&self) -> Param { Param::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for ParamNode { + fn from(ast: Param<'a>) -> ParamNode { + let syntax = ast.syntax().owned(); + ParamNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct Param<'a> { syntax: SyntaxNodeRef<'a>, @@ -1936,14 +2095,17 @@ impl<'a> Param<'a> { pub struct ParamListNode(SyntaxNode); impl ParamListNode { - pub fn new(ast: ParamList) -> ParamListNode { - let syntax = ast.syntax().owned(); - ParamListNode(syntax) - } pub fn ast(&self) -> ParamList { ParamList::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for ParamListNode { + fn from(ast: ParamList<'a>) -> ParamListNode { + let syntax = ast.syntax().owned(); + ParamListNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct ParamList<'a> { syntax: SyntaxNodeRef<'a>, @@ -1975,14 +2137,17 @@ impl<'a> ParamList<'a> { pub struct ParenExprNode(SyntaxNode); impl ParenExprNode { - pub fn new(ast: ParenExpr) -> ParenExprNode { - let syntax = ast.syntax().owned(); - ParenExprNode(syntax) - } pub fn ast(&self) -> ParenExpr { ParenExpr::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for ParenExprNode { + fn from(ast: ParenExpr<'a>) -> ParenExprNode { + let syntax = ast.syntax().owned(); + ParenExprNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct ParenExpr<'a> { syntax: SyntaxNodeRef<'a>, @@ -2006,14 +2171,17 @@ impl<'a> ParenExpr<'a> {} pub struct ParenTypeNode(SyntaxNode); impl ParenTypeNode { - pub fn new(ast: ParenType) -> ParenTypeNode { - let syntax = ast.syntax().owned(); - ParenTypeNode(syntax) - } pub fn ast(&self) -> ParenType { ParenType::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for ParenTypeNode { + fn from(ast: ParenType<'a>) -> ParenTypeNode { + let syntax = ast.syntax().owned(); + ParenTypeNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct ParenType<'a> { syntax: SyntaxNodeRef<'a>, @@ -2037,14 +2205,17 @@ impl<'a> ParenType<'a> {} pub struct PatNode(SyntaxNode); impl PatNode { - pub fn new(ast: Pat) -> PatNode { - let syntax = ast.syntax().owned(); - PatNode(syntax) - } pub fn ast(&self) -> Pat { Pat::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for PatNode { + fn from(ast: Pat<'a>) -> PatNode { + let syntax = ast.syntax().owned(); + PatNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub enum Pat<'a> { RefPat(RefPat<'a>), @@ -2099,14 +2270,17 @@ impl<'a> Pat<'a> {} pub struct PathNode(SyntaxNode); impl PathNode { - pub fn new(ast: Path) -> PathNode { - let syntax = ast.syntax().owned(); - PathNode(syntax) - } pub fn ast(&self) -> Path { Path::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for PathNode { + fn from(ast: Path<'a>) -> PathNode { + let syntax = ast.syntax().owned(); + PathNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct Path<'a> { syntax: SyntaxNodeRef<'a>, @@ -2138,14 +2312,17 @@ impl<'a> Path<'a> { pub struct PathExprNode(SyntaxNode); impl PathExprNode { - pub fn new(ast: PathExpr) -> PathExprNode { - let syntax = ast.syntax().owned(); - PathExprNode(syntax) - } pub fn ast(&self) -> PathExpr { PathExpr::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for PathExprNode { + fn from(ast: PathExpr<'a>) -> PathExprNode { + let syntax = ast.syntax().owned(); + PathExprNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct PathExpr<'a> { syntax: SyntaxNodeRef<'a>, @@ -2173,14 +2350,17 @@ impl<'a> PathExpr<'a> { pub struct PathPatNode(SyntaxNode); impl PathPatNode { - pub fn new(ast: PathPat) -> PathPatNode { - let syntax = ast.syntax().owned(); - PathPatNode(syntax) - } pub fn ast(&self) -> PathPat { PathPat::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for PathPatNode { + fn from(ast: PathPat<'a>) -> PathPatNode { + let syntax = ast.syntax().owned(); + PathPatNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct PathPat<'a> { syntax: SyntaxNodeRef<'a>, @@ -2204,14 +2384,17 @@ impl<'a> PathPat<'a> {} pub struct PathSegmentNode(SyntaxNode); impl PathSegmentNode { - pub fn new(ast: PathSegment) -> PathSegmentNode { - let syntax = ast.syntax().owned(); - PathSegmentNode(syntax) - } pub fn ast(&self) -> PathSegment { PathSegment::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for PathSegmentNode { + fn from(ast: PathSegment<'a>) -> PathSegmentNode { + let syntax = ast.syntax().owned(); + PathSegmentNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct PathSegment<'a> { syntax: SyntaxNodeRef<'a>, @@ -2239,14 +2422,17 @@ impl<'a> PathSegment<'a> { pub struct PathTypeNode(SyntaxNode); impl PathTypeNode { - pub fn new(ast: PathType) -> PathTypeNode { - let syntax = ast.syntax().owned(); - PathTypeNode(syntax) - } pub fn ast(&self) -> PathType { PathType::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for PathTypeNode { + fn from(ast: PathType<'a>) -> PathTypeNode { + let syntax = ast.syntax().owned(); + PathTypeNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct PathType<'a> { syntax: SyntaxNodeRef<'a>, @@ -2270,14 +2456,17 @@ impl<'a> PathType<'a> {} pub struct PlaceholderPatNode(SyntaxNode); impl PlaceholderPatNode { - pub fn new(ast: PlaceholderPat) -> PlaceholderPatNode { - let syntax = ast.syntax().owned(); - PlaceholderPatNode(syntax) - } pub fn ast(&self) -> PlaceholderPat { PlaceholderPat::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for PlaceholderPatNode { + fn from(ast: PlaceholderPat<'a>) -> PlaceholderPatNode { + let syntax = ast.syntax().owned(); + PlaceholderPatNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct PlaceholderPat<'a> { syntax: SyntaxNodeRef<'a>, @@ -2301,14 +2490,17 @@ impl<'a> PlaceholderPat<'a> {} pub struct PlaceholderTypeNode(SyntaxNode); impl PlaceholderTypeNode { - pub fn new(ast: PlaceholderType) -> PlaceholderTypeNode { - let syntax = ast.syntax().owned(); - PlaceholderTypeNode(syntax) - } pub fn ast(&self) -> PlaceholderType { PlaceholderType::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for PlaceholderTypeNode { + fn from(ast: PlaceholderType<'a>) -> PlaceholderTypeNode { + let syntax = ast.syntax().owned(); + PlaceholderTypeNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct PlaceholderType<'a> { syntax: SyntaxNodeRef<'a>, @@ -2332,14 +2524,17 @@ impl<'a> PlaceholderType<'a> {} pub struct PointerTypeNode(SyntaxNode); impl PointerTypeNode { - pub fn new(ast: PointerType) -> PointerTypeNode { - let syntax = ast.syntax().owned(); - PointerTypeNode(syntax) - } pub fn ast(&self) -> PointerType { PointerType::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for PointerTypeNode { + fn from(ast: PointerType<'a>) -> PointerTypeNode { + let syntax = ast.syntax().owned(); + PointerTypeNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct PointerType<'a> { syntax: SyntaxNodeRef<'a>, @@ -2363,14 +2558,17 @@ impl<'a> PointerType<'a> {} pub struct PrefixExprNode(SyntaxNode); impl PrefixExprNode { - pub fn new(ast: PrefixExpr) -> PrefixExprNode { - let syntax = ast.syntax().owned(); - PrefixExprNode(syntax) - } pub fn ast(&self) -> PrefixExpr { PrefixExpr::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for PrefixExprNode { + fn from(ast: PrefixExpr<'a>) -> PrefixExprNode { + let syntax = ast.syntax().owned(); + PrefixExprNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct PrefixExpr<'a> { syntax: SyntaxNodeRef<'a>, @@ -2394,14 +2592,17 @@ impl<'a> PrefixExpr<'a> {} pub struct RangeExprNode(SyntaxNode); impl RangeExprNode { - pub fn new(ast: RangeExpr) -> RangeExprNode { - let syntax = ast.syntax().owned(); - RangeExprNode(syntax) - } pub fn ast(&self) -> RangeExpr { RangeExpr::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for RangeExprNode { + fn from(ast: RangeExpr<'a>) -> RangeExprNode { + let syntax = ast.syntax().owned(); + RangeExprNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct RangeExpr<'a> { syntax: SyntaxNodeRef<'a>, @@ -2425,14 +2626,17 @@ impl<'a> RangeExpr<'a> {} pub struct RangePatNode(SyntaxNode); impl RangePatNode { - pub fn new(ast: RangePat) -> RangePatNode { - let syntax = ast.syntax().owned(); - RangePatNode(syntax) - } pub fn ast(&self) -> RangePat { RangePat::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for RangePatNode { + fn from(ast: RangePat<'a>) -> RangePatNode { + let syntax = ast.syntax().owned(); + RangePatNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct RangePat<'a> { syntax: SyntaxNodeRef<'a>, @@ -2456,14 +2660,17 @@ impl<'a> RangePat<'a> {} pub struct RefExprNode(SyntaxNode); impl RefExprNode { - pub fn new(ast: RefExpr) -> RefExprNode { - let syntax = ast.syntax().owned(); - RefExprNode(syntax) - } pub fn ast(&self) -> RefExpr { RefExpr::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for RefExprNode { + fn from(ast: RefExpr<'a>) -> RefExprNode { + let syntax = ast.syntax().owned(); + RefExprNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct RefExpr<'a> { syntax: SyntaxNodeRef<'a>, @@ -2487,14 +2694,17 @@ impl<'a> RefExpr<'a> {} pub struct RefPatNode(SyntaxNode); impl RefPatNode { - pub fn new(ast: RefPat) -> RefPatNode { - let syntax = ast.syntax().owned(); - RefPatNode(syntax) - } pub fn ast(&self) -> RefPat { RefPat::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for RefPatNode { + fn from(ast: RefPat<'a>) -> RefPatNode { + let syntax = ast.syntax().owned(); + RefPatNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct RefPat<'a> { syntax: SyntaxNodeRef<'a>, @@ -2518,14 +2728,17 @@ impl<'a> RefPat<'a> {} pub struct ReferenceTypeNode(SyntaxNode); impl ReferenceTypeNode { - pub fn new(ast: ReferenceType) -> ReferenceTypeNode { - let syntax = ast.syntax().owned(); - ReferenceTypeNode(syntax) - } pub fn ast(&self) -> ReferenceType { ReferenceType::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for ReferenceTypeNode { + fn from(ast: ReferenceType<'a>) -> ReferenceTypeNode { + let syntax = ast.syntax().owned(); + ReferenceTypeNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct ReferenceType<'a> { syntax: SyntaxNodeRef<'a>, @@ -2549,14 +2762,17 @@ impl<'a> ReferenceType<'a> {} pub struct RetTypeNode(SyntaxNode); impl RetTypeNode { - pub fn new(ast: RetType) -> RetTypeNode { - let syntax = ast.syntax().owned(); - RetTypeNode(syntax) - } pub fn ast(&self) -> RetType { RetType::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for RetTypeNode { + fn from(ast: RetType<'a>) -> RetTypeNode { + let syntax = ast.syntax().owned(); + RetTypeNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct RetType<'a> { syntax: SyntaxNodeRef<'a>, @@ -2580,14 +2796,17 @@ impl<'a> RetType<'a> {} pub struct ReturnExprNode(SyntaxNode); impl ReturnExprNode { - pub fn new(ast: ReturnExpr) -> ReturnExprNode { - let syntax = ast.syntax().owned(); - ReturnExprNode(syntax) - } pub fn ast(&self) -> ReturnExpr { ReturnExpr::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for ReturnExprNode { + fn from(ast: ReturnExpr<'a>) -> ReturnExprNode { + let syntax = ast.syntax().owned(); + ReturnExprNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct ReturnExpr<'a> { syntax: SyntaxNodeRef<'a>, @@ -2611,14 +2830,17 @@ impl<'a> ReturnExpr<'a> {} pub struct RootNode(SyntaxNode); impl RootNode { - pub fn new(ast: Root) -> RootNode { - let syntax = ast.syntax().owned(); - RootNode(syntax) - } pub fn ast(&self) -> Root { Root::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for RootNode { + fn from(ast: Root<'a>) -> RootNode { + let syntax = ast.syntax().owned(); + RootNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct Root<'a> { syntax: SyntaxNodeRef<'a>, @@ -2648,14 +2870,17 @@ impl<'a> Root<'a> { pub struct SelfParamNode(SyntaxNode); impl SelfParamNode { - pub fn new(ast: SelfParam) -> SelfParamNode { - let syntax = ast.syntax().owned(); - SelfParamNode(syntax) - } pub fn ast(&self) -> SelfParam { SelfParam::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for SelfParamNode { + fn from(ast: SelfParam<'a>) -> SelfParamNode { + let syntax = ast.syntax().owned(); + SelfParamNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct SelfParam<'a> { syntax: SyntaxNodeRef<'a>, @@ -2679,14 +2904,17 @@ impl<'a> SelfParam<'a> {} pub struct SlicePatNode(SyntaxNode); impl SlicePatNode { - pub fn new(ast: SlicePat) -> SlicePatNode { - let syntax = ast.syntax().owned(); - SlicePatNode(syntax) - } pub fn ast(&self) -> SlicePat { SlicePat::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for SlicePatNode { + fn from(ast: SlicePat<'a>) -> SlicePatNode { + let syntax = ast.syntax().owned(); + SlicePatNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct SlicePat<'a> { syntax: SyntaxNodeRef<'a>, @@ -2710,14 +2938,17 @@ impl<'a> SlicePat<'a> {} pub struct SliceTypeNode(SyntaxNode); impl SliceTypeNode { - pub fn new(ast: SliceType) -> SliceTypeNode { - let syntax = ast.syntax().owned(); - SliceTypeNode(syntax) - } pub fn ast(&self) -> SliceType { SliceType::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for SliceTypeNode { + fn from(ast: SliceType<'a>) -> SliceTypeNode { + let syntax = ast.syntax().owned(); + SliceTypeNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct SliceType<'a> { syntax: SyntaxNodeRef<'a>, @@ -2741,14 +2972,17 @@ impl<'a> SliceType<'a> {} pub struct StaticDefNode(SyntaxNode); impl StaticDefNode { - pub fn new(ast: StaticDef) -> StaticDefNode { - let syntax = ast.syntax().owned(); - StaticDefNode(syntax) - } pub fn ast(&self) -> StaticDef { StaticDef::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for StaticDefNode { + fn from(ast: StaticDef<'a>) -> StaticDefNode { + let syntax = ast.syntax().owned(); + StaticDefNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct StaticDef<'a> { syntax: SyntaxNodeRef<'a>, @@ -2775,14 +3009,17 @@ impl<'a> StaticDef<'a> {} pub struct StmtNode(SyntaxNode); impl StmtNode { - pub fn new(ast: Stmt) -> StmtNode { - let syntax = ast.syntax().owned(); - StmtNode(syntax) - } pub fn ast(&self) -> Stmt { Stmt::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for StmtNode { + fn from(ast: Stmt<'a>) -> StmtNode { + let syntax = ast.syntax().owned(); + StmtNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub enum Stmt<'a> { ExprStmt(ExprStmt<'a>), @@ -2813,14 +3050,17 @@ impl<'a> Stmt<'a> {} pub struct StructDefNode(SyntaxNode); impl StructDefNode { - pub fn new(ast: StructDef) -> StructDefNode { - let syntax = ast.syntax().owned(); - StructDefNode(syntax) - } pub fn ast(&self) -> StructDef { StructDef::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for StructDefNode { + fn from(ast: StructDef<'a>) -> StructDefNode { + let syntax = ast.syntax().owned(); + StructDefNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct StructDef<'a> { syntax: SyntaxNodeRef<'a>, @@ -2851,14 +3091,17 @@ impl<'a> StructDef<'a> { pub struct StructLitNode(SyntaxNode); impl StructLitNode { - pub fn new(ast: StructLit) -> StructLitNode { - let syntax = ast.syntax().owned(); - StructLitNode(syntax) - } pub fn ast(&self) -> StructLit { StructLit::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for StructLitNode { + fn from(ast: StructLit<'a>) -> StructLitNode { + let syntax = ast.syntax().owned(); + StructLitNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct StructLit<'a> { syntax: SyntaxNodeRef<'a>, @@ -2882,14 +3125,17 @@ impl<'a> StructLit<'a> {} pub struct StructPatNode(SyntaxNode); impl StructPatNode { - pub fn new(ast: StructPat) -> StructPatNode { - let syntax = ast.syntax().owned(); - StructPatNode(syntax) - } pub fn ast(&self) -> StructPat { StructPat::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for StructPatNode { + fn from(ast: StructPat<'a>) -> StructPatNode { + let syntax = ast.syntax().owned(); + StructPatNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct StructPat<'a> { syntax: SyntaxNodeRef<'a>, @@ -2913,14 +3159,17 @@ impl<'a> StructPat<'a> {} pub struct TokenTreeNode(SyntaxNode); impl TokenTreeNode { - pub fn new(ast: TokenTree) -> TokenTreeNode { - let syntax = ast.syntax().owned(); - TokenTreeNode(syntax) - } pub fn ast(&self) -> TokenTree { TokenTree::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for TokenTreeNode { + fn from(ast: TokenTree<'a>) -> TokenTreeNode { + let syntax = ast.syntax().owned(); + TokenTreeNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct TokenTree<'a> { syntax: SyntaxNodeRef<'a>, @@ -2944,14 +3193,17 @@ impl<'a> TokenTree<'a> {} pub struct TraitDefNode(SyntaxNode); impl TraitDefNode { - pub fn new(ast: TraitDef) -> TraitDefNode { - let syntax = ast.syntax().owned(); - TraitDefNode(syntax) - } pub fn ast(&self) -> TraitDef { TraitDef::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for TraitDefNode { + fn from(ast: TraitDef<'a>) -> TraitDefNode { + let syntax = ast.syntax().owned(); + TraitDefNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct TraitDef<'a> { syntax: SyntaxNodeRef<'a>, @@ -2977,14 +3229,17 @@ impl<'a> TraitDef<'a> {} pub struct TryExprNode(SyntaxNode); impl TryExprNode { - pub fn new(ast: TryExpr) -> TryExprNode { - let syntax = ast.syntax().owned(); - TryExprNode(syntax) - } pub fn ast(&self) -> TryExpr { TryExpr::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for TryExprNode { + fn from(ast: TryExpr<'a>) -> TryExprNode { + let syntax = ast.syntax().owned(); + TryExprNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct TryExpr<'a> { syntax: SyntaxNodeRef<'a>, @@ -3008,14 +3263,17 @@ impl<'a> TryExpr<'a> {} pub struct TupleExprNode(SyntaxNode); impl TupleExprNode { - pub fn new(ast: TupleExpr) -> TupleExprNode { - let syntax = ast.syntax().owned(); - TupleExprNode(syntax) - } pub fn ast(&self) -> TupleExpr { TupleExpr::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for TupleExprNode { + fn from(ast: TupleExpr<'a>) -> TupleExprNode { + let syntax = ast.syntax().owned(); + TupleExprNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct TupleExpr<'a> { syntax: SyntaxNodeRef<'a>, @@ -3039,14 +3297,17 @@ impl<'a> TupleExpr<'a> {} pub struct TuplePatNode(SyntaxNode); impl TuplePatNode { - pub fn new(ast: TuplePat) -> TuplePatNode { - let syntax = ast.syntax().owned(); - TuplePatNode(syntax) - } pub fn ast(&self) -> TuplePat { TuplePat::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for TuplePatNode { + fn from(ast: TuplePat<'a>) -> TuplePatNode { + let syntax = ast.syntax().owned(); + TuplePatNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct TuplePat<'a> { syntax: SyntaxNodeRef<'a>, @@ -3070,14 +3331,17 @@ impl<'a> TuplePat<'a> {} pub struct TupleStructPatNode(SyntaxNode); impl TupleStructPatNode { - pub fn new(ast: TupleStructPat) -> TupleStructPatNode { - let syntax = ast.syntax().owned(); - TupleStructPatNode(syntax) - } pub fn ast(&self) -> TupleStructPat { TupleStructPat::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for TupleStructPatNode { + fn from(ast: TupleStructPat<'a>) -> TupleStructPatNode { + let syntax = ast.syntax().owned(); + TupleStructPatNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct TupleStructPat<'a> { syntax: SyntaxNodeRef<'a>, @@ -3101,14 +3365,17 @@ impl<'a> TupleStructPat<'a> {} pub struct TupleTypeNode(SyntaxNode); impl TupleTypeNode { - pub fn new(ast: TupleType) -> TupleTypeNode { - let syntax = ast.syntax().owned(); - TupleTypeNode(syntax) - } pub fn ast(&self) -> TupleType { TupleType::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for TupleTypeNode { + fn from(ast: TupleType<'a>) -> TupleTypeNode { + let syntax = ast.syntax().owned(); + TupleTypeNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct TupleType<'a> { syntax: SyntaxNodeRef<'a>, @@ -3132,14 +3399,17 @@ impl<'a> TupleType<'a> {} pub struct TypeDefNode(SyntaxNode); impl TypeDefNode { - pub fn new(ast: TypeDef) -> TypeDefNode { - let syntax = ast.syntax().owned(); - TypeDefNode(syntax) - } pub fn ast(&self) -> TypeDef { TypeDef::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for TypeDefNode { + fn from(ast: TypeDef<'a>) -> TypeDefNode { + let syntax = ast.syntax().owned(); + TypeDefNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct TypeDef<'a> { syntax: SyntaxNodeRef<'a>, @@ -3166,14 +3436,17 @@ impl<'a> TypeDef<'a> {} pub struct TypeParamNode(SyntaxNode); impl TypeParamNode { - pub fn new(ast: TypeParam) -> TypeParamNode { - let syntax = ast.syntax().owned(); - TypeParamNode(syntax) - } pub fn ast(&self) -> TypeParam { TypeParam::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for TypeParamNode { + fn from(ast: TypeParam<'a>) -> TypeParamNode { + let syntax = ast.syntax().owned(); + TypeParamNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct TypeParam<'a> { syntax: SyntaxNodeRef<'a>, @@ -3198,14 +3471,17 @@ impl<'a> TypeParam<'a> {} pub struct TypeParamListNode(SyntaxNode); impl TypeParamListNode { - pub fn new(ast: TypeParamList) -> TypeParamListNode { - let syntax = ast.syntax().owned(); - TypeParamListNode(syntax) - } pub fn ast(&self) -> TypeParamList { TypeParamList::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for TypeParamListNode { + fn from(ast: TypeParamList<'a>) -> TypeParamListNode { + let syntax = ast.syntax().owned(); + TypeParamListNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct TypeParamList<'a> { syntax: SyntaxNodeRef<'a>, @@ -3237,14 +3513,17 @@ impl<'a> TypeParamList<'a> { pub struct TypeRefNode(SyntaxNode); impl TypeRefNode { - pub fn new(ast: TypeRef) -> TypeRefNode { - let syntax = ast.syntax().owned(); - TypeRefNode(syntax) - } pub fn ast(&self) -> TypeRef { TypeRef::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for TypeRefNode { + fn from(ast: TypeRef<'a>) -> TypeRefNode { + let syntax = ast.syntax().owned(); + TypeRefNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub enum TypeRef<'a> { ParenType(ParenType<'a>), @@ -3308,14 +3587,17 @@ impl<'a> TypeRef<'a> {} pub struct UseItemNode(SyntaxNode); impl UseItemNode { - pub fn new(ast: UseItem) -> UseItemNode { - let syntax = ast.syntax().owned(); - UseItemNode(syntax) - } pub fn ast(&self) -> UseItem { UseItem::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for UseItemNode { + fn from(ast: UseItem<'a>) -> UseItemNode { + let syntax = ast.syntax().owned(); + UseItemNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct UseItem<'a> { syntax: SyntaxNodeRef<'a>, @@ -3343,14 +3625,17 @@ impl<'a> UseItem<'a> { pub struct UseTreeNode(SyntaxNode); impl UseTreeNode { - pub fn new(ast: UseTree) -> UseTreeNode { - let syntax = ast.syntax().owned(); - UseTreeNode(syntax) - } pub fn ast(&self) -> UseTree { UseTree::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for UseTreeNode { + fn from(ast: UseTree<'a>) -> UseTreeNode { + let syntax = ast.syntax().owned(); + UseTreeNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct UseTree<'a> { syntax: SyntaxNodeRef<'a>, @@ -3382,14 +3667,17 @@ impl<'a> UseTree<'a> { pub struct UseTreeListNode(SyntaxNode); impl UseTreeListNode { - pub fn new(ast: UseTreeList) -> UseTreeListNode { - let syntax = ast.syntax().owned(); - UseTreeListNode(syntax) - } pub fn ast(&self) -> UseTreeList { UseTreeList::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for UseTreeListNode { + fn from(ast: UseTreeList<'a>) -> UseTreeListNode { + let syntax = ast.syntax().owned(); + UseTreeListNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct UseTreeList<'a> { syntax: SyntaxNodeRef<'a>, @@ -3417,14 +3705,17 @@ impl<'a> UseTreeList<'a> { pub struct WhereClauseNode(SyntaxNode); impl WhereClauseNode { - pub fn new(ast: WhereClause) -> WhereClauseNode { - let syntax = ast.syntax().owned(); - WhereClauseNode(syntax) - } pub fn ast(&self) -> WhereClause { WhereClause::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for WhereClauseNode { + fn from(ast: WhereClause<'a>) -> WhereClauseNode { + let syntax = ast.syntax().owned(); + WhereClauseNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct WhereClause<'a> { syntax: SyntaxNodeRef<'a>, @@ -3448,14 +3739,17 @@ impl<'a> WhereClause<'a> {} pub struct WhileExprNode(SyntaxNode); impl WhileExprNode { - pub fn new(ast: WhileExpr) -> WhileExprNode { - let syntax = ast.syntax().owned(); - WhileExprNode(syntax) - } pub fn ast(&self) -> WhileExpr { WhileExpr::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for WhileExprNode { + fn from(ast: WhileExpr<'a>) -> WhileExprNode { + let syntax = ast.syntax().owned(); + WhileExprNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct WhileExpr<'a> { syntax: SyntaxNodeRef<'a>, @@ -3484,14 +3778,17 @@ impl<'a> WhileExpr<'a> { pub struct WhitespaceNode(SyntaxNode); impl WhitespaceNode { - pub fn new(ast: Whitespace) -> WhitespaceNode { - let syntax = ast.syntax().owned(); - WhitespaceNode(syntax) - } pub fn ast(&self) -> Whitespace { Whitespace::cast(self.0.borrowed()).unwrap() } } + +impl<'a> From> for WhitespaceNode { + fn from(ast: Whitespace<'a>) -> WhitespaceNode { + let syntax = ast.syntax().owned(); + WhitespaceNode(syntax) + } +} #[derive(Debug, Clone, Copy)] pub struct Whitespace<'a> { syntax: SyntaxNodeRef<'a>, diff --git a/crates/ra_syntax/src/ast/generated.rs.tera b/crates/ra_syntax/src/ast/generated.rs.tera index d30038cba..1321f0def 100644 --- a/crates/ra_syntax/src/ast/generated.rs.tera +++ b/crates/ra_syntax/src/ast/generated.rs.tera @@ -17,15 +17,18 @@ use crate::{ pub struct {{ node }}Node(SyntaxNode); impl {{ node }}Node { - pub fn new(ast: {{ node }}) -> {{ node }}Node { - let syntax = ast.syntax().owned(); - {{ node }}Node(syntax) - } pub fn ast(&self) -> {{ node }} { {{ node }}::cast(self.0.borrowed()).unwrap() } } +impl<'a> From<{{ node }}<'a>> for {{ node }}Node { + fn from(ast: {{ node}}<'a>) -> {{ node }}Node { + let syntax = ast.syntax().owned(); + {{ node }}Node(syntax) + } +} + {%- if methods.enum %} #[derive(Debug, Clone, Copy)] pub enum {{ node }}<'a> { -- cgit v1.2.3