@@ -981,6 +981,75 @@ impl BinOpKind {
981
981
982
982
pub type BinOp = Spanned < BinOpKind > ;
983
983
984
+ // Sometimes `BinOpKind` and `AssignOpKind` need the same treatment. The
985
+ // operations covered by `AssignOpKind` are a subset of those covered by
986
+ // `BinOpKind`, so it makes sense to convert `AssignOpKind` to `BinOpKind`.
987
+ impl From < AssignOpKind > for BinOpKind {
988
+ fn from ( op : AssignOpKind ) -> BinOpKind {
989
+ match op {
990
+ AssignOpKind :: AddAssign => BinOpKind :: Add ,
991
+ AssignOpKind :: SubAssign => BinOpKind :: Sub ,
992
+ AssignOpKind :: MulAssign => BinOpKind :: Mul ,
993
+ AssignOpKind :: DivAssign => BinOpKind :: Div ,
994
+ AssignOpKind :: RemAssign => BinOpKind :: Rem ,
995
+ AssignOpKind :: BitXorAssign => BinOpKind :: BitXor ,
996
+ AssignOpKind :: BitAndAssign => BinOpKind :: BitAnd ,
997
+ AssignOpKind :: BitOrAssign => BinOpKind :: BitOr ,
998
+ AssignOpKind :: ShlAssign => BinOpKind :: Shl ,
999
+ AssignOpKind :: ShrAssign => BinOpKind :: Shr ,
1000
+ }
1001
+ }
1002
+ }
1003
+
1004
+ #[ derive( Clone , Copy , Debug , PartialEq , Encodable , Decodable , HashStable_Generic ) ]
1005
+ pub enum AssignOpKind {
1006
+ /// The `+=` operator (addition)
1007
+ AddAssign ,
1008
+ /// The `-=` operator (subtraction)
1009
+ SubAssign ,
1010
+ /// The `*=` operator (multiplication)
1011
+ MulAssign ,
1012
+ /// The `/=` operator (division)
1013
+ DivAssign ,
1014
+ /// The `%=` operator (modulus)
1015
+ RemAssign ,
1016
+ /// The `^=` operator (bitwise xor)
1017
+ BitXorAssign ,
1018
+ /// The `&=` operator (bitwise and)
1019
+ BitAndAssign ,
1020
+ /// The `|=` operator (bitwise or)
1021
+ BitOrAssign ,
1022
+ /// The `<<=` operator (shift left)
1023
+ ShlAssign ,
1024
+ /// The `>>=` operator (shift right)
1025
+ ShrAssign ,
1026
+ }
1027
+
1028
+ impl AssignOpKind {
1029
+ pub fn as_str ( & self ) -> & ' static str {
1030
+ use AssignOpKind :: * ;
1031
+ match self {
1032
+ AddAssign => "+=" ,
1033
+ SubAssign => "-=" ,
1034
+ MulAssign => "*=" ,
1035
+ DivAssign => "/=" ,
1036
+ RemAssign => "%=" ,
1037
+ BitXorAssign => "^=" ,
1038
+ BitAndAssign => "&=" ,
1039
+ BitOrAssign => "|=" ,
1040
+ ShlAssign => "<<=" ,
1041
+ ShrAssign => ">>=" ,
1042
+ }
1043
+ }
1044
+
1045
+ /// AssignOps are always by value.
1046
+ pub fn is_by_value ( self ) -> bool {
1047
+ true
1048
+ }
1049
+ }
1050
+
1051
+ pub type AssignOp = Spanned < AssignOpKind > ;
1052
+
984
1053
/// Unary operator.
985
1054
///
986
1055
/// Note that `&data` is not an operator, it's an `AddrOf` expression.
@@ -1593,7 +1662,7 @@ pub enum ExprKind {
1593
1662
/// An assignment with an operator.
1594
1663
///
1595
1664
/// E.g., `a += 1`.
1596
- AssignOp ( BinOp , P < Expr > , P < Expr > ) ,
1665
+ AssignOp ( AssignOp , P < Expr > , P < Expr > ) ,
1597
1666
/// Access of a named (e.g., `obj.foo`) or unnamed (e.g., `obj.0`) struct field.
1598
1667
Field ( P < Expr > , Ident ) ,
1599
1668
/// An indexing operation (e.g., `foo[2]`).
0 commit comments