diff options
| author | bors <bors@rust-lang.org> | 2024-07-20 18:04:01 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-07-20 18:04:01 +0000 |
| commit | ea7f3671c073a65873ece60ff806b374d32d35c1 (patch) | |
| tree | ec3799319dc77a9312f9604afb5ef727435ee475 | |
| parent | 60dfe6cba5868f67a87b386f6d0b6c9ba3418966 (diff) | |
| parent | 96b30036f1ca60e9b35741154a69d44ea815dd38 (diff) | |
Auto merge of #17649 - ShoyuVanilla:issue-17585, r=Veykril
fix: Panic in debug profile for tuple deconstruct with arity mismatch Fixes #17585, which doesn't affect daily use cases but quite annoying in development of r-a itself like writing tests. This PR applies similar approach as in #17534, skipping match usefulness check for patterns containing errors
| -rw-r--r-- | src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs | 9 | ||||
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/type_mismatch.rs | 12 |
2 files changed, 21 insertions, 0 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs b/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs index 7bf8af4caba..a12e201cf3d 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs @@ -86,6 +86,15 @@ impl<'db> MatchCheckCtx<'db> { arms: &[MatchArm<'db>], scrut_ty: Ty, ) -> Result<UsefulnessReport<'db, Self>, ()> { + if scrut_ty.contains_unknown() { + return Err(()); + } + for arm in arms { + if arm.pat.ty().contains_unknown() { + return Err(()); + } + } + // FIXME: Determine place validity correctly. For now, err on the safe side. let place_validity = PlaceValidity::MaybeInvalid; // Measured to take ~100ms on modern hardware. diff --git a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/type_mismatch.rs b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/type_mismatch.rs index 4c255322280..4e52d28051b 100644 --- a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/type_mismatch.rs +++ b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/type_mismatch.rs @@ -748,4 +748,16 @@ fn f() { "#, ); } + + #[test] + fn regression_17585() { + check_diagnostics( + r#" +fn f() { + let (_, _, _, ..) = (true, 42); + // ^^^^^^^^^^^^^ error: expected (bool, i32), found (bool, i32, {unknown}) +} +"#, + ); + } } |
