From e0e98fdbf6fde19fe92f62e5a2ae53f7b1898c41 Mon Sep 17 00:00:00 2001 From: Noa Date: Fri, 23 Jan 2026 12:54:35 -0600 Subject: [PATCH 1/4] Use std::fmt::from_fn --- crates/codegen/src/unparse.rs | 22 +++++-------------- .../compiler-core/src/bytecode/instruction.rs | 16 +++++--------- 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/crates/codegen/src/unparse.rs b/crates/codegen/src/unparse.rs index 849544ab946..eef2128587a 100644 --- a/crates/codegen/src/unparse.rs +++ b/crates/codegen/src/unparse.rs @@ -549,9 +549,9 @@ impl<'a, 'b, 'c> Unparser<'a, 'b, 'c> { conversion: ast::ConversionFlag, spec: Option<&ast::InterpolatedStringFormatSpec>, ) -> fmt::Result { - let buffered = to_string_fmt(|f| { - Unparser::new(f, self.source).unparse_expr(val, precedence::TEST + 1) - }); + let buffered = + fmt::from_fn(|f| Unparser::new(f, self.source).unparse_expr(val, precedence::TEST + 1)) + .to_string(); if let Some(ast::DebugText { leading, trailing }) = debug_text { self.p(leading)?; self.p(self.source.slice(val.range()))?; @@ -612,14 +612,15 @@ impl<'a, 'b, 'c> Unparser<'a, 'b, 'c> { fn unparse_fstring(&mut self, value: &ast::FStringValue) -> fmt::Result { self.p("f")?; - let body = to_string_fmt(|f| { + let body = fmt::from_fn(|f| { value.iter().try_for_each(|part| match part { ast::FStringPart::Literal(lit) => f.write_str(lit), ast::FStringPart::FString(ast::FString { elements, .. }) => { Unparser::new(f, self.source).unparse_fstring_body(elements) } }) - }); + }) + .to_string(); // .unparse_fstring_body(elements)); UnicodeEscape::new_repr(body.as_str().as_ref()) .str_repr() @@ -643,14 +644,3 @@ impl fmt::Display for UnparseExpr<'_> { Unparser::new(f, self.source).unparse_expr(self.expr, precedence::TEST) } } - -fn to_string_fmt(f: impl FnOnce(&mut fmt::Formatter<'_>) -> fmt::Result) -> String { - use core::cell::Cell; - struct Fmt(Cell>); - impl) -> fmt::Result> fmt::Display for Fmt { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - self.0.take().unwrap()(f) - } - } - Fmt(Cell::new(Some(f))).to_string() -} diff --git a/crates/compiler-core/src/bytecode/instruction.rs b/crates/compiler-core/src/bytecode/instruction.rs index dc03a0e6785..602106767bc 100644 --- a/crates/compiler-core/src/bytecode/instruction.rs +++ b/crates/compiler-core/src/bytecode/instruction.rs @@ -1179,18 +1179,12 @@ pub trait InstructionMetadata { level: usize, ) -> fmt::Result; - fn display<'a>( - &'a self, + fn display( + &self, arg: OpArg, - ctx: &'a impl InstrDisplayContext, - ) -> impl fmt::Display + 'a { - struct FmtFn(F); - impl) -> fmt::Result> fmt::Display for FmtFn { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - (self.0)(f) - } - } - FmtFn(move |f: &mut fmt::Formatter<'_>| self.fmt_dis(arg, f, ctx, false, 0, 0)) + ctx: &impl InstrDisplayContext, + ) -> impl fmt::Display { + fmt::from_fn(move |f| self.fmt_dis(arg, f, ctx, false, 0, 0)) } } From 41084baa90693fce7163c1bf0eb72e212cf431c2 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 23 Jan 2026 18:55:27 +0000 Subject: [PATCH 2/4] Auto-format: cargo fmt --all --- crates/compiler-core/src/bytecode/instruction.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/crates/compiler-core/src/bytecode/instruction.rs b/crates/compiler-core/src/bytecode/instruction.rs index 602106767bc..31c1ef3217b 100644 --- a/crates/compiler-core/src/bytecode/instruction.rs +++ b/crates/compiler-core/src/bytecode/instruction.rs @@ -1179,11 +1179,7 @@ pub trait InstructionMetadata { level: usize, ) -> fmt::Result; - fn display( - &self, - arg: OpArg, - ctx: &impl InstrDisplayContext, - ) -> impl fmt::Display { + fn display(&self, arg: OpArg, ctx: &impl InstrDisplayContext) -> impl fmt::Display { fmt::from_fn(move |f| self.fmt_dis(arg, f, ctx, false, 0, 0)) } } From 7ef73ca6f7330c94c970ff794e7a0be11a9e1e89 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 23 Jan 2026 18:55:28 +0000 Subject: [PATCH 3/4] Auto-format: ruff format --- scripts/update_lib/deps.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/update_lib/deps.py b/scripts/update_lib/deps.py index 6f59403b563..791f9d3aa23 100644 --- a/scripts/update_lib/deps.py +++ b/scripts/update_lib/deps.py @@ -101,6 +101,7 @@ def clear_import_graph_caches() -> None: }, } + def resolve_hard_dep_parent(name: str) -> str | None: """Resolve a hard_dep name to its parent module. From 5e5e4b5877f61738b31322ad563477eb6c28b498 Mon Sep 17 00:00:00 2001 From: Noa Date: Fri, 23 Jan 2026 13:00:40 -0600 Subject: [PATCH 4/4] Bump rust-version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index c326b41d62c..cab6d563cf0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -123,7 +123,7 @@ exclude = ["pymath"] version = "0.4.0" authors = ["RustPython Team"] edition = "2024" -rust-version = "1.91.0" +rust-version = "1.93.0" repository = "https://github.com/RustPython/RustPython" license = "MIT"