@@ -12,35 +12,36 @@ use super::BorrowKind;
1212pub fn function_name ( item : CrateItem ) -> String {
1313 let mut pretty_name = String :: new ( ) ;
1414 let body = item. body ( ) ;
15- pretty_name. push_str ( "fn " ) ;
16- pretty_name. push_str ( item. name ( ) . as_str ( ) ) ;
15+ pretty_name. push_str ( format ! ( "fn {}" , item. name( ) ) . as_str ( ) ) ;
1716 if body. arg_locals ( ) . is_empty ( ) {
1817 pretty_name. push_str ( "()" ) ;
1918 } else {
2019 pretty_name. push_str ( "(" ) ;
2120 }
2221 body. arg_locals ( ) . iter ( ) . enumerate ( ) . for_each ( |( index, local) | {
23- pretty_name. push_str ( format ! ( "_{}: " , index) . as_str ( ) ) ;
24- pretty_name. push_str ( & pretty_ty ( local. ty . kind ( ) ) ) ;
22+ pretty_name. push_str ( format ! ( "_{}: {}" , index, pretty_ty( local. ty. kind( ) ) ) . as_str ( ) ) ;
2523 } ) ;
2624 if !body. arg_locals ( ) . is_empty ( ) {
2725 pretty_name. push_str ( ")" ) ;
2826 }
2927 let return_local = body. ret_local ( ) ;
30- pretty_name. push_str ( " -> " ) ;
31- pretty_name. push_str ( & pretty_ty ( return_local. ty . kind ( ) ) ) ;
32- pretty_name. push_str ( " {" ) ;
28+ pretty_name. push_str ( format ! ( " -> {} {{" , pretty_ty( return_local. ty. kind( ) ) ) . as_str ( ) ) ;
3329 pretty_name
3430}
3531
3632pub fn function_body ( body : & Body ) -> String {
3733 let mut pretty_body = String :: new ( ) ;
3834 body. inner_locals ( ) . iter ( ) . enumerate ( ) . for_each ( |( index, local) | {
3935 pretty_body. push_str ( " " ) ;
40- pretty_body. push_str ( format ! ( "let {}" , ret_mutability( & local. mutability) ) . as_str ( ) ) ;
41- pretty_body. push_str ( format ! ( "_{}: " , index) . as_str ( ) ) ;
42- pretty_body. push_str ( format ! ( "{}" , pretty_ty( local. ty. kind( ) ) ) . as_str ( ) ) ;
43- pretty_body. push_str ( ";\n " ) ;
36+ pretty_body. push_str (
37+ format ! (
38+ "let {}_{}: {};\n " ,
39+ ret_mutability( & local. mutability) ,
40+ index,
41+ pretty_ty( local. ty. kind( ) )
42+ )
43+ . as_str ( ) ,
44+ ) ;
4445 } ) ;
4546 pretty_body
4647}
@@ -56,8 +57,7 @@ pub fn pretty_statement(statement: &StatementKind) -> String {
5657 let mut pretty = String :: new ( ) ;
5758 match statement {
5859 StatementKind :: Assign ( place, rval) => {
59- pretty. push_str ( format ! ( " _{} = " , place. local) . as_str ( ) ) ;
60- pretty. push_str ( format ! ( "{}" , & pretty_rvalue( rval) ) . as_str ( ) ) ;
60+ pretty. push_str ( format ! ( " _{} = {}" , place. local, pretty_rvalue( rval) ) . as_str ( ) ) ;
6161 }
6262 StatementKind :: FakeRead ( _, _) => todo ! ( ) ,
6363 StatementKind :: SetDiscriminant { .. } => todo ! ( ) ,
@@ -99,7 +99,7 @@ pub fn pretty_terminator<W: io::Write>(terminator: &TerminatorKind, w: &mut W) -
9999 Ok ( ( ) )
100100 }
101101 ( 1 , false ) => {
102- write ! ( w, " -> {:?}" , terminator. successors( ) . next( ) . unwrap( ) ) ?;
102+ write ! ( w, " -> bb {:?}" , terminator. successors( ) . next( ) . unwrap( ) ) ?;
103103 Ok ( ( ) )
104104 }
105105 _ => {
@@ -136,9 +136,7 @@ pub fn pretty_terminator_head(terminator: &TerminatorKind) -> String {
136136 Drop { place, .. } => format ! ( " drop(_{:?})" , place. local) ,
137137 Call { func, args, destination, .. } => {
138138 pretty. push_str ( " " ) ;
139- pretty. push_str ( format ! ( "_{} = " , destination. local) . as_str ( ) ) ;
140- pretty. push_str ( & pretty_operand ( func) ) ;
141- pretty. push_str ( "(" ) ;
139+ pretty. push_str ( format ! ( "_{} = {}(" , destination. local, pretty_operand( func) ) . as_str ( ) ) ;
142140 args. iter ( ) . enumerate ( ) . for_each ( |( i, arg) | {
143141 if i > 0 {
144142 pretty. push_str ( ", " ) ;
@@ -153,9 +151,9 @@ pub fn pretty_terminator_head(terminator: &TerminatorKind) -> String {
153151 if !expected {
154152 pretty. push_str ( "!" ) ;
155153 }
156- pretty. push_str ( format ! ( "{} bool)," , & pretty_operand ( cond ) ) . as_str ( ) ) ;
157- pretty . push_str ( & pretty_assert_message ( msg) ) ;
158- pretty . push_str ( ")" ) ;
154+ pretty. push_str (
155+ format ! ( "{} bool),{})" , & pretty_operand ( cond ) , pretty_assert_message( msg) ) . as_str ( ) ,
156+ ) ;
159157 pretty
160158 }
161159 CoroutineDrop => format ! ( " coroutine_drop" ) ,
@@ -282,16 +280,14 @@ pub fn pretty_operand(operand: &Operand) -> String {
282280 let mut pretty = String :: new ( ) ;
283281 match operand {
284282 Operand :: Copy ( copy) => {
285- pretty. push_str ( "" ) ;
286- pretty. push_str ( format ! ( "{}" , copy. local) . as_str ( ) ) ;
283+ pretty. push_str ( format ! ( "_{}" , copy. local) . as_str ( ) ) ;
287284 }
288285 Operand :: Move ( mv) => {
289- pretty. push_str ( "move " ) ;
290- pretty. push_str ( format ! ( "_{}" , mv. local) . as_str ( ) ) ;
286+ pretty. push_str ( format ! ( "move _{}" , mv. local) . as_str ( ) ) ;
291287 }
292288 Operand :: Constant ( cnst) => {
293- pretty. push_str ( "const " ) ;
294- pretty . push_str ( with ( |cx| cx. const_literal ( & cnst. literal ) ) . as_str ( ) ) ;
289+ pretty
290+ . push_str ( format ! ( "const {}" , with( |cx| cx. const_literal( & cnst. literal) ) ) . as_str ( ) ) ;
295291 }
296292 }
297293 pretty
@@ -301,14 +297,11 @@ pub fn pretty_rvalue(rval: &Rvalue) -> String {
301297 let mut pretty = String :: new ( ) ;
302298 match rval {
303299 Rvalue :: AddressOf ( muta, addr) => {
304- pretty. push_str ( "&raw " ) ;
305- pretty. push_str ( & ret_mutability ( muta) ) ;
306- pretty. push_str ( format ! ( "(*_{})" , addr. local) . as_str ( ) ) ;
300+ pretty. push_str ( format ! ( "&raw {}(*_{})" , & ret_mutability( muta) , addr. local) . as_str ( ) ) ;
307301 }
308302 Rvalue :: Aggregate ( aggregatekind, operands) => {
309303 // FIXME: Add pretty_aggregate function that returns a pretty string
310- pretty. push_str ( format ! ( "{:#?}" , aggregatekind) . as_str ( ) ) ;
311- pretty. push_str ( "(" ) ;
304+ pretty. push_str ( format ! ( "{:#?} (" , aggregatekind) . as_str ( ) ) ;
312305 operands. iter ( ) . enumerate ( ) . for_each ( |( i, op) | {
313306 pretty. push_str ( & pretty_operand ( op) ) ;
314307 if i != operands. len ( ) - 1 {
@@ -318,37 +311,27 @@ pub fn pretty_rvalue(rval: &Rvalue) -> String {
318311 pretty. push_str ( ")" ) ;
319312 }
320313 Rvalue :: BinaryOp ( bin, op1, op2) => {
321- pretty. push_str ( format ! ( "{:#?}" , bin) . as_str ( ) ) ;
322- pretty. push_str ( "(" ) ;
323- pretty. push_str ( format ! ( "_{}" , & pretty_operand( op1) ) . as_str ( ) ) ;
324- pretty. push_str ( ", " ) ;
325- pretty. push_str ( format ! ( "{}" , & pretty_operand( op2) ) . as_str ( ) ) ;
326- pretty. push_str ( ")" ) ;
314+ pretty. push_str (
315+ format ! ( "{:#?}({}, {})" , bin, & pretty_operand( op1) , pretty_operand( op2) ) . as_str ( ) ,
316+ ) ;
327317 }
328318 Rvalue :: Cast ( _, op, ty) => {
329- pretty. push_str ( & pretty_operand ( op) ) ;
330- pretty. push_str ( " as " ) ;
331- pretty. push_str ( & pretty_ty ( ty. kind ( ) ) ) ;
319+ pretty. push_str ( format ! ( "{} as {}" , pretty_operand( op) , pretty_ty( ty. kind( ) ) ) . as_str ( ) ) ;
332320 }
333321 Rvalue :: CheckedBinaryOp ( bin, op1, op2) => {
334- pretty. push_str ( format ! ( "Checked{:#?}" , bin) . as_str ( ) ) ;
335- pretty. push_str ( "(" ) ;
336- pretty. push_str ( format ! ( "_{}" , & pretty_operand( op1) ) . as_str ( ) ) ;
337- pretty. push_str ( ", " ) ;
338- pretty. push_str ( format ! ( "{}" , & pretty_operand( op2) ) . as_str ( ) ) ;
339- pretty. push_str ( ")" ) ;
322+ pretty. push_str (
323+ format ! ( "Checked{:#?}({}, {})" , bin, & pretty_operand( op1) , pretty_operand( op2) )
324+ . as_str ( ) ,
325+ ) ;
340326 }
341327 Rvalue :: CopyForDeref ( deref) => {
342- pretty. push_str ( "CopyForDeref" ) ;
343- pretty. push_str ( format ! ( "{}" , deref. local) . as_str ( ) ) ;
328+ pretty. push_str ( format ! ( "CopyForDeref{}" , deref. local) . as_str ( ) ) ;
344329 }
345330 Rvalue :: Discriminant ( place) => {
346- pretty. push_str ( "discriminant" ) ;
347- pretty. push_str ( format ! ( "{}" , place. local) . as_str ( ) ) ;
331+ pretty. push_str ( format ! ( "discriminant{}" , place. local) . as_str ( ) ) ;
348332 }
349333 Rvalue :: Len ( len) => {
350- pretty. push_str ( "len" ) ;
351- pretty. push_str ( format ! ( "{}" , len. local) . as_str ( ) ) ;
334+ pretty. push_str ( format ! ( "len{}" , len. local) . as_str ( ) ) ;
352335 }
353336 Rvalue :: Ref ( _, borrowkind, place) => {
354337 match borrowkind {
@@ -359,24 +342,19 @@ pub fn pretty_rvalue(rval: &Rvalue) -> String {
359342 pretty. push_str ( format ! ( "{}" , place. local) . as_str ( ) ) ;
360343 }
361344 Rvalue :: Repeat ( op, cnst) => {
362- pretty. push_str ( & pretty_operand ( op ) ) ;
363- pretty . push_str ( " " ) ;
364- pretty . push_str ( & pretty_ty ( cnst . ty ( ) . kind ( ) ) ) ;
345+ pretty. push_str (
346+ & format ! ( "{} \" \" {}" , & pretty_operand ( op ) , pretty_ty ( cnst . ty ( ) . kind ( ) ) ) . as_str ( ) ,
347+ ) ;
365348 }
366349 Rvalue :: ShallowInitBox ( _, _) => todo ! ( ) ,
367350 Rvalue :: ThreadLocalRef ( item) => {
368- pretty. push_str ( "thread_local_ref" ) ;
369- pretty. push_str ( format ! ( "{:#?}" , item) . as_str ( ) ) ;
351+ pretty. push_str ( format ! ( "thread_local_ref{:#?}" , item) . as_str ( ) ) ;
370352 }
371353 Rvalue :: NullaryOp ( nul, ty) => {
372- pretty. push_str ( format ! ( "{:#?}" , nul) . as_str ( ) ) ;
373- pretty. push_str ( & pretty_ty ( ty. kind ( ) ) ) ;
374- pretty. push_str ( " " ) ;
354+ pretty. push_str ( format ! ( "{:#?} {} \" \" " , nul, pretty_ty( ty. kind( ) ) ) . as_str ( ) ) ;
375355 }
376356 Rvalue :: UnaryOp ( un, op) => {
377- pretty. push_str ( & pretty_operand ( op) ) ;
378- pretty. push_str ( " " ) ;
379- pretty. push_str ( format ! ( "{:#?}" , un) . as_str ( ) ) ;
357+ pretty. push_str ( format ! ( "{} \" \" {:#?}" , pretty_operand( op) , un) . as_str ( ) ) ;
380358 }
381359 Rvalue :: Use ( op) => pretty. push_str ( & pretty_operand ( op) ) ,
382360 }
@@ -443,8 +421,7 @@ pub fn pretty_ty(ty: TyKind) -> String {
443421 DynKind :: Dyn => pretty. push_str ( "dyn " ) ,
444422 DynKind :: DynStar => pretty. push_str ( "dyn* " ) ,
445423 }
446- pretty. push_str ( format ! ( "{:#?}" , data) . as_str ( ) ) ;
447- pretty. push_str ( format ! ( " + {:#?} )" , region) . as_str ( ) ) ;
424+ pretty. push_str ( format ! ( "{:#?} + {:#?}" , data, region) . as_str ( ) ) ;
448425 pretty
449426 }
450427 RigidTy :: Never => "!" . to_string ( ) ,
0 commit comments