desugars operator overloading
match?
| -rw-r--r-- | Cargo.toml | 2 | ||||
| -rw-r--r-- | src/lib.rs | 23 |
2 files changed, 24 insertions, 1 deletions
@@ -1,6 +1,6 @@ [package] name = "lower-macros" -version = "0.2.7" +version = "0.2.8" authors = ["bend-n <[email protected]>"] description = "desugar math where the compiler wont" edition = "2021" @@ -273,6 +273,29 @@ fn walk(sub: &impl Sub, e: Expr) -> TokenStream { let args = args.into_iter().map(walk); quote!(#receiver . #method #turbofish (#(#args,)*)) } + Expr::Match(ExprMatch { expr, arms, .. }) => { + let arms = arms.into_iter().map( + |Arm { + pat, + guard, + + body, + // comma, + .. + }| { + let b = walk(*body); + let guard = match guard { + Some((i, x)) => { + let z = walk(*x); + quote! { #i #z } + } + None => quote! {}, + }; + quote! { #pat #guard => { #b } } + }, + ); + quote!(match #expr { #(#arms)* }) + } Expr::If(ExprIf { cond, then_branch, |