From 91f5d3275f110f627931646fb19f22d8c4dd41c3 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 7 Aug 2015 15:51:25 +0200 Subject: [PATCH 1/6] Turn nonzeroing move hints back off by default. This is a temporary workaround for the bugs that have been found in the implementation of PR #26173. * pnkfelix is unavailable in the short-term (i.e. for the next week) to fix them. * When the bugs are fixed, we will turn this back on by default. (If you want to play with the known-to-be-buggy optimization in the meantime, you can opt-back in via the debugging option that this commit is toggling.) --- src/librustc/session/config.rs | 4 ++-- src/librustc/session/mod.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index f74bb9ee89ad0..c5db7cd718b8e 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -596,8 +596,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, "Force drop flag checks on or off"), trace_macros: bool = (false, parse_bool, "For every macro invocation, print its name and arguments"), - disable_nonzeroing_move_hints: bool = (false, parse_bool, - "Force nonzeroing move optimization off"), + enable_nonzeroing_move_hints: bool = (false, parse_bool, + "Force nonzeroing move optimization on"), } pub fn default_lib_output() -> CrateType { diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index efd46d35f56b7..99a58f07ae62b 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -273,7 +273,7 @@ impl Session { self.opts.debugging_opts.print_enum_sizes } pub fn nonzeroing_move_hints(&self) -> bool { - !self.opts.debugging_opts.disable_nonzeroing_move_hints + self.opts.debugging_opts.enable_nonzeroing_move_hints } pub fn sysroot<'a>(&'a self) -> &'a Path { match self.opts.maybe_sysroot { From fc54934d8893f9fb6eed88c09557f2228146bef1 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 7 Aug 2015 16:21:22 +0200 Subject: [PATCH 2/6] Regression test for dropflag reinit issue. Fix #27401. --- .../run-pass/issue-27401-dropflag-reinit.rs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/test/run-pass/issue-27401-dropflag-reinit.rs diff --git a/src/test/run-pass/issue-27401-dropflag-reinit.rs b/src/test/run-pass/issue-27401-dropflag-reinit.rs new file mode 100644 index 0000000000000..99d5e5cd536df --- /dev/null +++ b/src/test/run-pass/issue-27401-dropflag-reinit.rs @@ -0,0 +1,34 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Check that when a `let`-binding occurs in a loop, its associated +// drop-flag is reinitialized (to indicate "needs-drop" at the end of +// the owning variable's scope). + +struct A<'a>(&'a mut i32); + +impl<'a> Drop for A<'a> { + fn drop(&mut self) { + *self.0 += 1; + } +} + +fn main() { + let mut cnt = 0; + for i in 0..2 { + let a = A(&mut cnt); + if i == 1 { // Note that + break; // both this break + } // and also + drop(a); // this move of `a` + // are necessary to expose the bug + } + assert_eq!(cnt, 2); +} From af32c015aa6fa33cbbc2986e7f72e5c83f242c35 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 7 Aug 2015 18:23:37 +0200 Subject: [PATCH 3/6] placate the pretty tests by ignoring my test. --- src/test/run-pass/issue-27401-dropflag-reinit.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/run-pass/issue-27401-dropflag-reinit.rs b/src/test/run-pass/issue-27401-dropflag-reinit.rs index 99d5e5cd536df..ab8f22e78be72 100644 --- a/src/test/run-pass/issue-27401-dropflag-reinit.rs +++ b/src/test/run-pass/issue-27401-dropflag-reinit.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-pretty #27582 + // Check that when a `let`-binding occurs in a loop, its associated // drop-flag is reinitialized (to indicate "needs-drop" at the end of // the owning variable's scope). From 999bdeca88a06938ac1e1c608091d3afe4d7e173 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sun, 5 Jul 2015 23:20:00 -0700 Subject: [PATCH 4/6] Stabilize the Duration API This commit stabilizes the `std::time` module and the `Duration` type. `Duration::span` remains unstable, and the `Display` implementation for `Duration` has been removed as it is still being reworked and all trait implementations for stable types are de facto stable. This is a [breaking-change] to those using `Duration`'s `Display` implementation. --- src/librustc/lib.rs | 1 - src/librustc/metadata/loader.rs | 2 +- src/librustc/util/common.rs | 4 +- src/libstd/sys/unix/condvar.rs | 4 +- src/libstd/sys/unix/net.rs | 8 +-- src/libstd/sys/unix/thread.rs | 4 +- src/libstd/sys/windows/mod.rs | 6 +- src/libstd/time/duration.rs | 67 +++++++---------------- src/libstd/time/mod.rs | 2 +- src/libtest/lib.rs | 3 +- src/test/bench/core-map.rs | 2 +- src/test/bench/core-set.rs | 2 +- src/test/bench/core-std.rs | 2 +- src/test/bench/msgsend-pipes-shared.rs | 4 +- src/test/bench/msgsend-pipes.rs | 4 +- src/test/bench/msgsend-ring-mutex-arcs.rs | 4 +- src/test/bench/shootout-pfib.rs | 2 +- src/test/bench/std-smallintmap.rs | 8 +-- src/test/bench/task-perf-alloc-unwind.rs | 2 +- 19 files changed, 51 insertions(+), 80 deletions(-) diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 1a15d98d53150..bb44abc4f078d 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -33,7 +33,6 @@ #![feature(collections)] #![feature(const_fn)] #![feature(core)] -#![feature(duration)] #![feature(duration_span)] #![feature(dynamic_lib)] #![feature(enumset)] diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index 81acaf66e08fc..2f481f70aafe9 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -722,7 +722,7 @@ fn get_metadata_section(target: &Target, filename: &Path) let dur = Duration::span(|| { ret = Some(get_metadata_section_imp(target, filename)); }); - info!("reading {:?} => {}", filename.file_name().unwrap(), dur); + info!("reading {:?} => {:?}", filename.file_name().unwrap(), dur); return ret.unwrap();; } diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs index 03aa4bc2ead76..db0f820e11bfc 100644 --- a/src/librustc/util/common.rs +++ b/src/librustc/util/common.rs @@ -57,8 +57,8 @@ pub fn time(do_it: bool, what: &str, u: U, f: F) -> T where // Hack up our own formatting for the duration to make it easier for scripts // to parse (always use the same number of decimal places and the same unit). const NANOS_PER_SEC: f64 = 1_000_000_000.0; - let secs = dur.secs() as f64; - let secs = secs + dur.extra_nanos() as f64 / NANOS_PER_SEC; + let secs = dur.as_secs() as f64; + let secs = secs + dur.subsec_nanos() as f64 / NANOS_PER_SEC; let mem_string = match get_resident() { Some(n) => { diff --git a/src/libstd/sys/unix/condvar.rs b/src/libstd/sys/unix/condvar.rs index 9dd8df7524dc0..5d18c1d628075 100644 --- a/src/libstd/sys/unix/condvar.rs +++ b/src/libstd/sys/unix/condvar.rs @@ -61,11 +61,11 @@ impl Condvar { let r = ffi::gettimeofday(&mut sys_now, ptr::null_mut()); debug_assert_eq!(r, 0); - let nsec = dur.extra_nanos() as libc::c_long + + let nsec = dur.subsec_nanos() as libc::c_long + (sys_now.tv_usec * 1000) as libc::c_long; let extra = (nsec / 1_000_000_000) as libc::time_t; let nsec = nsec % 1_000_000_000; - let seconds = dur.secs() as libc::time_t; + let seconds = dur.as_secs() as libc::time_t; let timeout = sys_now.tv_sec.checked_add(extra).and_then(|s| { s.checked_add(seconds) diff --git a/src/libstd/sys/unix/net.rs b/src/libstd/sys/unix/net.rs index 37eb7fd2ac803..e65f64f202980 100644 --- a/src/libstd/sys/unix/net.rs +++ b/src/libstd/sys/unix/net.rs @@ -79,19 +79,19 @@ impl Socket { pub fn set_timeout(&self, dur: Option, kind: libc::c_int) -> io::Result<()> { let timeout = match dur { Some(dur) => { - if dur.secs() == 0 && dur.extra_nanos() == 0 { + if dur.as_secs() == 0 && dur.subsec_nanos() == 0 { return Err(io::Error::new(io::ErrorKind::InvalidInput, "cannot set a 0 duration timeout")); } - let secs = if dur.secs() > libc::time_t::max_value() as u64 { + let secs = if dur.as_secs() > libc::time_t::max_value() as u64 { libc::time_t::max_value() } else { - dur.secs() as libc::time_t + dur.as_secs() as libc::time_t }; let mut timeout = libc::timeval { tv_sec: secs, - tv_usec: (dur.extra_nanos() / 1000) as libc::suseconds_t, + tv_usec: (dur.subsec_nanos() / 1000) as libc::suseconds_t, }; if timeout.tv_sec == 0 && timeout.tv_usec == 0 { timeout.tv_usec = 1; diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index 67ecd4d922980..8efd76b9abd66 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -131,8 +131,8 @@ impl Thread { pub fn sleep(dur: Duration) { let mut ts = libc::timespec { - tv_sec: dur.secs() as libc::time_t, - tv_nsec: dur.extra_nanos() as libc::c_long, + tv_sec: dur.as_secs() as libc::time_t, + tv_nsec: dur.subsec_nanos() as libc::c_long, }; // If we're awoken with a signal then the return value will be -1 and diff --git a/src/libstd/sys/windows/mod.rs b/src/libstd/sys/windows/mod.rs index b6d080109df05..b38945d891608 100644 --- a/src/libstd/sys/windows/mod.rs +++ b/src/libstd/sys/windows/mod.rs @@ -162,10 +162,10 @@ fn dur2timeout(dur: Duration) -> libc::DWORD { // * Nanosecond precision is rounded up // * Greater than u32::MAX milliseconds (50 days) is rounded up to INFINITE // (never time out). - dur.secs().checked_mul(1000).and_then(|ms| { - ms.checked_add((dur.extra_nanos() as u64) / 1_000_000) + dur.as_secs().checked_mul(1000).and_then(|ms| { + ms.checked_add((dur.subsec_nanos() as u64) / 1_000_000) }).and_then(|ms| { - ms.checked_add(if dur.extra_nanos() % 1_000_000 > 0 {1} else {0}) + ms.checked_add(if dur.subsec_nanos() % 1_000_000 > 0 {1} else {0}) }).map(|ms| { if ms > ::max_value() as u64 { libc::INFINITE diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index 28eaed40da802..ee287484256dd 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -8,14 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! Temporal quantification - -#![unstable(feature = "duration", reason = "recently added API per RFC 1040")] - #[cfg(stage0)] use prelude::v1::*; -use fmt; use ops::{Add, Sub, Mul, Div}; use sys::time::SteadyTime; @@ -43,11 +38,12 @@ const MILLIS_PER_SEC: u64 = 1_000; /// let five_seconds = Duration::new(5, 0); /// let five_seconds_and_five_nanos = five_seconds + Duration::new(0, 5); /// -/// assert_eq!(five_seconds_and_five_nanos.secs(), 5); -/// assert_eq!(five_seconds_and_five_nanos.extra_nanos(), 5); +/// assert_eq!(five_seconds_and_five_nanos.as_secs(), 5); +/// assert_eq!(five_seconds_and_five_nanos.subsec_nanos(), 5); /// /// let ten_millis = Duration::from_millis(10); /// ``` +#[stable(feature = "duration", since = "1.3.0")] #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)] pub struct Duration { secs: u64, @@ -60,6 +56,7 @@ impl Duration { /// /// If the nanoseconds is greater than 1 billion (the number of nanoseconds /// in a second), then it will carry over into the seconds provided. + #[stable(feature = "duration", since = "1.3.0")] pub fn new(secs: u64, nanos: u32) -> Duration { let secs = secs + (nanos / NANOS_PER_SEC) as u64; let nanos = nanos % NANOS_PER_SEC; @@ -79,11 +76,13 @@ impl Duration { } /// Creates a new `Duration` from the specified number of seconds. + #[stable(feature = "duration", since = "1.3.0")] pub fn from_secs(secs: u64) -> Duration { Duration { secs: secs, nanos: 0 } } /// Creates a new `Duration` from the specified number of milliseconds. + #[stable(feature = "duration", since = "1.3.0")] pub fn from_millis(millis: u64) -> Duration { let secs = millis / MILLIS_PER_SEC; let nanos = ((millis % MILLIS_PER_SEC) as u32) * NANOS_PER_MILLI; @@ -94,14 +93,16 @@ impl Duration { /// /// The extra precision represented by this duration is ignored (e.g. extra /// nanoseconds are not represented in the returned value). - pub fn secs(&self) -> u64 { self.secs } + #[stable(feature = "duration", since = "1.3.0")] + pub fn as_secs(&self) -> u64 { self.secs } /// Returns the nanosecond precision represented by this duration. /// /// This method does **not** return the length of the duration when /// represented by nanoseconds. The returned number always represents a /// fractional portion of a second (e.g. it is less than one billion). - pub fn extra_nanos(&self) -> u32 { self.nanos } + #[stable(feature = "duration", since = "1.3.0")] + pub fn subsec_nanos(&self) -> u32 { self.nanos } } impl Add for Duration { @@ -167,20 +168,6 @@ impl Div for Duration { } } -impl fmt::Display for Duration { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match (self.secs, self.nanos) { - (s, 0) => write!(f, "{}s", s), - (0, n) if n % NANOS_PER_MILLI == 0 => write!(f, "{}ms", - n / NANOS_PER_MILLI), - (0, n) if n % 1_000 == 0 => write!(f, "{}µs", n / 1_000), - (0, n) => write!(f, "{}ns", n), - (s, n) => write!(f, "{}.{}s", s, - format!("{:09}", n).trim_right_matches('0')) - } - } -} - #[cfg(test)] mod tests { use prelude::v1::*; @@ -198,20 +185,20 @@ mod tests { #[test] fn secs() { - assert_eq!(Duration::new(0, 0).secs(), 0); - assert_eq!(Duration::from_secs(1).secs(), 1); - assert_eq!(Duration::from_millis(999).secs(), 0); - assert_eq!(Duration::from_millis(1001).secs(), 1); + assert_eq!(Duration::new(0, 0).as_secs(), 0); + assert_eq!(Duration::from_secs(1).as_secs(), 1); + assert_eq!(Duration::from_millis(999).as_secs(), 0); + assert_eq!(Duration::from_millis(1001).as_secs(), 1); } #[test] fn nanos() { - assert_eq!(Duration::new(0, 0).extra_nanos(), 0); - assert_eq!(Duration::new(0, 5).extra_nanos(), 5); - assert_eq!(Duration::new(0, 1_000_000_001).extra_nanos(), 1); - assert_eq!(Duration::from_secs(1).extra_nanos(), 0); - assert_eq!(Duration::from_millis(999).extra_nanos(), 999 * 1_000_000); - assert_eq!(Duration::from_millis(1001).extra_nanos(), 1 * 1_000_000); + assert_eq!(Duration::new(0, 0).subsec_nanos(), 0); + assert_eq!(Duration::new(0, 5).subsec_nanos(), 5); + assert_eq!(Duration::new(0, 1_000_000_001).subsec_nanos(), 1); + assert_eq!(Duration::from_secs(1).subsec_nanos(), 0); + assert_eq!(Duration::from_millis(999).subsec_nanos(), 999 * 1_000_000); + assert_eq!(Duration::from_millis(1001).subsec_nanos(), 1 * 1_000_000); } #[test] @@ -258,18 +245,4 @@ mod tests { assert_eq!(Duration::new(99, 999_999_000) / 100, Duration::new(0, 999_999_990)); } - - #[test] - fn display() { - assert_eq!(Duration::new(0, 2).to_string(), "2ns"); - assert_eq!(Duration::new(0, 2_000_000).to_string(), "2ms"); - assert_eq!(Duration::new(2, 0).to_string(), "2s"); - assert_eq!(Duration::new(2, 2).to_string(), "2.000000002s"); - assert_eq!(Duration::new(2, 2_000_000).to_string(), - "2.002s"); - assert_eq!(Duration::new(0, 2_000_002).to_string(), - "2000002ns"); - assert_eq!(Duration::new(2, 2_000_002).to_string(), - "2.002000002s"); - } } diff --git a/src/libstd/time/mod.rs b/src/libstd/time/mod.rs index d535b19551995..29df882a0422c 100644 --- a/src/libstd/time/mod.rs +++ b/src/libstd/time/mod.rs @@ -10,7 +10,7 @@ //! Temporal quantification. -#![unstable(feature = "time")] +#![stable(feature = "time", since = "1.3.0")] pub use self::duration::Duration; diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 7777ea51f822e..a7fb88215b7dc 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -36,7 +36,6 @@ #![feature(asm)] #![feature(box_syntax)] -#![feature(duration)] #![feature(duration_span)] #![feature(fnbox)] #![feature(iter_cmp)] @@ -1105,7 +1104,7 @@ impl Bencher { } pub fn ns_elapsed(&mut self) -> u64 { - self.dur.secs() * 1_000_000_000 + (self.dur.extra_nanos() as u64) + self.dur.as_secs() * 1_000_000_000 + (self.dur.subsec_nanos() as u64) } pub fn ns_per_iter(&mut self) -> u64 { diff --git a/src/test/bench/core-map.rs b/src/test/bench/core-map.rs index af61b0aa0cdf4..ebb8036bacf1b 100644 --- a/src/test/bench/core-map.rs +++ b/src/test/bench/core-map.rs @@ -16,7 +16,7 @@ use std::__rand::{Rng, thread_rng}; use std::time::Duration; fn timed(label: &str, f: F) where F: FnMut() { - println!(" {}: {}", label, Duration::span(f)); + println!(" {}: {:?}", label, Duration::span(f)); } trait MutableMap { diff --git a/src/test/bench/core-set.rs b/src/test/bench/core-set.rs index d2537e09901cb..f4ee020d6e752 100644 --- a/src/test/bench/core-set.rs +++ b/src/test/bench/core-set.rs @@ -153,7 +153,7 @@ fn write_header(header: &str) { } fn write_row(label: &str, value: Duration) { - println!("{:30} {} s\n", label, value); + println!("{:30} {:?} s\n", label, value); } fn write_results(label: &str, results: &Results) { diff --git a/src/test/bench/core-std.rs b/src/test/bench/core-std.rs index e7d64dfe2c5a8..26fb3630487f2 100644 --- a/src/test/bench/core-std.rs +++ b/src/test/bench/core-std.rs @@ -51,7 +51,7 @@ fn maybe_run_test(argv: &[String], name: String, test: F) where F: FnOnce() { let dur = Duration::span(test); - println!("{}:\t\t{}", name, dur); + println!("{}:\t\t{:?}", name, dur); } fn shift_push() { diff --git a/src/test/bench/msgsend-pipes-shared.rs b/src/test/bench/msgsend-pipes-shared.rs index 2b7e204423e32..b210f5ac26ae0 100644 --- a/src/test/bench/msgsend-pipes-shared.rs +++ b/src/test/bench/msgsend-pipes-shared.rs @@ -88,8 +88,8 @@ fn run(args: &[String]) { }); let result = result.unwrap(); print!("Count is {}\n", result); - print!("Test took {}\n", dur); - let thruput = ((size / workers * workers) as f64) / (dur.secs() as f64); + print!("Test took {:?}\n", dur); + let thruput = ((size / workers * workers) as f64) / (dur.as_secs() as f64); print!("Throughput={} per sec\n", thruput); assert_eq!(result, num_bytes * size); } diff --git a/src/test/bench/msgsend-pipes.rs b/src/test/bench/msgsend-pipes.rs index 5a541420d2abf..056905f1ef691 100644 --- a/src/test/bench/msgsend-pipes.rs +++ b/src/test/bench/msgsend-pipes.rs @@ -95,8 +95,8 @@ fn run(args: &[String]) { }); let result = result.unwrap(); print!("Count is {}\n", result); - print!("Test took {}\n", dur); - let thruput = ((size / workers * workers) as f64) / (dur.secs() as f64); + print!("Test took {:?}\n", dur); + let thruput = ((size / workers * workers) as f64) / (dur.as_secs() as f64); print!("Throughput={} per sec\n", thruput); assert_eq!(result, num_bytes * size); } diff --git a/src/test/bench/msgsend-ring-mutex-arcs.rs b/src/test/bench/msgsend-ring-mutex-arcs.rs index 24ecaf4b02471..b7f9dc94a0bc0 100644 --- a/src/test/bench/msgsend-ring-mutex-arcs.rs +++ b/src/test/bench/msgsend-ring-mutex-arcs.rs @@ -107,9 +107,9 @@ fn main() { // all done, report stats. let num_msgs = num_tasks * msg_per_task; - let rate = (num_msgs as f64) / (dur.secs() as f64); + let rate = (num_msgs as f64) / (dur.as_secs() as f64); - println!("Sent {} messages in {}", num_msgs, dur); + println!("Sent {} messages in {:?}", num_msgs, dur); println!(" {} messages / second", rate); println!(" {} μs / message", 1000000. / rate); } diff --git a/src/test/bench/shootout-pfib.rs b/src/test/bench/shootout-pfib.rs index 2d5aae30ae8a9..b7553dc7c7043 100644 --- a/src/test/bench/shootout-pfib.rs +++ b/src/test/bench/shootout-pfib.rs @@ -114,7 +114,7 @@ fn main() { let dur = Duration::span(|| fibn = Some(fib(n))); let fibn = fibn.unwrap(); - println!("{}\t{}\t{}", n, fibn, dur); + println!("{}\t{}\t{:?}", n, fibn, dur); } } } diff --git a/src/test/bench/std-smallintmap.rs b/src/test/bench/std-smallintmap.rs index 6a39a6db0c728..64f2381d1c35d 100644 --- a/src/test/bench/std-smallintmap.rs +++ b/src/test/bench/std-smallintmap.rs @@ -54,8 +54,8 @@ fn main() { let maxf = max as f64; - println!("insert(): {} seconds\n", checkf); - println!(" : {} op/s\n", maxf / checkf.secs() as f64); - println!("get() : {} seconds\n", appendf); - println!(" : {} op/s\n", maxf / appendf.secs() as f64); + println!("insert(): {:?} seconds\n", checkf); + println!(" : {} op/s\n", maxf / checkf.as_secs() as f64); + println!("get() : {:?} seconds\n", appendf); + println!(" : {} op/s\n", maxf / appendf.as_secs() as f64); } diff --git a/src/test/bench/task-perf-alloc-unwind.rs b/src/test/bench/task-perf-alloc-unwind.rs index 3bd7b78125112..5f34d0f630149 100644 --- a/src/test/bench/task-perf-alloc-unwind.rs +++ b/src/test/bench/task-perf-alloc-unwind.rs @@ -36,7 +36,7 @@ fn run(repeat: isize, depth: isize) { recurse_or_panic(depth, None) }).join(); }); - println!("iter: {}", dur); + println!("iter: {:?}", dur); } } From e29a62f140f3bda4220b47e04623b5a7c7e3e736 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Fri, 7 Aug 2015 12:54:49 -0700 Subject: [PATCH 5/6] Add back and deprecate old methods. --- src/libstd/time/duration.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index ee287484256dd..c63bd275ffc27 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -96,6 +96,14 @@ impl Duration { #[stable(feature = "duration", since = "1.3.0")] pub fn as_secs(&self) -> u64 { self.secs } + #[deprecated(reason = "renamed to `as_secs`", since = "1.3.0")] + #[unstable(feature = "duration_deprecated")] + /// Returns the number of whole seconds represented by this duration. + /// + /// The extra precision represented by this duration is ignored (e.g. extra + /// nanoseconds are not represented in the returned value). + pub fn secs(&self) -> u64 { self.as_secs() } + /// Returns the nanosecond precision represented by this duration. /// /// This method does **not** return the length of the duration when @@ -103,6 +111,15 @@ impl Duration { /// fractional portion of a second (e.g. it is less than one billion). #[stable(feature = "duration", since = "1.3.0")] pub fn subsec_nanos(&self) -> u32 { self.nanos } + + #[deprecated(reason = "renamed to `subsec_nanos`", since = "1.3.0")] + #[unstable(feature = "duration_deprecated")] + /// Returns the nanosecond precision represented by this duration. + /// + /// This method does **not** return the length of the duration when + /// represented by nanoseconds. The returned number always represents a + /// fractional portion of a second (e.g. it is less than one billion). + pub fn extra_nanos(&self) -> u32 { self.subsec_nanos() } } impl Add for Duration { From b51e0090696c82c6156bbfcd0e67ac68df67379b Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Mon, 10 Aug 2015 22:31:17 -0400 Subject: [PATCH 6/6] Fix doc test --- src/libstd/time/duration.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index c63bd275ffc27..5270f9e618004 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -32,7 +32,6 @@ const MILLIS_PER_SEC: u64 = 1_000; /// # Examples /// /// ``` -/// #![feature(duration)] /// use std::time::Duration; /// /// let five_seconds = Duration::new(5, 0);