Skip to content

Commit

Permalink
Separate PlaceCtxt from UsefulnessCtxt
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Jan 25, 2024
1 parent d6bd64a commit 28b6471
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions compiler/rustc_pattern_analysis/src/usefulness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,28 +741,28 @@ pub struct UsefulnessCtxt<'a, Cx: TypeCx> {
#[derive(derivative::Derivative)]
#[derivative(Debug(bound = ""), Clone(bound = ""), Copy(bound = ""))]
struct PlaceCtxt<'a, Cx: TypeCx> {
#[derivative(Debug = "ignore")]
pub(crate) mcx: UsefulnessCtxt<'a, Cx>,
#[derivative(Debug = "ignore", Clone(clone_with = "Clone::clone"))] // See rust-derivative#90
pub(crate) cx: &'a Cx,
/// Type of the place under investigation.
#[derivative(Clone(clone_with = "Clone::clone"))] // See rust-derivative#90
pub(crate) ty: &'a Cx::Ty,
}

impl<'a, Cx: TypeCx> PlaceCtxt<'a, Cx> {
fn ctor_arity(&self, ctor: &Constructor<Cx>) -> usize {
self.mcx.tycx.ctor_arity(ctor, self.ty)
self.cx.ctor_arity(ctor, self.ty)
}
fn ctor_sub_tys(
&'a self,
ctor: &'a Constructor<Cx>,
) -> impl Iterator<Item = Cx::Ty> + ExactSizeIterator + Captures<'a> {
self.mcx.tycx.ctor_sub_tys(ctor, self.ty)
self.cx.ctor_sub_tys(ctor, self.ty)
}
fn ctors_for_ty(&self) -> Result<ConstructorSet<Cx>, Cx::Error> {
self.mcx.tycx.ctors_for_ty(self.ty)
self.cx.ctors_for_ty(self.ty)
}
fn wild_from_ctor(&self, ctor: Constructor<Cx>) -> WitnessPat<Cx> {
WitnessPat::wild_from_ctor(self.mcx.tycx, ctor, self.ty.clone())
WitnessPat::wild_from_ctor(self.cx, ctor, self.ty.clone())
}
}

Expand Down Expand Up @@ -1079,7 +1079,7 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
wildcard_row_is_relevant: self.wildcard_row_is_relevant && ctor_is_relevant,
};
for (i, row) in self.rows().enumerate() {
if ctor.is_covered_by(pcx.mcx.tycx, row.head().ctor()) {
if ctor.is_covered_by(pcx.cx, row.head().ctor()) {
let new_row = row.pop_head_constructor(ctor, arity, ctor_is_relevant, i);
matrix.expand_and_push(new_row);
}
Expand Down Expand Up @@ -1439,7 +1439,7 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
};

debug!("ty: {ty:?}");
let pcx = &PlaceCtxt { mcx, ty: &ty };
let pcx = &PlaceCtxt { cx: mcx.tycx, ty: &ty };
let ctors_for_ty = pcx.ctors_for_ty()?;

// Whether the place/column we are inspecting is known to contain valid data.
Expand Down

0 comments on commit 28b6471

Please sign in to comment.