Unnamed repository; edit this file 'description' to name the repository.
Merge pull request #19875 from ShoyuVanilla/issue-19844
fix: Skip pattern analysis on type mismatches
Chayim Refael Friedman 11 months ago
parent 7230ded · parent 8682c1b · commit 4f7af13
-rw-r--r--crates/hir-ty/src/diagnostics/expr.rs3
-rw-r--r--crates/ide-diagnostics/src/handlers/type_mismatch.rs14
2 files changed, 17 insertions, 0 deletions
diff --git a/crates/hir-ty/src/diagnostics/expr.rs b/crates/hir-ty/src/diagnostics/expr.rs
index 8665e9d33f..9eb7ffe1c7 100644
--- a/crates/hir-ty/src/diagnostics/expr.rs
+++ b/crates/hir-ty/src/diagnostics/expr.rs
@@ -324,6 +324,9 @@ impl ExprValidator {
let &Statement::Let { pat, initializer, else_branch: None, .. } = stmt else {
continue;
};
+ if self.infer.type_mismatch_for_pat(pat).is_some() {
+ continue;
+ }
let Some(initializer) = initializer else { continue };
let ty = &self.infer[initializer];
if ty.contains_unknown() {
diff --git a/crates/ide-diagnostics/src/handlers/type_mismatch.rs b/crates/ide-diagnostics/src/handlers/type_mismatch.rs
index 5253734867..076df1ab0f 100644
--- a/crates/ide-diagnostics/src/handlers/type_mismatch.rs
+++ b/crates/ide-diagnostics/src/handlers/type_mismatch.rs
@@ -1243,4 +1243,18 @@ fn foo(v: &Enum) {
"#,
);
}
+
+ #[test]
+ fn regression_19844() {
+ check_diagnostics(
+ r#"
+fn main() {
+ struct S {}
+ enum E { V() }
+ let E::V() = &S {};
+ // ^^^^^^ error: expected S, found E
+}
+"#,
+ );
+ }
}