diff options
author | Dawer <[email protected]> | 2021-04-29 06:04:24 +0100 |
---|---|---|
committer | Dawer <[email protected]> | 2021-05-31 20:03:45 +0100 |
commit | f4a95c93fe4c1050b18b3c8be25baddd6972ed84 (patch) | |
tree | d0daaf253953ffa93bafe7afd2eecb7b9d84fd54 /crates/hir_ty/src/diagnostics/pattern/deconstruct_pat.rs | |
parent | 26baab5d2836eb5affd93d1991b3e96853f13869 (diff) |
Remove unneeded indirection on PatCtxt
Diffstat (limited to 'crates/hir_ty/src/diagnostics/pattern/deconstruct_pat.rs')
-rw-r--r-- | crates/hir_ty/src/diagnostics/pattern/deconstruct_pat.rs | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/crates/hir_ty/src/diagnostics/pattern/deconstruct_pat.rs b/crates/hir_ty/src/diagnostics/pattern/deconstruct_pat.rs index 2f3555205..d41b95d2f 100644 --- a/crates/hir_ty/src/diagnostics/pattern/deconstruct_pat.rs +++ b/crates/hir_ty/src/diagnostics/pattern/deconstruct_pat.rs | |||
@@ -143,7 +143,7 @@ impl Constructor { | |||
143 | /// matrix, unless all of them are. | 143 | /// matrix, unless all of them are. |
144 | pub(super) fn split<'a>( | 144 | pub(super) fn split<'a>( |
145 | &self, | 145 | &self, |
146 | pcx: &PatCtxt<'_>, | 146 | pcx: PatCtxt<'_>, |
147 | ctors: impl Iterator<Item = &'a Constructor> + Clone, | 147 | ctors: impl Iterator<Item = &'a Constructor> + Clone, |
148 | ) -> SmallVec<[Self; 1]> { | 148 | ) -> SmallVec<[Self; 1]> { |
149 | match self { | 149 | match self { |
@@ -166,7 +166,7 @@ impl Constructor { | |||
166 | /// this checks for inclusion. | 166 | /// this checks for inclusion. |
167 | // We inline because this has a single call site in `Matrix::specialize_constructor`. | 167 | // We inline because this has a single call site in `Matrix::specialize_constructor`. |
168 | #[inline] | 168 | #[inline] |
169 | pub(super) fn is_covered_by(&self, pcx: &PatCtxt<'_>, other: &Self) -> bool { | 169 | pub(super) fn is_covered_by(&self, pcx: PatCtxt<'_>, other: &Self) -> bool { |
170 | // This must be kept in sync with `is_covered_by_any`. | 170 | // This must be kept in sync with `is_covered_by_any`. |
171 | match (self, other) { | 171 | match (self, other) { |
172 | // Wildcards cover anything | 172 | // Wildcards cover anything |
@@ -188,7 +188,7 @@ impl Constructor { | |||
188 | /// Faster version of `is_covered_by` when applied to many constructors. `used_ctors` is | 188 | /// Faster version of `is_covered_by` when applied to many constructors. `used_ctors` is |
189 | /// assumed to be built from `matrix.head_ctors()` with wildcards filtered out, and `self` is | 189 | /// assumed to be built from `matrix.head_ctors()` with wildcards filtered out, and `self` is |
190 | /// assumed to have been split from a wildcard. | 190 | /// assumed to have been split from a wildcard. |
191 | fn is_covered_by_any(&self, pcx: &PatCtxt<'_>, used_ctors: &[Constructor]) -> bool { | 191 | fn is_covered_by_any(&self, pcx: PatCtxt<'_>, used_ctors: &[Constructor]) -> bool { |
192 | if used_ctors.is_empty() { | 192 | if used_ctors.is_empty() { |
193 | return false; | 193 | return false; |
194 | } | 194 | } |
@@ -236,7 +236,7 @@ pub(super) struct SplitWildcard { | |||
236 | } | 236 | } |
237 | 237 | ||
238 | impl SplitWildcard { | 238 | impl SplitWildcard { |
239 | pub(super) fn new(pcx: &PatCtxt<'_>) -> Self { | 239 | pub(super) fn new(pcx: PatCtxt<'_>) -> Self { |
240 | // let cx = pcx.cx; | 240 | // let cx = pcx.cx; |
241 | // let make_range = |start, end| IntRange(todo!()); | 241 | // let make_range = |start, end| IntRange(todo!()); |
242 | 242 | ||
@@ -260,7 +260,7 @@ impl SplitWildcard { | |||
260 | /// do what you want. | 260 | /// do what you want. |
261 | pub(super) fn split<'a>( | 261 | pub(super) fn split<'a>( |
262 | &mut self, | 262 | &mut self, |
263 | pcx: &PatCtxt<'_>, | 263 | pcx: PatCtxt<'_>, |
264 | ctors: impl Iterator<Item = &'a Constructor> + Clone, | 264 | ctors: impl Iterator<Item = &'a Constructor> + Clone, |
265 | ) { | 265 | ) { |
266 | // Since `all_ctors` never contains wildcards, this won't recurse further. | 266 | // Since `all_ctors` never contains wildcards, this won't recurse further. |
@@ -270,21 +270,21 @@ impl SplitWildcard { | |||
270 | } | 270 | } |
271 | 271 | ||
272 | /// Whether there are any value constructors for this type that are not present in the matrix. | 272 | /// Whether there are any value constructors for this type that are not present in the matrix. |
273 | fn any_missing(&self, pcx: &PatCtxt<'_>) -> bool { | 273 | fn any_missing(&self, pcx: PatCtxt<'_>) -> bool { |
274 | self.iter_missing(pcx).next().is_some() | 274 | self.iter_missing(pcx).next().is_some() |
275 | } | 275 | } |
276 | 276 | ||
277 | /// Iterate over the constructors for this type that are not present in the matrix. | 277 | /// Iterate over the constructors for this type that are not present in the matrix. |
278 | pub(super) fn iter_missing<'a>( | 278 | pub(super) fn iter_missing<'a>( |
279 | &'a self, | 279 | &'a self, |
280 | pcx: &'a PatCtxt<'_>, | 280 | pcx: PatCtxt<'a>, |
281 | ) -> impl Iterator<Item = &'a Constructor> { | 281 | ) -> impl Iterator<Item = &'a Constructor> { |
282 | self.all_ctors.iter().filter(move |ctor| !ctor.is_covered_by_any(pcx, &self.matrix_ctors)) | 282 | self.all_ctors.iter().filter(move |ctor| !ctor.is_covered_by_any(pcx, &self.matrix_ctors)) |
283 | } | 283 | } |
284 | 284 | ||
285 | /// Return the set of constructors resulting from splitting the wildcard. As explained at the | 285 | /// Return the set of constructors resulting from splitting the wildcard. As explained at the |
286 | /// top of the file, if any constructors are missing we can ignore the present ones. | 286 | /// top of the file, if any constructors are missing we can ignore the present ones. |
287 | fn into_ctors(self, pcx: &PatCtxt<'_>) -> SmallVec<[Constructor; 1]> { | 287 | fn into_ctors(self, pcx: PatCtxt<'_>) -> SmallVec<[Constructor; 1]> { |
288 | if self.any_missing(pcx) { | 288 | if self.any_missing(pcx) { |
289 | // Some constructors are missing, thus we can specialize with the special `Missing` | 289 | // Some constructors are missing, thus we can specialize with the special `Missing` |
290 | // constructor, which stands for those constructors that are not seen in the matrix, | 290 | // constructor, which stands for those constructors that are not seen in the matrix, |
@@ -313,7 +313,7 @@ impl SplitWildcard { | |||
313 | // | 313 | // |
314 | // The exception is: if we are at the top-level, for example in an empty match, we | 314 | // The exception is: if we are at the top-level, for example in an empty match, we |
315 | // sometimes prefer reporting the list of constructors instead of just `_`. | 315 | // sometimes prefer reporting the list of constructors instead of just `_`. |
316 | let report_when_all_missing = pcx.is_top_level && !IntRange::is_integral(&pcx.ty); | 316 | let report_when_all_missing = pcx.is_top_level && !IntRange::is_integral(pcx.ty); |
317 | let ctor = if !self.matrix_ctors.is_empty() || report_when_all_missing { | 317 | let ctor = if !self.matrix_ctors.is_empty() || report_when_all_missing { |
318 | Missing | 318 | Missing |
319 | } else { | 319 | } else { |
@@ -381,8 +381,8 @@ impl Fields { | |||
381 | Fields::Vec(pats) | 381 | Fields::Vec(pats) |
382 | } | 382 | } |
383 | 383 | ||
384 | pub(crate) fn wildcards(pcx: &PatCtxt<'_>, constructor: &Constructor) -> Self { | 384 | pub(crate) fn wildcards(pcx: PatCtxt<'_>, constructor: &Constructor) -> Self { |
385 | let ty = &pcx.ty; | 385 | let ty = pcx.ty; |
386 | let cx = pcx.cx; | 386 | let cx = pcx.cx; |
387 | let wildcard_from_ty = |ty| cx.alloc_pat(Pat::Wild, ty); | 387 | let wildcard_from_ty = |ty| cx.alloc_pat(Pat::Wild, ty); |
388 | 388 | ||
@@ -446,7 +446,7 @@ impl Fields { | |||
446 | /// `ty`: `Option<bool>` | 446 | /// `ty`: `Option<bool>` |
447 | /// `self`: `[false]` | 447 | /// `self`: `[false]` |
448 | /// returns `Some(false)` | 448 | /// returns `Some(false)` |
449 | pub(super) fn apply(self, pcx: &PatCtxt<'_>, ctor: &Constructor) -> Pat { | 449 | pub(super) fn apply(self, pcx: PatCtxt<'_>, ctor: &Constructor) -> Pat { |
450 | let subpatterns_and_indices = self.patterns_and_indices(); | 450 | let subpatterns_and_indices = self.patterns_and_indices(); |
451 | let mut subpatterns = subpatterns_and_indices.iter().map(|&(_, p)| p); | 451 | let mut subpatterns = subpatterns_and_indices.iter().map(|&(_, p)| p); |
452 | 452 | ||