diff options
| author | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2016-06-30 07:39:32 +0000 |
|---|---|---|
| committer | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2016-06-30 07:39:32 +0000 |
| commit | a8751e077f32c4da4787986d9a93ca7645e7df95 (patch) | |
| tree | 1c007cf2b5f602bb7cfc104bdac157370fd08700 /src/libstd | |
| parent | bd7a3639a89e032bb28493b823c62c8abf751f65 (diff) | |
| parent | 3c29fc5f6cd69b1299cf5482a6bc991ba6b86a0f (diff) | |
| download | rust-a8751e077f32c4da4787986d9a93ca7645e7df95.tar.gz rust-a8751e077f32c4da4787986d9a93ca7645e7df95.zip | |
Rollup merge of #34547 - sanxiyn:pretty-lifetime, r=pnkfelix
Fix pretty-printing of lifetime bound Fix #34527.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/io/util.rs | 29 | ||||
| -rw-r--r-- | src/libstd/num/f32.rs | 18 | ||||
| -rw-r--r-- | src/libstd/num/f64.rs | 20 | ||||
| -rw-r--r-- | src/libstd/path.rs | 20 | ||||
| -rw-r--r-- | src/libstd/primitive_docs.rs | 6 | ||||
| -rw-r--r-- | src/libstd/thread/mod.rs | 13 |
6 files changed, 76 insertions, 30 deletions
diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs index 2815c0163d6..07f43f72ff5 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -78,14 +78,11 @@ pub struct Empty { _priv: () } /// A slightly sad example of not reading anything into a buffer: /// /// ``` -/// use std::io; -/// use std::io::Read; +/// use std::io::{self, Read}; /// -/// # fn foo() -> io::Result<String> { /// let mut buffer = String::new(); -/// try!(io::empty().read_to_string(&mut buffer)); -/// # Ok(buffer) -/// # } +/// io::empty().read_to_string(&mut buffer).unwrap(); +/// assert!(buffer.is_empty()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn empty() -> Empty { Empty { _priv: () } } @@ -113,6 +110,16 @@ pub struct Repeat { byte: u8 } /// /// All reads from this reader will succeed by filling the specified buffer with /// the given byte. +/// +/// # Examples +/// +/// ``` +/// use std::io::{self, Read}; +/// +/// let mut buffer = [0; 3]; +/// io::repeat(0b101).read_exact(&mut buffer).unwrap(); +/// assert_eq!(buffer, [0b101, 0b101, 0b101]); +/// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn repeat(byte: u8) -> Repeat { Repeat { byte: byte } } @@ -139,6 +146,16 @@ pub struct Sink { _priv: () } /// /// All calls to `write` on the returned instance will return `Ok(buf.len())` /// and the contents of the buffer will not be inspected. +/// +/// # Examples +/// +/// ```rust +/// use std::io::{self, Write}; +/// +/// let mut buffer = vec![1, 2, 3, 5, 8]; +/// let num_bytes = io::sink().write(&mut buffer).unwrap(); +/// assert_eq!(num_bytes, 5); +/// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn sink() -> Sink { Sink { _priv: () } } diff --git a/src/libstd/num/f32.rs b/src/libstd/num/f32.rs index ff80a4e3053..17d412411c0 100644 --- a/src/libstd/num/f32.rs +++ b/src/libstd/num/f32.rs @@ -217,7 +217,7 @@ impl f32 { /// // Values between `0` and `min` are Subnormal. /// assert!(!lower_than_min.is_normal()); /// ``` - /// [subnormal]: http://en.wikipedia.org/wiki/Denormal_number + /// [subnormal]: https://en.wikipedia.org/wiki/Denormal_number #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn is_normal(self) -> bool { num::Float::is_normal(self) } @@ -923,12 +923,12 @@ impl f32 { /// Computes the tangent of a number (in radians). /// /// ``` - /// use std::f64; + /// use std::f32; /// - /// let x = f64::consts::PI/4.0; + /// let x = f32::consts::PI / 4.0; /// let abs_difference = (x.tan() - 1.0).abs(); /// - /// assert!(abs_difference < 1e-10); + /// assert!(abs_difference <= f32::EPSILON); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] @@ -1052,12 +1052,14 @@ impl f32 { /// number is close to zero. /// /// ``` - /// let x = 7.0f64; + /// use std::f32; /// - /// // e^(ln(7)) - 1 - /// let abs_difference = (x.ln().exp_m1() - 6.0).abs(); + /// let x = 6.0f32; /// - /// assert!(abs_difference < 1e-10); + /// // e^(ln(6)) - 1 + /// let abs_difference = (x.ln().exp_m1() - 5.0).abs(); + /// + /// assert!(abs_difference <= f32::EPSILON); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] diff --git a/src/libstd/num/f64.rs b/src/libstd/num/f64.rs index b7750317870..70b7706535c 100644 --- a/src/libstd/num/f64.rs +++ b/src/libstd/num/f64.rs @@ -147,23 +147,23 @@ impl f64 { /// [subnormal][subnormal], or `NaN`. /// /// ``` - /// use std::f32; + /// use std::f64; /// - /// let min = f32::MIN_POSITIVE; // 1.17549435e-38f64 - /// let max = f32::MAX; - /// let lower_than_min = 1.0e-40_f32; - /// let zero = 0.0f32; + /// let min = f64::MIN_POSITIVE; // 2.2250738585072014e-308f64 + /// let max = f64::MAX; + /// let lower_than_min = 1.0e-308_f64; + /// let zero = 0.0f64; /// /// assert!(min.is_normal()); /// assert!(max.is_normal()); /// /// assert!(!zero.is_normal()); - /// assert!(!f32::NAN.is_normal()); - /// assert!(!f32::INFINITY.is_normal()); + /// assert!(!f64::NAN.is_normal()); + /// assert!(!f64::INFINITY.is_normal()); /// // Values between `0` and `min` are Subnormal. /// assert!(!lower_than_min.is_normal()); /// ``` - /// [subnormal]: http://en.wikipedia.org/wiki/Denormal_number + /// [subnormal]: https://en.wikipedia.org/wiki/Denormal_number #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn is_normal(self) -> bool { num::Float::is_normal(self) } @@ -655,9 +655,9 @@ impl f64 { /// ``` /// #![feature(float_extras)] /// - /// let x = 1.0f32; + /// let x = 1.0f64; /// - /// let abs_diff = (x.next_after(2.0) - 1.00000011920928955078125_f32).abs(); + /// let abs_diff = (x.next_after(2.0) - 1.0000000000000002220446049250313_f64).abs(); /// /// assert!(abs_diff < 1e-10); /// ``` diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 8dc46239f3d..c103ff7f4b0 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -525,6 +525,26 @@ impl<'a> Hash for PrefixComponent<'a> { /// /// See the module documentation for an in-depth explanation of components and /// their role in the API. +/// +/// This `enum` is created from iterating over the [`path::Components`] +/// `struct`. +/// +/// # Examples +/// +/// ```rust +/// use std::path::{Component, Path}; +/// +/// let path = Path::new("/tmp/foo/bar.txt"); +/// let components = path.components().collect::<Vec<_>>(); +/// assert_eq!(&components, &[ +/// Component::RootDir, +/// Component::Normal("tmp".as_ref()), +/// Component::Normal("foo".as_ref()), +/// Component::Normal("bar.txt".as_ref()), +/// ]); +/// ``` +/// +/// [`path::Components`]: struct.Components.html #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] #[stable(feature = "rust1", since = "1.0.0")] pub enum Component<'a> { diff --git a/src/libstd/primitive_docs.rs b/src/libstd/primitive_docs.rs index 11af768c5b9..be9cd6a6888 100644 --- a/src/libstd/primitive_docs.rs +++ b/src/libstd/primitive_docs.rs @@ -490,9 +490,6 @@ mod prim_tuple { } /// /// *[See also the `std::f32` module](f32/index.html).* /// -/// However, please note that examples are shared between the `f64` and `f32` -/// primitive types. So it's normal if you see usage of `f64` in there. -/// mod prim_f32 { } #[doc(primitive = "f64")] @@ -501,9 +498,6 @@ mod prim_f32 { } /// /// *[See also the `std::f64` module](f64/index.html).* /// -/// However, please note that examples are shared between the `f64` and `f32` -/// primitive types. So it's normal if you see usage of `f32` in there. -/// mod prim_f64 { } #[doc(primitive = "i8")] diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 3bee878de35..e9736fea7b3 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -394,6 +394,19 @@ pub fn sleep_ms(ms: u32) { /// signal being received or a spurious wakeup. Platforms which do not support /// nanosecond precision for sleeping will have `dur` rounded up to the nearest /// granularity of time they can sleep for. +/// +/// # Examples +/// +/// ```rust,no_run +/// use std::{thread, time}; +/// +/// let ten_millis = time::Duration::from_millis(10); +/// let now = time::Instant::now(); +/// +/// thread::sleep(ten_millis); +/// +/// assert!(now.elapsed() >= ten_millis); +/// ``` #[stable(feature = "thread_sleep", since = "1.4.0")] pub fn sleep(dur: Duration) { imp::Thread::sleep(dur) |
