Skip to content

Commit 4f7af13

Browse files
Merge pull request #19875 from ShoyuVanilla/issue-19844
fix: Skip pattern analysis on type mismatches
2 parents 7230ded + 8682c1b commit 4f7af13

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

crates/hir-ty/src/diagnostics/expr.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ impl ExprValidator {
324324
let &Statement::Let { pat, initializer, else_branch: None, .. } = stmt else {
325325
continue;
326326
};
327+
if self.infer.type_mismatch_for_pat(pat).is_some() {
328+
continue;
329+
}
327330
let Some(initializer) = initializer else { continue };
328331
let ty = &self.infer[initializer];
329332
if ty.contains_unknown() {

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,4 +1243,18 @@ fn foo(v: &Enum) {
12431243
"#,
12441244
);
12451245
}
1246+
1247+
#[test]
1248+
fn regression_19844() {
1249+
check_diagnostics(
1250+
r#"
1251+
fn main() {
1252+
struct S {}
1253+
enum E { V() }
1254+
let E::V() = &S {};
1255+
// ^^^^^^ error: expected S, found E
1256+
}
1257+
"#,
1258+
);
1259+
}
12461260
}

0 commit comments

Comments
 (0)