Skip to content

Commit e5e6c36

Browse files
bors[bot]iDawer
andauthored
Merge #8840
8840: fix: false positive "Missing match arm" when a tuple pattern is shorter than scrutinee type. r=Veykril a=iDawer ![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 fd109fb 2021-05-10 dev (This is part of the preparation for #8717) Co-authored-by: Dawer <[email protected]>
2 parents 260bcd9 + 2abb4c9 commit e5e6c36

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

crates/hir_ty/src/diagnostics/match_check.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,7 @@ fn main() {
11191119
(true, false, true) => (),
11201120
(true) => (),
11211121
}
1122+
match (true, false) { (true,) => {} }
11221123
match (0) { () => () }
11231124
match Unresolved::Bar { Unresolved::Baz => () }
11241125
}

crates/hir_ty/src/infer/pat.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,12 @@ impl<'a> InferenceContext<'a> {
126126
_ => &[],
127127
};
128128

129-
let (pre, post) = match ellipsis {
130-
Some(idx) => args.split_at(idx),
131-
None => (&args[..], &[][..]),
129+
let ((pre, post), n_uncovered_patterns) = match ellipsis {
130+
Some(idx) => {
131+
(args.split_at(idx), expectations.len().saturating_sub(args.len()))
132+
}
133+
None => ((&args[..], &[][..]), 0),
132134
};
133-
let n_uncovered_patterns = expectations.len().saturating_sub(args.len());
134135
let err_ty = self.err_ty();
135136
let mut expectations_iter =
136137
expectations.iter().map(|a| a.assert_ty_ref(&Interner)).chain(repeat(&err_ty));

crates/hir_ty/src/tests/patterns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ fn foo(tuple: (u8, i16, f32)) {
732732
111..112 'a': u8
733733
114..115 'b': i16
734734
124..126 '{}': ()
735-
136..142 '(a, b)': (u8, i16, f32)
735+
136..142 '(a, b)': (u8, i16)
736736
137..138 'a': u8
737737
140..141 'b': i16
738738
146..161 '{/*too short*/}': ()

0 commit comments

Comments
 (0)