diff options
| author | Nadrieril <nadrieril+git@gmail.com> | 2024-03-17 16:33:25 +0100 |
|---|---|---|
| committer | Nadrieril <nadrieril+git@gmail.com> | 2024-03-18 21:21:52 +0100 |
| commit | 3cfcd4ed962ffede6dc1405f26c34ac4b9c2462c (patch) | |
| tree | 397aa4f28866ca54f355a547907dec5a0a5d38cb | |
| parent | d3eeadc242cffece74f8ff5e24029b6881b25a70 (diff) | |
| download | rust-3cfcd4ed962ffede6dc1405f26c34ac4b9c2462c.tar.gz rust-3cfcd4ed962ffede6dc1405f26c34ac4b9c2462c.zip | |
Abstract over the uses of `compute_match_usefulness`
| -rw-r--r-- | crates/hir-ty/src/diagnostics/expr.rs | 17 | ||||
| -rw-r--r-- | crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs | 9 |
2 files changed, 11 insertions, 15 deletions
diff --git a/crates/hir-ty/src/diagnostics/expr.rs b/crates/hir-ty/src/diagnostics/expr.rs index b3128712dc4..20b0da441da 100644 --- a/crates/hir-ty/src/diagnostics/expr.rs +++ b/crates/hir-ty/src/diagnostics/expr.rs @@ -11,7 +11,6 @@ use hir_def::{ItemContainerId, Lookup}; use hir_expand::name; use itertools::Itertools; use rustc_hash::FxHashSet; -use rustc_pattern_analysis::usefulness::{compute_match_usefulness, PlaceValidity}; use syntax::{ast, AstNode}; use tracing::debug; use triomphe::Arc; @@ -234,13 +233,7 @@ impl ExprValidator { return; } - let report = match compute_match_usefulness( - &cx, - m_arms.as_slice(), - scrut_ty.clone(), - PlaceValidity::ValidOnly, - None, - ) { + let report = match cx.compute_match_usefulness(m_arms.as_slice(), scrut_ty.clone()) { Ok(report) => report, Err(()) => return, }; @@ -282,13 +275,7 @@ impl ExprValidator { continue; } - let report = match compute_match_usefulness( - &cx, - &[match_arm], - ty.clone(), - PlaceValidity::ValidOnly, - None, - ) { + let report = match cx.compute_match_usefulness(&[match_arm], ty.clone()) { Ok(v) => v, Err(e) => { debug!(?e, "match usefulness error"); 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 81ce51429c5..82b80a53e30 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,14 @@ 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>, ()> { + compute_match_usefulness(self, arms, scrut_ty, PlaceValidity::ValidOnly, None) + } + fn is_uninhabited(&self, ty: &Ty) -> bool { is_ty_uninhabited_from(ty, self.module, self.db) } |
