diff options
| author | bors <bors@rust-lang.org> | 2014-12-19 06:12:01 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-12-19 06:12:01 +0000 |
| commit | 6bdce25e155d846bb9252fa4a18baef7e74cf8bf (patch) | |
| tree | 80099a51ee183950cfa5661299e8dfcdeafd20c0 /src/libstd | |
| parent | 840de072085df360733c48396224e9966e2dc72c (diff) | |
| parent | 9b5de39c25b9b19ffcff3d519821b72a31d39d6c (diff) | |
| download | rust-6bdce25e155d846bb9252fa4a18baef7e74cf8bf.tar.gz rust-6bdce25e155d846bb9252fa4a18baef7e74cf8bf.zip | |
auto merge of #19899 : japaric/rust/unops-by-value, r=nikomatsakis
- The following operator traits now take their argument by value: `Neg`, `Not`. This breaks all existing implementations of these traits. - The unary operation `OP a` now "desugars" to `OpTrait::op_method(a)` and consumes its argument. [breaking-change] --- r? @nikomatsakis This PR is very similar to the binops-by-value PR cc @aturon
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/bitflags.rs | 11 | ||||
| -rw-r--r-- | src/libstd/time/duration.rs | 14 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/libstd/bitflags.rs b/src/libstd/bitflags.rs index 2be6f5057a1..f467b77dbf4 100644 --- a/src/libstd/bitflags.rs +++ b/src/libstd/bitflags.rs @@ -281,6 +281,8 @@ macro_rules! bitflags { } } + // NOTE(stage0): Remove impl after a snapshot + #[cfg(stage0)] impl Not<$BitFlags> for $BitFlags { /// Returns the complement of this set of flags. #[inline] @@ -288,6 +290,15 @@ macro_rules! bitflags { $BitFlags { bits: !self.bits } & $BitFlags::all() } } + + #[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot + impl Not<$BitFlags> for $BitFlags { + /// Returns the complement of this set of flags. + #[inline] + fn not(self) -> $BitFlags { + $BitFlags { bits: !self.bits } & $BitFlags::all() + } + } }; ($(#[$attr:meta])* flags $BitFlags:ident: $T:ty { $($(#[$Flag_attr:meta])* const $Flag:ident = $value:expr),+, diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index 8c4a5a6b8c7..85ed27853c4 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -265,6 +265,8 @@ impl Duration { } } +// NOTE(stage0): Remove impl after a snapshot +#[cfg(stage0)] impl Neg<Duration> for Duration { #[inline] fn neg(&self) -> Duration { @@ -276,6 +278,18 @@ impl Neg<Duration> for Duration { } } +#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot +impl Neg<Duration> for Duration { + #[inline] + fn neg(self) -> Duration { + if self.nanos == 0 { + Duration { secs: -self.secs, nanos: 0 } + } else { + Duration { secs: -self.secs - 1, nanos: NANOS_PER_SEC - self.nanos } + } + } +} + // NOTE(stage0): Remove impl after a snapshot #[cfg(stage0)] impl Add<Duration,Duration> for Duration { |
