From a309cb5d2ca72a324b3be3727c19cc2f1ad0a0a4 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Sat, 30 Dec 2023 04:09:02 +0900 Subject: [PATCH] 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()))