Skip to content

Commit 1893841

Browse files
committed
Update documentation.
This commit updates the unstable book and diagnostics to reflect that the `#[non_exhaustive]` attribute is now available for enum variants.
1 parent 3a88cd7 commit 1893841

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/doc/unstable-book/src/language-features/non-exhaustive.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ The tracking issue for this feature is: [#44109]
77
------------------------
88

99
The `non_exhaustive` gate allows you to use the `#[non_exhaustive]` attribute
10-
on structs and enums. When applied within a crate, users of the crate will need
11-
to use the `_` pattern when matching enums and use the `..` pattern when
12-
matching structs. Structs marked as `non_exhaustive` will not be able to be
13-
created normally outside of the defining crate. This is demonstrated below:
10+
on structs, enums and enum variants. When applied within a crate, users of the
11+
crate will need to use the `_` pattern when matching enums and use the `..`
12+
pattern when matching structs. Enum variants cannot be matched against.
13+
Structs and enum variants marked as `non_exhaustive` will not be able to
14+
be created normally outside of the defining crate. This is demonstrated
15+
below:
1416

1517
```rust,ignore (pseudo-Rust)
1618
use std::error::Error as StdError;
@@ -72,4 +74,3 @@ let config = Config { window_width: 640, window_height: 480 };
7274
// when marked non_exhaustive.
7375
let &Config { window_width, window_height, .. } = config;
7476
```
75-

src/librustc_typeck/diagnostics.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -4341,11 +4341,12 @@ foo.method(); // Ok!
43414341
"##,
43424342

43434343
E0638: r##"
4344-
This error indicates that the struct or enum must be matched non-exhaustively
4345-
as it has been marked as `non_exhaustive`.
4344+
This error indicates that the struct, enum or enum variant must be matched
4345+
non-exhaustively as it has been marked as `non_exhaustive`.
43464346
43474347
When applied within a crate, downstream users of the crate will need to use the
43484348
`_` pattern when matching enums and use the `..` pattern when matching structs.
4349+
Downstream crates cannot match against non-exhaustive enum variants.
43494350
43504351
For example, in the below example, since the enum is marked as
43514352
`non_exhaustive`, it is required that downstream crates match non-exhaustively
@@ -4390,10 +4391,10 @@ Similarly, for structs, match with `..` to avoid this error.
43904391
"##,
43914392

43924393
E0639: r##"
4393-
This error indicates that the struct or enum cannot be instantiated from
4394-
outside of the defining crate as it has been marked as `non_exhaustive` and as
4395-
such more fields/variants may be added in future that could cause adverse side
4396-
effects for this code.
4394+
This error indicates that the struct, enum or enum variant cannot be
4395+
instantiated from outside of the defining crate as it has been marked
4396+
as `non_exhaustive` and as such more fields/variants may be added in
4397+
future that could cause adverse side effects for this code.
43974398
43984399
It is recommended that you look for a `new` function or equivalent in the
43994400
crate's documentation.

0 commit comments

Comments
 (0)