@@ -72,10 +72,12 @@ Non-exhaustive types cannot be constructed outside of the defining crate:
72
72
73
73
- Non-exhaustive variants ([ ` struct ` ] [ struct ] or [ ` enum ` variant] [ enum ] ) cannot be constructed
74
74
with a [ _ StructExpression_ ] \( including with [ functional update syntax] ).
75
- - The visibility of the same-named constant of a [ unit-like struct] [ struct ]
76
- is lowered to ` min($vis, pub(crate)) ` .
77
- - The visibility of the same-named constructor function of a [ tuple struct] [ struct ]
78
- is lowered to ` min($vis, pub(crate)) ` .
75
+ - The implicitly defined same-named constant of a [ unit-like struct] [ struct ] ,
76
+ or the same-named constructor function of a [ tuple struct] [ struct ] ,
77
+ has a [ visibility] no greater than ` pub(crate) ` .
78
+ That is, if the struct’s visibility is ` pub ` , then the constant or constructor’s visibility
79
+ is ` pub(crate) ` , and otherwise the visibility of the two items is the same
80
+ (as is the case without ` #[non_exhaustive] ` ).
79
81
- [ ` enum ` ] [ enum ] instances can be constructed.
80
82
81
83
The following examples of construction do not compile when outside the defining crate:
@@ -120,8 +122,8 @@ let message = Message::Quit;
120
122
There are limitations when matching on non-exhaustive types outside of the defining crate:
121
123
122
124
- When pattern matching on a non-exhaustive variant ([ ` struct ` ] [ struct ] or [ ` enum ` variant] [ enum ] ),
123
- a [ _ StructPattern_ ] must be used which must include a ` .. ` . Tuple variant constructor visibility
124
- is lowered to ` min($vis, pub(crate) )` .
125
+ a [ _ StructPattern_ ] must be used which must include a ` .. ` . A tuple variant's constructor's
126
+ [ visibility ] is reduced to be no greater than ` pub(crate) ` .
125
127
- When pattern matching on a non-exhaustive [ ` enum ` ] [ enum ] , matching on a variant does not
126
128
contribute towards the exhaustiveness of the arms.
127
129
@@ -181,3 +183,4 @@ Non-exhaustive types are always considered inhabited in downstream crates.
181
183
[ enum ] : ../items/enumerations.md
182
184
[ functional update syntax ] : ../expressions/struct-expr.md#functional-update-syntax
183
185
[ struct ] : ../items/structs.md
186
+ [ visibility ] : ../visibility-and-privacy.md
0 commit comments