Skip to content

Commit d45708f

Browse files
committed
Don't trigger unresolved method/field diagnostics on types containing errors
1 parent 31c12ec commit d45708f

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

crates/hir-ty/src/chalk_ext.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{
1313
db::HirDatabase, from_assoc_type_id, from_chalk_trait_id, from_foreign_def_id,
1414
from_placeholder_idx, to_chalk_trait_id, utils::generics, AdtId, AliasEq, AliasTy, Binders,
1515
CallableDefId, CallableSig, FnPointer, ImplTraitId, Interner, Lifetime, ProjectionTy,
16-
QuantifiedWhereClause, Substitution, TraitRef, Ty, TyBuilder, TyKind, WhereClause,
16+
QuantifiedWhereClause, Substitution, TraitRef, Ty, TyBuilder, TyKind, TypeFlags, WhereClause,
1717
};
1818

1919
pub trait TyExt {
@@ -22,6 +22,7 @@ pub trait TyExt {
2222
fn is_floating_point(&self) -> bool;
2323
fn is_never(&self) -> bool;
2424
fn is_unknown(&self) -> bool;
25+
fn contains_unknown(&self) -> bool;
2526
fn is_ty_var(&self) -> bool;
2627

2728
fn as_adt(&self) -> Option<(hir_def::AdtId, &Substitution)>;
@@ -76,6 +77,10 @@ impl TyExt for Ty {
7677
matches!(self.kind(Interner), TyKind::Error)
7778
}
7879

80+
fn contains_unknown(&self) -> bool {
81+
self.data(Interner).flags.contains(TypeFlags::HAS_ERROR)
82+
}
83+
7984
fn is_ty_var(&self) -> bool {
8085
matches!(self.kind(Interner), TyKind::InferenceVar(_, _))
8186
}

crates/hir-ty/src/infer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ impl<'a> InferenceContext<'a> {
548548
{
549549
*ty = table.resolve_completely(ty.clone());
550550
// FIXME: Remove this when we are on par with rustc in terms of inference
551-
if ty.is_unknown() {
551+
if ty.contains_unknown() {
552552
return false;
553553
}
554554

@@ -557,7 +557,7 @@ impl<'a> InferenceContext<'a> {
557557
{
558558
let clear = if let Some(ty) = field_with_same_name {
559559
*ty = table.resolve_completely(ty.clone());
560-
ty.is_unknown()
560+
ty.contains_unknown()
561561
} else {
562562
false
563563
};

crates/ide-diagnostics/src/handlers/unresolved_field.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,19 @@ fn foo() {
129129
Foo.bar;
130130
// ^^^^^^^ 💡 error: no field `bar` on type `Foo`, but a method with a similar name exists
131131
}
132+
"#,
133+
);
134+
}
135+
136+
#[test]
137+
fn no_diagnostic_on_unknown() {
138+
check_diagnostics(
139+
r#"
140+
fn foo() {
141+
x.foo;
142+
(&x).foo;
143+
(&((x,),),).foo;
144+
}
132145
"#,
133146
);
134147
}

0 commit comments

Comments
 (0)