From 3927c01d080e65dde41d1e48653d09607d26ca68 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sun, 2 Apr 2023 13:58:09 +0900 Subject: [PATCH] revset: make error type opaque to try_transform_expression() It no longer handles RevsetResolutionError. --- lib/src/revset.rs | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/src/revset.rs b/lib/src/revset.rs index e380f8fbc..f3de5026f 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -13,6 +13,7 @@ // limitations under the License. use std::collections::HashMap; +use std::convert::Infallible; use std::ops::Range; use std::path::Path; use std::rc::Rc; @@ -1110,11 +1111,10 @@ fn transform_expression_bottom_up( expression: &Rc, mut f: impl FnMut(&Rc) -> TransformedExpression, ) -> TransformedExpression { - try_transform_expression(expression, |_| Ok(None), |expression| Ok(f(expression))).unwrap() + try_transform_expression::(expression, |_| Ok(None), |expression| Ok(f(expression))) + .unwrap() } -type TransformResult = Result; - /// Walks `expression` tree and applies transformation recursively. /// /// `pre` is the callback to rewrite subtree including children. It is @@ -1127,16 +1127,16 @@ type TransformResult = Result; /// If no nodes rewritten, this function returns `None`. /// `std::iter::successors()` could be used if the transformation needs to be /// applied repeatedly until converged. -fn try_transform_expression( +fn try_transform_expression( expression: &Rc, - mut pre: impl FnMut(&Rc) -> TransformResult, - mut post: impl FnMut(&Rc) -> TransformResult, -) -> TransformResult { - fn transform_child_rec( + mut pre: impl FnMut(&Rc) -> Result, + mut post: impl FnMut(&Rc) -> Result, +) -> Result { + fn transform_child_rec( expression: &Rc, - pre: &mut impl FnMut(&Rc) -> TransformResult, - post: &mut impl FnMut(&Rc) -> TransformResult, - ) -> TransformResult { + pre: &mut impl FnMut(&Rc) -> Result, + post: &mut impl FnMut(&Rc) -> Result, + ) -> Result { Ok(match expression.as_ref() { RevsetExpression::None => None, RevsetExpression::All => None, @@ -1216,11 +1216,11 @@ fn try_transform_expression( } #[allow(clippy::type_complexity)] - fn transform_rec_pair( + fn transform_rec_pair( (expression1, expression2): (&Rc, &Rc), - pre: &mut impl FnMut(&Rc) -> TransformResult, - post: &mut impl FnMut(&Rc) -> TransformResult, - ) -> Result, Rc)>, RevsetResolutionError> { + pre: &mut impl FnMut(&Rc) -> Result, + post: &mut impl FnMut(&Rc) -> Result, + ) -> Result, Rc)>, E> { match ( transform_rec(expression1, pre, post)?, transform_rec(expression2, pre, post)?, @@ -1234,11 +1234,11 @@ fn try_transform_expression( } } - fn transform_rec( + fn transform_rec( expression: &Rc, - pre: &mut impl FnMut(&Rc) -> TransformResult, - post: &mut impl FnMut(&Rc) -> TransformResult, - ) -> TransformResult { + pre: &mut impl FnMut(&Rc) -> Result, + post: &mut impl FnMut(&Rc) -> Result, + ) -> Result { if let Some(new_expression) = pre(expression)? { return Ok(Some(new_expression)); }