From 737472abf9c0ca2030ab8c2bb0b1d4af41167183 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 31 Mar 2019 19:37:29 +0200 Subject: Remove evil Deref impl --- dhall_core/src/core.rs | 17 ++++++----------- dhall_core/src/printer.rs | 10 ++++++++++ 2 files changed, 16 insertions(+), 11 deletions(-) (limited to 'dhall_core') 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 Expr> { } impl Clone for SubExpr { + #[inline(always)] fn clone(&self) -> Self { SubExpr(Rc::clone(&self.0)) } } -impl std::ops::Deref for SubExpr { - type Target = Rc>; +impl SubExpr { #[inline(always)] - fn deref(&self) -> &Self::Target { - &self.0 + pub fn as_ref(&self) -> &Expr { + self.0.as_ref() } } -// impl SubExpr { -// pub fn as_ref(&self) -> &Expr { -// self.0.as_ref() -// } -// } - // Remains of a previous life, where everything was in Boxes pub fn bx(x: Expr) -> SubExpr { SubExpr(Rc::new(x)) } +// Should probably rename this too pub fn rc(x: Expr) -> SubExpr { 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 Expr { } } +impl SubExpr { + fn fmt_phase( + &self, + f: &mut fmt::Formatter, + phase: PrintPhase, + ) -> Result<(), fmt::Error> { + self.0.as_ref().fmt_phase(f, phase) + } +} + fn fmt_list( open: &str, sep: &str, -- cgit v1.2.3