Skip to content

Commit d4ec8ef

Browse files
Fix some clippy lints for 1.99
1 parent 5db61a0 commit d4ec8ef

7 files changed

Lines changed: 14 additions & 22 deletions

File tree

crates/stdlib/src/_testconsole.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ mod _testconsole {
1717
let data = &*data;
1818

1919
// Interpret as UTF-16-LE pairs
20-
if !data.len().is_multiple_of(2) {
20+
let (chunks, []) = data.as_chunks::<2>() else {
2121
return Err(vm.new_value_error("buffer must contain UTF-16-LE data (even length)"));
22-
}
23-
let wchars: Vec<u16> = data
24-
.chunks_exact(2)
22+
};
23+
let wchars: Vec<u16> = chunks
2524
.map(|chunk| u16::from_le_bytes([chunk[0], chunk[1]]))
2625
.collect();
2726
host_testconsole::write_console_input(fd, &wchars).map_err(|e| e.into_pyexception(vm))

crates/vm/src/builtins/interpolation.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ impl Constructor for PyInterpolation {
6868
.as_bytes()
6969
.iter()
7070
.exactly_one()
71-
.ok()
72-
.is_some_and(|s| matches!(*s, b's' | b'r' | b'a'));
71+
.is_ok_and(|s| matches!(*s, b's' | b'r' | b'a'));
7372
if !has_flag {
7473
return Err(vm.new_value_error(
7574
"Interpolation() argument 'conversion' must be one of 's', 'a' or 'r'",

crates/vm/src/dict_inner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static KEYS_VERSION: AtomicU32 = AtomicU32::new(0);
6161
/// unrealistic in practice.
6262
fn next_keys_version() -> u32 {
6363
KEYS_VERSION
64-
.fetch_update(Relaxed, Relaxed, |v| v.checked_add(1))
64+
.try_update(Relaxed, Relaxed, |v| v.checked_add(1))
6565
.map_or(0, |v| v + 1)
6666
}
6767

crates/vm/src/stdlib/_sre.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,9 @@ mod _sre {
146146
let mut items = Vec::with_capacity(1);
147147
let v = template.borrow_vec();
148148
let literal = v.first().ok_or_else(err)?.clone();
149-
let trunks = v[1..].chunks_exact(2);
150-
151-
if !trunks.remainder().is_empty() {
149+
let (trunks, []) = v[1..].as_chunks::<2>() else {
152150
return Err(err());
153-
}
151+
};
154152

155153
for trunk in trunks {
156154
let index: usize = trunk[0]

crates/vm/src/stdlib/sys/monitoring.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ pub(crate) fn instrument_code(code: &PyCode, events: u32) {
344344
continue;
345345
}
346346
// Excluded: RESUME, END_FOR, CACHE (and their instrumented variants)
347-
let base = op.to_base().map_or(op, |b| b);
347+
let base = op.to_base().unwrap_or(op);
348348
if matches!(
349349
base,
350350
Instruction::Resume { .. } | Instruction::EndFor | Instruction::Cache
@@ -387,7 +387,7 @@ pub(crate) fn instrument_code(code: &PyCode, events: u32) {
387387
.skip(first_traceable)
388388
{
389389
let op = unit.op;
390-
let base = op.to_base().map_or(op, |b| b);
390+
let base = op.to_base().unwrap_or(op);
391391
if matches!(base, Instruction::ExtendedArg) {
392392
continue;
393393
}
@@ -425,7 +425,7 @@ pub(crate) fn instrument_code(code: &PyCode, events: u32) {
425425
let mut instr_idx = first_traceable;
426426
for unit in code.code.instructions[first_traceable..len].iter().copied() {
427427
let (op, arg) = arg_state.get(unit);
428-
let base = op.to_base().map_or(op, |b| b);
428+
let base = op.to_base().unwrap_or(op);
429429

430430
if matches!(base, Instruction::ExtendedArg) || matches!(base, Instruction::Cache) {
431431
instr_idx += 1;
@@ -460,7 +460,7 @@ pub(crate) fn instrument_code(code: &PyCode, events: u32) {
460460
&& !no_loc_mask.get(target_idx).copied().unwrap_or(false)
461461
{
462462
let target_op = code.code.instructions[target_idx].op;
463-
let target_base = target_op.to_base().map_or(target_op, |b| b);
463+
let target_base = target_op.to_base().unwrap_or(target_op);
464464
// Skip synthetic cleanup targets.
465465
if matches!(target_base, Instruction::PopIter) {
466466
instr_idx += 1;
@@ -483,7 +483,7 @@ pub(crate) fn instrument_code(code: &PyCode, events: u32) {
483483
&& !no_loc_mask.get(target_idx).copied().unwrap_or(false)
484484
{
485485
let target_op = code.code.instructions[target_idx].op;
486-
let target_base = target_op.to_base().map_or(target_op, |b| b);
486+
let target_base = target_op.to_base().unwrap_or(target_op);
487487
if !matches!(target_base, Instruction::PopIter)
488488
&& let Some((loc, _)) = line_locations.get(target_idx)
489489
&& loc.line.get() > 0

crates/vm/src/vm/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,10 +2092,7 @@ impl VirtualMachine {
20922092
if exc.class().is(self.ctx.exceptions.attribute_error) {
20932093
let exc = exc.as_object();
20942094
// Check if this exception was already augmented
2095-
let already_set = exc
2096-
.get_attr("name", self)
2097-
.ok()
2098-
.is_some_and(|v| !self.is_none(&v));
2095+
let already_set = exc.get_attr("name", self).is_ok_and(|v| !self.is_none(&v));
20992096
if already_set {
21002097
return;
21012098
}

crates/vm/src/vm/vm_object.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ impl VirtualMachine {
4747
/// Returns true if the file object's `closed` attribute is truthy.
4848
fn file_is_closed(&self, file: &PyObject) -> bool {
4949
file.get_attr("closed", self)
50-
.ok()
51-
.is_some_and(|v| v.try_to_bool(self).unwrap_or(false))
50+
.is_ok_and(|v| v.try_to_bool(self).unwrap_or_default())
5251
}
5352

5453
pub(crate) fn flush_std(&self) -> i32 {

0 commit comments

Comments
 (0)