@@ -106,32 +106,32 @@ The implicitly defined same-named constant of a [unit-like struct][struct], or t
106
106
> // Cannot construct an instance of `Config`; if new fields were added in
107
107
> // a new version of `upstream` then this would fail to compile, so it is
108
108
> // disallowed.
109
- > let config = Config { window_width : 640 , window_height : 480 };
109
+ > let config = Config { window_width : 640 , window_height : 480 }; // ERROR
110
110
>
111
111
> // Cannot construct an instance of `Token`; if new fields were added, then
112
112
> // it would not be a unit-like struct any more, so the same-named constant
113
113
> // created by it being a unit-like struct is not public outside the crate;
114
114
> // this code fails to compile.
115
- > let token = Token ;
115
+ > let token = Token ; // ERROR
116
116
>
117
117
> // Cannot construct an instance of `Id`; if new fields were added, then
118
118
> // its constructor function signature would change, so its constructor
119
119
> // function is not public outside the crate; this code fails to compile.
120
- > let id = Id (5 );
120
+ > let id = Id (5 ); // ERROR
121
121
>
122
122
> // Can construct an instance of `Error`; new variants being introduced would
123
123
> // not result in this failing to compile.
124
- > let error = Error :: Message (" foo" . to_string ());
124
+ > let error = Error :: Message (" foo" . to_string ()); // Ok
125
125
>
126
126
> // Cannot construct an instance of `Message::Send` or `Message::Reaction`;
127
127
> // if new fields were added in a new version of `upstream` then this would
128
128
> // fail to compile, so it is disallowed.
129
- > let message = Message :: Send { from : 0 , to : 1 , contents : " foo" . to_string (), };
130
- > let message = Message :: Reaction (0 );
129
+ > let message = Message :: Send { from : 0 , to : 1 , contents : " foo" . to_string () }; // ERROR
130
+ > let message = Message :: Reaction (0 ); // ERROR
131
131
>
132
132
> // Cannot construct an instance of `Message::Quit`; if this were converted to
133
133
> // a tuple-variant `upstream` then this would fail to compile.
134
- > let message = Message :: Quit ;
134
+ > let message = Message :: Quit ; // ERROR
135
135
> ```
136
136
137
137
r [attributes . type - system . non_exhaustive. match ]
@@ -149,23 +149,25 @@ Because a tuple variant's constructor's [visibility] is reduced to be no greater
149
149
> use upstream :: {Config , Token , Id , Error , Message };
150
150
>
151
151
> // Cannot match on a non-exhaustive struct without a wildcard.
152
- > if let Ok (Config { window_width , window_height }) = config {
152
+ > if let Ok (Config { window_width , window_height }) = config { // ERROR: `..` required
153
153
> // would compile with: `..`
154
154
> }
155
155
>
156
156
> // Cannot match a non-exhaustive unit-like or tuple struct except by using
157
157
> // braced struct syntax with a wildcard.
158
158
> // This would compile as `let Token { .. } = token;`
159
- > let upstream :: Token = token ;
159
+ > let upstream :: Token = token ; // ERROR
160
160
> // This would compile as `let Id { 0: id_number, .. } = id;`
161
- > let Id (id_number ) = id ;
161
+ > let Id (id_number ) = id ; // ERROR
162
162
>
163
163
> match message {
164
164
> // Cannot match on a non-exhaustive struct enum variant without including a wildcard.
165
- > Message :: Send { from , to , contents } => { },
165
+ > Message :: Send { from , to , contents } => { }, // ERROR: `..` required
166
166
> // Cannot match on a non-exhaustive tuple or unit enum variant.
167
- > Message :: Quit => { },
168
- > Message :: Reaction (x ) => { },
167
+ > Message :: Reaction (x ) => { }, // ERROR
168
+ > Message :: Quit => { }, // ERROR
169
+ > }
170
+ > ```
169
171
170
172
r [attributes . type - system . non_exhaustive. enum - exhaustiveness ]
171
173
When using a [`match ` expression ][expr . match ] on a non - exhaustive [`enum `][enum ] from an external crate , matching on a variant does not contribute towards the exhaustiveness of the arms . A [`_ ` wildcard ][patterns . wildcard] arm is needed to make the match exhaustive .
0 commit comments