@@ -2328,6 +2328,30 @@ impl BinOp {
2328
2328
use self :: BinOp :: * ;
2329
2329
matches ! ( self , Add | Sub | Mul | Shl | Shr )
2330
2330
}
2331
+
2332
+ pub fn try_as_string ( self ) -> Option < String > {
2333
+ use self :: BinOp :: * ;
2334
+
2335
+ match self {
2336
+ Add => Some ( "+" . to_string ( ) ) ,
2337
+ Sub => Some ( "-" . to_string ( ) ) ,
2338
+ Mul => Some ( "*" . to_string ( ) ) ,
2339
+ Div => Some ( "/" . to_string ( ) ) ,
2340
+ Rem => Some ( "%" . to_string ( ) ) ,
2341
+ BitXor => Some ( "^" . to_string ( ) ) ,
2342
+ BitAnd => Some ( "&" . to_string ( ) ) ,
2343
+ BitOr => Some ( "|" . to_string ( ) ) ,
2344
+ Shl => Some ( "<<" . to_string ( ) ) ,
2345
+ Shr => Some ( ">>" . to_string ( ) ) ,
2346
+ Eq => Some ( "=" . to_string ( ) ) ,
2347
+ Lt => Some ( "<" . to_string ( ) ) ,
2348
+ Le => Some ( "<=" . to_string ( ) ) ,
2349
+ Ne => Some ( "!=" . to_string ( ) ) ,
2350
+ Ge => Some ( ">=" . to_string ( ) ) ,
2351
+ Gt => Some ( ">" . to_string ( ) ) ,
2352
+ Offset => None ,
2353
+ }
2354
+ }
2331
2355
}
2332
2356
2333
2357
#[ derive( Copy , Clone , Debug , PartialEq , Eq , TyEncodable , TyDecodable , Hash , HashStable ) ]
@@ -2348,6 +2372,15 @@ pub enum UnOp {
2348
2372
Neg ,
2349
2373
}
2350
2374
2375
+ impl fmt:: Display for UnOp {
2376
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
2377
+ match self {
2378
+ UnOp :: Not => write ! ( f, "!" ) ,
2379
+ UnOp :: Neg => write ! ( f, "-" ) ,
2380
+ }
2381
+ }
2382
+ }
2383
+
2351
2384
impl < ' tcx > Debug for Rvalue < ' tcx > {
2352
2385
fn fmt ( & self , fmt : & mut Formatter < ' _ > ) -> fmt:: Result {
2353
2386
use self :: Rvalue :: * ;
0 commit comments