From 43baa2c0419709c13f7764212596f94d9900ba36 Mon Sep 17 00:00:00 2001 From: Jonathan Behrens Date: Sun, 22 Apr 2018 15:39:28 -0400 Subject: [PATCH 01/12] Add as_nanos function to duration --- src/libcore/time.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/libcore/time.rs b/src/libcore/time.rs index e22fe450bb1f6..8ebdbbd837090 100644 --- a/src/libcore/time.rs +++ b/src/libcore/time.rs @@ -263,6 +263,22 @@ impl Duration { #[inline] pub fn subsec_nanos(&self) -> u32 { self.nanos } + /// Returns the total number of nanoseconds contained by this `Duration`. + /// + /// # Examples + /// + /// ``` + /// use std::time::Duration; + /// + /// let duration = Duration::new(5, 730023852); + /// assert_eq!(duration.as_nanos(), 5730023852); + /// ``` + #[unstable(feature = "duration_nanos", issue = "0")] + #[inline] + pub fn as_nanos(&self) -> u128 { + self.secs as u128 * 1000_000_000 + self.nanos as u128 + } + /// Checked `Duration` addition. Computes `self + other`, returning [`None`] /// if overflow occurred. /// From 57b2067b115ad062cd75232e5c824cb8bbd34478 Mon Sep 17 00:00:00 2001 From: Jonathan Behrens Date: Sun, 22 Apr 2018 15:43:52 -0400 Subject: [PATCH 02/12] Use NANOS_PER_SEC constant --- src/libcore/time.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/time.rs b/src/libcore/time.rs index 8ebdbbd837090..807a152a2aa64 100644 --- a/src/libcore/time.rs +++ b/src/libcore/time.rs @@ -276,7 +276,7 @@ impl Duration { #[unstable(feature = "duration_nanos", issue = "0")] #[inline] pub fn as_nanos(&self) -> u128 { - self.secs as u128 * 1000_000_000 + self.nanos as u128 + self.secs as u128 * NANOS_PER_SEC as u128 + self.nanos as u128 } /// Checked `Duration` addition. Computes `self + other`, returning [`None`] From dc9e27d7488bcd28b7cc8ecf6c5ae349752faaf0 Mon Sep 17 00:00:00 2001 From: Jonathan Behrens Date: Sun, 22 Apr 2018 15:52:32 -0400 Subject: [PATCH 03/12] Add issue number --- src/libcore/time.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/time.rs b/src/libcore/time.rs index 807a152a2aa64..4c9c3b30b51ce 100644 --- a/src/libcore/time.rs +++ b/src/libcore/time.rs @@ -273,7 +273,7 @@ impl Duration { /// let duration = Duration::new(5, 730023852); /// assert_eq!(duration.as_nanos(), 5730023852); /// ``` - #[unstable(feature = "duration_nanos", issue = "0")] + #[unstable(feature = "duration_nanos", issue = "50167")] #[inline] pub fn as_nanos(&self) -> u128 { self.secs as u128 * NANOS_PER_SEC as u128 + self.nanos as u128 From b66ab1ad61b887cde9370b83149d4ec7789729fb Mon Sep 17 00:00:00 2001 From: Jonathan Behrens Date: Sun, 22 Apr 2018 17:19:35 -0400 Subject: [PATCH 04/12] Doctest of feature requires that feature --- src/libcore/time.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libcore/time.rs b/src/libcore/time.rs index 4c9c3b30b51ce..b2971e391cd76 100644 --- a/src/libcore/time.rs +++ b/src/libcore/time.rs @@ -268,6 +268,7 @@ impl Duration { /// # Examples /// /// ``` + /// # #![feature(duration_nanos)] /// use std::time::Duration; /// /// let duration = Duration::new(5, 730023852); From 799eda4128ad4517782de261a62d4284268de050 Mon Sep 17 00:00:00 2001 From: Jonathan Behrens Date: Tue, 24 Apr 2018 15:17:06 -0400 Subject: [PATCH 05/12] Issue number should be for tracking issue not PR --- src/libcore/time.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/time.rs b/src/libcore/time.rs index b2971e391cd76..f49917f848a07 100644 --- a/src/libcore/time.rs +++ b/src/libcore/time.rs @@ -274,7 +274,7 @@ impl Duration { /// let duration = Duration::new(5, 730023852); /// assert_eq!(duration.as_nanos(), 5730023852); /// ``` - #[unstable(feature = "duration_nanos", issue = "50167")] + #[unstable(feature = "duration_nanos", issue = "50202")] #[inline] pub fn as_nanos(&self) -> u128 { self.secs as u128 * NANOS_PER_SEC as u128 + self.nanos as u128 From 99f5136f9e2df5d60b371e9e19d2f6efe0d2e59e Mon Sep 17 00:00:00 2001 From: Jonathan Behrens Date: Sat, 19 May 2018 15:18:07 -0400 Subject: [PATCH 06/12] Add as_micros and as_millis methods --- src/libcore/time.rs | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/libcore/time.rs b/src/libcore/time.rs index f49917f848a07..f43d2db51e72e 100644 --- a/src/libcore/time.rs +++ b/src/libcore/time.rs @@ -263,18 +263,52 @@ impl Duration { #[inline] pub fn subsec_nanos(&self) -> u32 { self.nanos } + /// Returns the total number of milliseconds contained by this `Duration`. + /// + /// # Examples + /// + /// ``` + /// # #![feature(duration_as_u128)] + /// use std::time::Duration; + /// + /// let duration = Duration::new(5, 730023852); + /// assert_eq!(duration.as_millis(), 5730); + /// ``` + #[unstable(feature = "duration_as_u128", issue = "50202")] + #[inline] + pub fn as_millis(&self) -> u128 { + self.secs as u128 * MILLIS_PER_SEC as u128 + self.nanos as u128 / NANOS_PER_MILLI as u128 + } + + /// Returns the total number of microseconds contained by this `Duration`. + /// + /// # Examples + /// + /// ``` + /// # #![feature(duration_as_u128)] + /// use std::time::Duration; + /// + /// let duration = Duration::new(5, 730023852); + /// assert_eq!(duration.as_micros(), 5730023); + /// ``` + #[unstable(feature = "duration_as_u128", issue = "50202")] + #[inline] + pub fn as_micros(&self) -> u128 { + self.secs as u128 * MICROS_PER_SEC as u128 + self.nanos as u128 / NANOS_PER_MICRO as u128 + } + /// Returns the total number of nanoseconds contained by this `Duration`. /// /// # Examples /// /// ``` - /// # #![feature(duration_nanos)] + /// # #![feature(duration_as_u128)] /// use std::time::Duration; /// /// let duration = Duration::new(5, 730023852); /// assert_eq!(duration.as_nanos(), 5730023852); /// ``` - #[unstable(feature = "duration_nanos", issue = "50202")] + #[unstable(feature = "duration_as_u128", issue = "50202")] #[inline] pub fn as_nanos(&self) -> u128 { self.secs as u128 * NANOS_PER_SEC as u128 + self.nanos as u128 From 12878a78a7528dbe5888fe70fd5a0861c820c86a Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 20 May 2018 12:39:13 -0400 Subject: [PATCH 07/12] Provide more context for what the {f32,f64}::EPSILON values represent. --- src/libcore/num/f32.rs | 6 +++++- src/libcore/num/f64.rs | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs index 718dd42a61535..65332d4b97acc 100644 --- a/src/libcore/num/f32.rs +++ b/src/libcore/num/f32.rs @@ -33,7 +33,11 @@ pub const MANTISSA_DIGITS: u32 = 24; #[stable(feature = "rust1", since = "1.0.0")] pub const DIGITS: u32 = 6; -/// Difference between `1.0` and the next largest representable number. +/// [Machine epsilon] value for `f32`. +/// +/// This is the difference between `1.0` and the next largest representable number. +/// +/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon #[stable(feature = "rust1", since = "1.0.0")] pub const EPSILON: f32 = 1.19209290e-07_f32; diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs index f128c55c78afa..c9a643e7b334d 100644 --- a/src/libcore/num/f64.rs +++ b/src/libcore/num/f64.rs @@ -33,7 +33,11 @@ pub const MANTISSA_DIGITS: u32 = 53; #[stable(feature = "rust1", since = "1.0.0")] pub const DIGITS: u32 = 15; -/// Difference between `1.0` and the next largest representable number. +/// [Machine epsilon] value for `f64`. +/// +/// This is the difference between `1.0` and the next largest representable number. +/// +/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon #[stable(feature = "rust1", since = "1.0.0")] pub const EPSILON: f64 = 2.2204460492503131e-16_f64; From fc895665c9a6ba9bc0be7844cb7162797b557a34 Mon Sep 17 00:00:00 2001 From: Jonathan Behrens Date: Mon, 28 May 2018 19:01:50 -0400 Subject: [PATCH 08/12] Avoid 128-bit arithmetic where possible --- src/libcore/time.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcore/time.rs b/src/libcore/time.rs index f43d2db51e72e..72b03cd0965f5 100644 --- a/src/libcore/time.rs +++ b/src/libcore/time.rs @@ -277,7 +277,7 @@ impl Duration { #[unstable(feature = "duration_as_u128", issue = "50202")] #[inline] pub fn as_millis(&self) -> u128 { - self.secs as u128 * MILLIS_PER_SEC as u128 + self.nanos as u128 / NANOS_PER_MILLI as u128 + self.secs as u128 * MILLIS_PER_SEC as u128 + (self.nanos / NANOS_PER_MILLI) as u128 } /// Returns the total number of microseconds contained by this `Duration`. @@ -294,7 +294,7 @@ impl Duration { #[unstable(feature = "duration_as_u128", issue = "50202")] #[inline] pub fn as_micros(&self) -> u128 { - self.secs as u128 * MICROS_PER_SEC as u128 + self.nanos as u128 / NANOS_PER_MICRO as u128 + self.secs as u128 * MICROS_PER_SEC as u128 + (self.nanos / NANOS_PER_MICRO) as u128 } /// Returns the total number of nanoseconds contained by this `Duration`. From 9d770e9959ed5fedad31bfc04f946f5e268cfc37 Mon Sep 17 00:00:00 2001 From: Thayne McCombs Date: Mon, 28 May 2018 20:19:39 -0600 Subject: [PATCH 09/12] Stabilize SliceIndex trait. Fixes #35729 According to recommendations in https://github.com/rust-lang/rust/issues/35729#issuecomment-377784884 --- src/liballoc/lib.rs | 1 - src/liballoc/slice.rs | 2 +- src/libcore/slice/mod.rs | 32 ++++++++++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index 91de3ad0c390b..a56420d52d0d5 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -104,7 +104,6 @@ #![feature(ptr_internals)] #![feature(ptr_offset_from)] #![feature(rustc_attrs)] -#![feature(slice_get_slice)] #![feature(specialization)] #![feature(staged_api)] #![feature(str_internals)] diff --git a/src/liballoc/slice.rs b/src/liballoc/slice.rs index 161493f389226..8686ecd7bcf7b 100644 --- a/src/liballoc/slice.rs +++ b/src/liballoc/slice.rs @@ -121,7 +121,7 @@ pub use core::slice::{RSplit, RSplitMut}; pub use core::slice::{from_raw_parts, from_raw_parts_mut}; #[stable(feature = "from_ref", since = "1.28.0")] pub use core::slice::{from_ref, from_mut}; -#[unstable(feature = "slice_get_slice", issue = "35729")] +#[stable(feature = "slice_get_slice", since = "1.28.0")] pub use core::slice::SliceIndex; #[unstable(feature = "exact_chunks", issue = "47115")] pub use core::slice::{ExactChunks, ExactChunksMut}; diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index d52cc8cbe3f5b..43236c3310411 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -1977,35 +1977,63 @@ fn slice_index_overflow_fail() -> ! { panic!("attempted to index slice up to maximum usize"); } +mod private_slice_index { + use super::ops; + #[stable(feature = "slice_get_slice", since = "1.28.0")] + pub trait Sealed {} + + #[stable(feature = "slice_get_slice", since = "1.28.0")] + impl Sealed for usize {} + #[stable(feature = "slice_get_slice", since = "1.28.0")] + impl Sealed for ops::Range {} + #[stable(feature = "slice_get_slice", since = "1.28.0")] + impl Sealed for ops::RangeTo {} + #[stable(feature = "slice_get_slice", since = "1.28.0")] + impl Sealed for ops::RangeFrom {} + #[stable(feature = "slice_get_slice", since = "1.28.0")] + impl Sealed for ops::RangeFull {} + #[stable(feature = "slice_get_slice", since = "1.28.0")] + impl Sealed for ops::RangeInclusive {} + #[stable(feature = "slice_get_slice", since = "1.28.0")] + impl Sealed for ops::RangeToInclusive {} +} + /// A helper trait used for indexing operations. -#[unstable(feature = "slice_get_slice", issue = "35729")] +#[stable(feature = "slice_get_slice", since = "1.28.0")] #[rustc_on_unimplemented = "slice indices are of type `usize` or ranges of `usize`"] -pub trait SliceIndex { +pub trait SliceIndex: private_slice_index::Sealed { /// The output type returned by methods. + #[stable(feature = "slice_get_slice", since = "1.28.0")] type Output: ?Sized; /// Returns a shared reference to the output at this location, if in /// bounds. + #[unstable(feature = "slice_index_methods", issue = "0")] fn get(self, slice: &T) -> Option<&Self::Output>; /// Returns a mutable reference to the output at this location, if in /// bounds. + #[unstable(feature = "slice_index_methods", issue = "0")] fn get_mut(self, slice: &mut T) -> Option<&mut Self::Output>; /// Returns a shared reference to the output at this location, without /// performing any bounds checking. + #[unstable(feature = "slice_index_methods", issue = "0")] unsafe fn get_unchecked(self, slice: &T) -> &Self::Output; /// Returns a mutable reference to the output at this location, without /// performing any bounds checking. + #[unstable(feature = "slice_index_methods", issue = "0")] unsafe fn get_unchecked_mut(self, slice: &mut T) -> &mut Self::Output; /// Returns a shared reference to the output at this location, panicking /// if out of bounds. + #[unstable(feature = "slice_index_methods", issue = "0")] fn index(self, slice: &T) -> &Self::Output; /// Returns a mutable reference to the output at this location, panicking /// if out of bounds. + #[unstable(feature = "slice_index_methods", issue = "0")] fn index_mut(self, slice: &mut T) -> &mut Self::Output; } From 61b5bd25b528853f1b3064bbba3328a3360e8101 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Mon, 28 May 2018 08:36:14 -0400 Subject: [PATCH 10/12] Reword {ptr,mem}::replace docs. Fixes https://github.com/rust-lang/rust/issues/50657. --- src/libcore/mem.rs | 5 +++-- src/libcore/ptr.rs | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 059c099d66b56..e4e3b1c2a3a39 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -635,8 +635,9 @@ pub fn swap(x: &mut T, y: &mut T) { } } -/// Replaces the value at a mutable location with a new one, returning the old value, without -/// deinitializing either one. +/// Moves `src` into the referenced `dest`, returning the previous `dest` value. +/// +/// Neither value is dropped. /// /// # Examples /// diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 6c0709caa084b..39315d8f0c8f8 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -239,8 +239,9 @@ unsafe fn swap_nonoverlapping_bytes(x: *mut u8, y: *mut u8, len: usize) { } } -/// Replaces the value at `dest` with `src`, returning the old -/// value, without dropping either. +/// Moves `src` into the pointed `dest`, returning the previous `dest` value. +/// +/// Neither value is dropped. /// /// # Safety /// From 562d97d978fbe4cee2fe454c54bda30c1bed7035 Mon Sep 17 00:00:00 2001 From: Jon Purdy Date: Sat, 2 Jun 2018 00:20:00 -0700 Subject: [PATCH 11/12] Fix typos of 'ambiguous' --- src/librustc/traits/project.rs | 8 ++++---- src/librustc/traits/query/normalize.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/librustc/traits/project.rs b/src/librustc/traits/project.rs index c6b1d94e597c3..82f351782bbcd 100644 --- a/src/librustc/traits/project.rs +++ b/src/librustc/traits/project.rs @@ -146,7 +146,7 @@ impl<'tcx> ProjectionTyCandidateSet<'tcx> { // was not used). On other paths, it is not assigned, // and hence if those paths *could* reach the code that // comes after the match, this fn would not compile. - let convert_to_ambigious; + let convert_to_ambiguous; match self { None => { @@ -169,10 +169,10 @@ impl<'tcx> ProjectionTyCandidateSet<'tcx> { // clauses are the safer choice. See the comment on // `select::SelectionCandidate` and #21974 for more details. match (current, candidate) { - (ParamEnv(..), ParamEnv(..)) => convert_to_ambigious = (), + (ParamEnv(..), ParamEnv(..)) => convert_to_ambiguous = (), (ParamEnv(..), _) => return false, (_, ParamEnv(..)) => { unreachable!(); } - (_, _) => convert_to_ambigious = (), + (_, _) => convert_to_ambiguous = (), } } @@ -183,7 +183,7 @@ impl<'tcx> ProjectionTyCandidateSet<'tcx> { // We only ever get here when we moved from a single candidate // to ambiguous. - let () = convert_to_ambigious; + let () = convert_to_ambiguous; *self = Ambiguous; false } diff --git a/src/librustc/traits/query/normalize.rs b/src/librustc/traits/query/normalize.rs index 1e9e9c056c944..f08b95f59fa3d 100644 --- a/src/librustc/traits/query/normalize.rs +++ b/src/librustc/traits/query/normalize.rs @@ -33,7 +33,7 @@ impl<'cx, 'gcx, 'tcx> At<'cx, 'gcx, 'tcx> { /// normalized. If you don't care about regions, you should prefer /// `normalize_erasing_regions`, which is more efficient. /// - /// If the normalization succeeds and is unambigious, returns back + /// If the normalization succeeds and is unambiguous, returns back /// the normalized value along with various outlives relations (in /// the form of obligations that must be discharged). /// From cf24a1df331ae4314245825c4ce668bc74b6d55c Mon Sep 17 00:00:00 2001 From: Mark Simulacrum Date: Sat, 2 Jun 2018 07:50:35 -0600 Subject: [PATCH 12/12] Rustdoc itself no longer requires proc macros to build This avoids a full compiler build in order to build and/or run tests for rustdoc. --- src/bootstrap/test.rs | 3 +-- src/test/rustdoc/rustc-macro-crate.rs | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 9284778679215..c94cb57603206 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -952,8 +952,7 @@ impl Step for Compiletest { if suite.ends_with("fulldeps") || // FIXME: Does pretty need librustc compiled? Note that there are // fulldeps test suites with mode = pretty as well. - mode == "pretty" || - mode == "rustdoc" + mode == "pretty" { builder.ensure(compile::Rustc { compiler, target }); } diff --git a/src/test/rustdoc/rustc-macro-crate.rs b/src/test/rustdoc/rustc-macro-crate.rs index dc28732b55ee2..d46f968441172 100644 --- a/src/test/rustdoc/rustc-macro-crate.rs +++ b/src/test/rustdoc/rustc-macro-crate.rs @@ -9,6 +9,7 @@ // except according to those terms. // no-prefer-dynamic +// ignore-stage1 #![crate_type = "proc-macro"]