Skip to content

Commit b1a38c2

Browse files
authored
Fix rust 1.80 warnings (RustPython#5363)
* Fix rust 1.80 warnings * Fix nightly clippy warnings
1 parent f1f0530 commit b1a38c2

File tree

9 files changed

+20
-28
lines changed

9 files changed

+20
-28
lines changed

pylib/build.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
fn main() {
22
process_python_libs("../vm/Lib/python_builtins/*");
33

4-
#[cfg(not(feature = "stdlib"))]
54
process_python_libs("../vm/Lib/core_modules/*");
65
#[cfg(feature = "freeze-stdlib")]
76
if cfg!(windows) {

src/settings.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,7 @@ fn settings_from(matches: &ArgMatches) -> (Settings, RunMode) {
359359

360360
/// Get environment variable and turn it into integer.
361361
fn get_env_var_value(name: &str) -> Result<u8, std::env::VarError> {
362-
env::var(name).map(|value| {
363-
if let Ok(value) = u8::from_str(&value) {
364-
value
365-
} else {
366-
1
367-
}
368-
})
362+
env::var(name).map(|value| u8::from_str(&value).unwrap_or(1))
369363
}
370364

371365
/// Helper function to retrieve a sequence of paths from an environment variable.

stdlib/build.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
fn main() {
2+
println!(r#"cargo::rustc-check-cfg=cfg(osslconf, values("OPENSSL_NO_COMP"))"#);
3+
println!("cargo::rustc-check-cfg=cfg(ossl101)");
4+
println!("cargo::rustc-check-cfg=cfg(ossl102)");
5+
println!("cargo::rustc-check-cfg=cfg(ossl110)");
6+
println!("cargo::rustc-check-cfg=cfg(ossl110g)");
7+
println!("cargo::rustc-check-cfg=cfg(ossl111)");
28
#[allow(clippy::unusual_byte_groupings)]
39
if let Ok(v) = std::env::var("DEP_OPENSSL_VERSION_NUMBER") {
410
println!("cargo:rustc-env=OPENSSL_API_VERSION={v}");

stdlib/src/socket.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,13 +337,12 @@ mod _socket {
337337
target_os = "linux",
338338
any(
339339
target_arch = "aarch64",
340-
target_arch = "i686",
340+
target_arch = "x86",
341341
target_arch = "loongarch64",
342342
target_arch = "mips",
343343
target_arch = "powerpc",
344344
target_arch = "powerpc64",
345-
target_arch = "powerpc64le",
346-
target_arch = "riscv64gc",
345+
target_arch = "riscv64",
347346
target_arch = "s390x",
348347
target_arch = "x86_64"
349348
)
@@ -388,13 +387,12 @@ mod _socket {
388387
target_os = "linux",
389388
any(
390389
target_arch = "aarch64",
391-
target_arch = "i686",
390+
target_arch = "x86",
392391
target_arch = "loongarch64",
393392
target_arch = "mips",
394393
target_arch = "powerpc",
395394
target_arch = "powerpc64",
396-
target_arch = "powerpc64le",
397-
target_arch = "riscv64gc",
395+
target_arch = "riscv64",
398396
target_arch = "s390x",
399397
target_arch = "x86_64"
400398
)

vm/src/object/ext.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,8 @@ impl PyObject {
494494

495495
/// A borrow of a reference to a Python object. This avoids having clone the `PyRef<T>`/
496496
/// `PyObjectRef`, which isn't that cheap as that increments the atomic reference counter.
497+
// TODO: check if we still need this
498+
#[allow(dead_code)]
497499
pub struct PyLease<'a, T: PyObjectPayload> {
498500
inner: PyRwLockReadGuard<'a, PyRef<T>>,
499501
}

vm/src/object/traverse.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,12 @@ pub trait MaybeTraverse {
1919

2020
/// Type that need traverse it's children should impl `Traverse`(Not `MaybeTraverse`)
2121
/// # Safety
22-
/// impl `traverse()` with caution! Following those guideline so traverse doesn't cause memory error!:
23-
/// - Make sure that every owned object(Every PyObjectRef/PyRef) is called with traverse_fn **at most once**.
24-
/// If some field is not called, the worst results is just memory leak,
25-
/// but if some field is called repeatedly, panic and deadlock can happen.
26-
///
27-
/// - _**DO NOT**_ clone a `PyObjectRef` or `Pyef<T>` in `traverse()`
22+
/// Please carefully read [`traverse()`] and follow the guideline
2823
pub unsafe trait Traverse {
2924
/// impl `traverse()` with caution! Following those guideline so traverse doesn't cause memory error!:
3025
/// - Make sure that every owned object(Every PyObjectRef/PyRef) is called with traverse_fn **at most once**.
31-
/// If some field is not called, the worst results is just memory leak,
32-
/// but if some field is called repeatedly, panic and deadlock can happen.
26+
/// If some field is not called, the worst results is just memory leak,
27+
/// but if some field is called repeatedly, panic and deadlock can happen.
3328
///
3429
/// - _**DO NOT**_ clone a `PyObjectRef` or `Pyef<T>` in `traverse()`
3530
fn traverse(&self, traverse_fn: &mut TraverseFn);

vm/src/protocol/object.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,8 @@ impl PyObject {
118118
.class()
119119
.mro_find_map(|cls| cls.slots.getattro.load())
120120
.unwrap();
121-
getattro(self, attr_name, vm).map_err(|exc| {
122-
vm.set_attribute_error_context(&exc, self.to_owned(), attr_name.to_owned());
123-
exc
121+
getattro(self, attr_name, vm).inspect_err(|exc| {
122+
vm.set_attribute_error_context(exc, self.to_owned(), attr_name.to_owned());
124123
})
125124
}
126125

vm/src/stdlib/posix.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -871,10 +871,9 @@ pub mod module {
871871
let (rfd, wfd) = pipe().map_err(|err| err.into_pyexception(vm))?;
872872
set_inheritable(rfd, false, vm)
873873
.and_then(|_| set_inheritable(wfd, false, vm))
874-
.map_err(|err| {
874+
.inspect_err(|_| {
875875
let _ = close(rfd);
876876
let _ = close(wfd);
877-
err
878877
})?;
879878
Ok((rfd, wfd))
880879
}

vm/src/stdlib/time.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ mod decl {
302302
Ok(get_thread_time(vm)?.as_nanos() as u64)
303303
}
304304

305-
#[cfg(any(windows, all(target_arch = "wasm32", target_arch = "emscripten")))]
305+
#[cfg(any(windows, all(target_arch = "wasm32", target_os = "emscripten")))]
306306
pub(super) fn time_muldiv(ticks: i64, mul: i64, div: i64) -> u64 {
307307
let intpart = ticks / div;
308308
let ticks = ticks % div;

0 commit comments

Comments
 (0)