@@ -106,32 +106,32 @@ The implicitly defined same-named constant of a [unit-like struct][struct], or t
106106> // Cannot construct an instance of `Config`; if new fields were added in
107107> // a new version of `upstream` then this would fail to compile, so it is
108108> // disallowed.
109- > let config = Config { window_width : 640 , window_height : 480 };
109+ > let config = Config { window_width : 640 , window_height : 480 }; // ERROR
110110>
111111> // Cannot construct an instance of `Token`; if new fields were added, then
112112> // it would not be a unit-like struct any more, so the same-named constant
113113> // created by it being a unit-like struct is not public outside the crate;
114114> // this code fails to compile.
115- > let token = Token ;
115+ > let token = Token ; // ERROR
116116>
117117> // Cannot construct an instance of `Id`; if new fields were added, then
118118> // its constructor function signature would change, so its constructor
119119> // function is not public outside the crate; this code fails to compile.
120- > let id = Id (5 );
120+ > let id = Id (5 ); // ERROR
121121>
122122> // Can construct an instance of `Error`; new variants being introduced would
123123> // not result in this failing to compile.
124- > let error = Error :: Message (" foo" . to_string ());
124+ > let error = Error :: Message (" foo" . to_string ()); // Ok
125125>
126126> // Cannot construct an instance of `Message::Send` or `Message::Reaction`;
127127> // if new fields were added in a new version of `upstream` then this would
128128> // 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
131131>
132132> // Cannot construct an instance of `Message::Quit`; if this were converted to
133133> // a tuple enum variant `upstream`, this would fail to compile.
134- > let message = Message :: Quit ;
134+ > let message = Message :: Quit ; // ERROR
135135> ```
136136
137137r [attributes . type - system . non_exhaustive. match ]
@@ -149,23 +149,25 @@ Because a tuple enum variant's constructor's [visibility] is reduced to be no gr
149149> use upstream :: {Config , Token , Id , Error , Message };
150150>
151151> // 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
153153> // would compile with: `..`
154154> }
155155>
156156> // Cannot match a non-exhaustive unit-like or tuple struct except by using
157157> // braced struct syntax with a wildcard.
158158> // This would compile as `let Token { .. } = token;`
159- > let upstream :: Token = token ;
159+ > let upstream :: Token = token ; // ERROR
160160> // This would compile as `let Id { 0: id_number, .. } = id;`
161- > let Id (id_number ) = id ;
161+ > let Id (id_number ) = id ; // ERROR
162162>
163163> match message {
164164> // 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
166166> // 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+ > ```
169171
170172r [attributes . type - system . non_exhaustive. enum - exhaustiveness ]
171173When 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