summaryrefslogtreecommitdiff
path: root/dhall_core
diff options
context:
space:
mode:
authorNadrieril2019-03-31 19:37:29 +0200
committerNadrieril2019-03-31 19:37:29 +0200
commit737472abf9c0ca2030ab8c2bb0b1d4af41167183 (patch)
treea9477b48c7e029e5726c7faa54934bb429fd0ee6 /dhall_core
parent7374d0524ccd53b256107667b213597c05720d2d (diff)
Remove evil Deref impl
Diffstat (limited to 'dhall_core')
-rw-r--r--dhall_core/src/core.rs17
-rw-r--r--dhall_core/src/printer.rs10
2 files changed, 16 insertions, 11 deletions
diff --git a/dhall_core/src/core.rs b/dhall_core/src/core.rs
index 2d11068..3f01b55 100644
--- a/dhall_core/src/core.rs
+++ b/dhall_core/src/core.rs
@@ -305,30 +305,25 @@ impl<S: Clone, A: Clone> Expr<S, Expr<S, A>> {
}
impl<N, E> Clone for SubExpr<N, E> {
+ #[inline(always)]
fn clone(&self) -> Self {
SubExpr(Rc::clone(&self.0))
}
}
-impl<N, E> std::ops::Deref for SubExpr<N, E> {
- type Target = Rc<Expr<N, E>>;
+impl<N, E> SubExpr<N, E> {
#[inline(always)]
- fn deref(&self) -> &Self::Target {
- &self.0
+ pub fn as_ref(&self) -> &Expr<N, E> {
+ self.0.as_ref()
}
}
-// impl<N, E> SubExpr<N, E> {
-// pub fn as_ref(&self) -> &Expr<N, E> {
-// self.0.as_ref()
-// }
-// }
-
// Remains of a previous life, where everything was in Boxes
pub fn bx<N, E>(x: Expr<N, E>) -> SubExpr<N, E> {
SubExpr(Rc::new(x))
}
+// Should probably rename this too
pub fn rc<N, E>(x: Expr<N, E>) -> SubExpr<N, E> {
SubExpr(Rc::new(x))
}
@@ -414,7 +409,7 @@ where
ExprF::Note(_, e) => {
map_subexpr_rc_binder(e, map_expr, map_under_binder)
}
- _ => rc(map_subexpr(
+ e => rc(map_subexpr(
e,
map_expr,
|_| unreachable!(),
diff --git a/dhall_core/src/printer.rs b/dhall_core/src/printer.rs
index b7d7506..fb3b8e8 100644
--- a/dhall_core/src/printer.rs
+++ b/dhall_core/src/printer.rs
@@ -217,6 +217,16 @@ impl<S, A: Display> Expr<S, A> {
}
}
+impl<S, A: Display> SubExpr<S, A> {
+ fn fmt_phase(
+ &self,
+ f: &mut fmt::Formatter,
+ phase: PrintPhase,
+ ) -> Result<(), fmt::Error> {
+ self.0.as_ref().fmt_phase(f, phase)
+ }
+}
+
fn fmt_list<T, I, F>(
open: &str,
sep: &str,