From 6c561ac9d7b7ab9956d77fac9d9ebe496c85d086 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Fri, 27 Jun 2025 11:37:40 +0900 Subject: [PATCH] Fix stable clippy --- benches/execution.rs | 2 +- compiler/literal/src/float.rs | 2 +- examples/dis.rs | 2 +- examples/parse_folder.rs | 8 ++++---- jit/tests/common.rs | 2 +- stdlib/src/array.rs | 2 +- vm/src/builtins/genericalias.rs | 7 +++---- vm/src/frame.rs | 11 +++++++---- vm/src/stdlib/functools.rs | 12 +++++++++--- vm/src/stdlib/sys.rs | 5 ++--- vm/src/stdlib/typing.rs | 12 ++++++------ vm/src/vm/vm_object.rs | 4 ++-- wasm/wasm-unknown-test/Cargo.toml | 3 +++ 13 files changed, 41 insertions(+), 31 deletions(-) diff --git a/benches/execution.rs b/benches/execution.rs index 956975c22f..7a7ba247e5 100644 --- a/benches/execution.rs +++ b/benches/execution.rs @@ -71,7 +71,7 @@ pub fn benchmark_file_parsing(group: &mut BenchmarkGroup, name: &str, pub fn benchmark_pystone(group: &mut BenchmarkGroup, contents: String) { // Default is 50_000. This takes a while, so reduce it to 30k. for idx in (10_000..=30_000).step_by(10_000) { - let code_with_loops = format!("LOOPS = {}\n{}", idx, contents); + let code_with_loops = format!("LOOPS = {idx}\n{contents}"); let code_str = code_with_loops.as_str(); group.throughput(Throughput::Elements(idx as u64)); diff --git a/compiler/literal/src/float.rs b/compiler/literal/src/float.rs index 3764323de3..0c07d97c98 100644 --- a/compiler/literal/src/float.rs +++ b/compiler/literal/src/float.rs @@ -261,7 +261,7 @@ fn test_to_hex() { // println!("{} -> {}", f, hex); let roundtrip = hexf_parse::parse_hexf64(&hex, false).unwrap(); // println!(" -> {}", roundtrip); - assert!(f == roundtrip, "{} {} {}", f, hex, roundtrip); + assert!(f == roundtrip, "{f} {hex} {roundtrip}"); } } diff --git a/examples/dis.rs b/examples/dis.rs index c79b5e258c..504b734ca5 100644 --- a/examples/dis.rs +++ b/examples/dis.rs @@ -59,7 +59,7 @@ fn main() -> Result<(), lexopt::Error> { if script.exists() && script.is_file() { let res = display_script(script, mode, opts.clone(), expand_code_objects); if let Err(e) = res { - error!("Error while compiling {:?}: {}", script, e); + error!("Error while compiling {script:?}: {e}"); } } else { eprintln!("{script:?} is not a file."); diff --git a/examples/parse_folder.rs b/examples/parse_folder.rs index e05b34c265..462fd29256 100644 --- a/examples/parse_folder.rs +++ b/examples/parse_folder.rs @@ -41,9 +41,9 @@ fn main() { fn parse_folder(path: &Path) -> std::io::Result> { let mut res = vec![]; - info!("Parsing folder of python code: {:?}", path); + info!("Parsing folder of python code: {path:?}"); for entry in path.read_dir()? { - debug!("Entry: {:?}", entry); + debug!("Entry: {entry:?}"); let entry = entry?; let metadata = entry.metadata()?; @@ -56,7 +56,7 @@ fn parse_folder(path: &Path) -> std::io::Result> { let parsed_file = parse_python_file(&path); match &parsed_file.result { Ok(_) => {} - Err(y) => error!("Erreur in file {:?} {:?}", path, y), + Err(y) => error!("Erreur in file {path:?} {y:?}"), } res.push(parsed_file); @@ -66,7 +66,7 @@ fn parse_folder(path: &Path) -> std::io::Result> { } fn parse_python_file(filename: &Path) -> ParsedFile { - info!("Parsing file {:?}", filename); + info!("Parsing file {filename:?}"); match std::fs::read_to_string(filename) { Err(e) => ParsedFile { num_lines: 0, diff --git a/jit/tests/common.rs b/jit/tests/common.rs index 680090eb5b..78318bc406 100644 --- a/jit/tests/common.rs +++ b/jit/tests/common.rs @@ -172,7 +172,7 @@ impl StackMachine { if let Some(StackValue::Function(function)) = self.locals.get(name) { function.clone() } else { - panic!("There was no function named {}", name) + panic!("There was no function named {name}") } } } diff --git a/stdlib/src/array.rs b/stdlib/src/array.rs index 688e42a75f..a1a401943d 100644 --- a/stdlib/src/array.rs +++ b/stdlib/src/array.rs @@ -601,7 +601,7 @@ mod array { fn try_from(ch: WideChar) -> Result { // safe because every configuration of bytes for the types we support are valid - u32_to_char(ch.0 as u32) + u32_to_char(ch.0 as _) } } diff --git a/vm/src/builtins/genericalias.rs b/vm/src/builtins/genericalias.rs index 2ae5877751..6b6bdc29ac 100644 --- a/vm/src/builtins/genericalias.rs +++ b/vm/src/builtins/genericalias.rs @@ -388,10 +388,9 @@ pub fn subs_parameters PyResult>( new_args.push(substituted); } else { // CPython doesn't support default values in this context - return Err(vm.new_type_error(format!( - "No argument provided for parameter at index {}", - idx - ))); + return Err( + vm.new_type_error(format!("No argument provided for parameter at index {idx}")) + ); } } else { new_args.push(subs_tvars(arg.clone(), ¶meters, arg_items, vm)?); diff --git a/vm/src/frame.rs b/vm/src/frame.rs index 16ab4db266..5d5f3e8141 100644 --- a/vm/src/frame.rs +++ b/vm/src/frame.rs @@ -349,7 +349,10 @@ impl ExecutingFrame<'_> { } fn run(&mut self, vm: &VirtualMachine) -> PyResult { - flame_guard!(format!("Frame::run({})", self.code.obj_name)); + flame_guard!(format!( + "Frame::run({obj_name})", + obj_name = self.code.obj_name + )); // Execute until return or exception: let instructions = &self.code.instructions; let mut arg_state = bytecode::OpArgState::default(); @@ -941,7 +944,7 @@ impl ExecutingFrame<'_> { .get_attr(identifier!(vm, __exit__), vm) .map_err(|_exc| { vm.new_type_error({ - format!("'{} (missed __exit__ method)", error_string()) + format!("{} (missed __exit__ method)", error_string()) }) })?; self.push_value(exit); @@ -968,7 +971,7 @@ impl ExecutingFrame<'_> { .get_attr(identifier!(vm, __aexit__), vm) .map_err(|_exc| { vm.new_type_error({ - format!("'{} (missed __aexit__ method)", error_string()) + format!("{} (missed __aexit__ method)", error_string()) }) })?; self.push_value(aexit); @@ -1638,7 +1641,7 @@ impl ExecutingFrame<'_> { F: FnMut(PyObjectRef) -> PyResult<()>, { let Some(keys_method) = vm.get_method(mapping.clone(), vm.ctx.intern_str("keys")) else { - return Err(vm.new_type_error(format!("{} must be a mapping", error_prefix))); + return Err(vm.new_type_error(format!("{error_prefix} must be a mapping"))); }; let keys = keys_method?.call((), vm)?.get_iter(vm)?; diff --git a/vm/src/stdlib/functools.rs b/vm/src/stdlib/functools.rs index 841659b85a..f27a1ac143 100644 --- a/vm/src/stdlib/functools.rs +++ b/vm/src/stdlib/functools.rs @@ -286,7 +286,10 @@ mod _functools { key.str(vm)?.as_str().to_owned() }; let value_str = value.repr(vm)?; - parts.push(format!("{}={}", key_part, value_str.as_str())); + parts.push(format!( + "{key_part}={value_str}", + value_str = value_str.as_str() + )); } let class_name = zelf.class().name(); @@ -306,14 +309,17 @@ mod _functools { // For test modules, just use the class name without module prefix class_name.to_owned() } - _ => format!("{}.{}", module_name, class_name), + _ => format!("{module_name}.{class_name}"), } } Err(_) => class_name.to_owned(), } }; - Ok(format!("{}({})", qualified_name, parts.join(", "))) + Ok(format!( + "{qualified_name}({parts})", + parts = parts.join(", ") + )) } else { Ok("...".to_owned()) } diff --git a/vm/src/stdlib/sys.rs b/vm/src/stdlib/sys.rs index 1b9b8ff263..2e4f9e57e9 100644 --- a/vm/src/stdlib/sys.rs +++ b/vm/src/stdlib/sys.rs @@ -373,11 +373,10 @@ mod sys { let type_name = exc_val.class().name(); // TODO: fix error message let msg = format!( - "TypeError: print_exception(): Exception expected for value, {} found\n", - type_name + "TypeError: print_exception(): Exception expected for value, {type_name} found\n" ); use crate::py_io::Write; - write!(&mut crate::py_io::PyWriter(stderr, vm), "{}", msg)?; + write!(&mut crate::py_io::PyWriter(stderr, vm), "{msg}")?; Ok(()) } } diff --git a/vm/src/stdlib/typing.rs b/vm/src/stdlib/typing.rs index 58935b48b4..1105183350 100644 --- a/vm/src/stdlib/typing.rs +++ b/vm/src/stdlib/typing.rs @@ -171,11 +171,11 @@ pub(crate) mod decl { fn repr_str(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { let name = zelf.name.str(vm)?; let repr = if zelf.covariant { - format!("+{}", name) + format!("+{name}") } else if zelf.contravariant { - format!("-{}", name) + format!("-{name}") } else { - format!("~{}", name) + format!("~{name}") }; Ok(repr) } @@ -738,7 +738,7 @@ pub(crate) mod decl { #[inline(always)] fn repr_str(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { let name = zelf.name.str(vm)?; - Ok(format!("*{}", name)) + Ok(format!("*{name}")) } } @@ -785,7 +785,7 @@ pub(crate) mod decl { fn repr_str(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { // Check if origin is a ParamSpec if let Ok(name) = zelf.__origin__.get_attr("__name__", vm) { - return Ok(format!("{}.args", name.str(vm)?)); + return Ok(format!("{name}.args", name = name.str(vm)?)); } Ok(format!("{:?}.args", zelf.__origin__)) } @@ -864,7 +864,7 @@ pub(crate) mod decl { fn repr_str(zelf: &crate::Py, vm: &VirtualMachine) -> PyResult { // Check if origin is a ParamSpec if let Ok(name) = zelf.__origin__.get_attr("__name__", vm) { - return Ok(format!("{}.kwargs", name.str(vm)?)); + return Ok(format!("{name}.kwargs", name = name.str(vm)?)); } Ok(format!("{:?}.kwargs", zelf.__origin__)) } diff --git a/vm/src/vm/vm_object.rs b/vm/src/vm/vm_object.rs index a705a53e7e..69e8bcd8f3 100644 --- a/vm/src/vm/vm_object.rs +++ b/vm/src/vm/vm_object.rs @@ -38,7 +38,7 @@ impl VirtualMachine { let mut s = String::new(); self.write_exception(&mut s, &exc).unwrap(); error(&s); - panic!("{}; exception backtrace above", msg) + panic!("{msg}; exception backtrace above") } #[cfg(all( target_arch = "wasm32", @@ -49,7 +49,7 @@ impl VirtualMachine { use crate::convert::ToPyObject; let err_string: String = exc.to_pyobject(self).repr(self).unwrap().to_string(); eprintln!("{err_string}"); - panic!("{}; python exception not available", msg) + panic!("{msg}; python exception not available") } } diff --git a/wasm/wasm-unknown-test/Cargo.toml b/wasm/wasm-unknown-test/Cargo.toml index aac5e3539d..5945f69006 100644 --- a/wasm/wasm-unknown-test/Cargo.toml +++ b/wasm/wasm-unknown-test/Cargo.toml @@ -11,3 +11,6 @@ getrandom = "0.3" rustpython-vm = { path = "../../vm", default-features = false, features = ["compiler"] } [workspace] + +[patch.crates-io] +radium = { version = "1.1.0", git = "https://github.com/youknowone/ferrilab", branch = "fix-nightly" }