@@ -7,8 +7,7 @@ r[attributes.type-system.non_exhaustive]
77## The ` non_exhaustive ` attribute
88
99r[ attributes.type-system.non_exhaustive.intro]
10- The * ` non_exhaustive ` attribute* indicates that a type or variant may have
11- more fields or variants added in the future.
10+ The * ` non_exhaustive ` attribute* indicates that a type or variant may have more fields or variants added in the future.
1211
1312> [ !EXAMPLE]
1413> The following non-exhaustive definitions will be used in the examples that follow.
@@ -43,8 +42,7 @@ r[attributes.type-system.non_exhaustive.allowed-positions]
4342It can be applied to [`struct `s ][struct ], [`enum `s ][enum ], and `enum ` variants .
4443
4544r [attributes . type - system . non_exhaustive. syntax]
46- The `non_exhaustive ` attribute uses the [MetaWord ] syntax and thus does not
47- take any inputs .
45+ The `non_exhaustive ` attribute uses the [MetaWord ] syntax and thus does not take any inputs .
4846
4947r [attributes . type - system . non_exhaustive. same- crate ]
5048Within the defining crate , `non_exhaustive ` has no effect .
@@ -82,20 +80,13 @@ Within the defining crate, `non_exhaustive` has no effect.
8280
8381
8482r [attributes . type - system . non_exhaustive. external- crate ]
85- Outside of the defining crate , types annotated with `non_exhaustive ` have limitations that
86- preserve backwards compatibility when new fields or variants are added .
83+ Outside of the defining crate , types annotated with `non_exhaustive ` have limitations that preserve backwards compatibility when new fields or variants are added .
8784
8885r [attributes . type - system . non_exhaustive. construction]
8986Non - exhaustive types cannot be constructed outside of the defining crate :
9087
91- - Non - exhaustive variants ([`struct `][struct ] or [`enum ` variant ][enum ]) cannot be constructed
92- with a [StructExpression ] \(including with [functional update syntax ]).
93- - The implicitly defined same - named constant of a [unit - like struct ][struct ],
94- or the same - named constructor function of a [tuple struct ][struct ],
95- has a [visibility ] no greater than `pub (crate )`.
96- That is , if the struct ’s visibility is `pub `, then the constant or constructor ’s visibility
97- is `pub (crate )`, and otherwise the visibility of the two items is the same
98- (as is the case without `#[non_exhaustive]`).
88+ - Non - exhaustive variants ([`struct `][struct ] or [`enum ` variant ][enum ]) cannot be constructed with a [StructExpression ] \(including with [functional update syntax ]).
89+ - The implicitly defined same - named constant of a [unit - like struct ][struct ], or the same - named constructor function of a [tuple struct ][struct ], has a [visibility ] no greater than `pub (crate )`. That is , if the struct ’s visibility is `pub `, then the constant or constructor ’s visibility is `pub (crate )`, and otherwise the visibility of the two items is the same (as is the case without `#[non_exhaustive]`).
9990- [`enum `][enum ] instances can be constructed .
10091
10192> [! EXAMPLE ]
@@ -141,11 +132,8 @@ Non-exhaustive types cannot be constructed outside of the defining crate:
141132r [attributes . type - system . non_exhaustive. match ]
142133There are limitations when matching on non - exhaustive types outside of the defining crate :
143134
144- - When pattern matching on a non - exhaustive variant ([`struct `][struct ] or [`enum ` variant ][enum ]),
145- a [StructPattern ] must be used which must include a `.. `. A tuple enum variant 's constructor 's
146- [visibility ] is reduced to be no greater than `pub (crate )`.
147- - When pattern matching on a non - exhaustive [`enum `][enum ], matching on a variant does not
148- contribute towards the exhaustiveness of the arms .
135+ - When pattern matching on a non - exhaustive variant ([`struct `][struct ] or [`enum ` variant ][enum ]), a [StructPattern ] must be used which must include a `.. `. A tuple enum variant 's constructor 's [visibility ] is reduced to be no greater than `pub (crate )`.
136+ - When pattern matching on a non - exhaustive [`enum `][enum ], matching on a variant does not contribute towards the exhaustiveness of the arms .
149137
150138> [! EXAMPLE ]
151139> Using the definitions from [above ][attributes . type - system . non_exhaustive. intro], the following examples of matching do not compile when outside the defining crate :
0 commit comments