@@ -33,6 +33,24 @@ pub fn expand(input: TokenStream) -> TokenStream {
3333 Ok ( expr) => expr,
3434 Err ( e) => return e. to_compile_error ( ) ,
3535 } ;
36+
37+ // Rewrites each assignment `lhs = rhs` (produced by [`desugar_arrows`] from
38+ // `lhs ==> rhs`) into the boolean expression `(!(lhs)) || (rhs)`. Visiting
39+ // post-order means nested implications are rewritten innermost-first, so the
40+ // right-associative chain `a ==> b ==> c` becomes `!a || (!b || c)`.
41+ struct ImplicationRewriter ;
42+
43+ impl VisitMut for ImplicationRewriter {
44+ fn visit_expr_mut ( & mut self , expr : & mut syn:: Expr ) {
45+ syn:: visit_mut:: visit_expr_mut ( self , expr) ;
46+ if let syn:: Expr :: Assign ( assign) = expr {
47+ let left = & assign. left ;
48+ let right = & assign. right ;
49+ * expr = syn:: parse_quote!( ( !( #left) ) || ( #right) ) ;
50+ }
51+ }
52+ }
53+
3654 ImplicationRewriter . visit_expr_mut ( & mut expr) ;
3755
3856 expr. into_token_stream ( )
@@ -105,23 +123,6 @@ fn desugar_arrows(input: TokenStream) -> TokenStream {
105123 out
106124}
107125
108- /// Rewrites each assignment `lhs = rhs` (produced by [`desugar_arrows`] from
109- /// `lhs ==> rhs`) into the boolean expression `(!(lhs)) || (rhs)`. Visiting
110- /// post-order means nested implications are rewritten innermost-first, so the
111- /// right-associative chain `a ==> b ==> c` becomes `!a || (!b || c)`.
112- struct ImplicationRewriter ;
113-
114- impl VisitMut for ImplicationRewriter {
115- fn visit_expr_mut ( & mut self , expr : & mut syn:: Expr ) {
116- syn:: visit_mut:: visit_expr_mut ( self , expr) ;
117- if let syn:: Expr :: Assign ( assign) = expr {
118- let left = & assign. left ;
119- let right = & assign. right ;
120- * expr = syn:: parse_quote!( ( !( #left) ) || ( #right) ) ;
121- }
122- }
123- }
124-
125126#[ cfg( test) ]
126127mod tests {
127128 use super :: * ;
0 commit comments