Repository: rust-analyzer/rust-analyzer
Pull request #8840 (2021-05-14 19:41:34)

fix: false positive "Missing match arm" when a tuple pattern is shorter than scrutinee type.
![Screenshot_20210515_003035](https://user-images.githubusercontent.com/7803845/118320023-2bcb7380-b4eb-11eb-9de6-d8762f981dc2.jpg)
Match checking diagnostic shouldn't fire when there is type mismatches.

rust-analyzer fd109fb58 2021-05-10 dev

(This is part of the preparation for https://github.com/rust-analyzer/rust-analyzer/pull/8717)


Patch:
diff --git a/crates/flycheck/src/lib.rs b/crates/flycheck/src/lib.rs
index 93cf6a3d68..1682d8bde2 100644
--- a/crates/flycheck/src/lib.rs
+++ b/crates/flycheck/src/lib.rs
@@ -215,7 +215,6 @@ impl FlycheckActor {
             } => {
                 let mut cmd = Command::new(toolchain::cargo());
                 cmd.arg(command);
-                cmd.current_dir(&self.workspace_root);
                 cmd.args(&["--workspace", "--message-format=json", "--manifest-path"])
                     .arg(self.workspace_root.join("Cargo.toml"));
 
diff --git a/crates/hir_ty/src/diagnostics/match_check.rs b/crates/hir_ty/src/diagnostics/match_check.rs
index e9762622f3..6ee0529c62 100644
--- a/crates/hir_ty/src/diagnostics/match_check.rs
+++ b/crates/hir_ty/src/diagnostics/match_check.rs
@@ -1119,6 +1119,7 @@ fn main() {
         (true, false, true) => (),
         (true) => (),
     }
+    match (true, false) { (true,) => {} }
     match (0) { () => () }
     match Unresolved::Bar { Unresolved::Baz => () }
 }
diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs
index aea354cdec..60b94a6422 100644
--- a/crates/hir_ty/src/infer/pat.rs
+++ b/crates/hir_ty/src/infer/pat.rs
@@ -126,11 +126,12 @@ impl<'a> InferenceContext<'a> {
                     _ => &[],
                 };
 
-                let (pre, post) = match ellipsis {
-                    Some(idx) => args.split_at(idx),
-                    None => (&args[..], &[][..]),
+                let ((pre, post), n_uncovered_patterns) = match ellipsis {
+                    Some(idx) => {
+                        (args.split_at(idx), expectations.len().saturating_sub(args.len()))
+                    }
+                    None => ((&args[..], &[][..]), 0),
                 };
-                let n_uncovered_patterns = expectations.len().saturating_sub(args.len());
                 let err_ty = self.err_ty();
                 let mut expectations_iter =
                     expectations.iter().map(|a| a.assert_ty_ref(&Interner)).chain(repeat(&err_ty));
diff --git a/crates/project_model/src/build_data.rs b/crates/project_model/src/build_data.rs
index 3aa546980c..7b88dca630 100644
--- a/crates/project_model/src/build_data.rs
+++ b/crates/project_model/src/build_data.rs
@@ -143,7 +143,6 @@ impl WorkspaceBuildData {
             cmd.env("RA_RUSTC_WRAPPER", "1");
         }
 
-        cmd.current_dir(cargo_toml.parent().unwrap());
         cmd.args(&["check", "--quiet", "--workspace", "--message-format=json", "--manifest-path"])
             .arg(cargo_toml.as_ref());
 
diff --git a/crates/rust-analyzer/src/integrated_benchmarks.rs b/crates/rust-analyzer/src/integrated_benchmarks.rs
index ba2790acbd..56de9681c4 100644
--- a/crates/rust-analyzer/src/integrated_benchmarks.rs
+++ b/crates/rust-analyzer/src/integrated_benchmarks.rs
@@ -123,7 +123,7 @@ fn integrated_completion_benchmark() {
     };
 
     {
-        let _p = profile::span("unqualified path completion");
+        let _it = stdx::timeit("unqualified path completion");
         let _span = profile::cpu_span();
         let analysis = host.analysis();
         let config = CompletionConfig {
@@ -156,7 +156,7 @@ fn integrated_completion_benchmark() {
     };
 
     {
-        let _p = profile::span("dot completion");
+        let _it = stdx::timeit("dot completion");
         let _span = profile::cpu_span();
         let analysis = host.analysis();
         let config = CompletionConfig {


Test patch:
diff --git a/crates/hir_ty/src/tests/patterns.rs b/crates/hir_ty/src/tests/patterns.rs
index 33305f208f..a0a7b4d0b7 100644
--- a/crates/hir_ty/src/tests/patterns.rs
+++ b/crates/hir_ty/src/tests/patterns.rs
@@ -732,7 +732,7 @@ fn foo(tuple: (u8, i16, f32)) {
             111..112 'a': u8
             114..115 'b': i16
             124..126 '{}': ()
-            136..142 '(a, b)': (u8, i16, f32)
+            136..142 '(a, b)': (u8, i16)
             137..138 'a': u8
             140..141 'b': i16
             146..161 '{/*too short*/}': ()