Expand description

The non_exhaustive_omitted_patterns lint detects when a wildcard (_ or ..) in a pattern for a #[non_exhaustive] struct or enum is reachable.


// crate A
pub enum Bar {
    B, // added variant in non breaking change

// in crate B

match Bar::A {
    Bar::A => {},
    _ => {},

This will produce:

warning: reachable patterns not covered of non exhaustive enum
   --> $DIR/
LL |         _ => {}
   |         ^ pattern `B` not covered
 note: the lint level is defined here
  --> $DIR/
LL |         #[warn(non_exhaustive_omitted_patterns)]
   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = help: ensure that all possible cases are being handled by adding the suggested match arms
   = note: the matched value is of type `Bar` and the `non_exhaustive_omitted_patterns` attribute was found


Structs and enums tagged with #[non_exhaustive] force the user to add a (potentially redundant) wildcard when pattern-matching, to allow for future addition of fields or variants. The non_exhaustive_omitted_patterns lint detects when such a wildcard happens to actually catch some fields/variants. In other words, when the match without the wildcard would not be exhaustive. This lets the user be informed if new fields/variants were added.