Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
22 changes: 6 additions & 16 deletions crates/codegen/src/unparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))?;
Expand Down Expand Up @@ -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()
Expand All @@ -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<F>(Cell<Option<F>>);
impl<F: FnOnce(&mut fmt::Formatter<'_>) -> fmt::Result> fmt::Display for Fmt<F> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.take().unwrap()(f)
}
}
Fmt(Cell::new(Some(f))).to_string()
}
14 changes: 2 additions & 12 deletions crates/compiler-core/src/bytecode/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1179,18 +1179,8 @@ pub trait InstructionMetadata {
level: usize,
) -> fmt::Result;

fn display<'a>(
&'a self,
arg: OpArg,
ctx: &'a impl InstrDisplayContext,
) -> impl fmt::Display + 'a {
struct FmtFn<F>(F);
impl<F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result> fmt::Display for FmtFn<F> {
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))
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))
}
}

Expand Down
1 change: 1 addition & 0 deletions scripts/update_lib/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Loading