desugars operator overloading
match?
bendn 12 months ago
parent 6b7bb08 · commit 6fe9915
-rw-r--r--Cargo.toml2
-rw-r--r--src/lib.rs23
2 files changed, 24 insertions, 1 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 43df9fd..efe08ea 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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"
diff --git a/src/lib.rs b/src/lib.rs
index ba6dca3..2e9ac8f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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,