diff options
| author | Andrew Cann <shum@canndrew.org> | 2017-11-24 15:36:49 +0800 |
|---|---|---|
| committer | Andrew Cann <shum@canndrew.org> | 2017-11-24 16:51:00 +0800 |
| commit | bd7d541dbdc2280c49cd0ee148df5f004758c783 (patch) | |
| tree | 27352d922f371df610516f3fbb4168da67b55e2c /src/libstd | |
| parent | 31845201e8dc3af5c7c76506aa83263ffce7c400 (diff) | |
| download | rust-bd7d541dbdc2280c49cd0ee148df5f004758c783.tar.gz rust-bd7d541dbdc2280c49cd0ee148df5f004758c783.zip | |
Fix doc tests
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/primitive_docs.rs | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/src/libstd/primitive_docs.rs b/src/libstd/primitive_docs.rs index 751daac9c48..7c3d9fd8024 100644 --- a/src/libstd/primitive_docs.rs +++ b/src/libstd/primitive_docs.rs @@ -79,9 +79,12 @@ mod prim_bool { } /// write /// /// ``` +/// # #![feature(never_type)] +/// # fn foo() -> u32 { /// let x: ! = { -/// return 123; +/// return 123 /// }; +/// # } /// ``` /// /// Although the `let` is pointless here, it illustrates the meaning of `!`. Since `x` is never @@ -92,10 +95,13 @@ mod prim_bool { } /// A more realistic usage of `!` is in this code: /// /// ``` +/// # fn get_a_number() -> Option<u32> { None } +/// # loop { /// let num: u32 = match get_a_number() { /// Some(num) => num, /// None => break, -/// } +/// }; +/// # } /// ``` /// /// Both match arms must produce values of type `u32`, but since `break` never produces a value at @@ -110,18 +116,20 @@ mod prim_bool { } /// trait: /// /// ``` -/// trait FromStr { -/// type Error; -/// fn from_str(s: &str) -> Result<Self, Self::Error>; +/// trait FromStr: Sized { +/// type Err; +/// fn from_str(s: &str) -> Result<Self, Self::Err>; /// } /// ``` /// -/// When implementing this trait for `String` we need to pick a type for `Error`. And since +/// When implementing this trait for `String` we need to pick a type for `Err`. And since /// converting a string into a string will never result in an error, the appropriate type is `!`. -/// If we have to call `String::from_str` for some reason, the result will be a -/// `Result<String, !>`, which we can unpack like this: +/// (Currently the type actually used is an enum with no variants, though this is only because `!` +/// was added to Rust at a later date and it may change in the future). With an `Err` type of `!`, +/// if we have to call `String::from_str` for some reason the result will be a `Result<String, !>` +/// which we can unpack like this: /// -/// ``` +/// ```ignore (string-from-str-error-type-is-not-never-yet) /// let Ok(s) = String::from_str("hello"); /// ``` /// @@ -138,6 +146,11 @@ mod prim_bool { } /// for example: /// /// ``` +/// # #![feature(never_type)] +/// # use std::fmt; +/// # trait Debug { +/// # fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result; +/// # } /// impl Debug for ! { /// fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { /// *self |
