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:
commit
2ab69b898a
17 changed files with 121 additions and 50 deletions
|
@ -327,11 +327,22 @@ impl<'tcx> AdtDef<'tcx> {
|
|||
}
|
||||
|
||||
/// Returns `true` if the variant list of this ADT is `#[non_exhaustive]`.
|
||||
///
|
||||
/// Note that this function will return `true` even if the ADT has been
|
||||
/// defined in the crate currently being compiled. If that's not what you
|
||||
/// want, see [`Self::variant_list_has_applicable_non_exhaustive`].
|
||||
#[inline]
|
||||
pub fn is_variant_list_non_exhaustive(self) -> bool {
|
||||
self.flags().contains(AdtFlags::IS_VARIANT_LIST_NON_EXHAUSTIVE)
|
||||
}
|
||||
|
||||
/// Returns `true` if the variant list of this ADT is `#[non_exhaustive]`
|
||||
/// and has been defined in another crate.
|
||||
#[inline]
|
||||
pub fn variant_list_has_applicable_non_exhaustive(self) -> bool {
|
||||
self.is_variant_list_non_exhaustive() && !self.did().is_local()
|
||||
}
|
||||
|
||||
/// Returns the kind of the ADT.
|
||||
#[inline]
|
||||
pub fn adt_kind(self) -> AdtKind {
|
||||
|
|
|
@ -107,7 +107,7 @@ impl<'tcx> Ty<'tcx> {
|
|||
// For now, unions are always considered inhabited
|
||||
Adt(adt, _) if adt.is_union() => InhabitedPredicate::True,
|
||||
// Non-exhaustive ADTs from other crates are always considered inhabited
|
||||
Adt(adt, _) if adt.is_variant_list_non_exhaustive() && !adt.did().is_local() => {
|
||||
Adt(adt, _) if adt.variant_list_has_applicable_non_exhaustive() => {
|
||||
InhabitedPredicate::True
|
||||
}
|
||||
Never => InhabitedPredicate::False,
|
||||
|
|
|
@ -1208,12 +1208,23 @@ impl VariantDef {
|
|||
}
|
||||
}
|
||||
|
||||
/// Is this field list non-exhaustive?
|
||||
/// Returns `true` if the field list of this variant is `#[non_exhaustive]`.
|
||||
///
|
||||
/// Note that this function will return `true` even if the type has been
|
||||
/// defined in the crate currently being compiled. If that's not what you
|
||||
/// want, see [`Self::field_list_has_applicable_non_exhaustive`].
|
||||
#[inline]
|
||||
pub fn is_field_list_non_exhaustive(&self) -> bool {
|
||||
self.flags.intersects(VariantFlags::IS_FIELD_LIST_NON_EXHAUSTIVE)
|
||||
}
|
||||
|
||||
/// Returns `true` if the field list of this variant is `#[non_exhaustive]`
|
||||
/// and the type has been defined in another crate.
|
||||
#[inline]
|
||||
pub fn field_list_has_applicable_non_exhaustive(&self) -> bool {
|
||||
self.is_field_list_non_exhaustive() && !self.def_id.is_local()
|
||||
}
|
||||
|
||||
/// Computes the `Ident` of this variant by looking up the `Span`
|
||||
pub fn ident(&self, tcx: TyCtxt<'_>) -> Ident {
|
||||
Ident::new(self.name, tcx.def_ident_span(self.def_id).unwrap())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue