regex icon indicating copy to clipboard operation
regex copied to clipboard

Use `#[non_exhaustive]` attribute instead of `__Nonexhaustive` enum variant hack

Open rhysd opened this issue 3 years ago • 2 comments

#[non_exhaustive] was added at Rust 1.40. Since MSRV of this project is 1.41.1, the attribute is available. This PR replaces __Nonexhaustive enum variant hack with the attribute.

The benefits to use the attribute are:

  • The attribute is dedicated for this use case. So compiler's error message is better than an error around __Nonexhausitve variant.
  • #[non_exhaustive] allows the exhaustive pattern check at match in the crate where the enum/struct is implemented. This can catch bugs like 31d78a6.

rhysd avatar Jul 15 '22 08:07 rhysd

Hmmm, so I just recently closed a similar PR: https://github.com/rust-lang/regex/pull/781

My reasoning was that I wasn't sure if this was a breaking change or not.

But thinking about it, I cannot think of a way that this would break folks. Obviously, they might be using __Nonexhaustive, but that wasn't part of the public API. Otherwise, I think this change is actually okay?

BurntSushi avatar Jul 15 '22 11:07 BurntSushi

I considered this change may introduce some breaking change just before creating this PR, but I could come up with nothing too. Possibly it may change a data layout of enum or how a compiler optimizes it. But they are not an API change and usually don't break user code.

rhysd avatar Jul 16 '22 02:07 rhysd