-
Provide an idiom for testing exhaustiveness of pattern matches on
Expr
,Type
,Pat
,Item
,ForeignItem
,TraitItem
, andImplItem
(#694)match expr { Expr::Array(e) => {...} Expr::Assign(e) => {...} ... Expr::Yield(e) => {...} #[cfg(test)] Expr::__TestExhaustive(_) => unimplemented!(), #[cfg(not(test))] _ => { /* some sane fallback */ } }
The above is the only supported idiom for exhaustive matching of those enum. Do not write anything differently as it is not supported.
The conditional compilation on match-arms lets us fail your tests but not break your library when adding a variant. You will be notified by a test failure when a variant is added, so that you can add code to handle it, but your library will continue to compile and work for downstream users in the interim.