Skip to content

Commit 9776e66

Browse files
committed
style fix
1 parent 3c0f429 commit 9776e66

2 files changed

Lines changed: 19 additions & 18 deletions

File tree

thrust-macros/src/formula.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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)]
126127
mod tests {
127128
use super::*;

thrust-macros/src/spec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ fn rewrite_self_in_expr(expr: &mut syn::Expr) {
554554
}
555555

556556
/// Replaces every `self` identifier with `self_`, recursing into groups.
557-
pub(crate) fn rewrite_self_in_tokens(tokens: TokenStream2) -> TokenStream2 {
557+
pub fn rewrite_self_in_tokens(tokens: TokenStream2) -> TokenStream2 {
558558
use proc_macro2::TokenTree;
559559
tokens
560560
.into_iter()

0 commit comments

Comments
 (0)