@@ -32,7 +32,7 @@ struct Unparser<'a, 'b, 'c> {
3232
3333impl < ' 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
612618impl fmt:: Display for UnparseExpr < ' _ > {
0 commit comments