Description
syn currently allows users to opt into having their tests fail if a match of one of the enums it defines is non-exhaustive:
match expr {
Expr::Array(e) => {...}
Expr::Assign(e) => {...}
...
Expr::Yield(e) => {...}
#[cfg(test)]
Expr::__TestExhaustive(_) => unimplemented!(),
#[cfg(not(test))]
_ => { /* some sane fallback */ }
}
In the tracking issue for the #[non_exhaustive]
attribute, it was discussed to allow this in a less hacky way, for truly non-exhaustive enums, with dtolnay suggesting a lint (#44109 (comment)) like this:
match expr {
Expr::Array(e) => {...}
Expr::Assign(e) => {...}
...
Expr::Yield(e) => {...}
#[cfg_attr(test, deny(reachable))]
_ => { /* some sane fallback */ }
}
Later, a clippy issue was opened about the same thing and a PR opened to address it. However, that PR was closed because
the thing is that rustc already has exhaustiveness checks, and this is a lint that was proposed in a Rust RFC, so it would both be easy to implement in rustc and make sense. It feels weird to reimplement exhaustiveness checking in a partial way outside of rustc when we can have a perfect version of this lint in rustc.