X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustc_error_codes%2Ferror_codes%2FE0638.md;h=14cd31502b670f69d09200ad3157c11fdaa417f6;hb=4646a88b7a1e68326d092b9cbbbbdd616a51077f;hp=29b7586b07b4454c0b5e33e60c058214dcc0e445;hpb=9860a4eeb7e555b3a137b2aa0cde818d44a608dc;p=rust.git diff --git a/src/librustc_error_codes/error_codes/E0638.md b/src/librustc_error_codes/error_codes/E0638.md index 29b7586b07b..14cd31502b6 100644 --- a/src/librustc_error_codes/error_codes/E0638.md +++ b/src/librustc_error_codes/error_codes/E0638.md @@ -10,23 +10,23 @@ For example, in the below example, since the enum is marked as on it. ```rust,ignore (pseudo-Rust) -use std::error::Error as StdError; - -#[non_exhaustive] pub enum Error { - Message(String), - Other, +#[non_exhaustive] +pub enum Error { + Message(String), + Other, } -impl StdError for Error { - fn description(&self) -> &str { +impl Display for Error { + fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { // This will not error, despite being marked as non_exhaustive, as this // enum is defined within the current crate, it can be matched // exhaustively. - match *self { - Message(ref s) => s, - Other => "other or unknown error", - } - } + let display = match self { + Message(s) => s, + Other => "other or unknown error", + }; + formatter.write_str(display) + } } ``` @@ -38,9 +38,9 @@ use mycrate::Error; // This will not error as the non_exhaustive Error enum has been matched with a // wildcard. match error { - Message(ref s) => ..., - Other => ..., - _ => ..., + Message(s) => ..., + Other => ..., + _ => ..., } ```