Skip to content

Commit 48fa217

Browse files
authored
Merge pull request RustPython#3562 from fanninpm/new-clippy-lints-1.59
Fix Clippy lints introduced in Rust 1.59
2 parents 35cd720 + edbc17f commit 48fa217

File tree

8 files changed

+15
-23
lines changed

8 files changed

+15
-23
lines changed

Lib/test/test_threading.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,7 @@ def test_releasing_unacquired_lock(self):
10611061
lock = threading.Lock()
10621062
self.assertRaises(RuntimeError, lock.release)
10631063

1064+
@unittest.skip("TODO: RUSTPYTHON, flaky test")
10641065
def test_recursion_limit(self):
10651066
# Issue 9670
10661067
# test that excessive recursion within a non-main thread causes

common/src/cmp.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,11 @@ pub fn timing_safe_cmp(a: &[u8], b: &[u8]) -> bool {
1515
* chance to optimize and fold the code in any way that may change
1616
* the timing.
1717
*/
18-
let length: Volatile<usize>;
19-
let mut left: Volatile<*const u8>;
20-
let mut right: Volatile<*const u8>;
2118
let mut result: u8 = 0;
22-
2319
/* loop count depends on length of b */
24-
length = Volatile::new(len_b);
25-
left = Volatile::new(std::ptr::null());
26-
right = Volatile::new(b);
20+
let length: Volatile<usize> = Volatile::new(len_b);
21+
let mut left: Volatile<*const u8> = Volatile::new(std::ptr::null());
22+
let mut right: Volatile<*const u8> = Volatile::new(b);
2723

2824
/* don't use else here to keep the amount of CPU instructions constant,
2925
* volatile forces re-evaluation

derive/src/pyclass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ impl GetSetNursery {
636636
for ((name, _cfgs), (getter, setter, deleter)) in self.map.iter() {
637637
if getter.is_none() {
638638
errors.push(syn::Error::new_spanned(
639-
setter.as_ref().or_else(|| deleter.as_ref()).unwrap(),
639+
setter.as_ref().or(deleter.as_ref()).unwrap(),
640640
format!("Property '{}' is missing a getter", name),
641641
));
642642
};

derive/src/pymodule.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fn new_module_item(
119119
}),
120120
"pyclass" => Box::new(ClassItem {
121121
inner: ContentItemInner { index, attr_name },
122-
pyattrs: pyattrs.unwrap_or_else(Vec::new),
122+
pyattrs: pyattrs.unwrap_or_default(),
123123
}),
124124
other => unreachable!("#[pymodule] doesn't accept #[{}]", other),
125125
}

stdlib/src/socket.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ mod _socket {
11141114
let abstractpath = &path_u8[..abstractaddrlen];
11151115
vm.ctx.new_bytes(abstractpath.to_vec()).into()
11161116
} else {
1117-
let len = memchr::memchr(b'\0', path_u8).unwrap_or_else(|| path_u8.len());
1117+
let len = memchr::memchr(b'\0', path_u8).unwrap_or(path_u8.len());
11181118
let path = &path_u8[..len];
11191119
vm.ctx.new_str(String::from_utf8_lossy(path)).into()
11201120
}

vm/src/builtins/slice.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,12 +395,10 @@ fn to_isize_index(vm: &VirtualMachine, obj: &PyObject) -> PyResult<Option<isize>
395395
})?;
396396
let value = result.as_bigint();
397397
let is_negative = value.is_negative();
398-
Ok(Some(value.to_isize().unwrap_or_else(|| {
399-
if is_negative {
400-
isize::MIN
401-
} else {
402-
isize::MAX
403-
}
398+
Ok(Some(value.to_isize().unwrap_or(if is_negative {
399+
isize::MIN
400+
} else {
401+
isize::MAX
404402
})))
405403
}
406404

vm/src/cformat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl CFormatSpec {
140140
let precision = parse_precision(iter)?;
141141
consume_length(iter);
142142
let (format_type, format_char) = parse_format_type(iter)?;
143-
let precision = precision.or_else(|| match format_type {
143+
let precision = precision.or(match format_type {
144144
CFormatType::Float(_) => Some(CFormatQuantity::Amount(6)),
145145
_ => None,
146146
});

vm/src/stdlib/io.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ mod _io {
15671567
let mut data = self.reader().lock(vm)?;
15681568
let raw = data.check_init(vm)?;
15691569
ensure_unclosed(raw, "read of closed file", vm)?;
1570-
let n = size.to_usize().unwrap_or_else(|| data.buffer.len());
1570+
let n = size.to_usize().unwrap_or(data.buffer.len());
15711571
if n == 0 {
15721572
return Ok(Vec::new());
15731573
}
@@ -3214,10 +3214,7 @@ mod _io {
32143214
#[pymethod]
32153215
#[pymethod(name = "read1")]
32163216
fn read(self, size: OptionalSize, vm: &VirtualMachine) -> PyResult<Vec<u8>> {
3217-
let buf = self
3218-
.buffer(vm)?
3219-
.read(size.to_usize())
3220-
.unwrap_or_else(Vec::new);
3217+
let buf = self.buffer(vm)?.read(size.to_usize()).unwrap_or_default();
32213218
Ok(buf)
32223219
}
32233220

@@ -3277,7 +3274,7 @@ mod _io {
32773274

32783275
#[pymethod]
32793276
fn close(self, vm: &VirtualMachine) -> PyResult<()> {
3280-
let _ = self.try_resizable(vm)?;
3277+
drop(self.try_resizable(vm)?);
32813278
self.closed.store(true);
32823279
Ok(())
32833280
}

0 commit comments

Comments
 (0)