From b1a38c2d50ad224c00b7e9a22de0ba108033038b Mon Sep 17 00:00:00 2001 From: "Jeong, YunWon" <69878+youknowone@users.noreply.github.com> Date: Sun, 28 Jul 2024 10:43:40 +0900 Subject: [PATCH] Fix rust 1.80 warnings (#5363) * Fix rust 1.80 warnings * Fix nightly clippy warnings --- pylib/build.rs | 1 - src/settings.rs | 8 +------- stdlib/build.rs | 6 ++++++ stdlib/src/socket.rs | 10 ++++------ vm/src/object/ext.rs | 2 ++ vm/src/object/traverse.rs | 11 +++-------- vm/src/protocol/object.rs | 5 ++--- vm/src/stdlib/posix.rs | 3 +-- vm/src/stdlib/time.rs | 2 +- 9 files changed, 20 insertions(+), 28 deletions(-) diff --git a/pylib/build.rs b/pylib/build.rs index a541bc56d5..553b97202a 100644 --- a/pylib/build.rs +++ b/pylib/build.rs @@ -1,7 +1,6 @@ fn main() { process_python_libs("../vm/Lib/python_builtins/*"); - #[cfg(not(feature = "stdlib"))] process_python_libs("../vm/Lib/core_modules/*"); #[cfg(feature = "freeze-stdlib")] if cfg!(windows) { diff --git a/src/settings.rs b/src/settings.rs index 72c5f0680f..9a6aca85e2 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -359,13 +359,7 @@ fn settings_from(matches: &ArgMatches) -> (Settings, RunMode) { /// Get environment variable and turn it into integer. fn get_env_var_value(name: &str) -> Result { - env::var(name).map(|value| { - if let Ok(value) = u8::from_str(&value) { - value - } else { - 1 - } - }) + env::var(name).map(|value| u8::from_str(&value).unwrap_or(1)) } /// Helper function to retrieve a sequence of paths from an environment variable. diff --git a/stdlib/build.rs b/stdlib/build.rs index baaa99c4c8..d8dad9b974 100644 --- a/stdlib/build.rs +++ b/stdlib/build.rs @@ -1,4 +1,10 @@ fn main() { + println!(r#"cargo::rustc-check-cfg=cfg(osslconf, values("OPENSSL_NO_COMP"))"#); + println!("cargo::rustc-check-cfg=cfg(ossl101)"); + println!("cargo::rustc-check-cfg=cfg(ossl102)"); + println!("cargo::rustc-check-cfg=cfg(ossl110)"); + println!("cargo::rustc-check-cfg=cfg(ossl110g)"); + println!("cargo::rustc-check-cfg=cfg(ossl111)"); #[allow(clippy::unusual_byte_groupings)] if let Ok(v) = std::env::var("DEP_OPENSSL_VERSION_NUMBER") { println!("cargo:rustc-env=OPENSSL_API_VERSION={v}"); diff --git a/stdlib/src/socket.rs b/stdlib/src/socket.rs index 1c99e3d5f6..8012aeb624 100644 --- a/stdlib/src/socket.rs +++ b/stdlib/src/socket.rs @@ -337,13 +337,12 @@ mod _socket { target_os = "linux", any( target_arch = "aarch64", - target_arch = "i686", + target_arch = "x86", target_arch = "loongarch64", target_arch = "mips", target_arch = "powerpc", target_arch = "powerpc64", - target_arch = "powerpc64le", - target_arch = "riscv64gc", + target_arch = "riscv64", target_arch = "s390x", target_arch = "x86_64" ) @@ -388,13 +387,12 @@ mod _socket { target_os = "linux", any( target_arch = "aarch64", - target_arch = "i686", + target_arch = "x86", target_arch = "loongarch64", target_arch = "mips", target_arch = "powerpc", target_arch = "powerpc64", - target_arch = "powerpc64le", - target_arch = "riscv64gc", + target_arch = "riscv64", target_arch = "s390x", target_arch = "x86_64" ) diff --git a/vm/src/object/ext.rs b/vm/src/object/ext.rs index b8aa544fd9..ec8b59bda1 100644 --- a/vm/src/object/ext.rs +++ b/vm/src/object/ext.rs @@ -494,6 +494,8 @@ impl PyObject { /// A borrow of a reference to a Python object. This avoids having clone the `PyRef`/ /// `PyObjectRef`, which isn't that cheap as that increments the atomic reference counter. +// TODO: check if we still need this +#[allow(dead_code)] pub struct PyLease<'a, T: PyObjectPayload> { inner: PyRwLockReadGuard<'a, PyRef>, } diff --git a/vm/src/object/traverse.rs b/vm/src/object/traverse.rs index 5110f31b52..43a039d331 100644 --- a/vm/src/object/traverse.rs +++ b/vm/src/object/traverse.rs @@ -19,17 +19,12 @@ pub trait MaybeTraverse { /// Type that need traverse it's children should impl `Traverse`(Not `MaybeTraverse`) /// # Safety -/// impl `traverse()` with caution! Following those guideline so traverse doesn't cause memory error!: -/// - Make sure that every owned object(Every PyObjectRef/PyRef) is called with traverse_fn **at most once**. -/// If some field is not called, the worst results is just memory leak, -/// but if some field is called repeatedly, panic and deadlock can happen. -/// -/// - _**DO NOT**_ clone a `PyObjectRef` or `Pyef` in `traverse()` +/// Please carefully read [`traverse()`] and follow the guideline pub unsafe trait Traverse { /// impl `traverse()` with caution! Following those guideline so traverse doesn't cause memory error!: /// - Make sure that every owned object(Every PyObjectRef/PyRef) is called with traverse_fn **at most once**. - /// If some field is not called, the worst results is just memory leak, - /// but if some field is called repeatedly, panic and deadlock can happen. + /// If some field is not called, the worst results is just memory leak, + /// but if some field is called repeatedly, panic and deadlock can happen. /// /// - _**DO NOT**_ clone a `PyObjectRef` or `Pyef` in `traverse()` fn traverse(&self, traverse_fn: &mut TraverseFn); diff --git a/vm/src/protocol/object.rs b/vm/src/protocol/object.rs index f5c8eccfdb..8b9c0e446c 100644 --- a/vm/src/protocol/object.rs +++ b/vm/src/protocol/object.rs @@ -118,9 +118,8 @@ impl PyObject { .class() .mro_find_map(|cls| cls.slots.getattro.load()) .unwrap(); - getattro(self, attr_name, vm).map_err(|exc| { - vm.set_attribute_error_context(&exc, self.to_owned(), attr_name.to_owned()); - exc + getattro(self, attr_name, vm).inspect_err(|exc| { + vm.set_attribute_error_context(exc, self.to_owned(), attr_name.to_owned()); }) } diff --git a/vm/src/stdlib/posix.rs b/vm/src/stdlib/posix.rs index f5b445f18d..39a450b4f9 100644 --- a/vm/src/stdlib/posix.rs +++ b/vm/src/stdlib/posix.rs @@ -871,10 +871,9 @@ pub mod module { let (rfd, wfd) = pipe().map_err(|err| err.into_pyexception(vm))?; set_inheritable(rfd, false, vm) .and_then(|_| set_inheritable(wfd, false, vm)) - .map_err(|err| { + .inspect_err(|_| { let _ = close(rfd); let _ = close(wfd); - err })?; Ok((rfd, wfd)) } diff --git a/vm/src/stdlib/time.rs b/vm/src/stdlib/time.rs index e539e8bba8..d026f2953e 100644 --- a/vm/src/stdlib/time.rs +++ b/vm/src/stdlib/time.rs @@ -302,7 +302,7 @@ mod decl { Ok(get_thread_time(vm)?.as_nanos() as u64) } - #[cfg(any(windows, all(target_arch = "wasm32", target_arch = "emscripten")))] + #[cfg(any(windows, all(target_arch = "wasm32", target_os = "emscripten")))] pub(super) fn time_muldiv(ticks: i64, mul: i64, div: i64) -> u64 { let intpart = ticks / div; let ticks = ticks % div;