Skip to content

Commit 32a5ceb

Browse files
committed
Merge pull request #27668 from brson/beta-next
Beta next
2 parents dcab950 + 6a42e5d commit 32a5ceb

20 files changed

+71
-82
lines changed

mk/main.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ CFG_RELEASE_NUM=1.3.0
1818
# An optional number to put after the label, e.g. '.2' -> '-beta.2'
1919
# NB Make sure it starts with a dot to conform to semver pre-release
2020
# versions (section 9)
21-
CFG_PRERELEASE_VERSION=.2
21+
CFG_PRERELEASE_VERSION=.3
2222

2323
# Append a version-dependent hash to each library, so we can install different
2424
# versions in the same place

src/librustc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#![feature(clone_from_slice)]
3333
#![feature(collections)]
3434
#![feature(const_fn)]
35-
#![feature(duration)]
35+
#![feature(core)]
3636
#![feature(duration_span)]
3737
#![feature(dynamic_lib)]
3838
#![feature(enumset)]

src/librustc/metadata/loader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ fn get_metadata_section(target: &Target, filename: &Path)
722722
let dur = Duration::span(|| {
723723
ret = Some(get_metadata_section_imp(target, filename));
724724
});
725-
info!("reading {:?} => {}", filename.file_name().unwrap(), dur);
725+
info!("reading {:?} => {:?}", filename.file_name().unwrap(), dur);
726726
return ret.unwrap();;
727727
}
728728

src/librustc/util/common.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ pub fn time<T, U, F>(do_it: bool, what: &str, u: U, f: F) -> T where
5757
// Hack up our own formatting for the duration to make it easier for scripts
5858
// to parse (always use the same number of decimal places and the same unit).
5959
const NANOS_PER_SEC: f64 = 1_000_000_000.0;
60-
let secs = dur.secs() as f64;
61-
let secs = secs + dur.extra_nanos() as f64 / NANOS_PER_SEC;
60+
let secs = dur.as_secs() as f64;
61+
let secs = secs + dur.subsec_nanos() as f64 / NANOS_PER_SEC;
6262

