From 5a2538d174fd36a8ed7f4fa344b9583fc48bd977 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 11 Feb 2020 13:12:13 +0000 Subject: Remove the Embed variant from ExprKind --- dhall/src/syntax/ast/visitor.rs | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) (limited to 'dhall/src/syntax/ast/visitor.rs') diff --git a/dhall/src/syntax/ast/visitor.rs b/dhall/src/syntax/ast/visitor.rs index c09b8d4..fc90efd 100644 --- a/dhall/src/syntax/ast/visitor.rs +++ b/dhall/src/syntax/ast/visitor.rs @@ -10,11 +10,10 @@ use crate::syntax::*; /// preventing exactly this ! So we have to be more clever. The visitor pattern allows us to have /// only one mutable thing the whole time: the visitor itself. The visitor can then carry around /// multiple closures or just one, and Rust is ok with either. See for example TraverseRefVisitor. -pub trait ExprKindVisitor<'a, SE1, SE2, E1, E2>: Sized { +pub trait ExprKindVisitor<'a, SE1, SE2>: Sized { type Error; fn visit_subexpr(&mut self, subexpr: &'a SE1) -> Result; - fn visit_embed(self, embed: &'a E1) -> Result; fn visit_subexpr_under_binder( mut self, @@ -26,18 +25,18 @@ pub trait ExprKindVisitor<'a, SE1, SE2, E1, E2>: Sized { fn visit( self, - input: &'a ExprKind, - ) -> Result, Self::Error> { + input: &'a ExprKind, + ) -> Result, Self::Error> { visit_ref(self, input) } } -fn visit_ref<'a, V, SE1, SE2, E1, E2>( +fn visit_ref<'a, V, SE1, SE2>( mut v: V, - input: &'a ExprKind, -) -> Result, V::Error> + input: &'a ExprKind, +) -> Result, V::Error> where - V: ExprKindVisitor<'a, SE1, SE2, E1, E2>, + V: ExprKindVisitor<'a, SE1, SE2>, { fn vec<'a, T, U, Err, F: FnMut(&'a T) -> Result>( x: &'a [T], @@ -54,27 +53,27 @@ where None => None, }) } - fn dupmap<'a, V, SE1, SE2, E1, E2, T>( + fn dupmap<'a, V, SE1, SE2, T>( x: impl IntoIterator, mut v: V, ) -> Result where SE1: 'a, T: FromIterator<(Label, SE2)>, - V: ExprKindVisitor<'a, SE1, SE2, E1, E2>, + V: ExprKindVisitor<'a, SE1, SE2>, { x.into_iter() .map(|(k, x)| Ok((k.clone(), v.visit_subexpr(x)?))) .collect() } - fn optdupmap<'a, V, SE1, SE2, E1, E2, T>( + fn optdupmap<'a, V, SE1, SE2, T>( x: impl IntoIterator)>, mut v: V, ) -> Result where SE1: 'a, T: FromIterator<(Label, Option)>, - V: ExprKindVisitor<'a, SE1, SE2, E1, E2>, + V: ExprKindVisitor<'a, SE1, SE2>, { x.into_iter() .map(|(k, x)| { @@ -147,17 +146,15 @@ where } Assert(e) => Assert(v.visit_subexpr(e)?), Import(i) => Import(i.traverse_ref(|e| v.visit_subexpr(e))?), - Embed(a) => Embed(v.visit_embed(a)?), }) } pub struct TraverseRefMaybeBinderVisitor(pub F); -impl<'a, SE, E, SE2, Err, F> ExprKindVisitor<'a, SE, SE2, E, E> +impl<'a, SE, SE2, Err, F> ExprKindVisitor<'a, SE, SE2> for TraverseRefMaybeBinderVisitor where SE: 'a, - E: 'a + Clone, F: FnMut(Option<&'a Label>, &'a SE) -> Result, { type Error = Err; @@ -172,7 +169,4 @@ where ) -> Result { (self.0)(Some(label), subexpr) } - fn visit_embed(self, embed: &'a E) -> Result { - Ok(embed.clone()) - } } -- cgit v1.2.3