@@ -3,6 +3,8 @@ use crate::mir::{Operand, Rvalue, StatementKind};
3
3
use crate :: ty:: { DynKind , FloatTy , IntTy , RigidTy , TyKind , UintTy } ;
4
4
use crate :: { with, Body , CrateItem , Mutability } ;
5
5
6
+ use super :: BorrowKind ;
7
+
6
8
pub fn function_name ( item : CrateItem ) -> String {
7
9
let mut pretty_name = String :: new ( ) ;
8
10
let body = item. body ( ) ;
@@ -36,7 +38,6 @@ pub fn function_body(body: &Body) -> String {
36
38
pretty_body. push_str ( format ! ( "{}" , pretty_ty( local. ty. kind( ) ) ) . as_str ( ) ) ;
37
39
pretty_body. push_str ( ";\n " ) ;
38
40
} ) ;
39
- pretty_body. push_str ( "}" ) ;
40
41
pretty_body
41
42
}
42
43
@@ -98,6 +99,7 @@ pub fn pretty_rvalue(rval: &Rvalue) -> String {
98
99
pretty. push_str ( format ! ( "(*_{})" , addr. local) . as_str ( ) ) ;
99
100
}
100
101
Rvalue :: Aggregate ( aggregatekind, operands) => {
102
+ // FIXME: Add pretty_aggregate function that returns a pretty string
101
103
pretty. push_str ( format ! ( "{:#?}" , aggregatekind) . as_str ( ) ) ;
102
104
pretty. push_str ( "(" ) ;
103
105
operands. iter ( ) . enumerate ( ) . for_each ( |( i, op) | {
@@ -108,24 +110,26 @@ pub fn pretty_rvalue(rval: &Rvalue) -> String {
108
110
} ) ;
109
111
pretty. push_str ( ")" ) ;
110
112
}
111
- Rvalue :: BinaryOp ( bin, op, op2) => {
112
- pretty. push_str ( & pretty_operand ( op) ) ;
113
- pretty. push_str ( " " ) ;
113
+ Rvalue :: BinaryOp ( bin, op1, op2) => {
114
114
pretty. push_str ( format ! ( "{:#?}" , bin) . as_str ( ) ) ;
115
- pretty. push_str ( " " ) ;
116
- pretty. push_str ( & pretty_operand ( op2) ) ;
115
+ pretty. push_str ( "(" ) ;
116
+ pretty. push_str ( format ! ( "_{}" , & pretty_operand( op1) ) . as_str ( ) ) ;
117
+ pretty. push_str ( ", " ) ;
118
+ pretty. push_str ( format ! ( "{}" , & pretty_operand( op2) ) . as_str ( ) ) ;
119
+ pretty. push_str ( ")" ) ;
117
120
}
118
121
Rvalue :: Cast ( _, op, ty) => {
119
122
pretty. push_str ( & pretty_operand ( op) ) ;
120
123
pretty. push_str ( " as " ) ;
121
124
pretty. push_str ( & pretty_ty ( ty. kind ( ) ) ) ;
122
125
}
123
126
Rvalue :: CheckedBinaryOp ( bin, op1, op2) => {
124
- pretty. push_str ( & pretty_operand ( op1) ) ;
125
- pretty. push_str ( " " ) ;
126
- pretty. push_str ( format ! ( "{:#?}" , bin) . as_str ( ) ) ;
127
- pretty. push_str ( " " ) ;
128
- pretty. push_str ( & pretty_operand ( op2) ) ;
127
+ pretty. push_str ( format ! ( "Checked{:#?}" , bin) . as_str ( ) ) ;
128
+ pretty. push_str ( "(" ) ;
129
+ pretty. push_str ( format ! ( "_{}" , & pretty_operand( op1) ) . as_str ( ) ) ;
130
+ pretty. push_str ( ", " ) ;
131
+ pretty. push_str ( format ! ( "{}" , & pretty_operand( op2) ) . as_str ( ) ) ;
132
+ pretty. push_str ( ")" ) ;
129
133
}
130
134
Rvalue :: CopyForDeref ( deref) => {
131
135
pretty. push_str ( "CopyForDeref" ) ;
@@ -140,8 +144,11 @@ pub fn pretty_rvalue(rval: &Rvalue) -> String {
140
144
pretty. push_str ( format ! ( "{}" , len. local) . as_str ( ) ) ;
141
145
}
142
146
Rvalue :: Ref ( _, borrowkind, place) => {
143
- pretty. push_str ( "ref" ) ;
144
- pretty. push_str ( format ! ( "{:#?}" , borrowkind) . as_str ( ) ) ;
147
+ match borrowkind {
148
+ BorrowKind :: Shared => pretty. push_str ( "&" ) ,
149
+ BorrowKind :: Fake => pretty. push_str ( "&fake " ) ,
150
+ BorrowKind :: Mut { .. } => pretty. push_str ( "&mut " ) ,
151
+ }
145
152
pretty. push_str ( format ! ( "{}" , place. local) . as_str ( ) ) ;
146
153
}
147
154
Rvalue :: Repeat ( op, cnst) => {
@@ -196,7 +203,7 @@ pub fn pretty_ty(ty: TyKind) -> String {
196
203
FloatTy :: F64 => "f64" . to_string ( ) ,
197
204
} ,
198
205
RigidTy :: Adt ( def, _) => {
199
- format ! ( "{:#? }" , with( |cx| cx. def_ty ( def. 0 ) ) )
206
+ format ! ( "{}" , with( |cx| cx. adt_literal ( & def) ) )
200
207
}
201
208
RigidTy :: Str => "str" . to_string ( ) ,
202
209
RigidTy :: Array ( ty, len) => {
0 commit comments