@@ -7,9 +7,8 @@ extern crate rustc;
7
7
use std:: borrow:: ToOwned ;
8
8
use std:: rc:: Rc ;
9
9
use syntax:: ast:: {
10
- BinOp_ , BiAdd , BiSub , BiMul , Delimited ,
11
- Expr , ExprAssign , ExprAssignOp , ExprBinary , ExprUnary ,
12
- LitInt , UnsuffixedIntLit , Sign , UnNeg , UnNot ,
10
+ BinOp_ , BiAdd , BiSub , BiMul , BiDiv , BiRem , BiShl , BiShr , UnNeg ,
11
+ Delimited , Expr , ExprAssign , ExprAssignOp , ExprBinary , ExprUnary ,
13
12
Ident , Mac , TokenTree , TtDelimited
14
13
} ;
15
14
use syntax:: codemap:: { DUMMY_SP , Span } ;
@@ -35,14 +34,9 @@ impl<'cx> Folder for WrappingFolder<'cx> {
35
34
ExprUnary ( UnNeg , inner) => {
36
35
// Recurse in sub-expressions
37
36
let inner = self . fold_expr ( inner) ;
38
- // Rewrite `-a` to `a.wrapping_mul(!0)`
39
- // This is equivalent to `a.wrapping_mul(-1)`, except it
40
- // works on unsigned types as well
41
- let method = token:: str_to_ident ( "wrapping_mul" ) ;
42
- let zero = self . cx . expr_lit (
43
- DUMMY_SP , LitInt ( 0 , UnsuffixedIntLit ( Sign :: Plus ) ) ) ;
44
- let neg_one = self . cx . expr_unary ( DUMMY_SP , UnNot , zero) ;
45
- self . cx . expr_method_call ( expr. span , inner, method, vec ! [ neg_one] )
37
+ // Rewrite `-a` to `a.wrapping_neg()`
38
+ let method = token:: str_to_ident ( "wrapping_neg" ) ;
39
+ self . cx . expr_method_call ( expr. span , inner, method, vec ! [ ] )
46
40
. and_then ( |e| e)
47
41
}
48
42
ExprBinary ( op, left, right) => {
@@ -87,6 +81,10 @@ fn wrapping_method(op: BinOp_) -> Option<Ident> {
87
81
BiAdd => "wrapping_add" ,
88
82
BiSub => "wrapping_sub" ,
89
83
BiMul => "wrapping_mul" ,
84
+ BiDiv => "wrapping_div" ,
85
+ BiRem => "wrapping_rem" ,
86
+ BiShl => "wrapping_shl" ,
87
+ BiShr => "wrapping_shr" ,
90
88
_ => return None ,
91
89
} ) )
92
90
}
0 commit comments