Don't pass (the rather large) PatCtxt
by value
This commit is contained in:
parent
970ff3d45d
commit
544de44a6b
2 changed files with 17 additions and 17 deletions
|
@ -261,7 +261,7 @@ impl IntRange {
|
||||||
/// Lint on likely incorrect range patterns (#63987)
|
/// Lint on likely incorrect range patterns (#63987)
|
||||||
pub(super) fn lint_overlapping_range_endpoints<'a, 'p: 'a, 'tcx: 'a>(
|
pub(super) fn lint_overlapping_range_endpoints<'a, 'p: 'a, 'tcx: 'a>(
|
||||||
&self,
|
&self,
|
||||||
pcx: PatCtxt<'_, 'p, 'tcx>,
|
pcx: &PatCtxt<'_, 'p, 'tcx>,
|
||||||
pats: impl Iterator<Item = &'a DeconstructedPat<'p, 'tcx>>,
|
pats: impl Iterator<Item = &'a DeconstructedPat<'p, 'tcx>>,
|
||||||
column_count: usize,
|
column_count: usize,
|
||||||
hir_id: HirId,
|
hir_id: HirId,
|
||||||
|
@ -696,7 +696,7 @@ impl<'tcx> Constructor<'tcx> {
|
||||||
/// `EvalResult::Deny { .. }`.
|
/// `EvalResult::Deny { .. }`.
|
||||||
///
|
///
|
||||||
/// This means that the variant has a stdlib unstable feature marking it.
|
/// This means that the variant has a stdlib unstable feature marking it.
|
||||||
pub(super) fn is_unstable_variant(&self, pcx: PatCtxt<'_, '_, 'tcx>) -> bool {
|
pub(super) fn is_unstable_variant(&self, pcx: &PatCtxt<'_, '_, 'tcx>) -> bool {
|
||||||
if let Constructor::Variant(idx) = self && let ty::Adt(adt, _) = pcx.ty.kind() {
|
if let Constructor::Variant(idx) = self && let ty::Adt(adt, _) = pcx.ty.kind() {
|
||||||
let variant_def_id = adt.variant(*idx).def_id;
|
let variant_def_id = adt.variant(*idx).def_id;
|
||||||
// Filter variants that depend on a disabled unstable feature.
|
// Filter variants that depend on a disabled unstable feature.
|
||||||
|
@ -710,7 +710,7 @@ impl<'tcx> Constructor<'tcx> {
|
||||||
|
|
||||||
/// Checks if the `Constructor` is a `Constructor::Variant` with a `#[doc(hidden)]`
|
/// Checks if the `Constructor` is a `Constructor::Variant` with a `#[doc(hidden)]`
|
||||||
/// attribute from a type not local to the current crate.
|
/// attribute from a type not local to the current crate.
|
||||||
pub(super) fn is_doc_hidden_variant(&self, pcx: PatCtxt<'_, '_, 'tcx>) -> bool {
|
pub(super) fn is_doc_hidden_variant(&self, pcx: &PatCtxt<'_, '_, 'tcx>) -> bool {
|
||||||
if let Constructor::Variant(idx) = self && let ty::Adt(adt, _) = pcx.ty.kind() {
|
if let Constructor::Variant(idx) = self && let ty::Adt(adt, _) = pcx.ty.kind() {
|
||||||
let variant_def_id = adt.variants()[*idx].def_id;
|
let variant_def_id = adt.variants()[*idx].def_id;
|
||||||
return pcx.cx.tcx.is_doc_hidden(variant_def_id) && !variant_def_id.is_local();
|
return pcx.cx.tcx.is_doc_hidden(variant_def_id) && !variant_def_id.is_local();
|
||||||
|
@ -731,7 +731,7 @@ impl<'tcx> Constructor<'tcx> {
|
||||||
|
|
||||||
/// The number of fields for this constructor. This must be kept in sync with
|
/// The number of fields for this constructor. This must be kept in sync with
|
||||||
/// `Fields::wildcards`.
|
/// `Fields::wildcards`.
|
||||||
pub(super) fn arity(&self, pcx: PatCtxt<'_, '_, 'tcx>) -> usize {
|
pub(super) fn arity(&self, pcx: &PatCtxt<'_, '_, 'tcx>) -> usize {
|
||||||
match self {
|
match self {
|
||||||
Single | Variant(_) => match pcx.ty.kind() {
|
Single | Variant(_) => match pcx.ty.kind() {
|
||||||
ty::Tuple(fs) => fs.len(),
|
ty::Tuple(fs) => fs.len(),
|
||||||
|
@ -775,7 +775,7 @@ impl<'tcx> Constructor<'tcx> {
|
||||||
/// matrix, unless all of them are.
|
/// matrix, unless all of them are.
|
||||||
pub(super) fn split<'a>(
|
pub(super) fn split<'a>(
|
||||||
&self,
|
&self,
|
||||||
pcx: PatCtxt<'_, '_, 'tcx>,
|
pcx: &PatCtxt<'_, '_, 'tcx>,
|
||||||
ctors: impl Iterator<Item = &'a Constructor<'tcx>> + Clone,
|
ctors: impl Iterator<Item = &'a Constructor<'tcx>> + Clone,
|
||||||
) -> SmallVec<[Self; 1]>
|
) -> SmallVec<[Self; 1]>
|
||||||
where
|
where
|
||||||
|
@ -811,7 +811,7 @@ impl<'tcx> Constructor<'tcx> {
|
||||||
/// this checks for inclusion.
|
/// this checks for inclusion.
|
||||||
// We inline because this has a single call site in `Matrix::specialize_constructor`.
|
// We inline because this has a single call site in `Matrix::specialize_constructor`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(super) fn is_covered_by<'p>(&self, pcx: PatCtxt<'_, 'p, 'tcx>, other: &Self) -> bool {
|
pub(super) fn is_covered_by<'p>(&self, pcx: &PatCtxt<'_, 'p, 'tcx>, other: &Self) -> bool {
|
||||||
// This must be kept in sync with `is_covered_by_any`.
|
// This must be kept in sync with `is_covered_by_any`.
|
||||||
match (self, other) {
|
match (self, other) {
|
||||||
// Wildcards cover anything
|
// Wildcards cover anything
|
||||||
|
@ -865,7 +865,7 @@ impl<'tcx> Constructor<'tcx> {
|
||||||
/// assumed to have been split from a wildcard.
|
/// assumed to have been split from a wildcard.
|
||||||
fn is_covered_by_any<'p>(
|
fn is_covered_by_any<'p>(
|
||||||
&self,
|
&self,
|
||||||
pcx: PatCtxt<'_, 'p, 'tcx>,
|
pcx: &PatCtxt<'_, 'p, 'tcx>,
|
||||||
used_ctors: &[Constructor<'tcx>],
|
used_ctors: &[Constructor<'tcx>],
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if used_ctors.is_empty() {
|
if used_ctors.is_empty() {
|
||||||
|
@ -918,7 +918,7 @@ pub(super) struct SplitWildcard<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> SplitWildcard<'tcx> {
|
impl<'tcx> SplitWildcard<'tcx> {
|
||||||
pub(super) fn new<'p>(pcx: PatCtxt<'_, 'p, 'tcx>) -> Self {
|
pub(super) fn new<'p>(pcx: &PatCtxt<'_, 'p, 'tcx>) -> Self {
|
||||||
debug!("SplitWildcard::new({:?})", pcx.ty);
|
debug!("SplitWildcard::new({:?})", pcx.ty);
|
||||||
let cx = pcx.cx;
|
let cx = pcx.cx;
|
||||||
let make_range = |start, end| {
|
let make_range = |start, end| {
|
||||||
|
@ -1044,7 +1044,7 @@ impl<'tcx> SplitWildcard<'tcx> {
|
||||||
/// do what you want.
|
/// do what you want.
|
||||||
pub(super) fn split<'a>(
|
pub(super) fn split<'a>(
|
||||||
&mut self,
|
&mut self,
|
||||||
pcx: PatCtxt<'_, '_, 'tcx>,
|
pcx: &PatCtxt<'_, '_, 'tcx>,
|
||||||
ctors: impl Iterator<Item = &'a Constructor<'tcx>> + Clone,
|
ctors: impl Iterator<Item = &'a Constructor<'tcx>> + Clone,
|
||||||
) where
|
) where
|
||||||
'tcx: 'a,
|
'tcx: 'a,
|
||||||
|
@ -1056,21 +1056,21 @@ impl<'tcx> SplitWildcard<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether there are any value constructors for this type that are not present in the matrix.
|
/// Whether there are any value constructors for this type that are not present in the matrix.
|
||||||
fn any_missing(&self, pcx: PatCtxt<'_, '_, 'tcx>) -> bool {
|
fn any_missing(&self, pcx: &PatCtxt<'_, '_, 'tcx>) -> bool {
|
||||||
self.iter_missing(pcx).next().is_some()
|
self.iter_missing(pcx).next().is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Iterate over the constructors for this type that are not present in the matrix.
|
/// Iterate over the constructors for this type that are not present in the matrix.
|
||||||
pub(super) fn iter_missing<'a, 'p>(
|
pub(super) fn iter_missing<'a, 'p>(
|
||||||
&'a self,
|
&'a self,
|
||||||
pcx: PatCtxt<'a, 'p, 'tcx>,
|
pcx: &'a PatCtxt<'a, 'p, 'tcx>,
|
||||||
) -> impl Iterator<Item = &'a Constructor<'tcx>> + Captures<'p> {
|
) -> impl Iterator<Item = &'a Constructor<'tcx>> + Captures<'p> {
|
||||||
self.all_ctors.iter().filter(move |ctor| !ctor.is_covered_by_any(pcx, &self.matrix_ctors))
|
self.all_ctors.iter().filter(move |ctor| !ctor.is_covered_by_any(pcx, &self.matrix_ctors))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the set of constructors resulting from splitting the wildcard. As explained at the
|
/// Return the set of constructors resulting from splitting the wildcard. As explained at the
|
||||||
/// top of the file, if any constructors are missing we can ignore the present ones.
|
/// top of the file, if any constructors are missing we can ignore the present ones.
|
||||||
fn into_ctors(self, pcx: PatCtxt<'_, '_, 'tcx>) -> SmallVec<[Constructor<'tcx>; 1]> {
|
fn into_ctors(self, pcx: &PatCtxt<'_, '_, 'tcx>) -> SmallVec<[Constructor<'tcx>; 1]> {
|
||||||
if self.any_missing(pcx) {
|
if self.any_missing(pcx) {
|
||||||
// Some constructors are missing, thus we can specialize with the special `Missing`
|
// Some constructors are missing, thus we can specialize with the special `Missing`
|
||||||
// constructor, which stands for those constructors that are not seen in the matrix,
|
// constructor, which stands for those constructors that are not seen in the matrix,
|
||||||
|
@ -1285,7 +1285,7 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
|
||||||
/// Construct a pattern that matches everything that starts with this constructor.
|
/// Construct a pattern that matches everything that starts with this constructor.
|
||||||
/// For example, if `ctor` is a `Constructor::Variant` for `Option::Some`, we get the pattern
|
/// For example, if `ctor` is a `Constructor::Variant` for `Option::Some`, we get the pattern
|
||||||
/// `Some(_)`.
|
/// `Some(_)`.
|
||||||
pub(super) fn wild_from_ctor(pcx: PatCtxt<'_, 'p, 'tcx>, ctor: Constructor<'tcx>) -> Self {
|
pub(super) fn wild_from_ctor(pcx: &PatCtxt<'_, 'p, 'tcx>, ctor: Constructor<'tcx>) -> Self {
|
||||||
let fields = Fields::wildcards(pcx.cx, pcx.ty, &ctor);
|
let fields = Fields::wildcards(pcx.cx, pcx.ty, &ctor);
|
||||||
DeconstructedPat::new(ctor, fields, pcx.ty, DUMMY_SP)
|
DeconstructedPat::new(ctor, fields, pcx.ty, DUMMY_SP)
|
||||||
}
|
}
|
||||||
|
|
|
@ -469,7 +469,7 @@ impl<'p, 'tcx> Matrix<'p, 'tcx> {
|
||||||
/// This computes `S(constructor, self)`. See top of the file for explanations.
|
/// This computes `S(constructor, self)`. See top of the file for explanations.
|
||||||
fn specialize_constructor(
|
fn specialize_constructor(
|
||||||
&self,
|
&self,
|
||||||
pcx: PatCtxt<'_, 'p, 'tcx>,
|
pcx: &PatCtxt<'_, 'p, 'tcx>,
|
||||||
ctor: &Constructor<'tcx>,
|
ctor: &Constructor<'tcx>,
|
||||||
) -> Matrix<'p, 'tcx> {
|
) -> Matrix<'p, 'tcx> {
|
||||||
let mut matrix = Matrix::empty();
|
let mut matrix = Matrix::empty();
|
||||||
|
@ -575,7 +575,7 @@ impl<'p, 'tcx> Usefulness<'p, 'tcx> {
|
||||||
/// with the results of specializing with the other constructors.
|
/// with the results of specializing with the other constructors.
|
||||||
fn apply_constructor(
|
fn apply_constructor(
|
||||||
self,
|
self,
|
||||||
pcx: PatCtxt<'_, 'p, 'tcx>,
|
pcx: &PatCtxt<'_, 'p, 'tcx>,
|
||||||
matrix: &Matrix<'p, 'tcx>, // used to compute missing ctors
|
matrix: &Matrix<'p, 'tcx>, // used to compute missing ctors
|
||||||
ctor: &Constructor<'tcx>,
|
ctor: &Constructor<'tcx>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
@ -713,7 +713,7 @@ impl<'p, 'tcx> Witness<'p, 'tcx> {
|
||||||
///
|
///
|
||||||
/// left_ty: struct X { a: (bool, &'static str), b: usize}
|
/// left_ty: struct X { a: (bool, &'static str), b: usize}
|
||||||
/// pats: [(false, "foo"), 42] => X { a: (false, "foo"), b: 42 }
|
/// pats: [(false, "foo"), 42] => X { a: (false, "foo"), b: 42 }
|
||||||
fn apply_constructor(mut self, pcx: PatCtxt<'_, 'p, 'tcx>, ctor: &Constructor<'tcx>) -> Self {
|
fn apply_constructor(mut self, pcx: &PatCtxt<'_, 'p, 'tcx>, ctor: &Constructor<'tcx>) -> Self {
|
||||||
let pat = {
|
let pat = {
|
||||||
let len = self.0.len();
|
let len = self.0.len();
|
||||||
let arity = ctor.arity(pcx);
|
let arity = ctor.arity(pcx);
|
||||||
|
@ -830,7 +830,7 @@ fn is_useful<'p, 'tcx>(
|
||||||
let ty = v.head().ty();
|
let ty = v.head().ty();
|
||||||
let is_non_exhaustive = cx.is_foreign_non_exhaustive_enum(ty);
|
let is_non_exhaustive = cx.is_foreign_non_exhaustive_enum(ty);
|
||||||
debug!("v.head: {:?}, v.span: {:?}", v.head(), v.head().span());
|
debug!("v.head: {:?}, v.span: {:?}", v.head(), v.head().span());
|
||||||
let pcx = PatCtxt { cx, ty, span: v.head().span(), is_top_level, is_non_exhaustive };
|
let pcx = &PatCtxt { cx, ty, span: v.head().span(), is_top_level, is_non_exhaustive };
|
||||||
|
|
||||||
let v_ctor = v.head().ctor();
|
let v_ctor = v.head().ctor();
|
||||||
debug!(?v_ctor);
|
debug!(?v_ctor);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue