Skip to content

Commit 318ff30

Browse files
author
BO41
committed
Fix typo on now() comments
1 parent 7870050 commit 318ff30

File tree

1 file changed

+23
-28
lines changed

1 file changed

+23
-28
lines changed

src/libstd/time.rs

+23-28
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
use crate::cmp;
1616
use crate::error::Error;
1717
use crate::fmt;
18-
use crate::ops::{Add, Sub, AddAssign, SubAssign};
18+
use crate::ops::{Add, AddAssign, Sub, SubAssign};
1919
use crate::sys::time;
20-
use crate::sys_common::FromInner;
2120
use crate::sys_common::mutex::Mutex;
21+
use crate::sys_common::FromInner;
2222

2323
#[stable(feature = "time", since = "1.3.0")]
2424
pub use core::time::Duration;
@@ -216,17 +216,17 @@ impl Instant {
216216
// * https://bugzilla.mozilla.org/show_bug.cgi?id=1487778 - a similar
217217
// Firefox bug
218218
//
219-
// It simply seems that this it just happens so that a lot in the wild
220-
// we're seeing panics across various platforms where consecutive calls
219+
// It seems that this just happens a lot in the wild.
220+
// We're seeing panics across various platforms where consecutive calls
221221
// to `Instant::now`, such as via the `elapsed` function, are panicking
222222
// as they're going backwards. Placed here is a last-ditch effort to try
223223
// to fix things up. We keep a global "latest now" instance which is
224224
// returned instead of what the OS says if the OS goes backwards.
225225
//
226-
// To hopefully mitigate the impact of this though a few platforms are
226+
// To hopefully mitigate the impact of this, a few platforms are
227227
// whitelisted as "these at least haven't gone backwards yet".
228228
if time::Instant::actually_monotonic() {
229-
return Instant(os_now)
229+
return Instant(os_now);
230230
}
231231

232232
static LOCK: Mutex = Mutex::new();
@@ -353,8 +353,7 @@ impl Add<Duration> for Instant {
353353
///
354354
/// [`checked_add`]: ../../std/time/struct.Instant.html#method.checked_add
355355
fn add(self, other: Duration) -> Instant {
356-
self.checked_add(other)
357-
.expect("overflow when adding duration to instant")
356+
self.checked_add(other).expect("overflow when adding duration to instant")
358357
}
359358
}
360359

@@ -370,8 +369,7 @@ impl Sub<Duration> for Instant {
370369
type Output = Instant;
371370

372371
fn sub(self, other: Duration) -> Instant {
373-
self.checked_sub(other)
374-
.expect("overflow when subtracting duration from instant")
372+
self.checked_sub(other).expect("overflow when subtracting duration from instant")
375373
}
376374
}
377375

@@ -464,8 +462,7 @@ impl SystemTime {
464462
/// println!("{:?}", difference);
465463
/// ```
466464
#[stable(feature = "time2", since = "1.8.0")]
467-
pub fn duration_since(&self, earlier: SystemTime)
468-
-> Result<Duration, SystemTimeError> {
465+
pub fn duration_since(&self, earlier: SystemTime) -> Result<Duration, SystemTimeError> {
469466
self.0.sub_time(&earlier.0).map_err(SystemTimeError)
470467
}
471468

@@ -532,8 +529,7 @@ impl Add<Duration> for SystemTime {
532529
///
533530
/// [`checked_add`]: ../../std/time/struct.SystemTime.html#method.checked_add
534531
fn add(self, dur: Duration) -> SystemTime {
535-
self.checked_add(dur)
536-
.expect("overflow when adding duration to instant")
532+
self.checked_add(dur).expect("overflow when adding duration to instant")
537533
}
538534
}
539535

@@ -549,8 +545,7 @@ impl Sub<Duration> for SystemTime {
549545
type Output = SystemTime;
550546

551547
fn sub(self, dur: Duration) -> SystemTime {
552-
self.checked_sub(dur)
553-
.expect("overflow when subtracting duration from instant")
548+
self.checked_sub(dur).expect("overflow when subtracting duration from instant")
554549
}
555550
}
556551

@@ -626,7 +621,9 @@ impl SystemTimeError {
626621

627622
#[stable(feature = "time2", since = "1.8.0")]
628623
impl Error for SystemTimeError {
629-
fn description(&self) -> &str { "other time was not earlier than self" }
624+
fn description(&self) -> &str {
625+
"other time was not earlier than self"
626+
}
630627
}
631628

632629
#[stable(feature = "time2", since = "1.8.0")]
@@ -644,17 +641,16 @@ impl FromInner<time::SystemTime> for SystemTime {
644641

645642
#[cfg(test)]
646643
mod tests {
647-
use super::{Instant, SystemTime, Duration, UNIX_EPOCH};
644+
use super::{Duration, Instant, SystemTime, UNIX_EPOCH};
648645

649646
macro_rules! assert_almost_eq {
650-
($a:expr, $b:expr) => ({
647+
($a:expr, $b:expr) => {{
651648
let (a, b) = ($a, $b);
652649
if a != b {
653-
let (a, b) = if a > b {(a, b)} else {(b, a)};
654-
assert!(a - Duration::new(0, 1000) <= b,
655-
"{:?} is not almost equal to {:?}", a, b);
650+
let (a, b) = if a > b { (a, b) } else { (b, a) };
651+
assert!(a - Duration::new(0, 1000) <= b, "{:?} is not almost equal to {:?}", a, b);
656652
}
657-
})
653+
}};
658654
}
659655

660656
#[test]
@@ -729,7 +725,7 @@ mod tests {
729725
fn instant_saturating_duration_since_nopanic() {
730726
let a = Instant::now();
731727
let ret = (a - Duration::new(1, 0)).saturating_duration_since(a);
732-
assert_eq!(ret, Duration::new(0,0));
728+
assert_eq!(ret, Duration::new(0, 0));
733729
}
734730

735731
#[test]
@@ -755,15 +751,14 @@ mod tests {
755751

756752
let second = Duration::new(1, 0);
757753
assert_almost_eq!(a.duration_since(a - second).unwrap(), second);
758-
assert_almost_eq!(a.duration_since(a + second).unwrap_err()
759-
.duration(), second);
754+
assert_almost_eq!(a.duration_since(a + second).unwrap_err().duration(), second);
760755

761756
assert_almost_eq!(a - second + second, a);
762757
assert_almost_eq!(a.checked_sub(second).unwrap().checked_add(second).unwrap(), a);
763758

764759
let one_second_from_epoch = UNIX_EPOCH + Duration::new(1, 0);
765-
let one_second_from_epoch2 = UNIX_EPOCH + Duration::new(0, 500_000_000)
766-
+ Duration::new(0, 500_000_000);
760+
let one_second_from_epoch2 =
761+
UNIX_EPOCH + Duration::new(0, 500_000_000) + Duration::new(0, 500_000_000);
767762
assert_eq!(one_second_from_epoch, one_second_from_epoch2);
768763

769764
// checked_add_duration will not panic on overflow

0 commit comments

Comments
 (0)