about summary refs log tree commit diff
path: root/src/libstd/bitflags.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-12-15 22:11:44 +0000
committerbors <bors@rust-lang.org>2014-12-15 22:11:44 +0000
commit0669a432a2e09ad08886cb2138dbe9f5d681fb7f (patch)
tree5183544df317d80a6bce406242596dd997e61b64 /src/libstd/bitflags.rs
parent92e9e70d15bcf8d29890bf93793be402ad629229 (diff)
parent89d2061c8f1cc2bcd5e9bb8a97e214f482d5ff2c (diff)
auto merge of #19448 : japaric/rust/binops-by-value, r=nikomatsakis
- The following operator traits now take their arguments by value: `Add`, `Sub`, `Mul`, `Div`, `Rem`, `BitAnd`, `BitOr`, `BitXor`, `Shl`, `Shr`. This breaks all existing implementations of these traits.

- The binary operation `a OP b` now "desugars" to `OpTrait::op_method(a, b)` and consumes both arguments.

- `String` and `Vec` addition have been changed to reuse the LHS owned value, and to avoid internal cloning. Only the following asymmetric operations are available: `String + &str` and `Vec<T> + &[T]`, which are now a short-hand for the "append" operation.

[breaking-change]

---

This passes `make check` locally. I haven't touch the unary operators in this PR, but converting them to by value should be very similar to this PR. I can work on them after this gets the thumbs up.

@nikomatsakis r? the compiler changes
@aturon r? the library changes. I think the only controversial bit is the semantic change of the `Vec`/`String` `Add` implementation.
cc #19148 
Diffstat (limited to 'src/libstd/bitflags.rs')
-rw-r--r--src/libstd/bitflags.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/libstd/bitflags.rs b/src/libstd/bitflags.rs
index 8a6d329ec46..2be6f5057a1 100644
--- a/src/libstd/bitflags.rs
+++ b/src/libstd/bitflags.rs
@@ -205,6 +205,8 @@ macro_rules! bitflags {
             }
         }
 
+        // NOTE(stage0): Remove impl after a snapshot
+        #[cfg(stage0)]
         impl BitOr<$BitFlags, $BitFlags> for $BitFlags {
             /// Returns the union of the two sets of flags.
             #[inline]
@@ -213,6 +215,17 @@ macro_rules! bitflags {
             }
         }
 
+        #[cfg(not(stage0))]  // NOTE(stage0): Remove cfg after a snapshot
+        impl BitOr<$BitFlags, $BitFlags> for $BitFlags {
+            /// Returns the union of the two sets of flags.
+            #[inline]
+            fn bitor(self, other: $BitFlags) -> $BitFlags {
+                $BitFlags { bits: self.bits | other.bits }
+            }
+        }
+
+        // NOTE(stage0): Remove impl after a snapshot
+        #[cfg(stage0)]
         impl BitXor<$BitFlags, $BitFlags> for $BitFlags {
             /// Returns the left flags, but with all the right flags toggled.
             #[inline]
@@ -221,6 +234,17 @@ macro_rules! bitflags {
             }
         }
 
+        #[cfg(not(stage0))]  // NOTE(stage0): Remove cfg after a snapshot
+        impl BitXor<$BitFlags, $BitFlags> for $BitFlags {
+            /// Returns the left flags, but with all the right flags toggled.
+            #[inline]
+            fn bitxor(self, other: $BitFlags) -> $BitFlags {
+                $BitFlags { bits: self.bits ^ other.bits }
+            }
+        }
+
+        // NOTE(stage0): Remove impl after a snapshot
+        #[cfg(stage0)]
         impl BitAnd<$BitFlags, $BitFlags> for $BitFlags {
             /// Returns the intersection between the two sets of flags.
             #[inline]
@@ -229,6 +253,17 @@ macro_rules! bitflags {
             }
         }
 
+        #[cfg(not(stage0))]  // NOTE(stage0): Remove cfg after a snapshot
+        impl BitAnd<$BitFlags, $BitFlags> for $BitFlags {
+            /// Returns the intersection between the two sets of flags.
+            #[inline]
+            fn bitand(self, other: $BitFlags) -> $BitFlags {
+                $BitFlags { bits: self.bits & other.bits }
+            }
+        }
+
+        // NOTE(stage0): Remove impl after a snapshot
+        #[cfg(stage0)]
         impl Sub<$BitFlags, $BitFlags> for $BitFlags {
             /// Returns the set difference of the two sets of flags.
             #[inline]
@@ -237,6 +272,15 @@ macro_rules! bitflags {
             }
         }
 
+        #[cfg(not(stage0))]  // NOTE(stage0): Remove cfg after a snapshot
+        impl Sub<$BitFlags, $BitFlags> for $BitFlags {
+            /// Returns the set difference of the two sets of flags.
+            #[inline]
+            fn sub(self, other: $BitFlags) -> $BitFlags {
+                $BitFlags { bits: self.bits & !other.bits }
+            }
+        }
+
         impl Not<$BitFlags> for $BitFlags {
             /// Returns the complement of this set of flags.
             #[inline]