mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Abstract over the uses of compute_match_usefulness
This commit is contained in:
parent
d3eeadc242
commit
3cfcd4ed96
2 changed files with 11 additions and 15 deletions
|
@ -11,7 +11,6 @@ use hir_def::{ItemContainerId, Lookup};
|
||||||
use hir_expand::name;
|
use hir_expand::name;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
use rustc_pattern_analysis::usefulness::{compute_match_usefulness, PlaceValidity};
|
|
||||||
use syntax::{ast, AstNode};
|
use syntax::{ast, AstNode};
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
use triomphe::Arc;
|
use triomphe::Arc;
|
||||||
|
@ -234,13 +233,7 @@ impl ExprValidator {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let report = match compute_match_usefulness(
|
let report = match cx.compute_match_usefulness(m_arms.as_slice(), scrut_ty.clone()) {
|
||||||
&cx,
|
|
||||||
m_arms.as_slice(),
|
|
||||||
scrut_ty.clone(),
|
|
||||||
PlaceValidity::ValidOnly,
|
|
||||||
None,
|
|
||||||
) {
|
|
||||||
Ok(report) => report,
|
Ok(report) => report,
|
||||||
Err(()) => return,
|
Err(()) => return,
|
||||||
};
|
};
|
||||||
|
@ -282,13 +275,7 @@ impl ExprValidator {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let report = match compute_match_usefulness(
|
let report = match cx.compute_match_usefulness(&[match_arm], ty.clone()) {
|
||||||
&cx,
|
|
||||||
&[match_arm],
|
|
||||||
ty.clone(),
|
|
||||||
PlaceValidity::ValidOnly,
|
|
||||||
None,
|
|
||||||
) {
|
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
debug!(?e, "match usefulness error");
|
debug!(?e, "match usefulness error");
|
||||||
|
|
|
@ -8,6 +8,7 @@ use rustc_hash::FxHashMap;
|
||||||
use rustc_pattern_analysis::{
|
use rustc_pattern_analysis::{
|
||||||
constructor::{Constructor, ConstructorSet, VariantVisibility},
|
constructor::{Constructor, ConstructorSet, VariantVisibility},
|
||||||
index::IdxContainer,
|
index::IdxContainer,
|
||||||
|
usefulness::{compute_match_usefulness, PlaceValidity, UsefulnessReport},
|
||||||
Captures, PatCx, PrivateUninhabitedField,
|
Captures, PatCx, PrivateUninhabitedField,
|
||||||
};
|
};
|
||||||
use smallvec::{smallvec, SmallVec};
|
use smallvec::{smallvec, SmallVec};
|
||||||
|
@ -59,6 +60,14 @@ impl<'p> MatchCheckCtx<'p> {
|
||||||
Self { module, body, db, exhaustive_patterns, min_exhaustive_patterns }
|
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 {
|
fn is_uninhabited(&self, ty: &Ty) -> bool {
|
||||||
is_ty_uninhabited_from(ty, self.module, self.db)
|
is_ty_uninhabited_from(ty, self.module, self.db)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue