aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-02-21 13:12:15 +0000
committerAleksey Kladov <[email protected]>2019-02-21 13:12:15 +0000
commit7060a39d5c8dc2c72fe207536fee649ff615860f (patch)
tree33fc9206a9ee2f2f1c64eeb85748bf5e9cd1c3f8 /crates
parentb51b71bf258c6520ee60f865a3658b30ce44ef18 (diff)
simplify trait bounds
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_syntax/src/syntax_node.rs30
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
9use std::{fmt::{self, Write}, borrow::Borrow}; 9use std::{
10 fmt::{self, Write},
11 borrow::Borrow,
12};
10 13
11use rowan::{Types, TransparentNewType}; 14use 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
27pub type GreenNode = rowan::GreenNode<RaTypes>; 30pub(crate) type GreenNode = rowan::GreenNode<RaTypes>;
31
32/// Marker trait for CST and AST nodes
33pub trait SyntaxNodeWrapper: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>> {}
34impl<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)]
30pub struct TreeArc<T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>>( 38pub struct TreeArc<T: SyntaxNodeWrapper>(pub(crate) rowan::TreeArc<RaTypes, T>);
31 pub(crate) rowan::TreeArc<RaTypes, T>,
32);
33 39
34impl<T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>> Borrow<T> for TreeArc<T> { 40impl<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
40impl<T> TreeArc<T> 46impl<T> TreeArc<T>
41where 47where
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
52impl<T> std::ops::Deref for TreeArc<T> 58impl<T> std::ops::Deref for TreeArc<T>
53where 59where
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
62impl<T> PartialEq<T> for TreeArc<T> 68impl<T> PartialEq<T> for TreeArc<T>
63where 69where
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
73impl<T> Clone for TreeArc<T> 79impl<T> Clone for TreeArc<T>
74where 80where
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
82impl<T> fmt::Debug for TreeArc<T> 88impl<T> fmt::Debug for TreeArc<T>
83where 89where
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 {