Skip to content

Commit

Permalink
fix: silence mismatches involving unresolved projections
Browse files Browse the repository at this point in the history
  • Loading branch information
roife committed Mar 28, 2024
1 parent 899db83 commit a73e276
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions crates/hir-ty/src/chalk_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub trait TyExt {
fn contains_unknown(&self) -> bool;
fn is_ty_var(&self) -> bool;
fn is_union(&self) -> bool;
fn is_projection(&self) -> bool;

fn as_adt(&self) -> Option<(hir_def::AdtId, &Substitution)>;
fn as_builtin(&self) -> Option<BuiltinType>;
Expand Down Expand Up @@ -93,6 +94,11 @@ impl TyExt for Ty {
self.data(Interner).flags.contains(TypeFlags::HAS_ERROR)
}

Check warning on line 95 in crates/hir-ty/src/chalk_ext.rs

View workflow job for this annotation

GitHub Actions / Rust (ubuntu-latest)

Diff in /home/runner/work/rust-analyzer/rust-analyzer/crates/hir-ty/src/chalk_ext.rs

fn is_projection(&self) -> bool {
matches!(self.kind(Interner), TyKind::Alias(AliasTy::Projection(_))) ||
matches!(self.kind(Interner), TyKind::AssociatedType(_, _))
}

fn is_ty_var(&self) -> bool {
matches!(self.kind(Interner), TyKind::InferenceVar(_, _))
}
Expand Down
6 changes: 6 additions & 0 deletions crates/hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1679,6 +1679,12 @@ impl DefWithBody {
acc.extend(AnyDiagnostic::inference_diagnostic(db, self.into(), d, &source_map));
}
for (pat_or_expr, mismatch) in infer.type_mismatches() {
// Silence mismatches involving unresolved projections
let is_unknown_proj = |ty: &Ty| ty.contains_unknown() && ty.is_projection();
if is_unknown_proj(&mismatch.expected) || is_unknown_proj(&mismatch.actual) {
continue;
}

let expr_or_pat = match pat_or_expr {
ExprOrPatId::ExprId(expr) => source_map.expr_syntax(expr).map(Either::Left),
ExprOrPatId::PatId(pat) => source_map.pat_syntax(pat).map(Either::Right),
Expand Down

0 comments on commit a73e276

Please sign in to comment.