From d402974aa0af6de290245a9d2a69a5d56c4fa610 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 18 Jul 2019 19:23:05 +0300 Subject: [PATCH 1/8] migrate ra_syntax to the new rowan API --- Cargo.lock | 6 +- Cargo.toml | 1 + crates/ra_syntax/src/algo.rs | 10 +- crates/ra_syntax/src/algo/visit.rs | 12 +- crates/ra_syntax/src/ast.rs | 36 +- crates/ra_syntax/src/ast/expr_extensions.rs | 30 +- crates/ra_syntax/src/ast/extensions.rs | 64 +- crates/ra_syntax/src/ast/generated.rs | 2720 +++++------------ crates/ra_syntax/src/ast/generated.rs.tera | 51 +- crates/ra_syntax/src/ast/tokens.rs | 26 +- crates/ra_syntax/src/ast/traits.rs | 50 +- crates/ra_syntax/src/fuzz.rs | 14 +- crates/ra_syntax/src/lib.rs | 122 +- crates/ra_syntax/src/parsing/reparsing.rs | 20 +- crates/ra_syntax/src/ptr.rs | 11 +- crates/ra_syntax/src/syntax_node.rs | 335 +- crates/ra_syntax/src/syntax_text.rs | 25 +- crates/ra_syntax/src/validation.rs | 4 +- crates/ra_syntax/src/validation/block.rs | 2 +- crates/ra_syntax/src/validation/field_expr.rs | 2 +- 20 files changed, 1189 insertions(+), 2352 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 03f5be16be..16fef3dfd0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1313,7 +1313,7 @@ dependencies = [ "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "ra_parser 0.1.0", "ra_text_edit 0.1.0", - "rowan 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", + "rowan 0.5.5 (git+https://github.com/rust-analyzer/rowan?branch=cursor)", "smol_str 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "test_utils 0.1.0", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1585,7 +1585,7 @@ dependencies = [ [[package]] name = "rowan" version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" +source = "git+https://github.com/rust-analyzer/rowan?branch=cursor#d41b21587487f8b372ee779e37c557b873ba0715" dependencies = [ "colosseum 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2275,7 +2275,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0e7790c7f1cc73d831d28dc5a7deb316a006e7848e6a7f467cdb10a0a9e0fb1c" "checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" "checksum ron 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "17f52a24414403f81528b67488cf8edc4eda977d3af1646bb6b106a600ead78f" -"checksum rowan 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "500ba7550373d42593a5228085bad391517378fa31ad2a84defe100dd8259fef" +"checksum rowan 0.5.5 (git+https://github.com/rust-analyzer/rowan?branch=cursor)" = "" "checksum rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f4dccf6f4891ebcc0c39f9b6eb1a83b9bf5d747cb439ec6fba4f3b977038af" "checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" diff --git a/Cargo.toml b/Cargo.toml index c5155e8996..df1f6438da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,4 @@ incremental = true debug = true [patch.'crates-io'] +rowan = { git = "https://github.com/rust-analyzer/rowan", branch = "cursor" } diff --git a/crates/ra_syntax/src/algo.rs b/crates/ra_syntax/src/algo.rs index fad8da1323..e2de5e0e39 100644 --- a/crates/ra_syntax/src/algo.rs +++ b/crates/ra_syntax/src/algo.rs @@ -9,8 +9,8 @@ pub use rowan::TokenAtOffset; pub fn find_token_at_offset(node: &SyntaxNode, offset: TextUnit) -> TokenAtOffset { match node.0.token_at_offset(offset) { TokenAtOffset::None => TokenAtOffset::None, - TokenAtOffset::Single(n) => TokenAtOffset::Single(n.into()), - TokenAtOffset::Between(l, r) => TokenAtOffset::Between(l.into(), r.into()), + TokenAtOffset::Single(n) => TokenAtOffset::Single(SyntaxToken(n)), + TokenAtOffset::Between(l, r) => TokenAtOffset::Between(SyntaxToken(l), SyntaxToken(r)), } } @@ -22,7 +22,7 @@ pub fn find_token_at_offset(node: &SyntaxNode, offset: TextUnit) -> TokenAtOffse pub fn ancestors_at_offset( node: &SyntaxNode, offset: TextUnit, -) -> impl Iterator { +) -> impl Iterator { find_token_at_offset(node, offset) .map(|token| token.parent().ancestors()) .kmerge_by(|node1, node2| node1.range().len() < node2.range().len()) @@ -37,7 +37,7 @@ pub fn ancestors_at_offset( /// ``` /// /// then the shorter node will be silently preferred. -pub fn find_node_at_offset(syntax: &SyntaxNode, offset: TextUnit) -> Option<&N> { +pub fn find_node_at_offset(syntax: &SyntaxNode, offset: TextUnit) -> Option { ancestors_at_offset(syntax, offset).find_map(N::cast) } @@ -59,5 +59,5 @@ pub fn non_trivia_sibling(element: SyntaxElement, direction: Direction) -> Optio } pub fn find_covering_element(root: &SyntaxNode, range: TextRange) -> SyntaxElement { - root.0.covering_node(range).into() + SyntaxElement::new(root.0.covering_node(range)) } diff --git a/crates/ra_syntax/src/algo/visit.rs b/crates/ra_syntax/src/algo/visit.rs index 81a99228fd..87bd15cc0c 100644 --- a/crates/ra_syntax/src/algo/visit.rs +++ b/crates/ra_syntax/src/algo/visit.rs @@ -16,7 +16,7 @@ pub trait Visitor<'a>: Sized { fn visit(self, f: F) -> Vis where N: AstNode + 'a, - F: FnOnce(&'a N) -> Self::Output, + F: FnOnce(N) -> Self::Output, { Vis { inner: self, f, ph: PhantomData } } @@ -29,7 +29,7 @@ pub trait VisitorCtx<'a>: Sized { fn visit(self, f: F) -> VisCtx where N: AstNode + 'a, - F: FnOnce(&'a N, Self::Ctx) -> Self::Output, + F: FnOnce(N, Self::Ctx) -> Self::Output, { VisCtx { inner: self, f, ph: PhantomData } } @@ -74,13 +74,13 @@ impl<'a, V, N, F> Visitor<'a> for Vis where V: Visitor<'a>, N: AstNode + 'a, - F: FnOnce(&'a N) -> >::Output, + F: FnOnce(N) -> >::Output, { type Output = >::Output; fn accept(self, node: &'a SyntaxNode) -> Option { let Vis { inner, f, .. } = self; - inner.accept(node).or_else(|| N::cast(node).map(f)) + inner.accept(node).or_else(|| N::cast(node.clone()).map(f)) } } @@ -95,14 +95,14 @@ impl<'a, V, N, F> VisitorCtx<'a> for VisCtx where V: VisitorCtx<'a>, N: AstNode + 'a, - F: FnOnce(&'a N, >::Ctx) -> >::Output, + F: FnOnce(N, >::Ctx) -> >::Output, { type Output = >::Output; type Ctx = >::Ctx; fn accept(self, node: &'a SyntaxNode) -> Result { let VisCtx { inner, f, .. } = self; - inner.accept(node).or_else(|ctx| match N::cast(node) { + inner.accept(node).or_else(|ctx| match N::cast(node.clone()) { None => Err(ctx), Some(node) => Ok(f(node, ctx)), }) diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index 3dcf39f7e1..fe00e78d1d 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs @@ -9,7 +9,7 @@ mod expr_extensions; use std::marker::PhantomData; use crate::{ - syntax_node::{SyntaxNode, SyntaxNodeChildren, SyntaxToken, TreeArc}, + syntax_node::{SyntaxNode, SyntaxNodeChildren, SyntaxToken}, SmolStr, }; @@ -25,51 +25,49 @@ pub use self::{ /// 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 + ToOwned> -{ - fn cast(syntax: &SyntaxNode) -> Option<&Self> +pub trait AstNode { + fn cast(syntax: SyntaxNode) -> Option where Self: Sized; fn syntax(&self) -> &SyntaxNode; } /// Like `AstNode`, but wraps tokens rather than interior nodes. -pub trait AstToken<'a> { - fn cast(token: SyntaxToken<'a>) -> Option +pub trait AstToken { + fn cast(token: SyntaxToken) -> Option where Self: Sized; - fn syntax(&self) -> SyntaxToken<'a>; - fn text(&self) -> &'a SmolStr { + fn syntax(&self) -> &SyntaxToken; + fn text(&self) -> &SmolStr { self.syntax().text() } } /// An iterator over `SyntaxNode` children of a particular AST type. #[derive(Debug)] -pub struct AstChildren<'a, N> { - inner: SyntaxNodeChildren<'a>, +pub struct AstChildren { + inner: SyntaxNodeChildren, ph: PhantomData, } -impl<'a, N> AstChildren<'a, N> { - fn new(parent: &'a SyntaxNode) -> Self { +impl AstChildren { + fn new(parent: &SyntaxNode) -> Self { AstChildren { inner: parent.children(), ph: PhantomData } } } -impl<'a, N: AstNode + 'a> Iterator for AstChildren<'a, N> { - type Item = &'a N; - fn next(&mut self) -> Option<&'a N> { +impl Iterator for AstChildren { + type Item = N; + fn next(&mut self) -> Option { self.inner.by_ref().find_map(N::cast) } } -fn child_opt(parent: &P) -> Option<&C> { +fn child_opt(parent: &P) -> Option { children(parent).next() } -fn children(parent: &P) -> AstChildren { +fn children(parent: &P) -> AstChildren { AstChildren::new(parent.syntax()) } @@ -123,7 +121,7 @@ fn test_doc_comment_preserves_indents() { #[test] fn test_where_predicates() { - fn assert_bound(text: &str, bound: Option<&TypeBound>) { + fn assert_bound(text: &str, bound: Option) { assert_eq!(text, bound.unwrap().syntax().text().to_string()); } diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs index 4355e35875..ca1773908a 100644 --- a/crates/ra_syntax/src/ast/expr_extensions.rs +++ b/crates/ra_syntax/src/ast/expr_extensions.rs @@ -8,20 +8,20 @@ use crate::{ }; #[derive(Debug, Clone, PartialEq, Eq)] -pub enum ElseBranch<'a> { - Block(&'a ast::Block), - IfExpr(&'a ast::IfExpr), +pub enum ElseBranch { + Block(ast::Block), + IfExpr(ast::IfExpr), } impl ast::IfExpr { - pub fn then_branch(&self) -> Option<&ast::Block> { + pub fn then_branch(&self) -> Option { self.blocks().nth(0) } pub fn else_branch(&self) -> Option { let res = match self.blocks().nth(1) { Some(block) => ElseBranch::Block(block), None => { - let elif: &ast::IfExpr = child_opt(self)?; + let elif: ast::IfExpr = child_opt(self)?; ElseBranch::IfExpr(elif) } }; @@ -60,7 +60,7 @@ impl ast::PrefixExpr { } pub fn op_token(&self) -> Option { - self.syntax().first_child_or_token()?.as_token() + self.syntax().first_child_or_token()?.as_token().cloned() } } @@ -132,7 +132,7 @@ pub enum BinOp { impl ast::BinExpr { fn op_details(&self) -> Option<(SyntaxToken, BinOp)> { - self.syntax().children_with_tokens().filter_map(|it| it.as_token()).find_map(|c| { + self.syntax().children_with_tokens().filter_map(|it| it.as_token().cloned()).find_map(|c| { match c.kind() { T![||] => Some((c, BinOp::BooleanOr)), T![&&] => Some((c, BinOp::BooleanAnd)), @@ -178,15 +178,15 @@ impl ast::BinExpr { self.op_details().map(|t| t.0) } - pub fn lhs(&self) -> Option<&ast::Expr> { + pub fn lhs(&self) -> Option { children(self).nth(0) } - pub fn rhs(&self) -> Option<&ast::Expr> { + pub fn rhs(&self) -> Option { children(self).nth(1) } - pub fn sub_exprs(&self) -> (Option<&ast::Expr>, Option<&ast::Expr>) { + pub fn sub_exprs(&self) -> (Option, Option) { let mut children = children(self); let first = children.next(); let second = children.next(); @@ -194,9 +194,9 @@ impl ast::BinExpr { } } -pub enum ArrayExprKind<'a> { - Repeat { initializer: Option<&'a ast::Expr>, repeat: Option<&'a ast::Expr> }, - ElementList(AstChildren<'a, ast::Expr>), +pub enum ArrayExprKind { + Repeat { initializer: Option, repeat: Option }, + ElementList(AstChildren), } impl ast::ArrayExpr { @@ -275,12 +275,12 @@ impl ast::Literal { #[test] fn test_literal_with_attr() { let parse = ast::SourceFile::parse(r#"const _: &str = { #[attr] "Hello" };"#); - let lit = parse.tree.syntax().descendants().find_map(ast::Literal::cast).unwrap(); + let lit = parse.tree().syntax().descendants().find_map(ast::Literal::cast).unwrap(); assert_eq!(lit.token().text(), r#""Hello""#); } impl ast::NamedField { - pub fn parent_struct_lit(&self) -> &ast::StructLit { + pub fn parent_struct_lit(&self) -> ast::StructLit { self.syntax().ancestors().find_map(ast::StructLit::cast).unwrap() } } diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index 72a30232df..5420f67ff0 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs @@ -4,7 +4,7 @@ use itertools::Itertools; use crate::{ - ast::{self, child_opt, children, AstNode}, + ast::{self, child_opt, children, AstNode, SyntaxNode}, SmolStr, SyntaxElement, SyntaxKind::*, SyntaxToken, T, @@ -13,15 +13,20 @@ use ra_parser::SyntaxKind; impl ast::Name { pub fn text(&self) -> &SmolStr { - let ident = self.syntax().first_child_or_token().unwrap().as_token().unwrap(); - ident.text() + text_of_first_token(self.syntax()) } } impl ast::NameRef { pub fn text(&self) -> &SmolStr { - let ident = self.syntax().first_child_or_token().unwrap().as_token().unwrap(); - ident.text() + text_of_first_token(self.syntax()) + } +} + +fn text_of_first_token(node: &SyntaxNode) -> &SmolStr { + match node.0.green().children().first() { + Some(rowan::GreenElement::Token(it)) => it.text(), + _ => panic!(), } } @@ -50,10 +55,10 @@ impl ast::Attr { } } - pub fn as_call(&self) -> Option<(SmolStr, &ast::TokenTree)> { + pub fn as_call(&self) -> Option<(SmolStr, ast::TokenTree)> { let tt = self.value()?; let (_bra, attr, args, _ket) = tt.syntax().children_with_tokens().collect_tuple()?; - let args = ast::TokenTree::cast(args.as_node()?)?; + let args = ast::TokenTree::cast(args.as_node()?.clone())?; if attr.kind() == IDENT { Some((attr.as_token()?.text().clone(), args)) } else { @@ -86,16 +91,16 @@ impl ast::Attr { } } -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum PathSegmentKind<'a> { - Name(&'a ast::NameRef), +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum PathSegmentKind { + Name(ast::NameRef), SelfKw, SuperKw, CrateKw, } impl ast::PathSegment { - pub fn parent_path(&self) -> &ast::Path { + pub fn parent_path(&self) -> ast::Path { self.syntax() .parent() .and_then(ast::Path::cast) @@ -125,7 +130,7 @@ impl ast::PathSegment { } impl ast::Path { - pub fn parent_path(&self) -> Option<&ast::Path> { + pub fn parent_path(&self) -> Option { self.syntax().parent().and_then(ast::Path::cast) } } @@ -146,7 +151,7 @@ impl ast::UseTree { } impl ast::UseTreeList { - pub fn parent_use_tree(&self) -> &ast::UseTree { + pub fn parent_use_tree(&self) -> ast::UseTree { self.syntax() .parent() .and_then(ast::UseTree::cast) @@ -155,21 +160,21 @@ impl ast::UseTreeList { } impl ast::ImplBlock { - pub fn target_type(&self) -> Option<&ast::TypeRef> { + pub fn target_type(&self) -> Option { match self.target() { (Some(t), None) | (_, Some(t)) => Some(t), _ => None, } } - pub fn target_trait(&self) -> Option<&ast::TypeRef> { + pub fn target_trait(&self) -> Option { match self.target() { (Some(t), Some(_)) => Some(t), _ => None, } } - fn target(&self) -> (Option<&ast::TypeRef>, Option<&ast::TypeRef>) { + fn target(&self) -> (Option, Option) { let mut types = children(self); let first = types.next(); let second = types.next(); @@ -182,13 +187,13 @@ impl ast::ImplBlock { } #[derive(Debug, Clone, PartialEq, Eq)] -pub enum StructKind<'a> { - Tuple(&'a ast::PosFieldDefList), - Named(&'a ast::NamedFieldDefList), +pub enum StructKind { + Tuple(ast::PosFieldDefList), + Named(ast::NamedFieldDefList), Unit, } -impl StructKind<'_> { +impl StructKind { fn from_node(node: &N) -> StructKind { if let Some(nfdl) = child_opt::<_, ast::NamedFieldDefList>(node) { StructKind::Named(nfdl) @@ -218,7 +223,7 @@ impl ast::StructDef { } impl ast::EnumVariant { - pub fn parent_enum(&self) -> &ast::EnumDef { + pub fn parent_enum(&self) -> ast::EnumDef { self.syntax() .parent() .and_then(|it| it.parent()) @@ -231,10 +236,10 @@ impl ast::EnumVariant { } impl ast::FnDef { - pub fn semicolon_token(&self) -> Option> { + pub fn semicolon_token(&self) -> Option { self.syntax() .last_child_or_token() - .and_then(|it| it.as_token()) + .and_then(|it| it.as_token().cloned()) .filter(|it| it.kind() == T![;]) } } @@ -258,9 +263,9 @@ impl ast::ExprStmt { } #[derive(Debug, Clone, PartialEq, Eq)] -pub enum FieldKind<'a> { - Name(&'a ast::NameRef), - Index(SyntaxToken<'a>), +pub enum FieldKind { + Name(ast::NameRef), + Index(SyntaxToken), } impl ast::FieldExpr { @@ -271,6 +276,7 @@ impl ast::FieldExpr { .find(|c| c.kind() == SyntaxKind::INT_NUMBER || c.kind() == SyntaxKind::FLOAT_NUMBER) .as_ref() .and_then(SyntaxElement::as_token) + .cloned() } pub fn field_access(&self) -> Option { @@ -326,7 +332,7 @@ impl ast::SelfParam { pub fn self_kw_token(&self) -> SyntaxToken { self.syntax() .children_with_tokens() - .filter_map(|it| it.as_token()) + .filter_map(|it| it.as_token().cloned()) .find(|it| it.kind() == T![self]) .expect("invalid tree: self param must have self") } @@ -355,7 +361,7 @@ impl ast::LifetimeParam { pub fn lifetime_token(&self) -> Option { self.syntax() .children_with_tokens() - .filter_map(|it| it.as_token()) + .filter_map(|it| it.as_token().cloned()) .find(|it| it.kind() == LIFETIME) } } @@ -364,7 +370,7 @@ impl ast::WherePred { pub fn lifetime_token(&self) -> Option { self.syntax() .children_with_tokens() - .filter_map(|it| it.as_token()) + .filter_map(|it| it.as_token().cloned()) .find(|it| it.kind() == LIFETIME) } } diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 1d888e7094..a1f3202578 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -9,503 +9,365 @@ #![cfg_attr(rustfmt, rustfmt_skip)] -use rowan::TransparentNewType; - use crate::{ SyntaxNode, SyntaxKind::*, - syntax_node::{TreeArc}, ast::{self, AstNode}, }; // Alias -#[derive(Debug, PartialEq, Eq, Hash)] -#[repr(transparent)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Alias { pub(crate) syntax: SyntaxNode, } -unsafe impl TransparentNewType for Alias { - type Repr = rowan::SyntaxNode; -} impl AstNode for Alias { - fn cast(syntax: &SyntaxNode) -> Option<&Self> { + fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { - ALIAS => Some(Alias::from_repr(syntax.into_repr())), + ALIAS => Some(Alias { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl ToOwned for Alias { - type Owned = TreeArc; - fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } -} - impl ast::NameOwner for Alias {} impl Alias {} // ArgList -#[derive(Debug, PartialEq, Eq, Hash)] -#[repr(transparent)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ArgList { pub(crate) syntax: SyntaxNode, } -unsafe impl TransparentNewType for ArgList { - type Repr = rowan::SyntaxNode; -} impl AstNode for ArgList { - fn cast(syntax: &SyntaxNode) -> Option<&Self> { + fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { - ARG_LIST => Some(ArgList::from_repr(syntax.into_repr())), + ARG_LIST => Some(ArgList { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl ToOwned for ArgList { - type Owned = TreeArc; - fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } -} - impl ArgList { - pub fn args(&self) -> impl Iterator { + pub fn args(&self) -> impl Iterator { super::children(self) } } // ArrayExpr -#[derive(Debug, PartialEq, Eq, Hash)] -#[repr(transparent)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ArrayExpr { pub(crate) syntax: SyntaxNode, } -unsafe impl TransparentNewType for ArrayExpr { - type Repr = rowan::SyntaxNode; -} impl AstNode for ArrayExpr { - fn cast(syntax: &SyntaxNode) -> Option<&Self> { + fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { - ARRAY_EXPR => Some(ArrayExpr::from_repr(syntax.into_repr())), + ARRAY_EXPR => Some(ArrayExpr { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl ToOwned for ArrayExpr { - type Owned = TreeArc; - fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } -} - impl ArrayExpr { - pub fn exprs(&self) -> impl Iterator { + pub fn exprs(&self) -> impl Iterator { super::children(self) } } // ArrayType -#[derive(Debug, PartialEq, Eq, Hash)] -#[repr(transparent)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ArrayType { pub(crate) syntax: SyntaxNode, } -unsafe impl TransparentNewType for ArrayType { - type Repr = rowan::SyntaxNode; -} impl AstNode for ArrayType { - fn cast(syntax: &SyntaxNode) -> Option<&Self> { + fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { - ARRAY_TYPE => Some(ArrayType::from_repr(syntax.into_repr())), + ARRAY_TYPE => Some(ArrayType { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl ToOwned for ArrayType { - type Owned = TreeArc; - fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } -} - impl ArrayType { - pub fn type_ref(&self) -> Option<&TypeRef> { + pub fn type_ref(&self) -> Option { super::child_opt(self) } - pub fn expr(&self) -> Option<&Expr> { + pub fn expr(&self) -> Option { super::child_opt(self) } } // AssocTypeArg -#[derive(Debug, PartialEq, Eq, Hash)] -#[repr(transparent)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct AssocTypeArg { pub(crate) syntax: SyntaxNode, } -unsafe impl TransparentNewType for AssocTypeArg { - type Repr = rowan::SyntaxNode; -} impl AstNode for AssocTypeArg { - fn cast(syntax: &SyntaxNode) -> Option<&Self> { + fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { - ASSOC_TYPE_ARG => Some(AssocTypeArg::from_repr(syntax.into_repr())), + ASSOC_TYPE_ARG => Some(AssocTypeArg { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl ToOwned for AssocTypeArg { - type Owned = TreeArc; - fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } -} - impl AssocTypeArg { - pub fn name_ref(&self) -> Option<&NameRef> { + pub fn name_ref(&self) -> Option { super::child_opt(self) } - pub fn type_ref(&self) -> Option<&TypeRef> { + pub fn type_ref(&self) -> Option { super::child_opt(self) } } // Attr -#[derive(Debug, PartialEq, Eq, Hash)] -#[repr(transparent)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Attr { pub(crate) syntax: SyntaxNode, } -unsafe impl TransparentNewType for Attr { - type Repr = rowan::SyntaxNode; -} impl AstNode for Attr { - fn cast(syntax: &SyntaxNode) -> Option<&Self> { + fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { - ATTR => Some(Attr::from_repr(syntax.into_repr())), + ATTR => Some(Attr { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl ToOwned for Attr { - type Owned = TreeArc; - fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } -} - impl Attr { - pub fn value(&self) -> Option<&TokenTree> { + pub fn value(&self) -> Option { super::child_opt(self) } } // BinExpr -#[derive(Debug, PartialEq, Eq, Hash)] -#[repr(transparent)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct BinExpr { pub(crate) syntax: SyntaxNode, } -unsafe impl TransparentNewType for BinExpr { - type Repr = rowan::SyntaxNode; -} impl AstNode for BinExpr { - fn cast(syntax: &SyntaxNode) -> Option<&Self> { + fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { - BIN_EXPR => Some(BinExpr::from_repr(syntax.into_repr())), + BIN_EXPR => Some(BinExpr { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl ToOwned for BinExpr { - type Owned = TreeArc; - fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } -} - impl BinExpr {} // BindPat -#[derive(Debug, PartialEq, Eq, Hash)] -#[repr(transparent)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct BindPat { pub(crate) syntax: SyntaxNode, } -unsafe impl TransparentNewType for BindPat { - type Repr = rowan::SyntaxNode; -} impl AstNode for BindPat { - fn cast(syntax: &SyntaxNode) -> Option<&Self> { + fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { - BIND_PAT => Some(BindPat::from_repr(syntax.into_repr())), + BIND_PAT => Some(BindPat { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl ToOwned for BindPat { - type Owned = TreeArc; - fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } -} - impl ast::NameOwner for BindPat {} impl BindPat { - pub fn pat(&self) -> Option<&Pat> { + pub fn pat(&self) -> Option { super::child_opt(self) } } // Block -#[derive(Debug, PartialEq, Eq, Hash)] -#[repr(transparent)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Block { pub(crate) syntax: SyntaxNode, } -unsafe impl TransparentNewType for Block { - type Repr = rowan::SyntaxNode; -} impl AstNode for Block { - fn cast(syntax: &SyntaxNode) -> Option<&Self> { + fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { - BLOCK => Some(Block::from_repr(syntax.into_repr())), + BLOCK => Some(Block { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl ToOwned for Block { - type Owned = TreeArc; - fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } -} - impl ast::AttrsOwner for Block {} impl Block { - pub fn statements(&self) -> impl Iterator { + pub fn statements(&self) -> impl Iterator { super::children(self) } - pub fn expr(&self) -> Option<&Expr> { + pub fn expr(&self) -> Option { super::child_opt(self) } } // BlockExpr -#[derive(Debug, PartialEq, Eq, Hash)] -#[repr(transparent)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct BlockExpr { pub(crate) syntax: SyntaxNode, } -unsafe impl TransparentNewType for BlockExpr { - type Repr = rowan::SyntaxNode; -} impl AstNode for BlockExpr { - fn cast(syntax: &SyntaxNode) -> Option<&Self> { + fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { - BLOCK_EXPR => Some(BlockExpr::from_repr(syntax.into_repr())), + BLOCK_EXPR => Some(BlockExpr { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl ToOwned for BlockExpr { - type Owned = TreeArc; - fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } -} - impl BlockExpr { - pub fn block(&self) -> Option<&Block> { + pub fn block(&self) -> Option { super::child_opt(self) } } // BreakExpr -#[derive(Debug, PartialEq, Eq, Hash)] -#[repr(transparent)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct BreakExpr { pub(crate) syntax: SyntaxNode, } -unsafe impl TransparentNewType for BreakExpr { - type Repr = rowan::SyntaxNode; -} impl AstNode for BreakExpr { - fn cast(syntax: &SyntaxNode) -> Option<&Self> { + fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { - BREAK_EXPR => Some(BreakExpr::from_repr(syntax.into_repr())), + BREAK_EXPR => Some(BreakExpr { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl ToOwned for BreakExpr { - type Owned = TreeArc; - fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } -} - impl BreakExpr { - pub fn expr(&self) -> Option<&Expr> { + pub fn expr(&self) -> Option { super::child_opt(self) } } // CallExpr -#[derive(Debug, PartialEq, Eq, Hash)] -#[repr(transparent)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct CallExpr { pub(crate) syntax: SyntaxNode, } -unsafe impl TransparentNewType for CallExpr { - type Repr = rowan::SyntaxNode; -} impl AstNode for CallExpr { - fn cast(syntax: &SyntaxNode) -> Option<&Self> { + fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { - CALL_EXPR => Some(CallExpr::from_repr(syntax.into_repr())), + CALL_EXPR => Some(CallExpr { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl ToOwned for CallExpr { - type Owned = TreeArc; - fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } -} - impl ast::ArgListOwner for CallExpr {} impl CallExpr { - pub fn expr(&self) -> Option<&Expr> { + pub fn expr(&self) -> Option { super::child_opt(self) } } // CastExpr -#[derive(Debug, PartialEq, Eq, Hash)] -#[repr(transparent)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct CastExpr { pub(crate) syntax: SyntaxNode, } -unsafe impl TransparentNewType for CastExpr { - type Repr = rowan::SyntaxNode; -} impl AstNode for CastExpr { - fn cast(syntax: &SyntaxNode) -> Option<&Self> { + fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { - CAST_EXPR => Some(CastExpr::from_repr(syntax.into_repr())), + CAST_EXPR => Some(CastExpr { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl ToOwned for CastExpr { - type Owned = TreeArc; - fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } -} - impl CastExpr { - pub fn expr(&self) -> Option<&Expr> { + pub fn expr(&self) -> Option { super::child_opt(self) } - pub fn type_ref(&self) -> Option<&TypeRef> { + pub fn type_ref(&self) -> Option { super::child_opt(self) } } // Condition -#[derive(Debug, PartialEq, Eq, Hash)] -#[repr(transparent)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Condition { pub(crate) syntax: SyntaxNode, } -unsafe impl TransparentNewType for Condition { - type Repr = rowan::SyntaxNode; -} impl AstNode for Condition { - fn cast(syntax: &SyntaxNode) -> Option<&Self> { + fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { - CONDITION => Some(Condition::from_repr(syntax.into_repr())), + CONDITION => Some(Condition { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl ToOwned for Condition { - type Owned = TreeArc; - fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } -} - impl Condition { - pub fn pat(&self) -> Option<&Pat> { + pub fn pat(&self) -> Option { super::child_opt(self) } - pub fn expr(&self) -> Option<&Expr> { + pub fn expr(&self) -> Option { super::child_opt(self) } } // ConstDef -#[derive(Debug, PartialEq, Eq, Hash)] -#[repr(transparent)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ConstDef { pub(crate) syntax: SyntaxNode, } -unsafe impl TransparentNewType for ConstDef { - type Repr = rowan::SyntaxNode; -} impl AstNode for ConstDef { - fn cast(syntax: &SyntaxNode) -> Option<&Self> { + fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { - CONST_DEF => Some(ConstDef::from_repr(syntax.into_repr())), + CONST_DEF => Some(ConstDef { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl ToOwned for ConstDef { - type Owned = TreeArc; - fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } -} - impl ast::VisibilityOwner for ConstDef {} impl ast::NameOwner for ConstDef {} @@ -514,93 +376,66 @@ impl ast::AttrsOwner for ConstDef {} impl ast::DocCommentsOwner for ConstDef {} impl ast::TypeAscriptionOwner for ConstDef {} impl ConstDef { - pub fn body(&self) -> Option<&Expr> { + pub fn body(&self) -> Option { super::child_opt(self) } } // ContinueExpr -#[derive(Debug, PartialEq, Eq, Hash)] -#[repr(transparent)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ContinueExpr { pub(crate) syntax: SyntaxNode, } -unsafe impl TransparentNewType for ContinueExpr { - type Repr = rowan::SyntaxNode; -} impl AstNode for ContinueExpr { - fn cast(syntax: &SyntaxNode) -> Option<&Self> { + fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { - CONTINUE_EXPR => Some(ContinueExpr::from_repr(syntax.into_repr())), + CONTINUE_EXPR => Some(ContinueExpr { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl ToOwned for ContinueExpr { - type Owned = TreeArc; - fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } -} - impl ContinueExpr {} // DynTraitType -#[derive(Debug, PartialEq, Eq, Hash)] -#[repr(transparent)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct DynTraitType { pub(crate) syntax: SyntaxNode, } -unsafe impl TransparentNewType for DynTraitType { - type Repr = rowan::SyntaxNode; -} impl AstNode for DynTraitType { - fn cast(syntax: &SyntaxNode) -> Option<&Self> { + fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { - DYN_TRAIT_TYPE => Some(DynTraitType::from_repr(syntax.into_repr())), + DYN_TRAIT_TYPE => Some(DynTraitType { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl ToOwned for DynTraitType { - type Owned = TreeArc; - fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } -} - impl ast::TypeBoundsOwner for DynTraitType {} impl DynTraitType {} // EnumDef -#[derive(Debug, PartialEq, Eq, Hash)] -#[repr(transparent)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct EnumDef { pub(crate) syntax: SyntaxNode, } -unsafe impl TransparentNewType for EnumDef { - type Repr = rowan::SyntaxNode; -} impl AstNode for EnumDef { - fn cast(syntax: &SyntaxNode) -> Option<&Self> { + fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { - ENUM_DEF => Some(EnumDef::from_repr(syntax.into_repr())), + ENUM_DEF => Some(EnumDef { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl ToOwned for EnumDef { - type Owned = TreeArc; - fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } -} - impl ast::VisibilityOwner for EnumDef {} impl ast::NameOwner for EnumDef {} @@ -608,269 +443,247 @@ impl ast::TypeParamsOwner for EnumDef {} impl ast::AttrsOwner for EnumDef {} impl ast::DocCommentsOwner for EnumDef {} impl EnumDef { - pub fn variant_list(&self) -> Option<&EnumVariantList> { + pub fn variant_list(&self) -> Option { super::child_opt(self) } } // EnumVariant -#[derive(Debug, PartialEq, Eq, Hash)] -#[repr(transparent)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct EnumVariant { pub(crate) syntax: SyntaxNode, } -unsafe impl TransparentNewType for EnumVariant { - type Repr = rowan::SyntaxNode; -} impl AstNode for EnumVariant { - fn cast(syntax: &SyntaxNode) -> Option<&Self> { + fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { - ENUM_VARIANT => Some(EnumVariant::from_repr(syntax.into_repr())), + ENUM_VARIANT => Some(EnumVariant { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl ToOwned for EnumVariant { - type Owned = TreeArc; - fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } -} - impl ast::NameOwner for EnumVariant {} impl ast::DocCommentsOwner for EnumVariant {} impl ast::AttrsOwner for EnumVariant {} impl EnumVariant { - pub fn expr(&self) -> Option<&Expr> { + pub fn expr(&self) -> Option { super::child_opt(self) } } // EnumVariantList -#[derive(Debug, PartialEq, Eq, Hash)] -#[repr(transparent)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct EnumVariantList { pub(crate) syntax: SyntaxNode, } -unsafe impl TransparentNewType for EnumVariantList { - type Repr = rowan::SyntaxNode; -} impl AstNode for EnumVariantList { - fn cast(syntax: &SyntaxNode) -> Option<&Self> { + fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { - ENUM_VARIANT_LIST => Some(EnumVariantList::from_repr(syntax.into_repr())), + ENUM_VARIANT_LIST => Some(EnumVariantList { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl ToOwned for EnumVariantList { - type Owned = TreeArc; - fn to_owned(&self) -> TreeArc { TreeArc::cast(self.syntax.to_owned()) } -} - impl EnumVariantList { - pub fn variants(&self) -> impl Iterator { + pub fn variants(&self) -> impl Iterator { super::children(self) } } // Expr -#[derive(Debug, PartialEq, Eq, Hash)] -#[repr(transparent)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Expr { pub(crate) syntax: SyntaxNode, } -unsafe impl TransparentNewType for Expr { - type Repr = rowan::SyntaxNode; -} -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum ExprKind<'a> { - TupleExpr(&'a TupleExpr), - ArrayExpr(&'a ArrayExpr), - ParenExpr(&'a ParenExpr), - PathExpr(&'a PathExpr), - LambdaExpr(&'a LambdaExpr), - IfExpr(&'a IfExpr), - LoopExpr(&'a LoopExpr), - ForExpr(&'a ForExpr), - WhileExpr(&'a WhileExpr), - ContinueExpr(&'a ContinueExpr), - BreakExpr(&'a BreakExpr), - Label(&'a Label), - BlockExpr(&'a BlockExpr), - ReturnExpr(&'a ReturnExpr), - MatchExpr(&'a MatchExpr), - StructLit(&'a StructLit), - CallExpr(&'a CallExpr), - IndexExpr(&'a IndexExpr), - MethodCallExpr(&'a MethodCallExpr), - FieldExpr(&'a FieldExpr), - TryExpr(&'a TryExpr), - TryBlockExpr(&'a TryBlockExpr), - CastExpr(&'a CastExpr), - RefExpr(&'a RefExpr), - PrefixExpr(&'a PrefixExpr), - RangeExpr(&'a RangeExpr), - BinExpr(&'a BinExpr), - Literal(&'a Literal), - MacroCall(&'a MacroCall), +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum ExprKind { + TupleExpr(TupleExpr), + ArrayExpr(ArrayExpr), + ParenExpr(ParenExpr), + PathExpr(PathExpr), + LambdaExpr(LambdaExpr), + IfExpr(IfExpr), + LoopExpr(LoopExpr), + ForExpr(ForExpr), + WhileExpr(WhileExpr), + ContinueExpr(ContinueExpr), + BreakExpr(BreakExpr), + Label(Label), + BlockExpr(BlockExpr), + ReturnExpr(ReturnExpr), + MatchExpr(MatchExpr), + StructLit(StructLit), + CallExpr(CallExpr), + IndexExpr(IndexExpr), + MethodCallExpr(MethodCallExpr), + FieldExpr(FieldExpr), + TryExpr(TryExpr), + TryBlockExpr(TryBlockExpr), + CastExpr(CastExpr), + RefExpr(RefExpr), + PrefixExpr(PrefixExpr), + RangeExpr(RangeExpr), + BinExpr(BinExpr), + Literal(Literal), + MacroCall(MacroCall), } -impl<'a> From<&'a TupleExpr> for &'a Expr { - fn from(n: &'a TupleExpr) -> &'a Expr { - Expr::cast(&n.syntax).unwrap() +impl From for Expr { + fn from(n: TupleExpr) -> Expr { + Expr::cast(n.syntax).unwrap() } } -impl<'a> From<&'a ArrayExpr> for &'a Expr { - fn from(n: &'a ArrayExpr) -> &'a Expr { - Expr::cast(&n.syntax).unwrap() +impl From for Expr { + fn from(n: ArrayExpr) -> Expr { + Expr::cast(n.syntax).unwrap() } } -impl<'a> From<&'a ParenExpr> for &'a Expr { - fn from(n: &'a ParenExpr) -> &'a Expr { - Expr::cast(&n.syntax).unwrap() +impl From for Expr { + fn from(n: ParenExpr) -> Expr { + Expr::cast(n.syntax).unwrap() } } -impl<'a> From<&'a PathExpr> for &'a Expr { - fn from(n: &'a PathExpr) -> &'a Expr { - Expr::cast(&n.syntax).unwrap() +impl From for Expr { + fn from(n: PathExpr) -> Expr { + Expr::cast(n.syntax).unwrap() } } -impl<'a> From<&'a LambdaExpr> for &'a Expr { - fn from(n: &'a LambdaExpr) -> &'a Expr { - Expr::cast(&n.syntax).unwrap() +impl From for Expr { + fn from(n: LambdaExpr) -> Expr { + Expr::cast(n.syntax).unwrap() } } -impl<'a> From<&'a IfExpr> for &'a Expr { - fn from(n: &'a IfExpr) -> &'a Expr { - Expr::cast(&n.syntax).unwrap() +impl From for Expr { + fn from(n: IfExpr) -> Expr { + Expr::cast(n.syntax).unwrap() } } -impl<'a> From<&'a LoopExpr> for &'a Expr { - fn from(n: &'a LoopExpr) -> &'a Expr { - Expr::cast(&n.syntax).unwrap() +impl From for Expr { + fn from(n: LoopExpr) -> Expr { + Expr::cast(n.syntax).unwrap() } } -impl<'a> From<&'a ForExpr> for &'a Expr { - fn from(n: &'a ForExpr) -> &'a Expr { - Expr::cast(&n.syntax).unwrap() +impl From for Expr { + fn from(n: ForExpr) -> Expr { + Expr::cast(n.syntax).unwrap() } } -impl<'a> From<&'a WhileExpr> for &'a Expr { - fn from(n: &'a WhileExpr) -> &'a Expr { - Expr::cast(&n.syntax).unwrap() +impl From for Expr { + fn from(n: WhileExpr) -> Expr { + Expr::cast(n.syntax).unwrap() } } -impl<'a> From<&'a ContinueExpr> for &'a Expr { - fn from(n: &'a ContinueExpr) -> &'a Expr { - Expr::cast(&n.syntax).unwrap() +impl From for Expr { + fn from(n: ContinueExpr) -> Expr { + Expr::cast(n.syntax).unwrap() } } -impl<'a> From<&'a BreakExpr> for &'a Expr { - fn from(n: &'a BreakExpr) -> &'a Expr { - Expr::cast(&n.syntax).unwrap() +impl From for Expr { + fn from(n: BreakExpr) -> Expr { + Expr::cast(n.syntax).unwrap() } } -impl<'a> From<&'a Label> for &'a Expr { - fn from(n: &'a Label) -> &'a Expr { - Expr::cast(&n.syntax).unwrap() +impl From