From 9650183c732aacc702e17b714de8987663c13b09 Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 5 Nov 2024 22:07:54 -0500 Subject: [PATCH] Replace some "if let" statements with "matches!" macro for better formatting --- dust-lang/src/parser.rs | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/dust-lang/src/parser.rs b/dust-lang/src/parser.rs index 598a058..5c6f26a 100644 --- a/dust-lang/src/parser.rs +++ b/dust-lang/src/parser.rs @@ -222,10 +222,15 @@ impl<'src> Parser<'src> { } fn optimize_statement(&mut self) { - if let Some( - [Operation::LoadBoolean | Operation::LoadConstant, Operation::LoadBoolean | Operation::LoadConstant, Operation::Jump, Operation::Equal | Operation::Less | Operation::LessEqual], - ) = self.get_end_of_statement() - { + if matches!( + self.get_end_of_statement(), + Some([ + Operation::LoadBoolean | Operation::LoadConstant, + Operation::LoadBoolean | Operation::LoadConstant, + Operation::Jump, + Operation::Equal | Operation::Less | Operation::LessEqual + ],) + ) { log::trace!("Optimizing boolean comparison"); let mut instructions = self @@ -1017,10 +1022,15 @@ impl<'src> Parser<'src> { self.advance()?; self.parse_expression()?; - if let Some( - [Operation::LoadBoolean, Operation::LoadBoolean, Operation::Jump, Operation::Equal | Operation::Less | Operation::LessEqual], - ) = self.get_end_of_statement() - { + if matches!( + self.get_end_of_statement(), + Some([ + Operation::LoadBoolean, + Operation::LoadBoolean, + Operation::Jump, + Operation::Equal | Operation::Less | Operation::LessEqual + ],) + ) { self.chunk.instructions_mut().pop(); self.chunk.instructions_mut().pop(); } @@ -1152,10 +1162,15 @@ impl<'src> Parser<'src> { self.parse_expression()?; - if let Some( - [Operation::LoadBoolean, Operation::LoadBoolean, Operation::Jump, Operation::Equal | Operation::Less | Operation::LessEqual], - ) = self.get_end_of_statement() - { + if matches!( + self.get_end_of_statement(), + Some([ + Operation::LoadBoolean, + Operation::LoadBoolean, + Operation::Jump, + Operation::Equal | Operation::Less | Operation::LessEqual + ],) + ) { self.chunk.instructions_mut().pop(); self.chunk.instructions_mut().pop(); self.chunk.instructions_mut().pop();