Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 82fc735

Browse files
committed
fn unparse_expr -> UnparseExpr::new
1 parent fa91df6 commit 82fc735

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

compiler/codegen/src/compile.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{
1414
error::{CodegenError, CodegenErrorType, InternalError, PatternUnreachableReason},
1515
ir::{self, BlockIdx},
1616
symboltable::{self, CompilerScope, SymbolFlags, SymbolScope, SymbolTable},
17-
unparse::unparse_expr,
17+
unparse::UnparseExpr,
1818
};
1919
use itertools::Itertools;
2020
use malachite_bigint::BigInt;
@@ -3592,7 +3592,7 @@ impl Compiler {
35923592
| Expr::NoneLiteral(_)
35933593
);
35943594
let key_repr = if is_literal {
3595-
unparse_expr(key, &self.source_file).to_string()
3595+
UnparseExpr::new(key, &self.source_file).to_string()
35963596
} else if is_attribute {
35973597
String::new()
35983598
} else {
@@ -4146,7 +4146,7 @@ impl Compiler {
41464146
fn compile_annotation(&mut self, annotation: &Expr) -> CompileResult<()> {
41474147
if self.future_annotations {
41484148
self.emit_load_const(ConstantData::Str {
4149-
value: unparse_expr(annotation, &self.source_file)
4149+
value: UnparseExpr::new(annotation, &self.source_file)
41504150
.to_string()
41514151
.into(),
41524152
});

compiler/codegen/src/unparse.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct Unparser<'a, 'b, 'c> {
3232

3333
impl<'a, 'b, 'c> Unparser<'a, 'b, 'c> {
3434
const fn new(f: &'b mut fmt::Formatter<'a>, source: &'c SourceFile) -> Self {
35-
Unparser { f, source }
35+
Self { f, source }
3636
}
3737

3838
fn p(&mut self, s: &str) -> fmt::Result {
@@ -169,7 +169,7 @@ impl<'a, 'b, 'c> Unparser<'a, 'b, 'c> {
169169
} else {
170170
self.p("lambda")?;
171171
}
172-
write!(self, ": {}", unparse_expr(body, self.source))?;
172+
write!(self, ": {}", UnparseExpr::new(body, self.source))?;
173173
})
174174
}
175175
Expr::If(ruff::ExprIf {
@@ -195,7 +195,7 @@ impl<'a, 'b, 'c> Unparser<'a, 'b, 'c> {
195195
for item in items {
196196
self.p_delim(&mut first, ", ")?;
197197
if let Some(k) = &item.key {
198-
write!(self, "{}: ", unparse_expr(k, self.source))?;
198+
write!(self, "{}: ", UnparseExpr::new(k, self.source))?;
199199
} else {
200200
self.p("**")?;
201201
}
@@ -273,7 +273,7 @@ impl<'a, 'b, 'c> Unparser<'a, 'b, 'c> {
273273
range: _range,
274274
}) => {
275275
if let Some(value) = value {
276-
write!(self, "(yield {})", unparse_expr(value, self.source))?;
276+
write!(self, "(yield {})", UnparseExpr::new(value, self.source))?;
277277
} else {
278278
self.p("(yield)")?;
279279
}
@@ -282,7 +282,11 @@ impl<'a, 'b, 'c> Unparser<'a, 'b, 'c> {
282282
value,
283283
range: _range,
284284
}) => {
285-
write!(self, "(yield from {})", unparse_expr(value, self.source))?;
285+
write!(
286+
self,
287+
"(yield from {})",
288+
UnparseExpr::new(value, self.source)
289+
)?;
286290
}
287291
Expr::Compare(ruff::ExprCompare {
288292
left,
@@ -478,15 +482,15 @@ impl<'a, 'b, 'c> Unparser<'a, 'b, 'c> {
478482
fn unparse_function_arg(&mut self, arg: &ParameterWithDefault) -> fmt::Result {
479483
self.unparse_arg(&arg.parameter)?;
480484
if let Some(default) = &arg.default {
481-
write!(self, "={}", unparse_expr(default, self.source))?;
485+
write!(self, "={}", UnparseExpr::new(default, self.source))?;
482486
}
483487
Ok(())
484488
}
485489

486490
fn unparse_arg(&mut self, arg: &Parameter) -> fmt::Result {
487491
self.p_id(&arg.name)?;
488492
if let Some(ann) = &arg.annotation {
489-
write!(self, ": {}", unparse_expr(ann, self.source))?;
493+
write!(self, ": {}", UnparseExpr::new(ann, self.source))?;
490494
}
491495
Ok(())
492496
}
@@ -605,8 +609,10 @@ pub struct UnparseExpr<'a> {
605609
source: &'a SourceFile,
606610
}
607611

608-
pub const fn unparse_expr<'a>(expr: &'a Expr, source: &'a SourceFile) -> UnparseExpr<'a> {
609-
UnparseExpr { expr, source }
612+
impl<'a> UnparseExpr<'a> {
613+
pub const fn new(expr: &'a Expr, source: &'a SourceFile) -> Self {
614+
Self { expr, source }
615+
}
610616
}
611617

612618
impl fmt::Display for UnparseExpr<'_> {

0 commit comments

Comments
 (0)