Fix some clippy lints for 1.99 (#8412)

This commit is contained in:
Joshua Megnauth authored and GitHub committed 2026-07-30 22:11:31 +09:00
1 parent c7a19f0eea
commit 33eb99af44
10 files changed
+32 -29

No files matched your search

+1 -2
View File
@@ -1380,8 +1380,7 @@ impl FieldName {
FieldType::Index(index)
} else if first
.as_str()
.ok()
.is_some_and(|s| s.bytes().all(|b| b.is_ascii_digit()))
.is_ok_and(|s| s.bytes().all(|b| b.is_ascii_digit()))
{
// All-digit segment whose value overflows usize itself.
return Err(FormatParseError::TooManyDecimalDigits);
+13 -4
View File
@@ -557,6 +557,14 @@ impl TryFrom<&[u8]> for CodeUnit {
}
}
impl TryFrom<[u8; 2]> for CodeUnit {
type Error = MarshalError;
fn try_from(value: [u8; 2]) -> Result<Self, Self::Error> {
Ok(Self::new(value[0].try_into()?, value[1].into()))
}
}
pub struct CodeUnits {
units: UnsafeCell<Box<[CodeUnit]>>,
adaptive_counters: Box<[AtomicU16]>,
@@ -610,12 +618,13 @@ impl TryFrom<&[u8]> for CodeUnits {
type Error = MarshalError;
fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
if !value.len().is_multiple_of(2) {
let (chunks, []) = value.as_chunks::<2>() else {
return Err(Self::Error::InvalidBytecode);
}
};
let units = value
.chunks_exact(2)
let units = chunks
.iter()
.copied()
.map(CodeUnit::try_from)
.collect::<Result<Vec<_>, _>>()?;
Ok(units.into())
+3 -1
View File
@@ -1333,7 +1333,9 @@ pub fn readlink(path: &Path) -> Result<OsString, ReadlinkError> {
let path_slice = &buffer[path_start..path_end];
let mut wide_chars: Vec<u16> = path_slice
.chunks_exact(2)
.as_chunks::<2>()
.0
.iter()
.map(|chunk| u16::from_le_bytes([chunk[0], chunk[1]]))
.collect();
+4 -4
View File
@@ -17,11 +17,11 @@ mod _testconsole {
let data = &*data;
// Interpret as UTF-16-LE pairs
if !data.len().is_multiple_of(2) {
let (chunks, []) = data.as_chunks::<2>() else {
return Err(vm.new_value_error("buffer must contain UTF-16-LE data (even length)"));
}
let wchars: Vec<u16> = data
.chunks_exact(2)
};
let wchars: Vec<u16> = chunks
.iter()
.map(|chunk| u16::from_le_bytes([chunk[0], chunk[1]]))
.collect();
host_testconsole::write_console_input(fd, &wchars).map_err(|e| e.into_pyexception(vm))
+1 -2
View File
@@ -68,8 +68,7 @@ impl Constructor for PyInterpolation {
.as_bytes()
.iter()
.exactly_one()
.ok()
.is_some_and(|s| matches!(*s, b's' | b'r' | b'a'));
.is_ok_and(|s| matches!(*s, b's' | b'r' | b'a'));
if !has_flag {
return Err(vm.new_value_error(
"Interpolation() argument 'conversion' must be one of 's', 'a' or 'r'",
+1 -1
View File
@@ -61,7 +61,7 @@ static KEYS_VERSION: AtomicU32 = AtomicU32::new(0);
/// unrealistic in practice.
fn next_keys_version() -> u32 {
KEYS_VERSION
.fetch_update(Relaxed, Relaxed, |v| v.checked_add(1))
.try_update(Relaxed, Relaxed, |v| v.checked_add(1))
.map_or(0, |v| v + 1)
}
+2 -4
View File
@@ -146,11 +146,9 @@ mod _sre {
let mut items = Vec::with_capacity(1);
let v = template.borrow_vec();
let literal = v.first().ok_or_else(err)?.clone();
let trunks = v[1..].chunks_exact(2);
if !trunks.remainder().is_empty() {
let (trunks, []) = v[1..].as_chunks::<2>() else {
return Err(err());
}
};
for trunk in trunks {
let index: usize = trunk[0]
+5 -5
View File
@@ -344,7 +344,7 @@ pub(crate) fn instrument_code(code: &PyCode, events: u32) {
continue;
}
// Excluded: RESUME, END_FOR, CACHE (and their instrumented variants)
let base = op.to_base().map_or(op, |b| b);
let base = op.to_base().unwrap_or(op);
if matches!(
base,
Instruction::Resume { .. } | Instruction::EndFor | Instruction::Cache
@@ -387,7 +387,7 @@ pub(crate) fn instrument_code(code: &PyCode, events: u32) {
.skip(first_traceable)
{
let op = unit.op;
let base = op.to_base().map_or(op, |b| b);
let base = op.to_base().unwrap_or(op);
if matches!(base, Instruction::ExtendedArg) {
continue;
}
@@ -425,7 +425,7 @@ pub(crate) fn instrument_code(code: &PyCode, events: u32) {
let mut instr_idx = first_traceable;
for unit in code.code.instructions[first_traceable..len].iter().copied() {
let (op, arg) = arg_state.get(unit);
let base = op.to_base().map_or(op, |b| b);
let base = op.to_base().unwrap_or(op);
if matches!(base, Instruction::ExtendedArg) || matches!(base, Instruction::Cache) {
instr_idx += 1;
@@ -460,7 +460,7 @@ pub(crate) fn instrument_code(code: &PyCode, events: u32) {
&& !no_loc_mask.get(target_idx).copied().unwrap_or(false)
{
let target_op = code.code.instructions[target_idx].op;
let target_base = target_op.to_base().map_or(target_op, |b| b);
let target_base = target_op.to_base().unwrap_or(target_op);
// Skip synthetic cleanup targets.
if matches!(target_base, Instruction::PopIter) {
instr_idx += 1;
@@ -483,7 +483,7 @@ pub(crate) fn instrument_code(code: &PyCode, events: u32) {
&& !no_loc_mask.get(target_idx).copied().unwrap_or(false)
{
let target_op = code.code.instructions[target_idx].op;
let target_base = target_op.to_base().map_or(target_op, |b| b);
let target_base = target_op.to_base().unwrap_or(target_op);
if !matches!(target_base, Instruction::PopIter)
&& let Some((loc, _)) = line_locations.get(target_idx)
&& loc.line.get() > 0
+1 -4
View File
@@ -2092,10 +2092,7 @@ impl VirtualMachine {
if exc.class().is(self.ctx.exceptions.attribute_error) {
let exc = exc.as_object();
// Check if this exception was already augmented
let already_set = exc
.get_attr("name", self)
.ok()
.is_some_and(|v| !self.is_none(&v));
let already_set = exc.get_attr("name", self).is_ok_and(|v| !self.is_none(&v));
if already_set {
return;
}
+1 -2
View File
@@ -47,8 +47,7 @@ impl VirtualMachine {
/// Returns true if the file object's `closed` attribute is truthy.
fn file_is_closed(&self, file: &PyObject) -> bool {
file.get_attr("closed", self)
.ok()
.is_some_and(|v| v.try_to_bool(self).unwrap_or(false))
.is_ok_and(|v| v.try_to_bool(self).unwrap_or_default())
}
pub(crate) fn flush_std(&self) -> i32 {