From 7ba857a96eebbdd1cef0aa22407c870887d24aed Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 11 Apr 2019 19:11:33 +0200 Subject: Remove type parameter from TypeError --- dhall/src/error.rs | 6 +++--- dhall/src/traits/dynamic_type.rs | 12 ++++++------ dhall/src/typecheck.rs | 37 ++++++++++++++++++------------------- 3 files changed, 27 insertions(+), 28 deletions(-) (limited to 'dhall') diff --git a/dhall/src/error.rs b/dhall/src/error.rs index 0a02816..1243c94 100644 --- a/dhall/src/error.rs +++ b/dhall/src/error.rs @@ -6,7 +6,7 @@ pub enum Error { Parse(dhall_core::ParseError), Decode(crate::binary::DecodeError), Resolve(crate::imports::ImportError), - Typecheck(crate::typecheck::TypeError), + Typecheck(crate::typecheck::TypeError), Deserialize(String), } @@ -44,8 +44,8 @@ impl From for Error { Error::Resolve(err) } } -impl From> for Error { - fn from(err: crate::typecheck::TypeError) -> Error { +impl From for Error { + fn from(err: crate::typecheck::TypeError) -> Error { Error::Typecheck(err) } } diff --git a/dhall/src/traits/dynamic_type.rs b/dhall/src/traits/dynamic_type.rs index 66af320..d03f8cd 100644 --- a/dhall/src/traits/dynamic_type.rs +++ b/dhall/src/traits/dynamic_type.rs @@ -2,21 +2,21 @@ use crate::expr::*; use crate::traits::StaticType; use crate::typecheck::{TypeError, TypeMessage}; use dhall_core::context::Context; -use dhall_core::{Const, ExprF, X}; +use dhall_core::{Const, ExprF}; use std::borrow::Cow; pub trait DynamicType { - fn get_type<'a>(&'a self) -> Result, TypeError>; + fn get_type<'a>(&'a self) -> Result, TypeError>; } impl DynamicType for T { - fn get_type<'a>(&'a self) -> Result, TypeError> { + fn get_type<'a>(&'a self) -> Result, TypeError> { Ok(Cow::Owned(T::get_static_type())) } } impl DynamicType for Type { - fn get_type(&self) -> Result, TypeError> { + fn get_type(&self) -> Result, TypeError> { use TypeInternal::*; match &self.0 { Expr(e) => e.get_type(), @@ -30,7 +30,7 @@ impl DynamicType for Type { } impl DynamicType for Normalized { - fn get_type(&self) -> Result, TypeError> { + fn get_type(&self) -> Result, TypeError> { match &self.1 { Some(t) => Ok(Cow::Borrowed(t)), None => Err(TypeError::new( @@ -43,7 +43,7 @@ impl DynamicType for Normalized { } impl DynamicType for Typed { - fn get_type(&self) -> Result, TypeError> { + fn get_type(&self) -> Result, TypeError> { match &self.1 { Some(t) => Ok(Cow::Borrowed(t)), None => Err(TypeError::new( diff --git a/dhall/src/typecheck.rs b/dhall/src/typecheck.rs index ab4142b..4881972 100644 --- a/dhall/src/typecheck.rs +++ b/dhall/src/typecheck.rs @@ -12,10 +12,10 @@ use dhall_generator as dhall; use self::TypeMessage::*; impl Resolved { - pub fn typecheck(self) -> Result> { + pub fn typecheck(self) -> Result { type_of(self.0.clone()) } - pub fn typecheck_with(self, ty: &Type) -> Result> { + pub fn typecheck_with(self, ty: &Type) -> Result { let expr: SubExpr<_, _> = self.0.clone(); let ty: SubExpr<_, _> = ty.as_normalized()?.as_expr().absurd(); type_of(dhall::subexpr!(expr: ty)) @@ -26,7 +26,7 @@ impl Resolved { } } impl Typed { - fn get_type_move(self) -> Result> { + fn get_type_move(self) -> Result { self.1.ok_or(TypeError::new( &Context::new(), self.0, @@ -45,7 +45,7 @@ impl Normalized { } } impl Type { - pub fn as_normalized(&self) -> Result<&Normalized, TypeError> { + pub fn as_normalized(&self) -> Result<&Normalized, TypeError> { use TypeInternal::*; match &self.0 { Expr(e) => Ok(e), @@ -56,7 +56,7 @@ impl Type { )), } } - pub(crate) fn into_normalized(self) -> Result> { + pub(crate) fn into_normalized(self) -> Result { use TypeInternal::*; match self.0 { Expr(e) => Ok(*e), @@ -68,7 +68,7 @@ impl Type { } } // Expose the outermost constructor - fn unroll_ref(&self) -> Result<&Expr, TypeError> { + fn unroll_ref(&self) -> Result<&Expr, TypeError> { Ok(self.as_normalized()?.unroll_ref()) } fn shift(&self, delta: isize, var: &V