diff --git a/huff_cli/src/huffc.rs b/huff_cli/src/huffc.rs index f7a9187c..f2267f76 100644 --- a/huff_cli/src/huffc.rs +++ b/huff_cli/src/huffc.rs @@ -173,12 +173,12 @@ fn main() { // Check that constant override argument is valid // Key rule: Alphabetic chars + underscore // Value rule: Valid literal string (0x...) - if parts.len() != 2 - || parts[0].chars().any(|c| !(c.is_alphabetic() || c == '_')) - || !parts[1].starts_with("0x") - || parts[1][2..].chars().any(|c| { - !(c.is_numeric() - || matches!(c, '\u{0041}'..='\u{0046}' | '\u{0061}'..='\u{0066}')) + if parts.len() != 2 || + parts[0].chars().any(|c| !(c.is_alphabetic() || c == '_')) || + !parts[1].starts_with("0x") || + parts[1][2..].chars().any(|c| { + !(c.is_numeric() || + matches!(c, '\u{0041}'..='\u{0046}' | '\u{0061}'..='\u{0066}')) }) { eprintln!("Invalid constant override argument: {}", Paint::red(c.to_string())); diff --git a/huff_core/src/lib.rs b/huff_core/src/lib.rs index 39f2f00a..5d5e0e4d 100644 --- a/huff_core/src/lib.rs +++ b/huff_core/src/lib.rs @@ -438,8 +438,8 @@ impl<'a, 'l> Compiler<'a, 'l> { Err(mut e) => { // Return any errors except if the inputs is empty and the constructor // definition is missing - if e.kind != CodegenErrorKind::MissingMacroDefinition("CONSTRUCTOR".to_string()) - || !inputs.is_empty() + if e.kind != CodegenErrorKind::MissingMacroDefinition("CONSTRUCTOR".to_string()) || + !inputs.is_empty() { // Add File Source to Span let mut errs = e diff --git a/huff_core/tests/parser_errors.rs b/huff_core/tests/parser_errors.rs index c1d62715..a41a7c2e 100644 --- a/huff_core/tests/parser_errors.rs +++ b/huff_core/tests/parser_errors.rs @@ -247,9 +247,9 @@ fn test_invalid_token_in_label_definition() { fn test_invalid_single_arg() { for _ in 0..10_000 { let random_char = rand::random::() as char; - if random_char.is_numeric() - || !random_char.is_alphabetic() - || random_char.to_string().as_bytes().len() > 1 + if random_char.is_numeric() || + !random_char.is_alphabetic() || + random_char.to_string().as_bytes().len() > 1 { continue; } diff --git a/huff_lexer/src/lib.rs b/huff_lexer/src/lib.rs index 6b1e4ec9..f3774c34 100644 --- a/huff_lexer/src/lib.rs +++ b/huff_lexer/src/lib.rs @@ -348,8 +348,8 @@ impl<'a> Lexer<'a> { let kind = if let Some(kind) = &found_kind { kind.clone() - } else if self.context == Context::MacroBody - && BuiltinFunctionKind::try_from(&word).is_ok() + } else if self.context == Context::MacroBody && + BuiltinFunctionKind::try_from(&word).is_ok() { TokenKind::BuiltinFunction(word) } else { @@ -542,20 +542,20 @@ impl<'a> Lexer<'a> { /// by a colon or preceded by the keyword `function` pub fn check_keyword_rules(&mut self, found_kind: &Option) -> bool { match found_kind { - Some(TokenKind::Macro) - | Some(TokenKind::Fn) - | Some(TokenKind::Test) - | Some(TokenKind::Function) - | Some(TokenKind::Constant) - | Some(TokenKind::Error) - | Some(TokenKind::Event) - | Some(TokenKind::JumpTable) - | Some(TokenKind::JumpTablePacked) - | Some(TokenKind::CodeTable) => self.checked_lookback(TokenKind::Define), - Some(TokenKind::NonPayable) - | Some(TokenKind::Payable) - | Some(TokenKind::View) - | Some(TokenKind::Pure) => { + Some(TokenKind::Macro) | + Some(TokenKind::Fn) | + Some(TokenKind::Test) | + Some(TokenKind::Function) | + Some(TokenKind::Constant) | + Some(TokenKind::Error) | + Some(TokenKind::Event) | + Some(TokenKind::JumpTable) | + Some(TokenKind::JumpTablePacked) | + Some(TokenKind::CodeTable) => self.checked_lookback(TokenKind::Define), + Some(TokenKind::NonPayable) | + Some(TokenKind::Payable) | + Some(TokenKind::View) | + Some(TokenKind::Pure) => { let keys = [ TokenKind::NonPayable, TokenKind::Payable, diff --git a/huff_parser/src/lib.rs b/huff_parser/src/lib.rs index 85b9950d..7d1c0d42 100644 --- a/huff_parser/src/lib.rs +++ b/huff_parser/src/lib.rs @@ -727,8 +727,8 @@ impl Parser { pub fn parse_label(&mut self) -> Result, ParserError> { let mut statements: Vec = Vec::new(); self.match_kind(TokenKind::Colon)?; - while !self.check(TokenKind::Label("NEXT_LABEL".to_string())) - && !self.check(TokenKind::CloseBrace) + while !self.check(TokenKind::Label("NEXT_LABEL".to_string())) && + !self.check(TokenKind::CloseBrace) { match self.current_token.kind.clone() { TokenKind::Literal(val) => { @@ -930,9 +930,9 @@ impl Parser { } // name comes second (is optional) - if select_name - && (self.check(TokenKind::Ident("x".to_string())) - || self.check(TokenKind::PrimitiveType(PrimitiveEVMType::Address))) + if select_name && + (self.check(TokenKind::Ident("x".to_string())) || + self.check(TokenKind::PrimitiveType(PrimitiveEVMType::Address))) { // We need to check if the name is a keyword - not the type if !on_type { @@ -1106,8 +1106,8 @@ impl Parser { 0_usize } }) - .sum::() - / 2 + .sum::() / + 2 } }; diff --git a/huff_utils/src/abi.rs b/huff_utils/src/abi.rs index f76d2c28..02a8669e 100644 --- a/huff_utils/src/abi.rs +++ b/huff_utils/src/abi.rs @@ -303,10 +303,10 @@ impl FunctionParamType { pub fn is_memory_type(&self) -> bool { matches!( self, - FunctionParamType::Bytes - | FunctionParamType::String - | FunctionParamType::Tuple(_) - | FunctionParamType::Array(_, _) + FunctionParamType::Bytes | + FunctionParamType::String | + FunctionParamType::Tuple(_) | + FunctionParamType::Array(_, _) ) } } diff --git a/huff_utils/src/evm.rs b/huff_utils/src/evm.rs index bb710cb1..a93e73c4 100644 --- a/huff_utils/src/evm.rs +++ b/huff_utils/src/evm.rs @@ -783,38 +783,38 @@ impl Opcode { pub fn is_value_push(&self) -> bool { matches!( self, - Opcode::Push1 - | Opcode::Push2 - | Opcode::Push3 - | Opcode::Push4 - | Opcode::Push5 - | Opcode::Push6 - | Opcode::Push7 - | Opcode::Push8 - | Opcode::Push9 - | Opcode::Push10 - | Opcode::Push11 - | Opcode::Push12 - | Opcode::Push13 - | Opcode::Push14 - | Opcode::Push15 - | Opcode::Push16 - | Opcode::Push17 - | Opcode::Push18 - | Opcode::Push19 - | Opcode::Push20 - | Opcode::Push21 - | Opcode::Push22 - | Opcode::Push23 - | Opcode::Push24 - | Opcode::Push25 - | Opcode::Push26 - | Opcode::Push27 - | Opcode::Push28 - | Opcode::Push29 - | Opcode::Push30 - | Opcode::Push31 - | Opcode::Push32 + Opcode::Push1 | + Opcode::Push2 | + Opcode::Push3 | + Opcode::Push4 | + Opcode::Push5 | + Opcode::Push6 | + Opcode::Push7 | + Opcode::Push8 | + Opcode::Push9 | + Opcode::Push10 | + Opcode::Push11 | + Opcode::Push12 | + Opcode::Push13 | + Opcode::Push14 | + Opcode::Push15 | + Opcode::Push16 | + Opcode::Push17 | + Opcode::Push18 | + Opcode::Push19 | + Opcode::Push20 | + Opcode::Push21 | + Opcode::Push22 | + Opcode::Push23 | + Opcode::Push24 | + Opcode::Push25 | + Opcode::Push26 | + Opcode::Push27 | + Opcode::Push28 | + Opcode::Push29 | + Opcode::Push30 | + Opcode::Push31 | + Opcode::Push32 ) } diff --git a/huff_utils/src/files.rs b/huff_utils/src/files.rs index b4aceb17..efee81e6 100644 --- a/huff_utils/src/files.rs +++ b/huff_utils/src/files.rs @@ -360,11 +360,11 @@ impl Span { .as_ref() .map(|s| { let line_num = - &s[0..self.start].as_bytes().iter().filter(|&&c| c == b'\n').count() - + 1; + &s[0..self.start].as_bytes().iter().filter(|&&c| c == b'\n').count() + + 1; let line_start = &s[0..self.start].rfind('\n').unwrap_or(0); - let line_end = self.end - + s[self.end..s.len()] + let line_end = self.end + + s[self.end..s.len()] .find('\n') .unwrap_or(s.len() - self.end) .to_owned(); diff --git a/huff_utils/src/types.rs b/huff_utils/src/types.rs index 1d9bf58f..89885c88 100644 --- a/huff_utils/src/types.rs +++ b/huff_utils/src/types.rs @@ -126,9 +126,7 @@ impl TryFrom for EToken { ))) } _ => { - return Ok(EToken(Token::FixedBytes( - str_to_bytes32(cleaned_input).to_vec(), - ))) + return Ok(EToken(Token::FixedBytes(str_to_bytes32(cleaned_input).to_vec()))) } } } else {