Push the decision to skip fields further down

This commit is contained in:
Nadrieril
2024-02-06 02:44:48 +01:00
parent be01e28dce
commit ab06037269
4 changed files with 26 additions and 14 deletions

View File

@@ -82,6 +82,10 @@ use crate::usefulness::{compute_match_usefulness, ValidityConstraint};
pub trait Captures<'a> {}
impl<'a, T: ?Sized> Captures<'a> for T {}
/// `bool` newtype that indicates whether we should skip this field during analysis.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct SkipField(pub bool);
/// Context that provides type information about constructors.
///
/// Most of the crate is parameterized on a type that implements this trait.
@@ -105,13 +109,13 @@ pub trait TypeCx: Sized + fmt::Debug {
/// The number of fields for this constructor.
fn ctor_arity(&self, ctor: &Constructor<Self>, ty: &Self::Ty) -> usize;
/// The types of the fields for this constructor. The result must have a length of
/// `ctor_arity()`.
/// The types of the fields for this constructor. The result must contain `ctor_arity()`-many
/// fields that are not skipped.
fn ctor_sub_tys<'a>(
&'a self,
ctor: &'a Constructor<Self>,
ty: &'a Self::Ty,
) -> impl Iterator<Item = Self::Ty> + ExactSizeIterator + Captures<'a>;
) -> impl Iterator<Item = (Self::Ty, SkipField)> + ExactSizeIterator + Captures<'a>;
/// The set of all the constructors for `ty`.
///