Skip to content

Commit 208127c

Browse files
committed
Fix Rust 1.92 clippy warnings
1 parent 2ebf16a commit 208127c

3 files changed

Lines changed: 8 additions & 5 deletions

File tree

‎src/cli/commands.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3017,7 +3017,7 @@ fn ckb_fixture_little_endian_u128(hex_value: &str) -> std::result::Result<u128,
30173017
if bytes.is_empty() {
30183018
return Ok(0);
30193019
}
3020-
if bytes.len() % 2 != 0 {
3020+
if !bytes.len().is_multiple_of(2) {
30213021
return Err(format!("odd-length hex amount {hex_value}"));
30223022
}
30233023
let raw = hex::decode(bytes).map_err(|err| format!("invalid hex amount {hex_value}: {err}"))?;
@@ -5064,7 +5064,7 @@ fn decode_hex_arg(name: &str, value: &str, expected_len: Option<usize>) -> Resul
50645064
.or_else(|| trimmed.strip_prefix("0x"))
50655065
.or_else(|| trimmed.strip_prefix("0X"))
50665066
.unwrap_or(trimmed);
5067-
if hex.len() % 2 != 0 {
5067+
if !hex.len().is_multiple_of(2) {
50685068
return Err(crate::error::CompileError::without_span(format!("parameter '{}' hex value must contain full bytes", name)));
50695069
}
50705070
let bytes = hex

‎src/lib.rs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3222,7 +3222,7 @@ fn default_scheduler_witness_abi() -> String {
32223222
/// Decode a hex-encoded scheduler witness from compile metadata.
32233223
pub fn decode_scheduler_witness_hex(hex: &str) -> Result<Vec<u8>> {
32243224
let hex_bytes = hex.as_bytes();
3225-
if hex_bytes.len() % 2 != 0 {
3225+
if !hex_bytes.len().is_multiple_of(2) {
32263226
return Err(CompileError::without_span("scheduler witness hex string must contain full bytes"));
32273227
}
32283228
let mut bytes = Vec::with_capacity(hex_bytes.len() / 2);
@@ -13899,7 +13899,10 @@ where
1389913899
let total_size = read_u32(&bytes[..4], "total_size") as usize;
1390013900
assert_eq!(total_size, bytes.len(), "molecule table total size mismatch");
1390113901
let first_offset = read_u32(&bytes[4..8], "first_offset") as usize;
13902-
assert!(first_offset >= 8 && first_offset <= bytes.len() && first_offset % 4 == 0, "invalid first offset {first_offset}");
13902+
assert!(
13903+
first_offset >= 8 && first_offset <= bytes.len() && first_offset.is_multiple_of(4),
13904+
"invalid first offset {first_offset}"
13905+
);
1390313906
let field_count = first_offset / 4 - 1;
1390413907
assert_eq!(field_count, expected_fields, "unexpected molecule table field count");
1390513908
let mut offsets = bytes[4..first_offset].chunks_exact(4).map(|chunk| read_u32(chunk, "offset") as usize).collect::<Vec<_>>();

‎tests/ckb_compat_runner.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ fn little_endian_u128(hex_value: &str) -> Result<u128, String> {
178178
if bytes.is_empty() {
179179
return Ok(0);
180180
}
181-
if bytes.len() % 2 != 0 {
181+
if !bytes.len().is_multiple_of(2) {
182182
return Err(format!("odd-length hex amount {hex_value}"));
183183
}
184184
let raw = hex::decode(bytes).map_err(|err| format!("invalid hex amount {hex_value}: {err}"))?;

0 commit comments

Comments
 (0)