Add helper methods checking for "#[non_exhaustive] that's active"

A check for `#[non_exhaustive]` is often done in combination with
checking whether the type is local to the crate, in a variety of ways.
Create a helper method and standardize on it as the way to check for
this.
This commit is contained in:
Maja Kądziołka 2025-03-03 12:54:26 +01:00
parent 59a9b9e9d7
commit 61f70003c2
No known key found for this signature in database
15 changed files with 46 additions and 46 deletions

View file

@ -150,9 +150,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
/// Returns whether the given type is an enum from another crate declared `#[non_exhaustive]`.
pub fn is_foreign_non_exhaustive_enum(&self, ty: RevealedTy<'tcx>) -> bool {
match ty.kind() {
ty::Adt(def, ..) => {
def.is_enum() && def.is_variant_list_non_exhaustive() && !def.did().is_local()
}
ty::Adt(def, ..) => def.variant_list_has_applicable_non_exhaustive(),
_ => false,
}
}