From d86ffc40f66a8016f2d4cc1fec9f5292e89135de Mon Sep 17 00:00:00 2001 From: ZapAnton Date: Tue, 12 Feb 2019 16:07:24 +0300 Subject: [PATCH 01/18] Fixed the redundant_field_names clippy warnings --- vm/src/pyobject.rs | 2 +- vm/src/stdlib/json.rs | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/vm/src/pyobject.rs b/vm/src/pyobject.rs index 163821bd09..44202e9cc0 100644 --- a/vm/src/pyobject.rs +++ b/vm/src/pyobject.rs @@ -514,7 +514,7 @@ impl PyContext { // Initialized empty, as calling __hash__ is required for adding each object to the set // which requires a VM context - this is done in the objset code itself. let elements: HashMap = HashMap::new(); - PyObject::new(PyObjectPayload::Set { elements: elements }, self.set_type()) + PyObject::new(PyObjectPayload::Set { elements }, self.set_type()) } pub fn new_dict(&self) -> PyObjectRef { diff --git a/vm/src/stdlib/json.rs b/vm/src/stdlib/json.rs index 581646a03d..9941ac950e 100644 --- a/vm/src/stdlib/json.rs +++ b/vm/src/stdlib/json.rs @@ -189,10 +189,7 @@ fn json_dumps(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { // TODO: Implement non-trivial serialisation case arg_check!(vm, args, required = [(obj, None)]); let res = { - let serializer = PyObjectSerializer { - pyobject: obj, - vm: vm, - }; + let serializer = PyObjectSerializer { pyobject: obj, vm }; serde_json::to_string(&serializer) }; let string = res.map_err(|err| vm.new_type_error(format!("{}", err)))?; @@ -204,7 +201,7 @@ fn json_loads(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { // TODO: Implement non-trivial deserialisation case arg_check!(vm, args, required = [(string, Some(vm.ctx.str_type()))]); let res = { - let de = PyObjectDeserializer { vm: vm }; + let de = PyObjectDeserializer { vm }; // TODO: Support deserializing string sub-classes de.deserialize(&mut serde_json::Deserializer::from_str(&objstr::get_value( &string, From 0d1b85a8da0c28e953bbd8c9b2715590205d2752 Mon Sep 17 00:00:00 2001 From: ZapAnton Date: Tue, 12 Feb 2019 16:28:49 +0300 Subject: [PATCH 02/18] Fixed the collapsible_if clippy warning --- vm/src/obj/objbytearray.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/vm/src/obj/objbytearray.rs b/vm/src/obj/objbytearray.rs index b4afaa6398..24698277ea 100644 --- a/vm/src/obj/objbytearray.rs +++ b/vm/src/obj/objbytearray.rs @@ -214,12 +214,10 @@ fn bytearray_istitle(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { let current = char::from(*c); let next = if let Some(k) = iter.peek() { char::from(**k) + } else if current.is_uppercase() { + return Ok(vm.new_bool(!prev_cased)); } else { - if current.is_uppercase() { - return Ok(vm.new_bool(!prev_cased)); - } else { - return Ok(vm.new_bool(prev_cased)); - } + return Ok(vm.new_bool(prev_cased)); }; if (is_cased(current) && next.is_uppercase() && !prev_cased) From 606ddd221669bf874bb70d30e746860364eeeadf Mon Sep 17 00:00:00 2001 From: ZapAnton Date: Tue, 12 Feb 2019 16:30:03 +0300 Subject: [PATCH 03/18] Fixed the needless_return clippy warnings --- vm/src/obj/objset.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/vm/src/obj/objset.rs b/vm/src/obj/objset.rs index 413a0285f4..a6e11def9f 100644 --- a/vm/src/obj/objset.rs +++ b/vm/src/obj/objset.rs @@ -180,48 +180,48 @@ pub fn set_contains(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { } fn set_eq(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { - return set_compare_inner( + set_compare_inner( vm, args, &|zelf: usize, other: usize| -> bool { zelf != other }, false, - ); + ) } fn set_ge(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { - return set_compare_inner( + set_compare_inner( vm, args, &|zelf: usize, other: usize| -> bool { zelf < other }, false, - ); + ) } fn set_gt(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { - return set_compare_inner( + set_compare_inner( vm, args, &|zelf: usize, other: usize| -> bool { zelf <= other }, false, - ); + ) } fn set_le(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { - return set_compare_inner( + set_compare_inner( vm, args, &|zelf: usize, other: usize| -> bool { zelf < other }, true, - ); + ) } fn set_lt(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { - return set_compare_inner( + set_compare_inner( vm, args, &|zelf: usize, other: usize| -> bool { zelf <= other }, true, - ); + ) } fn set_compare_inner( From 00cfa47f6401ad09d9871434332a81e1f60783ca Mon Sep 17 00:00:00 2001 From: ZapAnton Date: Tue, 12 Feb 2019 16:35:28 +0300 Subject: [PATCH 04/18] Fixed the should_implement_trait clippy warning --- vm/src/format.rs | 6 +++++- vm/src/obj/objstr.rs | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/vm/src/format.rs b/vm/src/format.rs index 6dfa77c7e3..e89e4f731d 100644 --- a/vm/src/format.rs +++ b/vm/src/format.rs @@ -496,8 +496,12 @@ impl FormatString { None => Err(FormatParseError::UnmatchedBracket), } } +} + +impl FromStr for FormatString { + type Err = FormatParseError; - pub fn from_str(text: &str) -> Result { + fn from_str(text: &str) -> Result { let mut cur_text: &str = text; let mut parts: Vec = Vec::new(); while !cur_text.is_empty() { diff --git a/vm/src/obj/objstr.rs b/vm/src/obj/objstr.rs index f71df5c25f..1a8e7f9480 100644 --- a/vm/src/obj/objstr.rs +++ b/vm/src/obj/objstr.rs @@ -9,6 +9,7 @@ use super::objtype; use num_traits::ToPrimitive; use std::hash::{Hash, Hasher}; use std::ops::Range; +use std::str::FromStr; // rust's builtin to_lowercase isn't sufficient for casefold extern crate caseless; extern crate unicode_segmentation; From 8b6d0b37213d8dba1db4e46037769ba62dac8aff Mon Sep 17 00:00:00 2001 From: ZapAnton Date: Tue, 12 Feb 2019 16:37:02 +0300 Subject: [PATCH 05/18] Fixed the op_ref clippy warning --- vm/src/frame.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm/src/frame.rs b/vm/src/frame.rs index 7d77280985..cf971a38f2 100644 --- a/vm/src/frame.rs +++ b/vm/src/frame.rs @@ -197,7 +197,7 @@ impl Frame { } bytecode::Instruction::Rotate { amount } => { // Shuffles top of stack amount down - if amount < &2 { + if *amount < 2 { panic!("Can only rotate two or more values"); } From 66569160fc5f5d0f162e467b048f017cb3a62db0 Mon Sep 17 00:00:00 2001 From: ZapAnton Date: Tue, 12 Feb 2019 16:38:15 +0300 Subject: [PATCH 06/18] Fixed the redundant_closure clippy warning --- vm/src/import.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm/src/import.rs b/vm/src/import.rs index d7393bd674..49fe08d944 100644 --- a/vm/src/import.rs +++ b/vm/src/import.rs @@ -77,7 +77,7 @@ pub fn import( let import_error = vm.context().exceptions.import_error.clone(); Err(vm.new_exception(import_error, format!("cannot import name '{}'", symbol))) }, - |obj| Ok(obj), + Ok, ) } else { Ok(module) From 9144109f7d964143f57e9e1eca9f55417176493f Mon Sep 17 00:00:00 2001 From: ZapAnton Date: Tue, 12 Feb 2019 16:39:38 +0300 Subject: [PATCH 07/18] Fixed the useless_vec clippy warning --- vm/src/obj/objcode.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm/src/obj/objcode.rs b/vm/src/obj/objcode.rs index 2649c11903..1998bfab90 100644 --- a/vm/src/obj/objcode.rs +++ b/vm/src/obj/objcode.rs @@ -14,7 +14,7 @@ pub fn init(context: &PyContext) { context.set_attr(code_type, "__new__", context.new_rustfunc(code_new)); context.set_attr(code_type, "__repr__", context.new_rustfunc(code_repr)); - for (name, f) in vec![ + for (name, f) in &[ ( "co_argcount", code_co_argcount as fn(&mut VirtualMachine, PyFuncArgs) -> PyResult, From 050bf459b0964048530f7719b9f0f6382095c46d Mon Sep 17 00:00:00 2001 From: ZapAnton Date: Tue, 12 Feb 2019 16:40:08 +0300 Subject: [PATCH 08/18] Fixed the into_iter_on_ref clippy warning --- vm/src/obj/objmap.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm/src/obj/objmap.rs b/vm/src/obj/objmap.rs index 79ee7ddf8a..bde61e3d67 100644 --- a/vm/src/obj/objmap.rs +++ b/vm/src/obj/objmap.rs @@ -14,7 +14,7 @@ fn map_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { let function = &args.args[1]; let iterables = &args.args[2..]; let iterators = iterables - .into_iter() + .iter() .map(|iterable| objiter::get_iter(vm, iterable)) .collect::, _>>()?; Ok(PyObject::new( From 45b9ef9719e9cb638ab7abe51b4971d6878b6d02 Mon Sep 17 00:00:00 2001 From: ZapAnton Date: Tue, 12 Feb 2019 16:42:53 +0300 Subject: [PATCH 09/18] Fixed the op_ref clippy warnings --- vm/src/obj/objrange.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vm/src/obj/objrange.rs b/vm/src/obj/objrange.rs index b9801cb304..bc631fa97c 100644 --- a/vm/src/obj/objrange.rs +++ b/vm/src/obj/objrange.rs @@ -42,8 +42,8 @@ impl RangeType { #[inline] fn offset(&self, value: &BigInt) -> Option { match self.step.sign() { - Sign::Plus if value >= &self.start && value < &self.end => Some(value - &self.start), - Sign::Minus if value <= &self.start && value > &self.end => Some(&self.start - value), + Sign::Plus if *value >= self.start && *value < self.end => Some(value - &self.start), + Sign::Minus if *value <= self.start && *value > self.end => Some(&self.start - value), _ => None, } } From 5fe373555f5f88cb336a15275502a757dc614b07 Mon Sep 17 00:00:00 2001 From: ZapAnton Date: Tue, 12 Feb 2019 16:43:59 +0300 Subject: [PATCH 10/18] Fixed the match_bool clippy warning --- vm/src/obj/objrange.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/vm/src/obj/objrange.rs b/vm/src/obj/objrange.rs index bc631fa97c..0cfb4bdf09 100644 --- a/vm/src/obj/objrange.rs +++ b/vm/src/obj/objrange.rs @@ -68,9 +68,10 @@ impl RangeType { #[inline] pub fn count(&self, value: &BigInt) -> usize { - match self.index_of(value).is_some() { - true => 1, - false => 0, + if self.index_of(value).is_some() { + 1 + } else { + 0 } } From 291dba6bb61708863980da2e859318b0227beef6 Mon Sep 17 00:00:00 2001 From: ZapAnton Date: Tue, 12 Feb 2019 16:44:47 +0300 Subject: [PATCH 11/18] Fixed the toplevel_ref_arg clippy warning --- vm/src/obj/objrange.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm/src/obj/objrange.rs b/vm/src/obj/objrange.rs index 0cfb4bdf09..a65420129e 100644 --- a/vm/src/obj/objrange.rs +++ b/vm/src/obj/objrange.rs @@ -146,7 +146,7 @@ pub fn get_value(obj: &PyObjectRef) -> RangeType { } pub fn init(context: &PyContext) { - let ref range_type = context.range_type; + let range_type = &context.range_type; let range_doc = "range(stop) -> range object\n\ range(start, stop[, step]) -> range object\n\n\ From 38930984ec4c2ccd9011ae3e4f84181518063c2a Mon Sep 17 00:00:00 2001 From: ZapAnton Date: Tue, 12 Feb 2019 16:45:44 +0300 Subject: [PATCH 12/18] Fixed the redundant_pattern_matching clippy warning --- vm/src/obj/objrange.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm/src/obj/objrange.rs b/vm/src/obj/objrange.rs index a65420129e..c95407f62f 100644 --- a/vm/src/obj/objrange.rs +++ b/vm/src/obj/objrange.rs @@ -199,7 +199,7 @@ fn range_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult { ] ); - let start = if let Some(_) = second { + let start = if second.is_some() { objint::get_value(first) } else { BigInt::zero() From 206ccc55fba53fc0486c02ba285ed32464158afc Mon Sep 17 00:00:00 2001 From: ZapAnton Date: Tue, 12 Feb 2019 16:49:34 +0300 Subject: [PATCH 13/18] Fixed the len_without_is_empty clippy warning --- vm/src/obj/objsequence.rs | 5 +++++ vm/src/obj/objstr.rs | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/vm/src/obj/objsequence.rs b/vm/src/obj/objsequence.rs index 31c1b7b71a..32d3523313 100644 --- a/vm/src/obj/objsequence.rs +++ b/vm/src/obj/objsequence.rs @@ -15,6 +15,7 @@ pub trait PySliceableSequence { fn do_stepped_slice_reverse(&self, range: Range, step: usize) -> Self; fn empty() -> Self; fn len(&self) -> usize; + fn is_empty(&self) -> bool; fn get_pos(&self, p: i32) -> Option { if p < 0 { if -p as usize > self.len() { @@ -127,6 +128,10 @@ impl PySliceableSequence for Vec { fn len(&self) -> usize { self.len() } + + fn is_empty(&self) -> bool { + self.is_empty() + } } pub fn get_item( diff --git a/vm/src/obj/objstr.rs b/vm/src/obj/objstr.rs index 1a8e7f9480..f533378f32 100644 --- a/vm/src/obj/objstr.rs +++ b/vm/src/obj/objstr.rs @@ -1070,6 +1070,10 @@ impl PySliceableSequence for String { fn len(&self) -> usize { to_graphemes(self).len() } + + fn is_empty(&self) -> bool { + self.is_empty() + } } /// Convert a string-able `value` to a vec of graphemes From ef6561200840782669bdc1091f593e6cf0bba076 Mon Sep 17 00:00:00 2001 From: ZapAnton Date: Tue, 12 Feb 2019 16:59:15 +0300 Subject: [PATCH 14/18] Fixed the clone_double_ref clippy warning --- vm/src/obj/objsequence.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm/src/obj/objsequence.rs b/vm/src/obj/objsequence.rs index 32d3523313..3f6f67bf61 100644 --- a/vm/src/obj/objsequence.rs +++ b/vm/src/obj/objsequence.rs @@ -293,7 +293,7 @@ pub fn seq_mul(elements: &[PyObjectRef], product: &PyObjectRef) -> Vec Date: Tue, 12 Feb 2019 17:09:52 +0300 Subject: [PATCH 15/18] Fixed the useless_asref clippy warnings --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index e6d5e5684d..8788c47bbb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -195,7 +195,7 @@ fn run_shell(vm: &mut VirtualMachine) -> PyResult { debug!("You entered {:?}", input); if shell_exec(vm, &input, vars.clone()) { // Line was complete. - rl.add_history_entry(input.trim_end().as_ref()); + rl.add_history_entry(input.trim_end()); input = String::new(); } else { loop { @@ -208,7 +208,7 @@ fn run_shell(vm: &mut VirtualMachine) -> PyResult { Ok(line) => { if line.len() == 0 { if shell_exec(vm, &input, vars.clone()) { - rl.add_history_entry(input.trim_end().as_ref()); + rl.add_history_entry(input.trim_end()); input = String::new(); break; } From e8467c3bfe89d6d8a6fb4a434b6285db7167f57b Mon Sep 17 00:00:00 2001 From: ZapAnton Date: Tue, 12 Feb 2019 17:10:53 +0300 Subject: [PATCH 16/18] Fixed the redundant_closure clippy warning --- wasm/lib/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wasm/lib/src/lib.rs b/wasm/lib/src/lib.rs index 7ad3f19560..7b530d78ae 100644 --- a/wasm/lib/src/lib.rs +++ b/wasm/lib/src/lib.rs @@ -145,7 +145,7 @@ fn eval(vm: &mut VirtualMachine, source: &str, vars: PyObjectRef) -> PyResult { /// - `stdout?`: `(out: string) => void`: A function to replace the native print /// function, by default `console.log`. pub fn eval_py(source: &str, options: Option) -> Result { - let options = options.unwrap_or_else(|| Object::new()); + let options = options.unwrap_or_else(Object::new); let js_vars = { let prop = Reflect::get(&options, &"vars".into())?; if prop.is_undefined() { From 08d767b0107a33f5f3b4fffcbce699faa93f5b17 Mon Sep 17 00:00:00 2001 From: ZapAnton Date: Tue, 12 Feb 2019 17:12:11 +0300 Subject: [PATCH 17/18] Fixed the unnecessary_mut_passed clippy warning --- wasm/lib/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wasm/lib/src/lib.rs b/wasm/lib/src/lib.rs index 7b530d78ae..ff7fe1f531 100644 --- a/wasm/lib/src/lib.rs +++ b/wasm/lib/src/lib.rs @@ -199,7 +199,7 @@ pub fn eval_py(source: &str, options: Option) -> Result) -> Result Date: Tue, 12 Feb 2019 17:13:09 +0300 Subject: [PATCH 18/18] Fixed the len_zero clippy warning --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 8788c47bbb..075fe966a3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -206,7 +206,7 @@ fn run_shell(vm: &mut VirtualMachine) -> PyResult { //}; match rl.readline(&ps2) { Ok(line) => { - if line.len() == 0 { + if line.is_empty() { if shell_exec(vm, &input, vars.clone()) { rl.add_history_entry(input.trim_end()); input = String::new();