1
Fork 0

Fix doc tests

This commit is contained in:
Andrew Cann 2017-11-24 15:36:49 +08:00
parent 31845201e8
commit bd7d541dbd

View file

@ -79,9 +79,12 @@ mod prim_bool { }
/// write /// write
/// ///
/// ``` /// ```
/// # #![feature(never_type)]
/// # fn foo() -> u32 {
/// let x: ! = { /// let x: ! = {
/// return 123; /// return 123
/// }; /// };
/// # }
/// ``` /// ```
/// ///
/// Although the `let` is pointless here, it illustrates the meaning of `!`. Since `x` is never /// 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: /// A more realistic usage of `!` is in this code:
/// ///
/// ``` /// ```
/// # fn get_a_number() -> Option<u32> { None }
/// # loop {
/// let num: u32 = match get_a_number() { /// let num: u32 = match get_a_number() {
/// Some(num) => num, /// Some(num) => num,
/// None => break, /// None => break,
/// } /// };
/// # }
/// ``` /// ```
/// ///
/// Both match arms must produce values of type `u32`, but since `break` never produces a value at /// 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:
/// ///
/// ``` /// ```
/// trait FromStr { /// trait FromStr: Sized {
/// type Error; /// type Err;
/// fn from_str(s: &str) -> Result<Self, Self::Error>; /// 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 `!`. /// 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 /// (Currently the type actually used is an enum with no variants, though this is only because `!`
/// `Result<String, !>`, which we can unpack like this: /// 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"); /// let Ok(s) = String::from_str("hello");
/// ``` /// ```
/// ///
@ -138,6 +146,11 @@ mod prim_bool { }
/// for example: /// for example:
/// ///
/// ``` /// ```
/// # #![feature(never_type)]
/// # use std::fmt;
/// # trait Debug {
/// # fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result;
/// # }
/// impl Debug for ! { /// impl Debug for ! {
/// fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { /// fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
/// *self /// *self