From 0d980906852c9a22120c1b7992d2cc0661a63a80 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 1 May 2024 19:45:58 +0200 Subject: rebel-lang: reuse assignment code for let statements This should ensure that let with expression is always equivalent to let + separate initialization. --- crates/rebel-parse/src/ast/pat.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'crates/rebel-parse') diff --git a/crates/rebel-parse/src/ast/pat.rs b/crates/rebel-parse/src/ast/pat.rs index 7365b19..7528185 100644 --- a/crates/rebel-parse/src/ast/pat.rs +++ b/crates/rebel-parse/src/ast/pat.rs @@ -43,3 +43,15 @@ impl<'a> DestrPat<'a> { } } } + +impl<'a> From<&Pat<'a>> for DestrPat<'a> { + fn from(value: &Pat<'a>) -> Self { + match value { + Pat::Paren(pat) => DestrPat::Paren(Box::new(pat.as_ref().into())), + Pat::Ident(ident) => DestrPat::Path(Path { + root: PathRoot::Relative, + components: vec![*ident], + }), + } + } +} -- cgit v1.2.3