Skip to content

Commit

Permalink
feat: update MSRV to 1.65
Browse files Browse the repository at this point in the history
regex-automata bumped its MSRV to 1.65, follow it. This allows using the
new let else syntax, which we need to do to satisfy clippy.
  • Loading branch information
vthib committed Oct 15, 2023
1 parent 9afa6e9 commit 1d5b005
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 55 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ jobs:
fail_ci_if_error: true

msrv:
name: Rust 1.62.0
name: Rust 1.65.0
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@1.62.0
- uses: dtolnay/rust-toolchain@1.65.0
# Only check boreal (and boreal-parser).
# boreal-cli is a useful tool, but MSRV on it is not really useful.
- run: |
Expand Down
2 changes: 1 addition & 1 deletion boreal-parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ keywords = ["boreal", "yara", "parser"]
categories = ["parser-implementations"]
edition = "2021"
# MSRV
rust-version = "1.62"
rust-version = "1.65"

[dependencies]
# Parsing library
Expand Down
18 changes: 6 additions & 12 deletions boreal-parser/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,13 @@ fn quoted_no_rtrim(input: Input) -> ParseResult<Vec<u8>> {
Some((_, '\\')) => res.push(b'\\'),
Some((_, 'x')) => match (chars.next(), chars.next()) {
(Some((i1, a)), Some((i2, b))) => {
let a = match a.to_digit(16) {
Some(a) => a,
None => {
index = i1;
break;
}
let Some(a) = a.to_digit(16) else {
index = i1;
break;
};
let b = match b.to_digit(16) {
Some(b) => b,
None => {
index = i2;
break;
}
let Some(b) = b.to_digit(16) else {
index = i2;
break;
};
#[allow(clippy::cast_possible_truncation)]
res.push(((a as u8) << 4) + (b as u8));
Expand Down
2 changes: 1 addition & 1 deletion boreal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ keywords = ["boreal", "yara", "string-matching", "scan"]
categories = ["text-processing"]
edition = "2021"
# MSRV
rust-version = "1.62"
rust-version = "1.65"

[features]
default = ["hash", "object", "memmap"]
Expand Down
15 changes: 5 additions & 10 deletions boreal/src/compiler/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,10 @@ pub(super) fn compile_identifier<'a, 'b>(

// Extract first operation, it must be a subfielding.
let mut ops = identifier.operations.into_iter();
let first_op = match ops.next() {
Some(v) => v,
None => {
return Err(CompilationError::InvalidIdentifierUse {
span: identifier_span.clone(),
})
}
let Some(first_op) = ops.next() else {
return Err(CompilationError::InvalidIdentifierUse {
span: identifier_span.clone(),
});
};
let subfield = match &first_op.op {
IdentifierOperationType::Subfield(subfield) => subfield,
Expand Down Expand Up @@ -329,9 +326,7 @@ impl ModuleUse<'_, '_> {

StaticValue::Function { fun, .. } => {
let mut ops = self.operations.into_iter();
let arguments = if let Some(ValueOperation::FunctionCall(v)) = ops.next() {
v
} else {
let Some(ValueOperation::FunctionCall(arguments)) = ops.next() else {
return None;
};
Expression::Module(ModuleExpression::Function {
Expand Down
10 changes: 4 additions & 6 deletions boreal/src/evaluator/ac_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,8 @@ impl AcScan {

// Upscale to the original literal shape before feeding it to the matcher verification
// function.
let start = match mat.start().checked_sub(start_offset) {
Some(v) => v,
None => continue,
let Some(start) = mat.start().checked_sub(start_offset) else {
continue;
};
let end = match mat.end().checked_add(end_offset) {
Some(v) if v <= scan_data.mem.len() => v,
Expand All @@ -184,9 +183,8 @@ impl AcScan {
let m = start..end;

// Verify the literal is valid.
let match_type = match var.confirm_ac_literal(scan_data.mem, &m, literal_index) {
Some(ty) => ty,
None => continue,
let Some(match_type) = var.confirm_ac_literal(scan_data.mem, &m, literal_index) else {
continue;
};

let var_matches = &mut matches[variable_index];
Expand Down
13 changes: 5 additions & 8 deletions boreal/src/matcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,11 @@ impl Matcher {
}

pub fn find_next_match_at(&self, mem: &[u8], mut offset: usize) -> Option<Range<usize>> {
let regex = match &self.kind {
MatcherKind::Raw(r) => r,
_ => {
// This variable should have been covered by the AC pass, so we should
// not be able to reach this code.
debug_assert!(false);
return None;
}
let MatcherKind::Raw(regex) = &self.kind else {
// This variable should have been covered by the AC pass, so we should
// not be able to reach this code.
debug_assert!(false);
return None;
};

while offset < mem.len() {
Expand Down
25 changes: 10 additions & 15 deletions boreal/src/module/pe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1485,9 +1485,8 @@ fn add_thunk<Pe: ImageNtHeaders, F>(
("rva", rva.into()),
]));
} else {
let name = match hint_name(thunk.address()) {
Ok(name) => name,
Err(_) => return,
let Ok(name) = hint_name(thunk.address()) else {
return;
};

data_functions.push(DataFunction {
Expand Down Expand Up @@ -1617,9 +1616,8 @@ fn add_exports(

// Now, add names
for (name_pointer, ordinal_index) in table.name_iter() {
let mut name = match table.name_from_pointer(name_pointer) {
Ok(v) => v,
Err(_) => continue,
let Ok(mut name) = table.name_from_pointer(name_pointer) else {
continue;
};
if name.len() > MAX_EXPORT_NAME_LENGTH {
name = &name[..MAX_EXPORT_NAME_LENGTH];
Expand Down Expand Up @@ -1766,9 +1764,8 @@ fn add_resources(
ResourceNameOrId::Id(_) => None,
};

let table = match entry.data(dir) {
Ok(ResourceDirectoryEntryData::Table(table)) => table,
_ => continue,
let Ok(ResourceDirectoryEntryData::Table(table)) = entry.data(dir) else {
continue;
};
for entry in table.entries {
// Second level is id
Expand All @@ -1778,9 +1775,8 @@ fn add_resources(
ResourceNameOrId::Id(_) => None,
};

let table = match entry.data(dir) {
Ok(ResourceDirectoryEntryData::Table(table)) => table,
_ => continue,
let Ok(ResourceDirectoryEntryData::Table(table)) = entry.data(dir) else {
continue;
};
for entry in table.entries {
// Third level is language
Expand Down Expand Up @@ -1859,9 +1855,8 @@ fn add_resources(
}

pub fn add_version_infos(mem: &[u8], offset: u32, out: &mut HashMap<&'static str, Value>) {
let infos = match version_info::read_version_info(mem, offset as usize) {
Some(infos) => infos,
None => return,
let Some(infos) = version_info::read_version_info(mem, offset as usize) else {
return;
};

out.extend([
Expand Down

0 comments on commit 1d5b005

Please sign in to comment.