Skip to content

Commit

Permalink
fix: handle ignore_in_diagnostics in more places
Browse files Browse the repository at this point in the history
  • Loading branch information
roife committed Mar 30, 2024
1 parent 7dd2a22 commit 30e58cc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
6 changes: 2 additions & 4 deletions crates/hir-ty/src/diagnostics/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,8 @@ pub fn record_pattern_missing_fields(
fn types_of_subpatterns_do_match(pat: PatId, body: &Body, infer: &InferenceResult) -> bool {
fn walk(pat: PatId, body: &Body, infer: &InferenceResult, has_type_mismatches: &mut bool) {
match infer.type_mismatch_for_pat(pat) {
Some(_) => *has_type_mismatches = true,
None => {
body[pat].walk_child_pats(|subpat| walk(subpat, body, infer, has_type_mismatches))
}
Some(mismatch) if !mismatch.ignored_in_diagnostics => *has_type_mismatches = true,
_ => body[pat].walk_child_pats(|subpat| walk(subpat, body, infer, has_type_mismatches)),
}
}

Expand Down
11 changes: 7 additions & 4 deletions crates/hir-ty/src/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,13 @@ impl InferenceResult {
self.type_mismatches.iter().map(|(expr_or_pat, mismatch)| (*expr_or_pat, mismatch))
}
pub fn expr_type_mismatches(&self) -> impl Iterator<Item = (ExprId, &TypeMismatch)> {
self.type_mismatches.iter().filter_map(|(expr_or_pat, mismatch)| match *expr_or_pat {
ExprOrPatId::ExprId(expr) => Some((expr, mismatch)),
_ => None,
})
self.type_mismatches
.iter()
.filter(|(_, mismatch)| !mismatch.ignored_in_diagnostics)
.filter_map(|(expr_or_pat, mismatch)| match *expr_or_pat {
ExprOrPatId::ExprId(expr) => Some((expr, mismatch)),
_ => None,
})
}
pub fn closure_info(&self, closure: &ClosureId) -> &(Vec<CapturedItem>, FnTrait) {
self.closure_info.get(closure).unwrap()
Expand Down
10 changes: 8 additions & 2 deletions crates/rust-analyzer/src/cli/analysis_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,10 @@ impl flags::AnalysisStats {
ty.display(db)
);
}
if let Some(mismatch) = inference_result.type_mismatch_for_expr(expr_id) {
if let Some(mismatch) = inference_result
.type_mismatch_for_expr(expr_id)
.filter(|mismatch| !mismatch.ignored_in_diagnostics)
{
num_expr_type_mismatches += 1;
if verbosity.is_verbose() {
if let Some((path, start, end)) = expr_syntax_range(db, vfs, &sm, expr_id) {
Expand Down Expand Up @@ -809,7 +812,10 @@ impl flags::AnalysisStats {
ty.display(db)
);
}
if let Some(mismatch) = inference_result.type_mismatch_for_pat(pat_id) {
if let Some(mismatch) = inference_result
.type_mismatch_for_pat(pat_id)
.filter(|mismatch| !mismatch.ignored_in_diagnostics)
{
num_pat_type_mismatches += 1;
if verbosity.is_verbose() {
if let Some((path, start, end)) = pat_syntax_range(db, vfs, &sm, pat_id) {
Expand Down

0 comments on commit 30e58cc

Please sign in to comment.