6363
let mem_string = match get_resident() {
6464
Some(n) => {

src/libstd/sys/unix/condvar.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ impl Condvar {
6060
let r = ffi::gettimeofday(&mut sys_now, ptr::null_mut());
6161
debug_assert_eq!(r, 0);
6262

63-
let nsec = dur.extra_nanos() as libc::c_long +
63+
let nsec = dur.subsec_nanos() as libc::c_long +
6464
(sys_now.tv_usec * 1000) as libc::c_long;
6565
let extra = (nsec / 1_000_000_000) as libc::time_t;
6666
let nsec = nsec % 1_000_000_000;
67-
let seconds = dur.secs() as libc::time_t;
67+
let seconds = dur.as_secs() as libc::time_t;
6868

6969
let timeout = sys_now.tv_sec.checked_add(extra).and_then(|s| {
7070
s.checked_add(seconds)

src/libstd/sys/unix/net.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,19 @@ impl Socket {
7979
pub fn set_timeout(&self, dur: Option<Duration>, kind: libc::c_int) -> io::Result<()> {
8080
let timeout = match dur {
8181
Some(dur) => {
82-
if dur.secs() == 0 && dur.extra_nanos() == 0 {
82+
if dur.as_secs() == 0 && dur.subsec_nanos() == 0 {
8383
return Err(io::Error::new(io::ErrorKind::InvalidInput,
8484
"cannot set a 0 duration timeout"));
8585
}
8686

87-
let secs = if dur.secs() > libc::time_t::max_value() as u64 {
87+
let secs = if dur.as_secs() > libc::time_t::max_value() as u64 {
8888
libc::time_t::max_value()
8989
} else {
90-
dur.secs() as libc::time_t
90+
dur.as_secs() as libc::time_t
9191
};
9292
let mut timeout = libc::timeval {
9393
tv_sec: secs,
94-
tv_usec: (dur.extra_nanos() / 1000) as libc::suseconds_t,
94+
tv_usec: (dur.subsec_nanos() / 1000) as libc::suseconds_t,
9595
};
9696
if timeout.tv_sec == 0 && timeout.tv_usec == 0 {
9797
timeout.tv_usec = 1;

src/libstd/sys/unix/thread.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ impl Thread {
131131

132132
pub fn sleep(dur: Duration) {
133133
let mut ts = libc::timespec {
134-
tv_sec: dur.secs() as libc::time_t,
135-
tv_nsec: dur.extra_nanos() as libc::c_long,
134+
tv_sec: dur.as_secs() as libc::time_t,
135+
tv_nsec: dur.subsec_nanos() as libc::c_long,
136136
};
137137

138138
// If we're awoken with a signal then the return value will be -1 and

src/libstd/sys/windows/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ fn dur2timeout(dur: Duration) -> libc::DWORD {
162162
// * Nanosecond precision is rounded up
163163
// * Greater than u32::MAX milliseconds (50 days) is rounded up to INFINITE
164164
// (never time out).
165-
dur.secs().checked_mul(1000).and_then(|ms| {
166-
ms.checked_add((dur.extra_nanos() as u64) / 1_000_000)
165+
dur.as_secs().checked_mul(1000).and_then(|ms| {
166+
ms.checked_add((dur.subsec_nanos() as u64) / 1_000_000)
167167
}).and_then(|ms| {
168-
ms.checked_add(if dur.extra_nanos() % 1_000_000 > 0 {1} else {0})
168+
ms.checked_add(if dur.subsec_nanos() % 1_000_000 > 0 {1} else {0})
169169
}).map(|ms| {
170170
if ms > <libc::DWORD>::max_value() as u64 {
171171
libc::INFINITE

src/libstd/time/duration.rs

+38-48
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! Temporal quantification
12-
13-
#![unstable(feature = "duration", reason = "recently added API per RFC 1040")]
14-
11+
#[cfg(stage0)]
1512
use prelude::v1::*;
1613

17-
use fmt;
1814
use ops::{Add, Sub, Mul, Div};
1915
use sys::time::SteadyTime;
2016

@@ -36,17 +32,17 @@ const MILLIS_PER_SEC: u64 = 1_000;
3632
/// # Examples
3733
///
3834
/// ```
39-
/// #![feature(duration)]
4035
/// use std::time::Duration;
4136
///
4237
/// let five_seconds = Duration::new(5, 0);
4338
/// let five_seconds_and_five_nanos = five_seconds + Duration::new(0, 5);
4439
///
45-
/// assert_eq!(five_seconds_and_five_nanos.secs(), 5);
46-
/// assert_eq!(five_seconds_and_five_nanos.extra_nanos(), 5);
40+
/// assert_eq!(five_seconds_and_five_nanos.as_secs(), 5);
41+
/// assert_eq!(five_seconds_and_five_nanos.subsec_nanos(), 5);
4742
///
4843
/// let ten_millis = Duration::from_millis(10);
4944
/// ```
45+
#[stable(feature = "duration", since = "1.3.0")]
5046
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
5147
pub struct Duration {
5248
secs: u64,
@@ -59,6 +55,7 @@ impl Duration {
5955
///
6056
/// If the nanoseconds is greater than 1 billion (the number of nanoseconds
6157
/// in a second), then it will carry over into the seconds provided.
58+
#[stable(feature = "duration", since = "1.3.0")]
6259
pub fn new(secs: u64, nanos: u32) -> Duration {
6360
let secs = secs + (nanos / NANOS_PER_SEC) as u64;
6461
let nanos = nanos % NANOS_PER_SEC;
@@ -78,11 +75,13 @@ impl Duration {
7875
}
7976

8077
/// Creates a new `Duration` from the specified number of seconds.
78+
#[stable(feature = "duration", since = "1.3.0")]
8179
pub fn from_secs(secs: u64) -> Duration {
8280
Duration { secs: secs, nanos: 0 }
8381
}
8482

8583
/// Creates a new `Duration` from the specified number of milliseconds.
84+
#[stable(feature = "duration", since = "1.3.0")]
8685
pub fn from_millis(millis: u64) -> Duration {
8786
let secs = millis / MILLIS_PER_SEC;
8887
let nanos = ((millis % MILLIS_PER_SEC) as u32) * NANOS_PER_MILLI;
@@ -93,14 +92,33 @@ impl Duration {
9392
///
9493
/// The extra precision represented by this duration is ignored (e.g. extra
9594
/// nanoseconds are not represented in the returned value).
96-
pub fn secs(&self) -> u64 { self.secs }
95+
#[stable(feature = "duration", since = "1.3.0")]
96+
pub fn as_secs(&self) -> u64 { self.secs }
97+
98+
#[deprecated(reason = "renamed to `as_secs`", since = "1.3.0")]
99+
#[unstable(feature = "duration_deprecated")]
100+
/// Returns the number of whole seconds represented by this duration.
101+
///
102+
/// The extra precision represented by this duration is ignored (e.g. extra
103+
/// nanoseconds are not represented in the returned value).
104+
pub fn secs(&self) -> u64 { self.as_secs() }
105+
106+
/// Returns the nanosecond precision represented by this duration.
107+
///
108+
/// This method does **not** return the length of the duration when
109+
/// represented by nanoseconds. The returned number always represents a
110+
/// fractional portion of a second (e.g. it is less than one billion).
111+
#[stable(feature = "duration", since = "1.3.0")]
112+
pub fn subsec_nanos(&self) -> u32 { self.nanos }
97113

114+
#[deprecated(reason = "renamed to `subsec_nanos`", since = "1.3.0")]
115+
#[unstable(feature = "duration_deprecated")]
98116
/// Returns the nanosecond precision represented by this duration.
99117
///
100118
/// This method does **not** return the length of the duration when
101119
/// represented by nanoseconds. The returned number always represents a
102120
/// fractional portion of a second (e.g. it is less than one billion).
103-
pub fn extra_nanos(&self) -> u32 { self.nanos }
121+
pub fn extra_nanos(&self) -> u32 { self.subsec_nanos() }
104122
}
105123

106124
impl Add for Duration {
@@ -166,20 +184,6 @@ impl Div<u32> for Duration {
166184
}
167185
}
168186

169-
impl fmt::Display for Duration {
170-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
171-
match (self.secs, self.nanos) {
172-
(s, 0) => write!(f, "{}s", s),
173-
(0, n) if n % NANOS_PER_MILLI == 0 => write!(f, "{}ms",
174-
n / NANOS_PER_MILLI),
175-
(0, n) if n % 1_000 == 0 => write!(f, "{}µs", n / 1_000),
176-
(0, n) => write!(f, "{}ns", n),
177-
(s, n) => write!(f, "{}.{}s", s,
178-
format!("{:09}", n).trim_right_matches('0'))
179-
}
180-
}
181-
}
182-
183187
#[cfg(test)]
184188
mod tests {
185189
use prelude::v1::*;
@@ -197,20 +201,20 @@ mod tests {
197201

198202
#[test]
199203
fn secs() {
200-
assert_eq!(Duration::new(0, 0).secs(), 0);
201-
assert_eq!(Duration::from_secs(1).secs(), 1);
202-
assert_eq!(Duration::from_millis(999).secs(), 0);
203-
assert_eq!(Duration::from_millis(1001).secs(), 1);
204+
assert_eq!(Duration::new(0, 0).as_secs(), 0);
205+
assert_eq!(Duration::from_secs(1).as_secs(), 1);
206+
assert_eq!(Duration::from_millis(999).as_secs(), 0);
207+
assert_eq!(Duration::from_millis(1001).as_secs(), 1);
204208
}
205209

206210
#[test]
207211
fn nanos() {
208-
assert_eq!(Duration::new(0, 0).extra_nanos(), 0);
209-
assert_eq!(Duration::new(0, 5).extra_nanos(), 5);
210-
assert_eq!(Duration::new(0, 1_000_000_001).extra_nanos(), 1);
211-
assert_eq!(Duration::from_secs(1).extra_nanos(), 0);
212-
assert_eq!(Duration::from_millis(999).extra_nanos(), 999 * 1_000_000);
213-
assert_eq!(Duration::from_millis(1001).extra_nanos(), 1 * 1_000_000);
212+
assert_eq!(Duration::new(0, 0).subsec_nanos(), 0);
213+
assert_eq!(Duration::new(0, 5).subsec_nanos(), 5);
214+
assert_eq!(Duration::new(0, 1_000_000_001).subsec_nanos(), 1);
215+
assert_eq!(Duration::from_secs(1).subsec_nanos(), 0);
216+
assert_eq!(Duration::from_millis(999).subsec_nanos(), 999 * 1_000_000);
217+
assert_eq!(Duration::from_millis(1001).subsec_nanos(), 1 * 1_000_000);
214218
}
215219

216220
#[test]
@@ -257,18 +261,4 @@ mod tests {
257261
assert_eq!(Duration::new(99, 999_999_000) / 100,
258262
Duration::new(0, 999_999_990));
259263
}
260-
261-
#[test]
262-
fn display() {
263-
assert_eq!(Duration::new(0, 2).to_string(), "2ns");
264-
assert_eq!(Duration::new(0, 2_000_000).to_string(), "2ms");
265-
assert_eq!(Duration::new(2, 0).to_string(), "2s");
266-
assert_eq!(Duration::new(2, 2).to_string(), "2.000000002s");
267-
assert_eq!(Duration::new(2, 2_000_000).to_string(),
268-
"2.002s");
269-
assert_eq!(Duration::new(0, 2_000_002).to_string(),
270-
"2000002ns");
271-
assert_eq!(Duration::new(2, 2_000_002).to_string(),
272-
"2.002000002s");
273-
}
274264
}

src/libstd/time/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
//! Temporal quantification.
1212
13-
#![unstable(feature = "time")]
13+
#![stable(feature = "time", since = "1.3.0")]
1414

1515
pub use self::duration::Duration;
1616

src/libtest/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
#![feature(asm)]
3838
#![feature(box_syntax)]
39-
#![feature(duration)]
4039
#![feature(duration_span)]
4140
#![feature(fnbox)]
4241
#![feature(iter_cmp)]
@@ -1104,7 +1103,7 @@ impl Bencher {
11041103
}
11051104

11061105
pub fn ns_elapsed(&mut self) -> u64 {
1107-
self.dur.secs() * 1_000_000_000 + (self.dur.extra_nanos() as u64)
1106+
self.dur.as_secs() * 1_000_000_000 + (self.dur.subsec_nanos() as u64)
11081107
}
11091108

11101109
pub fn ns_per_iter(&mut self) -> u64 {

src/test/bench/core-map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::__rand::{Rng, thread_rng};
1616
use std::time::Duration;
1717

1818
fn timed<F>(label: &str, f: F) where F: FnMut() {
19-
println!(" {}: {}", label, Duration::span(f));
19+
println!(" {}: {:?}", label, Duration::span(f));
2020
}
2121

2222
trait MutableMap {

src/test/bench/core-set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ fn write_header(header: &str) {
153153
}
154154

155155
fn write_row(label: &str, value: Duration) {
156-
println!("{:30} {} s\n", label, value);
156+
println!("{:30} {:?} s\n", label, value);
157157
}
158158

159159
fn write_results(label: &str, results: &Results) {

src/test/bench/core-std.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn maybe_run_test<F>(argv: &[String], name: String, test: F) where F: FnOnce() {
5151

5252
let dur = Duration::span(test);
5353

54-
println!("{}:\t\t{}", name, dur);
54+
println!("{}:\t\t{:?}", name, dur);
5555
}
5656

5757
fn shift_push() {

src/test/bench/msgsend-pipes-shared.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ fn run(args: &[String]) {
8888
});
8989
let result = result.unwrap();
9090
print!("Count is {}\n", result);
91-
print!("Test took {}\n", dur);
92-
let thruput = ((size / workers * workers) as f64) / (dur.secs() as f64);
91+
print!("Test took {:?}\n", dur);
92+
let thruput = ((size / workers * workers) as f64) / (dur.as_secs() as f64);
9393
print!("Throughput={} per sec\n", thruput);
9494
assert_eq!(result, num_bytes * size);
9595
}

src/test/bench/msgsend-pipes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ fn run(args: &[String]) {
9595
});
9696
let result = result.unwrap();
9797
print!("Count is {}\n", result);
98-
print!("Test took {}\n", dur);
99-
let thruput = ((size / workers * workers) as f64) / (dur.secs() as f64);
98+
print!("Test took {:?}\n", dur);
99+
let thruput = ((size / workers * workers) as f64) / (dur.as_secs() as f64);
100100
print!("Throughput={} per sec\n", thruput);
101101
assert_eq!(result, num_bytes * size);
102102
}

src/test/bench/msgsend-ring-mutex-arcs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ fn main() {
107107

108108
// all done, report stats.
109109
let num_msgs = num_tasks * msg_per_task;
110-
let rate = (num_msgs as f64) / (dur.secs() as f64);
110+
let rate = (num_msgs as f64) / (dur.as_secs() as f64);
111111

112-
println!("Sent {} messages in {}", num_msgs, dur);
112+
println!("Sent {} messages in {:?}", num_msgs, dur);
113113
println!(" {} messages / second", rate);
114114
println!(" {} μs / message", 1000000. / rate);
115115
}

src/test/bench/shootout-pfib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ fn main() {
114114
let dur = Duration::span(|| fibn = Some(fib(n)));
115115
let fibn = fibn.unwrap();
116116

117-
println!("{}\t{}\t{}", n, fibn, dur);
117+
println!("{}\t{}\t{:?}", n, fibn, dur);
118118
}
119119
}
120120
}

src/test/bench/std-smallintmap.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ fn main() {
5454

5555
let maxf = max as f64;
5656

57-
println!("insert(): {} seconds\n", checkf);
58-
println!(" : {} op/s\n", maxf / checkf.secs() as f64);
59-
println!("get() : {} seconds\n", appendf);
60-
println!(" : {} op/s\n", maxf / appendf.secs() as f64);
57+
println!("insert(): {:?} seconds\n", checkf);
58+
println!(" : {} op/s\n", maxf / checkf.as_secs() as f64);
59+
println!("get() : {:?} seconds\n", appendf);
60+
println!(" : {} op/s\n", maxf / appendf.as_secs() as f64);
6161
}

src/test/bench/task-perf-alloc-unwind.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn run(repeat: isize, depth: isize) {
3636
recurse_or_panic(depth, None)
3737
}).join();
3838
});
39-
println!("iter: {}", dur);
39+
println!("iter: {:?}", dur);
4040
}
4141
}
4242

0 commit comments

Comments
 (0)