Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 3cfcd4e

Browse files
committed
Abstract over the uses of compute_match_usefulness
1 parent d3eeadc commit 3cfcd4e

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

crates/hir-ty/src/diagnostics/expr.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use hir_def::{ItemContainerId, Lookup};
1111
use hir_expand::name;
1212
use itertools::Itertools;
1313
use rustc_hash::FxHashSet;
14-
use rustc_pattern_analysis::usefulness::{compute_match_usefulness, PlaceValidity};
1514
use syntax::{ast, AstNode};
1615
use tracing::debug;
1716
use triomphe::Arc;
@@ -234,13 +233,7 @@ impl ExprValidator {
234233
return;
235234
}
236235

237-
let report = match compute_match_usefulness(
238-
&cx,
239-
m_arms.as_slice(),
240-
scrut_ty.clone(),
241-
PlaceValidity::ValidOnly,
242-
None,
243-
) {
236+
let report = match cx.compute_match_usefulness(m_arms.as_slice(), scrut_ty.clone()) {
244237
Ok(report) => report,
245238
Err(()) => return,
246239
};
@@ -282,13 +275,7 @@ impl ExprValidator {
282275
continue;
283276
}
284277

285-
let report = match compute_match_usefulness(
286-
&cx,
287-
&[match_arm],
288-
ty.clone(),
289-
PlaceValidity::ValidOnly,
290-
None,
291-
) {
278+
let report = match cx.compute_match_usefulness(&[match_arm], ty.clone()) {
292279
Ok(v) => v,
293280
Err(e) => {
294281
debug!(?e, "match usefulness error");

crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_hash::FxHashMap;
88
use rustc_pattern_analysis::{
99
constructor::{Constructor, ConstructorSet, VariantVisibility},
1010
index::IdxContainer,
11+
usefulness::{compute_match_usefulness, PlaceValidity, UsefulnessReport},
1112
Captures, PatCx, PrivateUninhabitedField,
1213
};
1314
use smallvec::{smallvec, SmallVec};
@@ -59,6 +60,14 @@ impl<'p> MatchCheckCtx<'p> {
5960
Self { module, body, db, exhaustive_patterns, min_exhaustive_patterns }
6061
}
6162

63+
pub(crate) fn compute_match_usefulness(
64+
&self,
65+
arms: &[MatchArm<'p>],
66+
scrut_ty: Ty,
67+
) -> Result<UsefulnessReport<'p, Self>, ()> {
68+
compute_match_usefulness(self, arms, scrut_ty, PlaceValidity::ValidOnly, None)
69+
}
70+
6271
fn is_uninhabited(&self, ty: &Ty) -> bool {
6372
is_ty_uninhabited_from(ty, self.module, self.db)
6473
}

0 commit comments

Comments
 (0)