diff --git a/src/doc/book/error-handling.md b/src/doc/book/error-handling.md index 11086af10bd3d..12cb71973ab25 100644 --- a/src/doc/book/error-handling.md +++ b/src/doc/book/error-handling.md @@ -2019,6 +2019,16 @@ impl Error for CliError { CliError::NotFound => "not found", } } + + fn cause(&self) -> Option<&error::Error> { + match *self { + CliError::Io(ref err) => Some(err), + CliError::Parse(ref err) => Some(err), + // Our custom error doesn't have an underlying cause, but we could + // modify it so that it does. + CliError::NotFound() => None, + } + } } ``` diff --git a/src/doc/book/match.md b/src/doc/book/match.md index acffaf4544b10..1c327c376e203 100644 --- a/src/doc/book/match.md +++ b/src/doc/book/match.md @@ -36,10 +36,10 @@ give us an error: error: non-exhaustive patterns: `_` not covered ``` -Rust is telling us that we forgot a value. The compiler infers from `x` that it -can have any positive 32bit value; for example 1 to 2,147,483,647. The `_` acts +Rust is telling us that we forgot some value. The compiler infers from `x` that it +can have any 32bit integer value; for example -2,147,483,648 to 2,147,483,647. The `_` acts as a 'catch-all', and will catch all possible values that *aren't* specified in -an arm of `match`. As you can see with the previous example, we provide `match` +an arm of `match`. As you can see in the previous example, we provide `match` arms for integers 1-5, if `x` is 6 or any other value, then it is caught by `_`. `match` is also an expression, which means we can use it on the right-hand diff --git a/src/doc/book/primitive-types.md b/src/doc/book/primitive-types.md index 840609d1dd629..8dfbf4ada765f 100644 --- a/src/doc/book/primitive-types.md +++ b/src/doc/book/primitive-types.md @@ -7,7 +7,7 @@ of these ones, as well, but these are the most primitive. # Booleans -Rust has a built in boolean type, named `bool`. It has two values, `true` and `false`: +Rust has a built-in boolean type, named `bool`. It has two values, `true` and `false`: ```rust let x = true; @@ -89,13 +89,13 @@ Unsigned types use a `u` for their category, and signed types use `i`. The `i` is for ‘integer’. So `u8` is an eight-bit unsigned number, and `i8` is an eight-bit signed number. -## Fixed size types +## Fixed-size types -Fixed size types have a specific number of bits in their representation. Valid +Fixed-size types have a specific number of bits in their representation. Valid bit sizes are `8`, `16`, `32`, and `64`. So, `u32` is an unsigned, 32-bit integer, and `i64` is a signed, 64-bit integer. -## Variable sized types +## Variable-size types Rust also provides types whose size depends on the size of a pointer of the underlying machine. These types have ‘size’ as the category, and come in signed diff --git a/src/doc/book/references-and-borrowing.md b/src/doc/book/references-and-borrowing.md index 74983c1255333..a08d53f958ba3 100644 --- a/src/doc/book/references-and-borrowing.md +++ b/src/doc/book/references-and-borrowing.md @@ -212,7 +212,7 @@ fn main() { In other words, the mutable borrow is held through the rest of our example. What we want is for the mutable borrow by `y` to end so that the resource can be -returned to the owner, `x`. `x` can then provide a mutable borrow to `println!`. +returned to the owner, `x`. `x` can then provide a immutable borrow to `println!`. In Rust, borrowing is tied to the scope that the borrow is valid for. And our scopes look like this: diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index 042cbea64bd26..49aa0238a996a 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -14,6 +14,21 @@ //! by the compiler to implement comparison operators. Rust programs may //! implement `PartialOrd` to overload the `<`, `<=`, `>`, and `>=` operators, //! and may implement `PartialEq` to overload the `==` and `!=` operators. +//! +//! # Examples +//! +//! ``` +//! let x: u32 = 0; +//! let y: u32 = 1; +//! +//! // these two lines are equivalent +//! assert_eq!(x < y, true); +//! assert_eq!(x.lt(&y), true); +//! +//! // these two lines are also equivalent +//! assert_eq!(x == y, false); +//! assert_eq!(x.eq(&y), false); +//! ``` #![stable(feature = "rust1", since = "1.0.0")] @@ -44,6 +59,16 @@ use option::Option::{self, Some}; /// only if `a != b`. /// /// This trait can be used with `#[derive]`. +/// +/// # Examples +/// +/// ``` +/// let x: u32 = 0; +/// let y: u32 = 1; +/// +/// assert_eq!(x == y, false); +/// assert_eq!(x.eq(&y), false); +/// ``` #[lang = "eq"] #[stable(feature = "rust1", since = "1.0.0")] pub trait PartialEq { @@ -226,6 +251,16 @@ impl PartialOrd for Ordering { /// /// This trait can be used with `#[derive]`. When `derive`d, it will produce an ordering /// based on the top-to-bottom declaration order of the struct's members. +/// +/// # Examples +/// +/// ``` +/// let x : u32 = 0; +/// let y : u32 = 1; +/// +/// assert_eq!(x < y, true); +/// assert_eq!(x.lt(&y), true); +/// ``` #[lang = "ord"] #[stable(feature = "rust1", since = "1.0.0")] pub trait PartialOrd: PartialEq { diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 19cfc13ea615c..300868721e3ab 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -3167,8 +3167,8 @@ x <<= 2; To fix this error, please check that this type implements this binary operation. Example: -```compile_fail -let x = 12u32; // the `u32` type does implement the `ShlAssign` trait +``` +let mut x = 12u32; // the `u32` type does implement the `ShlAssign` trait x <<= 2; // ok! ```