From 2e354f480b0b83debc06a4311a9709cd8c0df305 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 25 Jan 2019 02:09:31 +0300 Subject: use ToOwned trait instead of inherent method --- crates/ra_syntax/src/ast.rs | 5 +- crates/ra_syntax/src/ast/generated.rs | 496 +++++++++++++++++++++++++++++ crates/ra_syntax/src/ast/generated.rs.tera | 8 + crates/ra_syntax/src/yellow.rs | 22 +- 4 files changed, 523 insertions(+), 8 deletions(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index bcbd4c60c..b92cc082e 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs @@ -15,12 +15,13 @@ use crate::{ /// conversion itself has zero runtime cost: ast and syntax nodes have exactly /// the same representation: a pointer to the tree root and a pointer to the /// node itself. -pub trait AstNode: rowan::TransparentNewType> { +pub trait AstNode: + rowan::TransparentNewType> + ToOwned> +{ fn cast(syntax: &SyntaxNode) -> Option<&Self> where Self: Sized; fn syntax(&self) -> &SyntaxNode; - fn to_owned(&self) -> TreeArc; } pub trait AstToken: AstNode { diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index ac6c8a835..e39b58827 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -35,6 +35,10 @@ impl AstNode for ArgList { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for ArgList { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -63,6 +67,10 @@ impl AstNode for ArrayExpr { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for ArrayExpr { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -91,6 +99,10 @@ impl AstNode for ArrayType { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for ArrayType { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -123,6 +135,10 @@ impl AstNode for AssocTypeArg { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for AssocTypeArg { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -155,6 +171,10 @@ impl AstNode for Attr { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for Attr { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -183,6 +203,10 @@ impl AstNode for BinExpr { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for BinExpr { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -207,6 +231,10 @@ impl AstNode for BindPat { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for BindPat { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -236,6 +264,10 @@ impl AstNode for Block { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for Block { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -268,6 +300,10 @@ impl AstNode for BlockExpr { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for BlockExpr { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -296,6 +332,10 @@ impl AstNode for BreakExpr { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for BreakExpr { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -324,6 +364,10 @@ impl AstNode for Byte { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for Byte { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -349,6 +393,10 @@ impl AstNode for ByteString { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for ByteString { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -374,6 +422,10 @@ impl AstNode for CallExpr { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for CallExpr { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -403,6 +455,10 @@ impl AstNode for CastExpr { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for CastExpr { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -435,6 +491,10 @@ impl AstNode for Char { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for Char { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -460,6 +520,10 @@ impl AstNode for Comment { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for Comment { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -485,6 +549,10 @@ impl AstNode for Condition { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for Condition { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -517,6 +585,10 @@ impl AstNode for ConstDef { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for ConstDef { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -546,6 +618,10 @@ impl AstNode for ContinueExpr { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for ContinueExpr { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -570,6 +646,10 @@ impl AstNode for DynTraitType { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for DynTraitType { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -594,6 +674,10 @@ impl AstNode for EnumDef { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for EnumDef { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -627,6 +711,10 @@ impl AstNode for EnumVariant { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for EnumVariant { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -657,6 +745,10 @@ impl AstNode for EnumVariantList { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for EnumVariantList { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -742,6 +834,10 @@ impl AstNode for Expr { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for Expr { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -800,6 +896,10 @@ impl AstNode for ExprStmt { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for ExprStmt { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -828,6 +928,10 @@ impl AstNode for ExternCrateItem { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for ExternCrateItem { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -852,6 +956,10 @@ impl AstNode for FalseKw { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for FalseKw { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -877,6 +985,10 @@ impl AstNode for FieldExpr { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for FieldExpr { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -909,6 +1021,10 @@ impl AstNode for FieldPat { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for FieldPat { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -938,6 +1054,10 @@ impl AstNode for FieldPatList { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for FieldPatList { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -970,6 +1090,10 @@ impl AstNode for FloatNumber { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for FloatNumber { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -995,6 +1119,10 @@ impl AstNode for FnDef { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for FnDef { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -1036,6 +1164,10 @@ impl AstNode for FnPointerType { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for FnPointerType { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -1068,6 +1200,10 @@ impl AstNode for ForExpr { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for ForExpr { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -1101,6 +1237,10 @@ impl AstNode for ForType { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for ForType { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -1129,6 +1269,10 @@ impl AstNode for IfExpr { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for IfExpr { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -1157,6 +1301,10 @@ impl AstNode for ImplBlock { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for ImplBlock { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -1194,6 +1342,10 @@ impl AstNode for ImplItem { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for ImplItem { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -1228,6 +1380,10 @@ impl AstNode for ImplTraitType { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for ImplTraitType { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -1252,6 +1408,10 @@ impl AstNode for IndexExpr { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for IndexExpr { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -1276,6 +1436,10 @@ impl AstNode for IntNumber { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for IntNumber { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -1301,6 +1465,10 @@ impl AstNode for ItemList { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for ItemList { + type Owned = TreeArc; fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } } @@ -1331,6 +1499,10 @@ impl AstNode for Label { } } fn syntax(&self) -> &SyntaxNode { &self.syntax } +} + +impl ToOwned for Label { + type Owned = TreeArc