From 8c5b3ff15f2125e9d731fc199e194e1993c36b37 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 7 Dec 2020 14:15:43 +0000 Subject: Thread cx everywhere else imports are read --- serde_dhall/src/value.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'serde_dhall/src/value.rs') diff --git a/serde_dhall/src/value.rs b/serde_dhall/src/value.rs index e5f5acd..b259c4b 100644 --- a/serde_dhall/src/value.rs +++ b/serde_dhall/src/value.rs @@ -5,6 +5,7 @@ use dhall::operations::OpKind; use dhall::semantics::{Hir, HirKind, Nir, NirKind}; pub use dhall::syntax::NumKind; use dhall::syntax::{Expr, ExprKind, Span}; +use dhall::Ctxt; use crate::{Error, ErrorKind, FromDhall, Result, ToDhall}; @@ -206,7 +207,11 @@ pub enum SimpleType { } impl Value { - pub(crate) fn from_nir_and_ty(x: &Nir, ty: &Nir) -> Result { + pub(crate) fn from_nir_and_ty<'cx>( + cx: Ctxt<'cx>, + x: &Nir<'cx>, + ty: &Nir<'cx>, + ) -> Result { Ok(if let Some(val) = SimpleValue::from_nir(x) { // The type must be simple if the value is simple. let ty = SimpleType::from_nir(ty).unwrap(); @@ -218,7 +223,7 @@ impl Value { kind: ValueKind::Ty(ty), } } else { - let expr = x.to_hir_noenv().to_expr(Default::default()); + let expr = x.to_hir_noenv().to_expr(cx, Default::default()); return Err(Error(ErrorKind::Deserialize(format!( "this is neither a simple type nor a simple value: {}", expr @@ -342,7 +347,7 @@ impl SimpleValue { let type_error = || { Error(ErrorKind::Serialize(format!( "expected a value of type {}, found {:?}", - ty.unwrap().to_hir().to_expr(Default::default()), + ty.unwrap().to_expr(), self ))) }; @@ -439,7 +444,9 @@ impl SimpleValue { /// Converts back to the corresponding AST expression. pub(crate) fn to_expr(&self, ty: Option<&SimpleType>) -> Result { - Ok(self.to_hir(ty)?.to_expr(Default::default())) + Ctxt::with_new(|cx| { + Ok(self.to_hir(ty)?.to_expr(cx, Default::default())) + }) } } @@ -514,7 +521,7 @@ impl SimpleType { /// Converts back to the corresponding AST expression. pub(crate) fn to_expr(&self) -> Expr { - self.to_hir().to_expr(Default::default()) + Ctxt::with_new(|cx| self.to_hir().to_expr(cx, Default::default())) } } -- cgit v1.2.3