From a309cb5d2ca72a324b3be3727c19cc2f1ad0a0a4 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Sat, 30 Dec 2023 04:09:02 +0900 Subject: [PATCH 1/2] Fix 1.75 clippy warnings --- common/src/hash.rs | 4 +--- compiler/codegen/src/compile.rs | 5 ++--- stdlib/src/socket.rs | 2 +- vm/src/builtins/object.rs | 4 +++- vm/src/exceptions.rs | 4 ++-- vm/src/warn.rs | 20 ++++++++------------ 6 files changed, 17 insertions(+), 22 deletions(-) diff --git a/common/src/hash.rs b/common/src/hash.rs index 6169003ab..f514dac32 100644 --- a/common/src/hash.rs +++ b/common/src/hash.rs @@ -59,9 +59,7 @@ impl HashSecret { impl HashSecret { pub fn hash_value(&self, data: &T) -> PyHash { - let mut hasher = self.build_hasher(); - data.hash(&mut hasher); - fix_sentinel(mod_int(hasher.finish() as PyHash)) + fix_sentinel(mod_int(self.hash_one(data) as _)) } pub fn hash_iter<'a, T: 'a, I, F, E>(&self, iter: I, hashf: F) -> Result diff --git a/compiler/codegen/src/compile.rs b/compiler/codegen/src/compile.rs index 217c2dc02..e5976047a 100644 --- a/compiler/codegen/src/compile.rs +++ b/compiler/codegen/src/compile.rs @@ -507,9 +507,8 @@ impl Compiler { SymbolScope::Cell => { cache = &mut info.cellvar_cache; NameOpType::Deref - } - // // TODO: is this right? - // SymbolScope::Unknown => NameOpType::Global, + } // TODO: is this right? + // SymbolScope::Unknown => NameOpType::Global, }; if NameUsage::Load == usage && name == "__debug__" { diff --git a/stdlib/src/socket.rs b/stdlib/src/socket.rs index b417a1739..fd9ad74fd 100644 --- a/stdlib/src/socket.rs +++ b/stdlib/src/socket.rs @@ -54,7 +54,7 @@ mod _socket { // put IPPROTO_MAX later use c::{ AF_INET, AF_INET6, AF_UNSPEC, INADDR_ANY, INADDR_LOOPBACK, INADDR_NONE, IPPROTO_ICMP, - IPPROTO_ICMPV6, IPPROTO_IP, IPPROTO_IP as IPPROTO_IPIP, IPPROTO_IPV6, IPPROTO_TCP, + IPPROTO_ICMPV6, IPPROTO_IP, IPPROTO_IPIP, IPPROTO_IPV6, IPPROTO_TCP, IPPROTO_TCP as SOL_TCP, IPPROTO_UDP, MSG_CTRUNC, MSG_DONTROUTE, MSG_OOB, MSG_PEEK, MSG_TRUNC, MSG_WAITALL, NI_DGRAM, NI_MAXHOST, NI_NAMEREQD, NI_NOFQDN, NI_NUMERICHOST, NI_NUMERICSERV, SHUT_RD, SHUT_RDWR, SHUT_WR, SOCK_DGRAM, SOCK_STREAM, SOL_SOCKET, diff --git a/vm/src/builtins/object.rs b/vm/src/builtins/object.rs index 351e559df..efe6aa980 100644 --- a/vm/src/builtins/object.rs +++ b/vm/src/builtins/object.rs @@ -61,7 +61,9 @@ impl Constructor for PyBaseObject { name, methods ))); } - _ => unreachable!("unimplemented_abstract_method_count is always positive"), + // TODO: remove `allow` when redox build doesn't complain about it + #[allow(unreachable_patterns)] + _ => unreachable!(), } } } diff --git a/vm/src/exceptions.rs b/vm/src/exceptions.rs index 19b035d98..d83e7e48d 100644 --- a/vm/src/exceptions.rs +++ b/vm/src/exceptions.rs @@ -779,7 +779,7 @@ impl ExceptionZoo { let errno_getter = ctx.new_readonly_getset("errno", excs.os_error, |exc: PyBaseExceptionRef| { let args = exc.args(); - args.get(0) + args.first() .filter(|_| args.len() > 1 && args.len() <= 5) .cloned() }); @@ -1116,7 +1116,7 @@ pub(super) mod types { args: ::rustpython_vm::function::FuncArgs, vm: &::rustpython_vm::VirtualMachine, ) -> ::rustpython_vm::PyResult<()> { - zelf.set_attr("value", vm.unwrap_or_none(args.args.get(0).cloned()), vm)?; + zelf.set_attr("value", vm.unwrap_or_none(args.args.first().cloned()), vm)?; Ok(()) } } diff --git a/vm/src/warn.rs b/vm/src/warn.rs index ba4571485..d0acccbf2 100644 --- a/vm/src/warn.rs +++ b/vm/src/warn.rs @@ -87,17 +87,13 @@ pub fn warn( } fn get_default_action(vm: &VirtualMachine) -> PyResult { - vm.state - .warnings - .default_action - .clone() - .try_into() - .map_err(|_| { - vm.new_value_error(format!( - "_warnings.defaultaction must be a string, not '{}'", - vm.state.warnings.default_action - )) - }) + Ok(vm.state.warnings.default_action.clone().into()) + // .map_err(|_| { + // vm.new_value_error(format!( + // "_warnings.defaultaction must be a string, not '{}'", + // vm.state.warnings.default_action + // )) + // }) } fn get_filter( @@ -125,7 +121,7 @@ fn get_filter( .ok_or_else(|| vm.new_value_error(format!("_warnings.filters item {i} isn't a 5-tuple")))?; /* Python code: action, msg, cat, mod, ln = item */ - let action = if let Some(action) = tmp_item.get(0) { + let action = if let Some(action) = tmp_item.first() { action.str(vm).map(|action| action.into_object()) } else { Err(vm.new_type_error("action must be a string".to_string())) From 506c8a633ee6c2b361f7f7847678db184d5462b2 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Sat, 30 Dec 2023 12:17:22 +0900 Subject: [PATCH 2/2] Fix redox and nightly --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- compiler/codegen/src/symboltable.rs | 4 ++-- stdlib/src/resource.rs | 4 ++-- stdlib/src/socket.rs | 14 +++++++------- vm/src/builtins/type.rs | 4 ++-- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7bd76c978..e81b3ce97 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1120,9 +1120,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.141" +version = "0.2.151" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" +checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" [[package]] name = "libffi" diff --git a/Cargo.toml b/Cargo.toml index 35a03003a..71e9d221d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -56,7 +56,7 @@ indexmap = { version = "1.9.3", features = ["std"] } insta = "1.33.0" itertools = "0.11.0" is-macro = "0.3.0" -libc = "0.2.133" +libc = "0.2.151" log = "0.4.16" nix = "0.26" malachite-bigint = "0.2.0" diff --git a/compiler/codegen/src/symboltable.rs b/compiler/codegen/src/symboltable.rs index 5283abad5..75e327fe3 100644 --- a/compiler/codegen/src/symboltable.rs +++ b/compiler/codegen/src/symboltable.rs @@ -230,10 +230,10 @@ mod stack { res.unwrap_or_else(|x| panic::resume_unwind(x)) } - pub fn iter(&self) -> impl Iterator + DoubleEndedIterator + '_ { + pub fn iter(&self) -> impl DoubleEndedIterator + '_ { self.as_ref().iter().copied() } - pub fn iter_mut(&mut self) -> impl Iterator + DoubleEndedIterator + '_ { + pub fn iter_mut(&mut self) -> impl DoubleEndedIterator + '_ { self.as_mut().iter_mut().map(|x| &mut **x) } // pub fn top(&self) -> Option<&T> { diff --git a/stdlib/src/resource.rs b/stdlib/src/resource.rs index 85ba5d7be..075e19128 100644 --- a/stdlib/src/resource.rs +++ b/stdlib/src/resource.rs @@ -11,10 +11,10 @@ mod resource { use std::{io, mem}; cfg_if::cfg_if! { - if #[cfg(any(target_os = "linux", target_os = "android"))] { + if #[cfg(target_os = "android")] { use libc::RLIM_NLIMITS; } else { - // in bsd-ish platforms, this constant isn't abi-stable across os versions, so we just + // This constant isn't abi-stable across os versions, so we just // pick a high number so we don't get false positive ValueErrors and just bubble up the // EINVAL that get/setrlimit return on an invalid resource const RLIM_NLIMITS: i32 = 256; diff --git a/stdlib/src/socket.rs b/stdlib/src/socket.rs index fd9ad74fd..d0642f19e 100644 --- a/stdlib/src/socket.rs +++ b/stdlib/src/socket.rs @@ -54,19 +54,19 @@ mod _socket { // put IPPROTO_MAX later use c::{ AF_INET, AF_INET6, AF_UNSPEC, INADDR_ANY, INADDR_LOOPBACK, INADDR_NONE, IPPROTO_ICMP, - IPPROTO_ICMPV6, IPPROTO_IP, IPPROTO_IPIP, IPPROTO_IPV6, IPPROTO_TCP, - IPPROTO_TCP as SOL_TCP, IPPROTO_UDP, MSG_CTRUNC, MSG_DONTROUTE, MSG_OOB, MSG_PEEK, - MSG_TRUNC, MSG_WAITALL, NI_DGRAM, NI_MAXHOST, NI_NAMEREQD, NI_NOFQDN, NI_NUMERICHOST, - NI_NUMERICSERV, SHUT_RD, SHUT_RDWR, SHUT_WR, SOCK_DGRAM, SOCK_STREAM, SOL_SOCKET, - SO_BROADCAST, SO_ERROR, SO_LINGER, SO_OOBINLINE, SO_REUSEADDR, SO_TYPE, TCP_NODELAY, + IPPROTO_ICMPV6, IPPROTO_IP, IPPROTO_IPV6, IPPROTO_TCP, IPPROTO_TCP as SOL_TCP, IPPROTO_UDP, + MSG_CTRUNC, MSG_DONTROUTE, MSG_OOB, MSG_PEEK, MSG_TRUNC, MSG_WAITALL, NI_DGRAM, NI_MAXHOST, + NI_NAMEREQD, NI_NOFQDN, NI_NUMERICHOST, NI_NUMERICSERV, SHUT_RD, SHUT_RDWR, SHUT_WR, + SOCK_DGRAM, SOCK_STREAM, SOL_SOCKET, SO_BROADCAST, SO_ERROR, SO_LINGER, SO_OOBINLINE, + SO_REUSEADDR, SO_TYPE, TCP_NODELAY, }; #[cfg(not(target_os = "redox"))] #[pyattr] use c::{ AF_DECnet, AF_APPLETALK, AF_IPX, IPPROTO_AH, IPPROTO_DSTOPTS, IPPROTO_EGP, IPPROTO_ESP, - IPPROTO_FRAGMENT, IPPROTO_HOPOPTS, IPPROTO_IDP, IPPROTO_IGMP, IPPROTO_NONE, IPPROTO_PIM, - IPPROTO_PUP, IPPROTO_RAW, IPPROTO_ROUTING, + IPPROTO_FRAGMENT, IPPROTO_HOPOPTS, IPPROTO_IDP, IPPROTO_IGMP, IPPROTO_IPIP, IPPROTO_NONE, + IPPROTO_PIM, IPPROTO_PUP, IPPROTO_RAW, IPPROTO_ROUTING, }; #[cfg(unix)] diff --git a/vm/src/builtins/type.rs b/vm/src/builtins/type.rs index e0da4f7dc..6e1ddebb2 100644 --- a/vm/src/builtins/type.rs +++ b/vm/src/builtins/type.rs @@ -299,7 +299,7 @@ impl PyType { } } - pub fn iter_mro(&self) -> impl Iterator + DoubleEndedIterator { + pub fn iter_mro(&self) -> impl DoubleEndedIterator { std::iter::once(self).chain(self.mro.iter().map(|cls| -> &PyType { cls })) } @@ -420,7 +420,7 @@ impl Py { self.as_object().is(cls.borrow()) || self.mro.iter().any(|c| c.is(cls.borrow())) } - pub fn iter_mro(&self) -> impl Iterator> + DoubleEndedIterator { + pub fn iter_mro(&self) -> impl DoubleEndedIterator> { std::iter::once(self).chain(self.mro.iter().map(|x| x.deref())) }