1
Fork 0

Rollup merge of #138001 - meithecatte:privately-uninhabited, r=Nadrieril

mir_build: consider privacy when checking for irrefutable patterns

This PR fixes #137999.

Note that, since this makes the compiler reject code that was previously accepted, it will probably need a crater run.

I include a commit that factors out a common code pattern into a helper function, purely because the fact that this was repeated all over the place was bothering me. Let me know if I should split that into a separate PR instead.
This commit is contained in:
Matthias Krüger 2025-03-19 16:52:54 +01:00 committed by GitHub
commit 2ab69b898a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 121 additions and 50 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,
}
}