]> git.proxmox.com Git - rustc.git/blob - src/librustc_error_codes/error_codes/E0638.md
New upstream version 1.41.1+dfsg1
[rustc.git] / src / librustc_error_codes / error_codes / E0638.md
1 This error indicates that the struct, enum or enum variant must be matched
2 non-exhaustively as it has been marked as `non_exhaustive`.
3
4 When applied within a crate, downstream users of the crate will need to use the
5 `_` pattern when matching enums and use the `..` pattern when matching structs.
6 Downstream crates cannot match against non-exhaustive enum variants.
7
8 For example, in the below example, since the enum is marked as
9 `non_exhaustive`, it is required that downstream crates match non-exhaustively
10 on it.
11
12 ```rust,ignore (pseudo-Rust)
13 use std::error::Error as StdError;
14
15 #[non_exhaustive] pub enum Error {
16 Message(String),
17 Other,
18 }
19
20 impl StdError for Error {
21 fn description(&self) -> &str {
22 // This will not error, despite being marked as non_exhaustive, as this
23 // enum is defined within the current crate, it can be matched
24 // exhaustively.
25 match *self {
26 Message(ref s) => s,
27 Other => "other or unknown error",
28 }
29 }
30 }
31 ```
32
33 An example of matching non-exhaustively on the above enum is provided below:
34
35 ```rust,ignore (pseudo-Rust)
36 use mycrate::Error;
37
38 // This will not error as the non_exhaustive Error enum has been matched with a
39 // wildcard.
40 match error {
41 Message(ref s) => ...,
42 Other => ...,
43 _ => ...,
44 }
45 ```
46
47 Similarly, for structs, match with `..` to avoid this error.