Tracking issue: #44019
Version target: TBD
As per the stabilization guide, I'd like to propose stabilizing #[non_exhaustive]
:
cc @rust-lang/lang
The non_exhaustive
attribute is used to indicate that a type will have
more fields/variants added in the future. It can be applied to
structs, enums and enum variants.
Within the defining crate, types annotated with non_exhaustive
behave exactly
the same as if the type were not annotated with non_exhaustive
:
In downstream crates, types annotated with non_exhaustive
have limitations that
preserve backwards compatibility when new fields/variants are added.
Non-exhaustive types cannot be constructed in downstream crates:
Non-exhaustive types cannot be used in a match
/if let
expression without a
wildcard arm:
Non-exhaustive types are always considered inhabited in downstream crates.
N/A
It is not specified in the RFC what the inhabitedness of non-exhaustive types used extern
crates should be. Since #60529, non-exhaustive types are always considered inhabited in
extern crates.
The tests are all in src/test/ui/rfc-2008-non-exhaustive
. Here are some of them:
See RFC 2008.
#[non_exhaustive]
in rust-lang-nursery/reference#609 by @davidtwco#[non_exhaustive]
in rust-lang/book#1955 by @davidtwco