Skip to content

Commit 5f347d7

Browse files
author
Jorge Aparicio
committed
libstd: convert Duration unops to by value
1 parent 340f042 commit 5f347d7

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/libstd/time/duration.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ impl Duration {
265265
}
266266
}
267267

268+
// NOTE(stage0): Remove impl after a snapshot
269+
#[cfg(stage0)]
268270
impl Neg<Duration> for Duration {
269271
#[inline]
270272
fn neg(&self) -> Duration {
@@ -276,6 +278,18 @@ impl Neg<Duration> for Duration {
276278
}
277279
}
278280

281+
#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
282+
impl Neg<Duration> for Duration {
283+
#[inline]
284+
fn neg(self) -> Duration {
285+
if self.nanos == 0 {
286+
Duration { secs: -self.secs, nanos: 0 }
287+
} else {
288+
Duration { secs: -self.secs - 1, nanos: NANOS_PER_SEC - self.nanos }
289+
}
290+
}
291+
}
292+
279293
// NOTE(stage0): Remove impl after a snapshot
280294
#[cfg(stage0)]
281295
impl Add<Duration,Duration> for Duration {

0 commit comments

Comments
 (0)