@@ -87,6 +87,7 @@ ast_enum_of_structs! {
87
87
/// see names getting repeated in your code, like accessing
88
88
/// `receiver.receiver` or `pat.pat` or `cond.cond`.
89
89
#[ cfg_attr( doc_cfg, doc( cfg( any( feature = "full" , feature = "derive" ) ) ) ) ]
90
+ #[ cfg_attr( not( syn_no_non_exhaustive) , non_exhaustive) ]
90
91
pub enum Expr {
91
92
/// A slice literal expression: `[a, b, c, d]`.
92
93
Array ( ExprArray ) ,
@@ -224,31 +225,27 @@ ast_enum_of_structs! {
224
225
/// A yield expression: `yield expr`.
225
226
Yield ( ExprYield ) ,
226
227
227
- // The following is the only supported idiom for exhaustive matching of
228
- // this enum.
228
+ // Not public API.
229
+ //
230
+ // For testing exhaustiveness in downstream code, use the following idiom:
229
231
//
230
232
// match expr {
231
233
// Expr::Array(expr) => {...}
232
234
// Expr::Assign(expr) => {...}
233
235
// ...
234
236
// Expr::Yield(expr) => {...}
235
237
//
236
- // #[cfg(test)]
237
- // Expr::__TestExhaustive(_) => unimplemented!(),
238
- // #[cfg(not(test))]
238
+ // #[cfg_attr(test, deny(non_exhaustive_omitted_patterns))]
239
239
// _ => { /* some sane fallback */ }
240
240
// }
241
241
//
242
242
// This way we fail your tests but don't break your library when adding
243
243
// a variant. You will be notified by a test failure when a variant is
244
244
// added, so that you can add code to handle it, but your library will
245
245
// continue to compile and work for downstream users in the interim.
246
- //
247
- // Once `deny(reachable)` is available in rustc, Expr will be
248
- // reimplemented as a non_exhaustive enum.
249
- // https://github.com/rust-lang/rust/issues/44109#issuecomment-521781237
246
+ #[ cfg( syn_no_non_exhaustive) ]
250
247
#[ doc( hidden) ]
251
- __TestExhaustive ( crate :: private ) ,
248
+ __NonExhaustive ,
252
249
}
253
250
}
254
251
@@ -838,9 +835,7 @@ impl Expr {
838
835
| Expr :: Yield ( ExprYield { attrs, .. } ) => mem:: replace ( attrs, new) ,
839
836
Expr :: Verbatim ( _) => Vec :: new ( ) ,
840
837
841
- #[ cfg( test) ]
842
- Expr :: __TestExhaustive( _) => unimplemented ! ( ) ,
843
- #[ cfg( not( test) ) ]
838
+ #[ cfg( syn_no_non_exhaustive) ]
844
839
_ => unreachable ! ( ) ,
845
840
}
846
841
}
@@ -2510,9 +2505,7 @@ pub(crate) mod parsing {
2510
2505
Pat :: Verbatim ( _) => { }
2511
2506
Pat :: Wild ( pat) => pat. attrs = attrs,
2512
2507
2513
- #[ cfg( test) ]
2514
- Pat :: __TestExhaustive( _) => unimplemented ! ( ) ,
2515
- #[ cfg( not( test) ) ]
2508
+ #[ cfg( syn_no_non_exhaustive) ]
2516
2509
_ => unreachable ! ( ) ,
2517
2510
}
2518
2511
Ok ( pat)
0 commit comments