diff options
author | Aleksey Kladov <[email protected]> | 2019-01-07 13:42:10 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-08 08:20:15 +0000 |
commit | b73c51ff9bdf96ea22af0b9c431f201dcc8ddcd3 (patch) | |
tree | 6708f69cb7de64fe0d5a48f2bb2220f4743eede2 | |
parent | 5618c8ade1885ca17a56d9303a7559b332ae3e9e (diff) |
wrap TreePtr
-rw-r--r-- | Cargo.lock | 18 | ||||
-rw-r--r-- | crates/ra_syntax/src/yellow.rs | 52 |
2 files changed, 54 insertions, 16 deletions
diff --git a/Cargo.lock b/Cargo.lock index 85818fa1e..6de46a5f3 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -221,7 +221,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
221 | dependencies = [ | 221 | dependencies = [ |
222 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", | 222 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", |
223 | "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", | 223 | "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", |
224 | "syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)", | 224 | "syn 0.15.24 (registry+https://github.com/rust-lang/crates.io-index)", |
225 | ] | 225 | ] |
226 | 226 | ||
227 | [[package]] | 227 | [[package]] |
@@ -284,7 +284,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
284 | dependencies = [ | 284 | dependencies = [ |
285 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", | 285 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", |
286 | "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", | 286 | "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", |
287 | "syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)", | 287 | "syn 0.15.24 (registry+https://github.com/rust-lang/crates.io-index)", |
288 | "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", | 288 | "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", |
289 | ] | 289 | ] |
290 | 290 | ||
@@ -501,7 +501,7 @@ dependencies = [ | |||
501 | "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", | 501 | "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", |
502 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", | 502 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", |
503 | "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", | 503 | "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", |
504 | "syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)", | 504 | "syn 0.15.24 (registry+https://github.com/rust-lang/crates.io-index)", |
505 | ] | 505 | ] |
506 | 506 | ||
507 | [[package]] | 507 | [[package]] |
@@ -585,7 +585,7 @@ dependencies = [ | |||
585 | "pest_meta 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", | 585 | "pest_meta 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", |
586 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", | 586 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", |
587 | "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", | 587 | "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", |
588 | "syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)", | 588 | "syn 0.15.24 (registry+https://github.com/rust-lang/crates.io-index)", |
589 | ] | 589 | ] |
590 | 590 | ||
591 | [[package]] | 591 | [[package]] |
@@ -970,7 +970,7 @@ dependencies = [ | |||
970 | [[package]] | 970 | [[package]] |
971 | name = "rowan" | 971 | name = "rowan" |
972 | version = "0.2.0" | 972 | version = "0.2.0" |
973 | source = "git+https://github.com/rust-analyzer/rowan.git?branch=new-impl#688693ceec26b7be82918832c427b4bcb230fe24" | 973 | source = "git+https://github.com/rust-analyzer/rowan.git?branch=new-impl#6b50db0f68a989c512e3bbebfbc8ede70ca7f221" |
974 | dependencies = [ | 974 | dependencies = [ |
975 | "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", | 975 | "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", |
976 | "smol_str 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", | 976 | "smol_str 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", |
@@ -1075,7 +1075,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1075 | dependencies = [ | 1075 | dependencies = [ |
1076 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", | 1076 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", |
1077 | "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", | 1077 | "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", |
1078 | "syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)", | 1078 | "syn 0.15.24 (registry+https://github.com/rust-lang/crates.io-index)", |
1079 | ] | 1079 | ] |
1080 | 1080 | ||
1081 | [[package]] | 1081 | [[package]] |
@@ -1140,7 +1140,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1140 | 1140 | ||
1141 | [[package]] | 1141 | [[package]] |
1142 | name = "syn" | 1142 | name = "syn" |
1143 | version = "0.15.23" | 1143 | version = "0.15.24" |
1144 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1144 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1145 | dependencies = [ | 1145 | dependencies = [ |
1146 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", | 1146 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", |
@@ -1155,7 +1155,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1155 | dependencies = [ | 1155 | dependencies = [ |
1156 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", | 1156 | "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", |
1157 | "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", | 1157 | "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", |
1158 | "syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)", | 1158 | "syn 0.15.24 (registry+https://github.com/rust-lang/crates.io-index)", |
1159 | "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", | 1159 | "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", |
1160 | ] | 1160 | ] |
1161 | 1161 | ||
@@ -1593,7 +1593,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
1593 | "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" | 1593 | "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" |
1594 | "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" | 1594 | "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" |
1595 | "checksum superslice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b50b13d42370e0f5fc62eafdd5c2d20065eaf5458dab215ff3e20e63eea96b30" | 1595 | "checksum superslice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b50b13d42370e0f5fc62eafdd5c2d20065eaf5458dab215ff3e20e63eea96b30" |
1596 | "checksum syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)" = "9545a6a093a3f0bd59adb472700acc08cad3776f860f16a897dfce8c88721cbc" | 1596 | "checksum syn 0.15.24 (registry+https://github.com/rust-lang/crates.io-index)" = "734ecc29cd36e8123850d9bf21dfd62ef8300aaa8f879aabaa899721808be37c" |
1597 | "checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" | 1597 | "checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" |
1598 | "checksum tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "7e91405c14320e5c79b3d148e1c86f40749a36e490642202a31689cb1a3452b2" | 1598 | "checksum tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "7e91405c14320e5c79b3d148e1c86f40749a36e490642202a31689cb1a3452b2" |
1599 | "checksum tera 0.11.20 (registry+https://github.com/rust-lang/crates.io-index)" = "4b505279e19d8f7d24b1a9dc58327c9c36174b1a2c7ebdeac70792d017cb64f3" | 1599 | "checksum tera 0.11.20 (registry+https://github.com/rust-lang/crates.io-index)" = "4b505279e19d8f7d24b1a9dc58327c9c36174b1a2c7ebdeac70792d017cb64f3" |
diff --git a/crates/ra_syntax/src/yellow.rs b/crates/ra_syntax/src/yellow.rs index 6dc846f33..38e680a9c 100644 --- a/crates/ra_syntax/src/yellow.rs +++ b/crates/ra_syntax/src/yellow.rs | |||
@@ -18,19 +18,56 @@ impl Types for RaTypes { | |||
18 | type RootData = Vec<SyntaxError>; | 18 | type RootData = Vec<SyntaxError>; |
19 | } | 19 | } |
20 | 20 | ||
21 | pub type GreenNode = ::rowan::GreenNode<RaTypes>; | 21 | pub type GreenNode = rowan::GreenNode<RaTypes>; |
22 | pub type TreePtr<T> = ::rowan::TreePtr<RaTypes, T>; | 22 | |
23 | #[derive(Clone, PartialEq, Eq, Hash)] | ||
24 | pub struct TreePtr<T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>>( | ||
25 | pub(crate) rowan::TreePtr<RaTypes, T>, | ||
26 | ); | ||
27 | |||
28 | impl<T> TreePtr<T> | ||
29 | where | ||
30 | T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, | ||
31 | { | ||
32 | pub(crate) fn cast<U>(this: TreePtr<T>) -> TreePtr<U> | ||
33 | where | ||
34 | U: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, | ||
35 | { | ||
36 | TreePtr(rowan::TreePtr::cast(this.0)) | ||
37 | } | ||
38 | } | ||
39 | |||
40 | impl<T> std::ops::Deref for TreePtr<T> | ||
41 | where | ||
42 | T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, | ||
43 | { | ||
44 | type Target = T; | ||
45 | fn deref(&self) -> &T { | ||
46 | self.0.deref() | ||
47 | } | ||
48 | } | ||
49 | |||
50 | impl<T> fmt::Debug for TreePtr<T> | ||
51 | where | ||
52 | T: TransparentNewType<Repr = rowan::SyntaxNode<RaTypes>>, | ||
53 | T: fmt::Debug, | ||
54 | { | ||
55 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||
56 | fmt::Debug::fmt(&self.0, fmt) | ||
57 | } | ||
58 | } | ||
23 | 59 | ||
24 | #[derive(PartialEq, Eq, Hash)] | 60 | #[derive(PartialEq, Eq, Hash)] |
25 | #[repr(transparent)] | 61 | #[repr(transparent)] |
26 | pub struct SyntaxNode(pub(crate) ::rowan::SyntaxNode<RaTypes>); | 62 | pub struct SyntaxNode(pub(crate) rowan::SyntaxNode<RaTypes>); |
27 | unsafe impl TransparentNewType for SyntaxNode { | 63 | unsafe impl TransparentNewType for SyntaxNode { |
28 | type Repr = ::rowan::SyntaxNode<RaTypes>; | 64 | type Repr = rowan::SyntaxNode<RaTypes>; |
29 | } | 65 | } |
30 | 66 | ||
31 | impl SyntaxNode { | 67 | impl SyntaxNode { |
32 | pub(crate) fn new(green: GreenNode, errors: Vec<SyntaxError>) -> TreePtr<SyntaxNode> { | 68 | pub(crate) fn new(green: GreenNode, errors: Vec<SyntaxError>) -> TreePtr<SyntaxNode> { |
33 | TreePtr::cast(::rowan::SyntaxNode::new(green, errors)) | 69 | let ptr = TreePtr(rowan::SyntaxNode::new(green, errors)); |
70 | TreePtr::cast(ptr) | ||
34 | } | 71 | } |
35 | } | 72 | } |
36 | 73 | ||
@@ -75,7 +112,8 @@ impl SyntaxNode { | |||
75 | self.0.replace_self(replacement) | 112 | self.0.replace_self(replacement) |
76 | } | 113 | } |
77 | pub fn to_owned(&self) -> TreePtr<SyntaxNode> { | 114 | pub fn to_owned(&self) -> TreePtr<SyntaxNode> { |
78 | TreePtr::cast(self.0.to_owned()) | 115 | let ptr = TreePtr(self.0.to_owned()); |
116 | TreePtr::cast(ptr) | ||
79 | } | 117 | } |
80 | pub fn kind(&self) -> SyntaxKind { | 118 | pub fn kind(&self) -> SyntaxKind { |
81 | self.0.kind() | 119 | self.0.kind() |
@@ -120,7 +158,7 @@ impl fmt::Debug for SyntaxNode { | |||
120 | } | 158 | } |
121 | 159 | ||
122 | #[derive(Debug)] | 160 | #[derive(Debug)] |
123 | pub struct SyntaxNodeChildren<'a>(::rowan::SyntaxNodeChildren<'a, RaTypes>); | 161 | pub struct SyntaxNodeChildren<'a>(rowan::SyntaxNodeChildren<'a, RaTypes>); |
124 | 162 | ||
125 | impl<'a> Iterator for SyntaxNodeChildren<'a> { | 163 | impl<'a> Iterator for SyntaxNodeChildren<'a> { |
126 | type Item = &'a SyntaxNode; | 164 | type Item = &'a SyntaxNode; |