From 4135da42ac6ec8490547845c94ba7a32783bd0a9 Mon Sep 17 00:00:00 2001 From: "Jeong, YunWon" <69878+youknowone@users.noreply.github.com> Date: Fri, 6 Oct 2023 03:17:03 +0900 Subject: [PATCH] Fix clippy (#5083) * Fix clippy * Fix nightly clippy --- compiler/codegen/src/symboltable.rs | 2 +- src/shell/helper.rs | 2 +- stdlib/src/zlib.rs | 6 +++--- vm/src/frame.rs | 28 ++++++++++++---------------- vm/src/import.rs | 5 +---- vm/src/macros.rs | 2 ++ vm/src/stdlib/ast.rs | 2 +- vm/src/stdlib/sys.rs | 4 ++-- wasm/lib/src/lib.rs | 2 +- 9 files changed, 24 insertions(+), 29 deletions(-) diff --git a/compiler/codegen/src/symboltable.rs b/compiler/codegen/src/symboltable.rs index e09f0c4aa..5283abad5 100644 --- a/compiler/codegen/src/symboltable.rs +++ b/compiler/codegen/src/symboltable.rs @@ -297,7 +297,7 @@ impl SymbolTableAnalyzer { &mut self, symbol: &mut Symbol, st_typ: SymbolTableType, - sub_tables: &mut [SymbolTable], + sub_tables: &[SymbolTable], ) -> SymbolTableResult { if symbol .flags diff --git a/src/shell/helper.rs b/src/shell/helper.rs index 83d72907b..34691e799 100644 --- a/src/shell/helper.rs +++ b/src/shell/helper.rs @@ -119,8 +119,8 @@ impl<'vm> ShellHelper<'vm> { // only the completions that don't start with a '_' let no_underscore = all_completions .iter() + .filter(|&s| !s.as_str().starts_with('_')) .cloned() - .filter(|s| !s.as_str().starts_with('_')) .collect::>(); // if there are only completions that start with a '_', give them all of the diff --git a/stdlib/src/zlib.rs b/stdlib/src/zlib.rs index 92cefc863..37ee1c83f 100644 --- a/stdlib/src/zlib.rs +++ b/stdlib/src/zlib.rs @@ -310,7 +310,7 @@ mod zlib { fn save_unused_input( &self, - d: &mut Decompress, + d: &Decompress, data: &[u8], stream_end: bool, orig_in: u64, @@ -349,7 +349,7 @@ mod zlib { Ok((buf, false)) => (Ok(buf), false), Err(err) => (Err(err), false), }; - self.save_unused_input(&mut d, data, stream_end, orig_in, vm); + self.save_unused_input(&d, data, stream_end, orig_in, vm); let leftover = if stream_end { b"" @@ -390,7 +390,7 @@ mod zlib { Ok((buf, stream_end)) => (Ok(buf), stream_end), Err(err) => (Err(err), false), }; - self.save_unused_input(&mut d, &data, stream_end, orig_in, vm); + self.save_unused_input(&d, &data, stream_end, orig_in, vm); *data = PyBytes::from(Vec::new()).into_ref(&vm.ctx); diff --git a/vm/src/frame.rs b/vm/src/frame.rs index e53b57a2e..719aa6288 100644 --- a/vm/src/frame.rs +++ b/vm/src/frame.rs @@ -1946,22 +1946,18 @@ impl ExecutingFrame<'_> { impl fmt::Debug for Frame { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let state = self.state.lock(); - let stack_str = state - .stack - .iter() - .map(|elem| { - if elem.payload_is::() { - "\n > {frame}".to_owned() - } else { - format!("\n > {elem:?}") - } - }) - .collect::(); - let block_str = state - .blocks - .iter() - .map(|elem| format!("\n > {elem:?}")) - .collect::(); + let stack_str = state.stack.iter().fold(String::new(), |mut s, elem| { + if elem.payload_is::() { + s.push_str("\n > {frame}"); + } else { + std::fmt::write(&mut s, format_args!("\n > {elem:?}")).unwrap(); + } + s + }); + let block_str = state.blocks.iter().fold(String::new(), |mut s, elem| { + std::fmt::write(&mut s, format_args!("\n > {elem:?}")).unwrap(); + s + }); // TODO: fix this up let locals = self.locals.clone(); write!( diff --git a/vm/src/import.rs b/vm/src/import.rs index 0edc2f77a..918424296 100644 --- a/vm/src/import.rs +++ b/vm/src/import.rs @@ -31,10 +31,7 @@ pub(crate) fn init_importlib_base(vm: &mut VirtualMachine) -> PyResult PyResult<()> { +pub(crate) fn init_importlib_package(vm: &VirtualMachine, importlib: PyObjectRef) -> PyResult<()> { thread::enter_vm(vm, || { flame_guard!("install_external"); diff --git a/vm/src/macros.rs b/vm/src/macros.rs index c058764f3..4554a65c2 100644 --- a/vm/src/macros.rs +++ b/vm/src/macros.rs @@ -116,10 +116,12 @@ macro_rules! match_class { // The default arm, binding the original object to the specified identifier. (match ($obj:expr) { $binding:ident => $default:expr $(,)? }) => {{ + #[allow(clippy::redundant_locals)] let $binding = $obj; $default }}; (match ($obj:expr) { ref $binding:ident => $default:expr $(,)? }) => {{ + #[allow(clippy::redundant_locals)] let $binding = &$obj; $default }}; diff --git a/vm/src/stdlib/ast.rs b/vm/src/stdlib/ast.rs index bf34528e2..50b3153d0 100644 --- a/vm/src/stdlib/ast.rs +++ b/vm/src/stdlib/ast.rs @@ -168,7 +168,7 @@ fn range_from_object( None }; let range = SourceRange { - start: location.unwrap_or(SourceLocation::default()), + start: location.unwrap_or_default(), end: end_location, }; Ok(range) diff --git a/vm/src/stdlib/sys.rs b/vm/src/stdlib/sys.rs index 81498a7b0..65d50eaa1 100644 --- a/vm/src/stdlib/sys.rs +++ b/vm/src/stdlib/sys.rs @@ -784,8 +784,8 @@ mod sys { impl PyThreadInfo { const INFO: Self = PyThreadInfo { name: crate::stdlib::thread::_thread::PYTHREAD_NAME, - /// As I know, there's only way to use lock as "Mutex" in Rust - /// with satisfying python document spec. + // As I know, there's only way to use lock as "Mutex" in Rust + // with satisfying python document spec. lock: Some("mutex+cond"), version: None, }; diff --git a/wasm/lib/src/lib.rs b/wasm/lib/src/lib.rs index 07bb2f5f7..85546c78d 100644 --- a/wasm/lib/src/lib.rs +++ b/wasm/lib/src/lib.rs @@ -52,7 +52,7 @@ pub mod eval { fn run_py(source: &str, options: Option, mode: Mode) -> Result { let vm = VMStore::init(PY_EVAL_VM_ID.into(), Some(true)); - let options = options.unwrap_or_else(Object::new); + let options = options.unwrap_or_default(); let js_vars = { let prop = Reflect::get(&options, &"vars".into())?; if prop.is_undefined() {