diff --git a/boreal-cli/tests/cli.rs b/boreal-cli/tests/cli.rs index 2b3a4d33..c7334577 100644 --- a/boreal-cli/tests/cli.rs +++ b/boreal-cli/tests/cli.rs @@ -689,6 +689,7 @@ fn test_input_cannot_read() { let child = temp.path().join("child"); let _file = fs::OpenOptions::new() .create(true) + .truncate(true) .write(true) .mode(0o000) .open(&child) diff --git a/boreal-parser/src/expression/boolean_expression.rs b/boreal-parser/src/expression/boolean_expression.rs index 43172b97..c0021d3a 100644 --- a/boreal-parser/src/expression/boolean_expression.rs +++ b/boreal-parser/src/expression/boolean_expression.rs @@ -322,7 +322,7 @@ mod tests { use super::*; use crate::{ expression::{Identifier, MAX_EXPR_RECURSION}, - regex::{self, Literal, Regex}, + regex::{self, Literal}, test_helpers::{parse, parse_check, parse_err, parse_err_type, test_public_type}, }; use std::ops::Range; diff --git a/boreal-parser/src/expression/for_expression.rs b/boreal-parser/src/expression/for_expression.rs index 3ad29357..b69d1538 100644 --- a/boreal-parser/src/expression/for_expression.rs +++ b/boreal-parser/src/expression/for_expression.rs @@ -351,9 +351,7 @@ fn rule_enum_element(input: Input) -> ParseResult { #[cfg(test)] mod tests { use super::*; - use crate::expression::{ - ExpressionKind, Identifier, IdentifierOperation, IdentifierOperationType, - }; + use crate::expression::{Identifier, IdentifierOperation, IdentifierOperationType}; use crate::test_helpers::{parse, parse_err, test_public_type}; #[test] diff --git a/boreal-parser/src/expression/mod.rs b/boreal-parser/src/expression/mod.rs index b474c668..54177392 100644 --- a/boreal-parser/src/expression/mod.rs +++ b/boreal-parser/src/expression/mod.rs @@ -282,7 +282,7 @@ pub enum ExpressionKind { /// Which variables to select. set: VariableSet, - /// ParsedExpr to evaluate for each variable. + /// `ParsedExpr` to evaluate for each variable. /// /// The body can contain `$`, `#`, `@` or `!` to refer to the /// currently selected variable. @@ -383,10 +383,10 @@ pub enum ForSelection { All, /// None of the variables in the set must match the condition. None, - /// ParsedExpr that should evaluate to a number, indicating: - /// - if as_percent is false, how many variables in the set must match + /// `ParsedExpr` that should evaluate to a number, indicating: + /// - if `as_percent` is false, how many variables in the set must match /// the condition. - /// - if as_percent is true, which percentage of variables in the set + /// - if `as_percent` is true, which percentage of variables in the set /// msut match the condition. /// the condition. /// diff --git a/boreal-parser/src/rule.rs b/boreal-parser/src/rule.rs index 14ce23e1..5e1ca577 100644 --- a/boreal-parser/src/rule.rs +++ b/boreal-parser/src/rule.rs @@ -563,7 +563,7 @@ fn condition(input: Input) -> ParseResult { #[cfg(test)] mod tests { - use crate::expression::{Expression, ExpressionKind, ForSelection, VariableSet}; + use crate::expression::{ExpressionKind, ForSelection, VariableSet}; use crate::hex_string::{Mask, Token}; use crate::regex::Literal; use crate::test_helpers::test_public_type; diff --git a/boreal-parser/src/string.rs b/boreal-parser/src/string.rs index 094e8e49..5850720a 100644 --- a/boreal-parser/src/string.rs +++ b/boreal-parser/src/string.rs @@ -1,5 +1,4 @@ //! Parsing related to strings and identifiers. -use std::borrow::ToOwned; use nom::{ bytes::complete::take_while, diff --git a/boreal/src/compiler/expression.rs b/boreal/src/compiler/expression.rs index 6113a0cc..e0bf47a3 100644 --- a/boreal/src/compiler/expression.rs +++ b/boreal/src/compiler/expression.rs @@ -972,9 +972,9 @@ pub enum ForSelection { /// None of the variables in the set must match the condition. None, /// Expression that should evaluate to a number, indicating: - /// - if as_percent is false, how many variables in the set must match + /// - if `as_percent` is false, how many variables in the set must match /// the condition. - /// - if as_percent is true, which percentage of variables in the set + /// - if `as_percent` is true, which percentage of variables in the set /// must match the condition. /// the condition. /// @@ -1307,8 +1307,7 @@ fn compile_identifier_as_iterator( } else if compiler .namespace .rules_indexes - .get(&identifier.name) - .is_some() + .contains_key(&identifier.name) { return Err(CompilationError::NonIterableIdentifier { span: identifier_span.clone(), diff --git a/boreal/src/matcher/analysis.rs b/boreal/src/matcher/analysis.rs index e38bda82..758f9430 100644 --- a/boreal/src/matcher/analysis.rs +++ b/boreal/src/matcher/analysis.rs @@ -47,7 +47,7 @@ pub fn analyze_hir(hir: &Hir, dot_all: bool) -> HirAnalysis { } struct HirAnalyser { - /// Is the dot_all flag set. + /// Is the `dot_all` flag set. /// /// This is an input of the visitor, and not an output as other fields are. dot_all: bool, diff --git a/boreal/src/memory.rs b/boreal/src/memory.rs index d1cfd9b1..9ec6d6f6 100644 --- a/boreal/src/memory.rs +++ b/boreal/src/memory.rs @@ -217,9 +217,7 @@ impl Memory<'_> { // Adjust ending offset relative to the region base and length let relative_end = std::cmp::min(region.length, end - region.start); - let Some(fetched_region) = fragmented.obj.fetch(&fragmented.params) else { - return None; - }; + let fetched_region = fragmented.obj.fetch(&fragmented.params)?; cb(&fetched_region.mem[relative_start..relative_end]); has_called_cb = true; diff --git a/boreal/src/scanner/mod.rs b/boreal/src/scanner/mod.rs index c4ef6ff6..bd8f2329 100644 --- a/boreal/src/scanner/mod.rs +++ b/boreal/src/scanner/mod.rs @@ -762,8 +762,6 @@ impl std::fmt::Display for DefineSymbolError { #[cfg(test)] mod tests { - use std::collections::HashMap; - use crate::module::{EvalContext, ScanContext, StaticValue, Type, Value as ModuleValue}; use crate::test_helpers::{test_type_traits, test_type_traits_non_clonable}; use crate::Compiler;