diff options
author | Aleksey Kladov <[email protected]> | 2019-02-21 13:12:15 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-02-21 13:12:15 +0000 |
commit | 7060a39d5c8dc2c72fe207536fee649ff615860f (patch) | |
tree | 33fc9206a9ee2f2f1c64eeb85748bf5e9cd1c3f8 /crates/ra_syntax | |
parent | b51b71bf258c6520ee60f865a3658b30ce44ef18 (diff) |
simplify trait bounds
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r-- | crates/ra_syntax/src/syntax_node.rs | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/crates/ra_syntax/src/syntax_node.rs b/crates/ra_syntax/src/syntax_node.rs index bcfacde72..4d54ae614 100644 --- a/crates/ra_syntax/src/syntax_node.rs +++ b/crates/ra_syntax/src/syntax_node.rs | |||
@@ -6,7 +6,10 @@ | |||
6 | //! The *real* implementation is in the (language-agnostic) `rowan` crate, this | 6 | //! The *real* implementation is in the (language-agnostic) `rowan` crate, this |
7 | //! modules just wraps its API. | 7 | //! modules just wraps its API. |
8 | 8 | ||
9 | use std::{fmt::{self, Write}, borrow::Borrow}; | 9 | use std::{ |
10 | fmt::{self, Write}, | ||
11 | borrow::Borrow, | ||
12 | }; | ||
10 | 13 | ||
11 | use rowan::{Types, TransparentNewType}; | 14 | use rowan::{Types, TransparentNewType}; |
12 | 15 | ||
@@ -24,14 +27,17 @@ impl Types for RaTypes { | |||
24 | type RootData = Vec<SyntaxError>; | 27 | type RootData = Vec<SyntaxError>; |
25 | } | 28 | } |
26 | 29 | ||
27 | pub type GreenNode = rowan::GreenNode<RaTypes>; | 30 | pub(crate) type GreenNode = rowan::GreenNode<RaTypes>; |
31 | |||
32 | /// Marker trait for CST and AST nodes | ||
33 | pub trait SyntaxNodeWrapper: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>> {} | ||
34 | impl<T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>> SyntaxNodeWrapper for T {} | ||
28 | 35 | ||
36 | /// An owning smart pointer for CST or AST node. | ||
29 | #[derive(PartialEq, Eq, Hash)] | 37 | #[derive(PartialEq, Eq, Hash)] |
30 | pub struct TreeArc<T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>>( | 38 | pub struct TreeArc<T: SyntaxNodeWrapper>(pub(crate) rowan::TreeArc<RaTypes, T>); |
31 | pub(crate) rowan::TreeArc<RaTypes, T>, | ||
32 | ); | ||
33 | 39 | ||
34 | impl<T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>> Borrow<T> for TreeArc<T> { | 40 | impl<T: SyntaxNodeWrapper> Borrow<T> for TreeArc<T> { |
35 | fn borrow(&self) -> &T { | 41 | fn borrow(&self) -> &T { |
36 | &*self | 42 | &*self |
37 | } | 43 | } |
@@ -39,11 +45,11 @@ impl<T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>> Borrow<T> for Tre | |||
39 | 45 | ||
40 | impl<T> TreeArc<T> | 46 | impl<T> TreeArc<T> |
41 | where | 47 | where |
42 | T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, | 48 | T: SyntaxNodeWrapper, |
43 | { | 49 | { |
44 | pub(crate) fn cast<U>(this: TreeArc<T>) -> TreeArc<U> | 50 | pub(crate) fn cast<U>(this: TreeArc<T>) -> TreeArc<U> |
45 | where | 51 | where |
46 | U: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, | 52 | U: SyntaxNodeWrapper, |
47 | { | 53 | { |
48 | TreeArc(rowan::TreeArc::cast(this.0)) | 54 | TreeArc(rowan::TreeArc::cast(this.0)) |
49 | } | 55 | } |
@@ -51,7 +57,7 @@ where | |||
51 | 57 | ||
52 | impl<T> std::ops::Deref for TreeArc<T> | 58 | impl<T> std::ops::Deref for TreeArc<T> |
53 | where | 59 | where |
54 | T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, | 60 | T: SyntaxNodeWrapper, |
55 | { | 61 | { |
56 | type Target = T; | 62 | type Target = T; |
57 | fn deref(&self) -> &T { | 63 | fn deref(&self) -> &T { |
@@ -61,7 +67,7 @@ where | |||
61 | 67 | ||
62 | impl<T> PartialEq<T> for TreeArc<T> | 68 | impl<T> PartialEq<T> for TreeArc<T> |
63 | where | 69 | where |
64 | T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, | 70 | T: SyntaxNodeWrapper, |
65 | T: PartialEq<T>, | 71 | T: PartialEq<T>, |
66 | { | 72 | { |
67 | fn eq(&self, other: &T) -> bool { | 73 | fn eq(&self, other: &T) -> bool { |
@@ -72,7 +78,7 @@ where | |||
72 | 78 | ||
73 | impl<T> Clone for TreeArc<T> | 79 | impl<T> Clone for TreeArc<T> |
74 | where | 80 | where |
75 | T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, | 81 | T: SyntaxNodeWrapper, |
76 | { | 82 | { |
77 | fn clone(&self) -> TreeArc<T> { | 83 | fn clone(&self) -> TreeArc<T> { |
78 | TreeArc(self.0.clone()) | 84 | TreeArc(self.0.clone()) |
@@ -81,7 +87,7 @@ where | |||
81 | 87 | ||
82 | impl<T> fmt::Debug for TreeArc<T> | 88 | impl<T> fmt::Debug for TreeArc<T> |
83 | where | 89 | where |
84 | T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, | 90 | T: SyntaxNodeWrapper, |
85 | T: fmt::Debug, | 91 | T: fmt::Debug, |
86 | { | 92 | { |
87 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | 93 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { |