Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs')
-rw-r--r--crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs b/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs
index 81ce51429c..f45beb4c92 100644
--- a/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs
+++ b/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs
@@ -8,6 +8,7 @@ use rustc_hash::FxHashMap;
use rustc_pattern_analysis::{
constructor::{Constructor, ConstructorSet, VariantVisibility},
index::IdxContainer,
+ usefulness::{compute_match_usefulness, PlaceValidity, UsefulnessReport},
Captures, PatCx, PrivateUninhabitedField,
};
use smallvec::{smallvec, SmallVec};
@@ -59,6 +60,18 @@ impl<'p> MatchCheckCtx<'p> {
Self { module, body, db, exhaustive_patterns, min_exhaustive_patterns }
}
+ pub(crate) fn compute_match_usefulness(
+ &self,
+ arms: &[MatchArm<'p>],
+ scrut_ty: Ty,
+ ) -> Result<UsefulnessReport<'p, Self>, ()> {
+ // FIXME: Determine place validity correctly. For now, err on the safe side.
+ let place_validity = PlaceValidity::MaybeInvalid;
+ // Measured to take ~100ms on modern hardware.
+ let complexity_limit = Some(500000);
+ compute_match_usefulness(self, arms, scrut_ty, place_validity, complexity_limit)
+ }
+
fn is_uninhabited(&self, ty: &Ty) -> bool {
is_ty_uninhabited_from(ty, self.module, self.db)
}
@@ -465,7 +478,6 @@ impl<'p> PatCx for MatchCheckCtx<'p> {
}
fn complexity_exceeded(&self) -> Result<(), Self::Error> {
- // FIXME(Nadrieril): make use of the complexity counter.
Err(())
}
}