From d402974aa0af6de290245a9d2a69a5d56c4fa610 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 18 Jul 2019 19:23:05 +0300 Subject: migrate ra_syntax to the new rowan API --- crates/ra_syntax/src/ast/generated.rs.tera | 51 +++++++++--------------------- 1 file changed, 15 insertions(+), 36 deletions(-) (limited to 'crates/ra_syntax/src/ast/generated.rs.tera') diff --git a/crates/ra_syntax/src/ast/generated.rs.tera b/crates/ra_syntax/src/ast/generated.rs.tera index c8a13fc5f..f3365c560 100644 --- a/crates/ra_syntax/src/ast/generated.rs.tera +++ b/crates/ra_syntax/src/ast/generated.rs.tera @@ -11,94 +11,73 @@ the below applies to the result of this template #![cfg_attr(rustfmt, rustfmt_skip)] -use rowan::TransparentNewType; - use crate::{ SyntaxNode, SyntaxKind::*, - syntax_node::{TreeArc}, ast::{self, AstNode}, }; {% for node, methods in ast %} // {{ node }} {%- if methods.enum %} -#[derive(Debug, PartialEq, Eq, Hash)] -#[repr(transparent)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct {{ node }} { pub(crate) syntax: SyntaxNode, } -unsafe impl TransparentNewType for {{ node }} { - type Repr = rowan::SyntaxNode; -} -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum {{ node }}Kind<'a> { +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum {{ node }}Kind { {%- for kind in methods.enum %} - {{ kind }}(&'a {{ kind }}), + {{ kind }}({{ kind }}), {%- endfor %} } {%- for kind in methods.enum %} -impl<'a> From<&'a {{ kind }}> for &'a {{ node }} { - fn from(n: &'a {{ kind }}) -> &'a {{ node }} { - {{ node }}::cast(&n.syntax).unwrap() +impl From<{{ kind }}> for {{ node }} { + fn from(n: {{ kind }}) -> {{ node }} { + {{ node }}::cast(n.syntax).unwrap() } } {%- endfor %} impl AstNode for {{ node }} { - fn cast(syntax: &SyntaxNode) -> Option<&Self> { + fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { {%- for kind in methods.enum %} | {{ kind | SCREAM }} - {%- endfor %} => Some({{ node }}::from_repr(syntax.into_repr())), + {%- endfor %} => Some({{ node }} { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl ToOwned for {{ node }} { - type Owned = TreeArc<{{ node }}>; - fn to_owned(&self) -> TreeArc<{{ node }}> { TreeArc::cast(self.syntax.to_owned()) } -} - impl {{ node }} { pub fn kind(&self) -> {{ node }}Kind { match self.syntax.kind() { {%- for kind in methods.enum %} - {{ kind | SCREAM }} => {{ node }}Kind::{{ kind }}({{ kind }}::cast(&self.syntax).unwrap()), + {{ kind | SCREAM }} => {{ node }}Kind::{{ kind }}({{ kind }}::cast(self.syntax.clone()).unwrap()), {%- endfor %} _ => unreachable!(), } } } {% else %} -#[derive(Debug, PartialEq, Eq, Hash)] -#[repr(transparent)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct {{ node }} { pub(crate) syntax: SyntaxNode, } -unsafe impl TransparentNewType for {{ node }} { - type Repr = rowan::SyntaxNode; -} impl AstNode for {{ node }} { - fn cast(syntax: &SyntaxNode) -> Option<&Self> { + fn cast(syntax: SyntaxNode) -> Option { match syntax.kind() { - {{ node | SCREAM }} => Some({{ node }}::from_repr(syntax.into_repr())), + {{ node | SCREAM }} => Some({{ node }} { syntax }), _ => None, } } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl ToOwned for {{ node }} { - type Owned = TreeArc<{{ node }}>; - fn to_owned(&self) -> TreeArc<{{ node }}> { TreeArc::cast(self.syntax.to_owned()) } -} - {% endif %} {% if methods.traits -%} @@ -113,7 +92,7 @@ impl {{ node }} { {%- for m in methods.collections -%} {%- set method_name = m.0 -%} {%- set ChildName = m.1 %} - pub fn {{ method_name }}(&self) -> impl Iterator { + pub fn {{ method_name }}(&self) -> impl Iterator { super::children(self) } {% endfor -%} @@ -129,7 +108,7 @@ impl {{ node }} { {%- set method_name = m.0 -%} {%- set ChildName = m.1 %} {%- endif %} - pub fn {{ method_name }}(&self) -> Option<&{{ ChildName }}> { + pub fn {{ method_name }}(&self) -> Option<{{ ChildName }}> { super::child_opt(self) } {% endfor -%} -- cgit v1.2.3