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/usefulness.rs | |
parent | 26baab5d2836eb5affd93d1991b3e96853f13869 (diff) |
Remove unneeded indirection on PatCtxt
Diffstat (limited to 'crates/hir_ty/src/diagnostics/pattern/usefulness.rs')
-rw-r--r-- | crates/hir_ty/src/diagnostics/pattern/usefulness.rs | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/crates/hir_ty/src/diagnostics/pattern/usefulness.rs b/crates/hir_ty/src/diagnostics/pattern/usefulness.rs index 89e6c6593..7d9ab849b 100644 --- a/crates/hir_ty/src/diagnostics/pattern/usefulness.rs +++ b/crates/hir_ty/src/diagnostics/pattern/usefulness.rs | |||
@@ -51,11 +51,11 @@ impl<'a> MatchCheckCtx<'a> { | |||
51 | } | 51 | } |
52 | } | 52 | } |
53 | 53 | ||
54 | #[derive(Clone)] | 54 | #[derive(Copy, Clone)] |
55 | pub(super) struct PatCtxt<'a> { | 55 | pub(super) struct PatCtxt<'a> { |
56 | pub(super) cx: &'a MatchCheckCtx<'a>, | 56 | pub(super) cx: &'a MatchCheckCtx<'a>, |
57 | /// Type of the current column under investigation. | 57 | /// Type of the current column under investigation. |
58 | pub(super) ty: Ty, | 58 | pub(super) ty: &'a Ty, |
59 | /// Whether the current pattern is the whole pattern as found in a match arm, or if it's a | 59 | /// Whether the current pattern is the whole pattern as found in a match arm, or if it's a |
60 | /// subpattern. | 60 | /// subpattern. |
61 | pub(super) is_top_level: bool, | 61 | pub(super) is_top_level: bool, |
@@ -223,7 +223,7 @@ impl Matrix { | |||
223 | /// This computes `S(constructor, self)`. See top of the file for explanations. | 223 | /// This computes `S(constructor, self)`. See top of the file for explanations. |
224 | fn specialize_constructor( | 224 | fn specialize_constructor( |
225 | &self, | 225 | &self, |
226 | pcx: &PatCtxt<'_>, | 226 | pcx: PatCtxt<'_>, |
227 | ctor: &Constructor, | 227 | ctor: &Constructor, |
228 | ctor_wild_subpatterns: &Fields, | 228 | ctor_wild_subpatterns: &Fields, |
229 | ) -> Matrix { | 229 | ) -> Matrix { |
@@ -447,7 +447,7 @@ impl Usefulness { | |||
447 | /// with the results of specializing with the other constructors. | 447 | /// with the results of specializing with the other constructors. |
448 | fn apply_constructor( | 448 | fn apply_constructor( |
449 | self, | 449 | self, |
450 | pcx: &PatCtxt<'_>, | 450 | pcx: PatCtxt<'_>, |
451 | matrix: &Matrix, | 451 | matrix: &Matrix, |
452 | ctor: &Constructor, | 452 | ctor: &Constructor, |
453 | ctor_wild_subpatterns: &Fields, | 453 | ctor_wild_subpatterns: &Fields, |
@@ -555,7 +555,7 @@ impl Witness { | |||
555 | /// pats: [(false, "foo"), 42] => X { a: (false, "foo"), b: 42 } | 555 | /// pats: [(false, "foo"), 42] => X { a: (false, "foo"), b: 42 } |
556 | fn apply_constructor( | 556 | fn apply_constructor( |
557 | mut self, | 557 | mut self, |
558 | pcx: &PatCtxt<'_>, | 558 | pcx: PatCtxt<'_>, |
559 | ctor: &Constructor, | 559 | ctor: &Constructor, |
560 | ctor_wild_subpatterns: &Fields, | 560 | ctor_wild_subpatterns: &Fields, |
561 | ) -> Self { | 561 | ) -> Self { |
@@ -623,7 +623,7 @@ fn is_useful( | |||
623 | // FIXME(Nadrieril): Hack to work around type normalization issues (see rust-lang/rust#72476). | 623 | // FIXME(Nadrieril): Hack to work around type normalization issues (see rust-lang/rust#72476). |
624 | // TODO(iDawer): ty.strip_references() ? | 624 | // TODO(iDawer): ty.strip_references() ? |
625 | let ty = matrix.heads().next().map_or(cx.type_of(v.head()), |r| cx.type_of(r)); | 625 | let ty = matrix.heads().next().map_or(cx.type_of(v.head()), |r| cx.type_of(r)); |
626 | let pcx = PatCtxt { cx, ty, is_top_level }; | 626 | let pcx = PatCtxt { cx, ty: &ty, is_top_level }; |
627 | 627 | ||
628 | // If the first pattern is an or-pattern, expand it. | 628 | // If the first pattern is an or-pattern, expand it. |
629 | let ret = if v.head().is_or_pat(cx) { | 629 | let ret = if v.head().is_or_pat(cx) { |
@@ -657,20 +657,20 @@ fn is_useful( | |||
657 | // } | 657 | // } |
658 | 658 | ||
659 | // We split the head constructor of `v`. | 659 | // We split the head constructor of `v`. |
660 | let split_ctors = v_ctor.split(&pcx, matrix.head_ctors(cx)); | 660 | let split_ctors = v_ctor.split(pcx, matrix.head_ctors(cx)); |
661 | // For each constructor, we compute whether there's a value that starts with it that would | 661 | // For each constructor, we compute whether there's a value that starts with it that would |
662 | // witness the usefulness of `v`. | 662 | // witness the usefulness of `v`. |
663 | let start_matrix = matrix; | 663 | let start_matrix = matrix; |
664 | let usefulnesses = split_ctors.into_iter().map(|ctor| { | 664 | let usefulnesses = split_ctors.into_iter().map(|ctor| { |
665 | // debug!("specialize({:?})", ctor); | 665 | // debug!("specialize({:?})", ctor); |
666 | // We cache the result of `Fields::wildcards` because it is used a lot. | 666 | // We cache the result of `Fields::wildcards` because it is used a lot. |
667 | let ctor_wild_subpatterns = Fields::wildcards(&pcx, &ctor); | 667 | let ctor_wild_subpatterns = Fields::wildcards(pcx, &ctor); |
668 | let spec_matrix = | 668 | let spec_matrix = |
669 | start_matrix.specialize_constructor(&pcx, &ctor, &ctor_wild_subpatterns); | 669 | start_matrix.specialize_constructor(pcx, &ctor, &ctor_wild_subpatterns); |
670 | let v = v.pop_head_constructor(&ctor_wild_subpatterns, cx); | 670 | let v = v.pop_head_constructor(&ctor_wild_subpatterns, cx); |
671 | let usefulness = | 671 | let usefulness = |
672 | is_useful(cx, &spec_matrix, &v, witness_preference, is_under_guard, false); | 672 | is_useful(cx, &spec_matrix, &v, witness_preference, is_under_guard, false); |
673 | usefulness.apply_constructor(&pcx, start_matrix, &ctor, &ctor_wild_subpatterns) | 673 | usefulness.apply_constructor(pcx, start_matrix, &ctor, &ctor_wild_subpatterns) |
674 | }); | 674 | }); |
675 | Usefulness::merge(witness_preference, usefulnesses) | 675 | Usefulness::merge(witness_preference, usefulnesses) |
676 | }; | 676 | }; |