@@ -32,7 +32,7 @@ struct Unparser<'a, 'b, 'c> {
32
32
33
33
impl < ' a , ' b , ' c > Unparser < ' a , ' b , ' c > {
34
34
const fn new ( f : & ' b mut fmt:: Formatter < ' a > , source : & ' c SourceFile ) -> Self {
35
- Unparser { f, source }
35
+ Self { f, source }
36
36
}
37
37
38
38
fn p ( & mut self , s : & str ) -> fmt:: Result {
@@ -169,7 +169,7 @@ impl<'a, 'b, 'c> Unparser<'a, 'b, 'c> {
169
169
} else {
170
170
self . p( "lambda" ) ?;
171
171
}
172
- write!( self , ": {}" , unparse_expr ( body, self . source) ) ?;
172
+ write!( self , ": {}" , UnparseExpr :: new ( body, self . source) ) ?;
173
173
} )
174
174
}
175
175
Expr :: If ( ruff:: ExprIf {
@@ -195,7 +195,7 @@ impl<'a, 'b, 'c> Unparser<'a, 'b, 'c> {
195
195
for item in items {
196
196
self . p_delim ( & mut first, ", " ) ?;
197
197
if let Some ( k) = & item. key {
198
- write ! ( self , "{}: " , unparse_expr ( k, self . source) ) ?;
198
+ write ! ( self , "{}: " , UnparseExpr :: new ( k, self . source) ) ?;
199
199
} else {
200
200
self . p ( "**" ) ?;
201
201
}
@@ -273,7 +273,7 @@ impl<'a, 'b, 'c> Unparser<'a, 'b, 'c> {
273
273
range : _range,
274
274
} ) => {
275
275
if let Some ( value) = value {
276
- write ! ( self , "(yield {})" , unparse_expr ( value, self . source) ) ?;
276
+ write ! ( self , "(yield {})" , UnparseExpr :: new ( value, self . source) ) ?;
277
277
} else {
278
278
self . p ( "(yield)" ) ?;
279
279
}
@@ -282,7 +282,11 @@ impl<'a, 'b, 'c> Unparser<'a, 'b, 'c> {
282
282
value,
283
283
range : _range,
284
284
} ) => {
285
- write ! ( self , "(yield from {})" , unparse_expr( value, self . source) ) ?;
285
+ write ! (
286
+ self ,
287
+ "(yield from {})" ,
288
+ UnparseExpr :: new( value, self . source)
289
+ ) ?;
286
290
}
287
291
Expr :: Compare ( ruff:: ExprCompare {
288
292
left,
@@ -478,15 +482,15 @@ impl<'a, 'b, 'c> Unparser<'a, 'b, 'c> {
478
482
fn unparse_function_arg ( & mut self , arg : & ParameterWithDefault ) -> fmt:: Result {
479
483
self . unparse_arg ( & arg. parameter ) ?;
480
484
if let Some ( default) = & arg. default {
481
- write ! ( self , "={}" , unparse_expr ( default , self . source) ) ?;
485
+ write ! ( self , "={}" , UnparseExpr :: new ( default , self . source) ) ?;
482
486
}
483
487
Ok ( ( ) )
484
488
}
485
489
486
490
fn unparse_arg ( & mut self , arg : & Parameter ) -> fmt:: Result {
487
491
self . p_id ( & arg. name ) ?;
488
492
if let Some ( ann) = & arg. annotation {
489
- write ! ( self , ": {}" , unparse_expr ( ann, self . source) ) ?;
493
+ write ! ( self , ": {}" , UnparseExpr :: new ( ann, self . source) ) ?;
490
494
}
491
495
Ok ( ( ) )
492
496
}
@@ -605,8 +609,10 @@ pub struct UnparseExpr<'a> {
605
609
source : & ' a SourceFile ,
606
610
}
607
611
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
+ }
610
616
}
611
617
612
618
impl fmt:: Display for UnparseExpr < ' _ > {
0 commit comments