From d4bda6c02e1b092649db41bafc331752caabd6d9 Mon Sep 17 00:00:00 2001 From: Noah <33094578+coolreader18@users.noreply.github.com> Date: Mon, 16 Mar 2020 20:56:45 -0500 Subject: [PATCH] Fix some clippy lints that were 'allow'ed --- compiler/src/symboltable.rs | 13 +++++-------- parser/src/function.rs | 17 +++++++---------- vm/src/lib.rs | 6 +----- vm/src/obj/objcode.rs | 3 +-- vm/src/obj/objint.rs | 1 - vm/src/obj/objproperty.rs | 9 +++------ vm/src/stdlib/imp.rs | 6 ++---- vm/src/stdlib/io.rs | 5 ++--- vm/src/stdlib/itertools.rs | 2 ++ vm/src/stdlib/warnings.rs | 6 ++---- vm/src/version.rs | 3 +-- vm/src/vm.rs | 6 ++---- 12 files changed, 28 insertions(+), 49 deletions(-) diff --git a/compiler/src/symboltable.rs b/compiler/src/symboltable.rs index d08aa4f2e3..0ad3633398 100644 --- a/compiler/src/symboltable.rs +++ b/compiler/src/symboltable.rs @@ -741,7 +741,6 @@ impl SymbolTableBuilder { Ok(()) } - #[allow(clippy::single_match)] fn register_name(&mut self, name: &str, role: SymbolUsage) -> SymbolTableResult { let scope_depth = self.tables.len(); let table = self.tables.last_mut().unwrap(); @@ -777,13 +776,11 @@ impl SymbolTableBuilder { // Some more checks: match role { - SymbolUsage::Nonlocal => { - if scope_depth < 2 { - return Err(SymbolTableError { - error: format!("cannot define nonlocal '{}' at top level.", name), - location, - }); - } + SymbolUsage::Nonlocal if scope_depth < 2 => { + return Err(SymbolTableError { + error: format!("cannot define nonlocal '{}' at top level.", name), + location, + }) } _ => { // Ok! diff --git a/parser/src/function.rs b/parser/src/function.rs index 96366d3c57..d62ea28a2e 100644 --- a/parser/src/function.rs +++ b/parser/src/function.rs @@ -6,7 +6,6 @@ use crate::error::{LexicalError, LexicalErrorType}; type ParameterDefs = (Vec, Vec); type ParameterDef = (ast::Parameter, Option); -#[allow(clippy::collapsible_if)] pub fn parse_params( params: (Vec, Vec), ) -> Result { @@ -16,15 +15,13 @@ pub fn parse_params( let mut try_default = |name: &ast::Parameter, default| { if let Some(default) = default { defaults.push(default); - } else { - if !defaults.is_empty() { - // Once we have started with defaults, all remaining arguments must - // have defaults - return Err(LexicalError { - error: LexicalErrorType::DefaultArgumentError, - location: name.location, - }); - } + } else if !defaults.is_empty() { + // Once we have started with defaults, all remaining arguments must + // have defaults + return Err(LexicalError { + error: LexicalErrorType::DefaultArgumentError, + location: name.location, + }); } Ok(()) }; diff --git a/vm/src/lib.rs b/vm/src/lib.rs index 1dbf723bc3..b324f1b58e 100644 --- a/vm/src/lib.rs +++ b/vm/src/lib.rs @@ -6,11 +6,7 @@ //! - Base objects // for methods like vm.to_str(), not the typical use of 'to' as a method prefix -#![allow( - clippy::wrong_self_convention, - clippy::let_and_return, - clippy::implicit_hasher -)] +#![allow(clippy::wrong_self_convention, clippy::implicit_hasher)] #![doc(html_logo_url = "https://raw.githubusercontent.com/RustPython/RustPython/master/logo.png")] #![doc(html_root_url = "https://docs.rs/rustpython-vm/")] diff --git a/vm/src/obj/objcode.rs b/vm/src/obj/objcode.rs index ebe620333c..0bf11c679d 100644 --- a/vm/src/obj/objcode.rs +++ b/vm/src/obj/objcode.rs @@ -45,8 +45,7 @@ impl PyValue for PyCode { #[pyimpl] impl PyCodeRef { #[pyslot] - #[allow(clippy::new_ret_no_self)] - fn new(_cls: PyClassRef, vm: &VirtualMachine) -> PyResult { + fn new(_cls: PyClassRef, vm: &VirtualMachine) -> PyResult> { Err(vm.new_type_error("Cannot directly create code object".to_owned())) } diff --git a/vm/src/obj/objint.rs b/vm/src/obj/objint.rs index 42ff7677da..7ca22649d7 100644 --- a/vm/src/obj/objint.rs +++ b/vm/src/obj/objint.rs @@ -118,7 +118,6 @@ impl_try_from_object_int!( (u64, to_u64), ); -#[allow(clippy::collapsible_if)] fn inner_pow(int1: &BigInt, int2: &BigInt, vm: &VirtualMachine) -> PyResult { if int2.is_negative() { let v1 = try_float(int1, vm)?; diff --git a/vm/src/obj/objproperty.rs b/vm/src/obj/objproperty.rs index f97c9a8ed3..e9491e69e8 100644 --- a/vm/src/obj/objproperty.rs +++ b/vm/src/obj/objproperty.rs @@ -73,7 +73,6 @@ struct PropertyArgs { } impl SlotDescriptor for PyProperty { - #[allow(clippy::collapsible_if)] fn descr_get( vm: &VirtualMachine, zelf: PyObjectRef, @@ -83,12 +82,10 @@ impl SlotDescriptor for PyProperty { let (zelf, obj) = Self::_unwrap(zelf, obj, vm)?; if vm.is_none(&obj) { Ok(zelf.into_object()) + } else if let Some(getter) = zelf.getter.as_ref() { + vm.invoke(&getter, obj) } else { - if let Some(getter) = zelf.getter.as_ref() { - vm.invoke(&getter, obj) - } else { - Err(vm.new_attribute_error("unreadable attribute".to_string())) - } + Err(vm.new_attribute_error("unreadable attribute".to_string())) } } } diff --git a/vm/src/stdlib/imp.rs b/vm/src/stdlib/imp.rs index ee0d78de65..43e8fa9321 100644 --- a/vm/src/stdlib/imp.rs +++ b/vm/src/stdlib/imp.rs @@ -86,7 +86,7 @@ fn imp_fix_co_filename(_code: PyObjectRef, _path: PyStringRef) { pub fn make_module(vm: &VirtualMachine) -> PyObjectRef { let ctx = &vm.ctx; - let module = py_module!(vm, "_imp", { + py_module!(vm, "_imp", { "extension_suffixes" => ctx.new_function(imp_extension_suffixes), "acquire_lock" => ctx.new_function(imp_acquire_lock), "release_lock" => ctx.new_function(imp_release_lock), @@ -99,7 +99,5 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef { "init_frozen" => ctx.new_function(imp_init_frozen), "is_frozen_package" => ctx.new_function(imp_is_frozen_package), "_fix_co_filename" => ctx.new_function(imp_fix_co_filename), - }); - - module + }) } diff --git a/vm/src/stdlib/io.rs b/vm/src/stdlib/io.rs index fc1c8ea4af..af7408be8f 100644 --- a/vm/src/stdlib/io.rs +++ b/vm/src/stdlib/io.rs @@ -925,7 +925,7 @@ pub fn io_open(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult { _ => unimplemented!("'a' mode is not yet implemented"), }; - let io_obj = match typ.chars().next().unwrap() { + match typ.chars().next().unwrap() { // If the mode is text this buffer type is consumed on construction of // a TextIOWrapper which is subsequently returned. 't' => { @@ -937,8 +937,7 @@ pub fn io_open(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult { // For Buffered class construct "raw" IO class e.g. FileIO and pass this into corresponding field 'b' => buffered, _ => unreachable!(), - }; - io_obj + } } pub fn make_module(vm: &VirtualMachine) -> PyObjectRef { diff --git a/vm/src/stdlib/itertools.rs b/vm/src/stdlib/itertools.rs index 2b4de0e259..3ffc01e806 100644 --- a/vm/src/stdlib/itertools.rs +++ b/vm/src/stdlib/itertools.rs @@ -767,6 +767,8 @@ impl PyItertoolsTee { .into_object()) } + // TODO: make tee() a function, rename this class to itertools._tee and make + // teedata a python class #[pyslot] #[allow(clippy::new_ret_no_self)] fn tp_new( diff --git a/vm/src/stdlib/warnings.rs b/vm/src/stdlib/warnings.rs index 175f5a118a..3a872bf983 100644 --- a/vm/src/stdlib/warnings.rs +++ b/vm/src/stdlib/warnings.rs @@ -34,9 +34,7 @@ fn warnings_warn(args: WarnArgs, vm: &VirtualMachine) -> PyResult<()> { pub fn make_module(vm: &VirtualMachine) -> PyObjectRef { let ctx = &vm.ctx; - let module = py_module!(vm, "_warnings", { + py_module!(vm, "_warnings", { "warn" => ctx.new_function(warnings_warn), - }); - - module + }) } diff --git a/vm/src/version.rs b/vm/src/version.rs index af82e95984..f8aa7bbda1 100644 --- a/vm/src/version.rs +++ b/vm/src/version.rs @@ -102,9 +102,8 @@ fn get_git_timestamp_datetime() -> DateTime { let timestamp = timestamp.parse::().unwrap_or(0); let datetime = UNIX_EPOCH + Duration::from_secs(timestamp); - let datetime = DateTime::::from(datetime); - datetime + datetime.into() } pub fn get_git_date() -> String { diff --git a/vm/src/vm.rs b/vm/src/vm.rs index 777c5f7e40..40d2cf9a7b 100644 --- a/vm/src/vm.rs +++ b/vm/src/vm.rs @@ -768,8 +768,7 @@ impl VirtualMachine { self.trace_event(TraceEvent::Return)?; result } else if class.has_attr("__call__") { - let result = self.call_method(&callable, "__call__", args); - result + self.call_method(&callable, "__call__", args) } else { Err(self.new_type_error(format!( "'{}' object is not callable", @@ -783,8 +782,7 @@ impl VirtualMachine { where T: Into, { - let res = self._invoke(func_ref, args.into()); - res + self._invoke(func_ref, args.into()) } /// Call registered trace function.