From b73c51ff9bdf96ea22af0b9c431f201dcc8ddcd3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 7 Jan 2019 16:42:10 +0300 Subject: [PATCH] wrap TreePtr --- Cargo.lock | 18 ++++++------ crates/ra_syntax/src/yellow.rs | 52 +++++++++++++++++++++++++++++----- 2 files changed, 54 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 85818fa1e4f..6de46a5f354 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -221,7 +221,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.24 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -284,7 +284,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.24 (registry+https://github.com/rust-lang/crates.io-index)", "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -501,7 +501,7 @@ dependencies = [ "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.24 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -585,7 +585,7 @@ dependencies = [ "pest_meta 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.24 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -970,7 +970,7 @@ dependencies = [ [[package]] name = "rowan" version = "0.2.0" -source = "git+https://github.com/rust-analyzer/rowan.git?branch=new-impl#688693ceec26b7be82918832c427b4bcb230fe24" +source = "git+https://github.com/rust-analyzer/rowan.git?branch=new-impl#6b50db0f68a989c512e3bbebfbc8ede70ca7f221" dependencies = [ "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "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" dependencies = [ "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.24 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1140,7 +1140,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "syn" -version = "0.15.23" +version = "0.15.24" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "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" dependencies = [ "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.24 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1593,7 +1593,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" "checksum superslice 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b50b13d42370e0f5fc62eafdd5c2d20065eaf5458dab215ff3e20e63eea96b30" -"checksum syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)" = "9545a6a093a3f0bd59adb472700acc08cad3776f860f16a897dfce8c88721cbc" +"checksum syn 0.15.24 (registry+https://github.com/rust-lang/crates.io-index)" = "734ecc29cd36e8123850d9bf21dfd62ef8300aaa8f879aabaa899721808be37c" "checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" "checksum tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "7e91405c14320e5c79b3d148e1c86f40749a36e490642202a31689cb1a3452b2" "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 6dc846f33a4..38e680a9c14 100644 --- a/crates/ra_syntax/src/yellow.rs +++ b/crates/ra_syntax/src/yellow.rs @@ -18,19 +18,56 @@ impl Types for RaTypes { type RootData = Vec; } -pub type GreenNode = ::rowan::GreenNode; -pub type TreePtr = ::rowan::TreePtr; +pub type GreenNode = rowan::GreenNode; + +#[derive(Clone, PartialEq, Eq, Hash)] +pub struct TreePtr>>( + pub(crate) rowan::TreePtr, +); + +impl TreePtr +where + T: TransparentNewType>, +{ + pub(crate) fn cast(this: TreePtr) -> TreePtr + where + U: TransparentNewType>, + { + TreePtr(rowan::TreePtr::cast(this.0)) + } +} + +impl std::ops::Deref for TreePtr +where + T: TransparentNewType>, +{ + type Target = T; + fn deref(&self) -> &T { + self.0.deref() + } +} + +impl fmt::Debug for TreePtr +where + T: TransparentNewType>, + T: fmt::Debug, +{ + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.0, fmt) + } +} #[derive(PartialEq, Eq, Hash)] #[repr(transparent)] -pub struct SyntaxNode(pub(crate) ::rowan::SyntaxNode); +pub struct SyntaxNode(pub(crate) rowan::SyntaxNode); unsafe impl TransparentNewType for SyntaxNode { - type Repr = ::rowan::SyntaxNode; + type Repr = rowan::SyntaxNode; } impl SyntaxNode { pub(crate) fn new(green: GreenNode, errors: Vec) -> TreePtr { - TreePtr::cast(::rowan::SyntaxNode::new(green, errors)) + let ptr = TreePtr(rowan::SyntaxNode::new(green, errors)); + TreePtr::cast(ptr) } } @@ -75,7 +112,8 @@ pub(crate) fn replace_with(&self, replacement: GreenNode) -> GreenNode { self.0.replace_self(replacement) } pub fn to_owned(&self) -> TreePtr { - TreePtr::cast(self.0.to_owned()) + let ptr = TreePtr(self.0.to_owned()); + TreePtr::cast(ptr) } pub fn kind(&self) -> SyntaxKind { self.0.kind() @@ -120,7 +158,7 @@ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { } #[derive(Debug)] -pub struct SyntaxNodeChildren<'a>(::rowan::SyntaxNodeChildren<'a, RaTypes>); +pub struct SyntaxNodeChildren<'a>(rowan::SyntaxNodeChildren<'a, RaTypes>); impl<'a> Iterator for SyntaxNodeChildren<'a> { type Item = &'a SyntaxNode;