File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
crates/hir_ty/src/diagnostics Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ pub(crate) enum PatternError {
25
25
Unimplemented ,
26
26
UnresolvedVariant ,
27
27
MissingField ,
28
+ ExtraFields ,
28
29
}
29
30
30
31
#[ derive( Clone , Debug , PartialEq ) ]
@@ -182,6 +183,11 @@ impl<'a> PatCtxt<'a> {
182
183
expected_len : usize ,
183
184
ellipsis : Option < usize > ,
184
185
) -> Vec < FieldPat > {
186
+ if pats. len ( ) > expected_len {
187
+ self . errors . push ( PatternError :: ExtraFields ) ;
188
+ return Vec :: new ( ) ;
189
+ }
190
+
185
191
pats. iter ( )
186
192
. enumerate_and_adjust ( expected_len, ellipsis)
187
193
. map ( |( i, & subpattern) | FieldPat {
@@ -702,6 +708,25 @@ fn main() {
702
708
) ;
703
709
}
704
710
711
+ #[ test]
712
+ fn malformed_match_arm_extra_fields ( ) {
713
+ check_diagnostics (
714
+ r#"
715
+ enum A { B(isize, isize), C }
716
+ fn main() {
717
+ match A::B(1, 2) {
718
+ A::B(_, _, _) => (),
719
+ // ^^^^^^^^^^^^^ Internal: match check bailed out
720
+ }
721
+ match A::B(1, 2) {
722
+ A::C(_) => (),
723
+ // ^^^^^^^ Internal: match check bailed out
724
+ }
725
+ }
726
+ "# ,
727
+ ) ;
728
+ }
729
+
705
730
#[ test]
706
731
fn expr_diverges ( ) {
707
732
check_diagnostics (
You can’t perform that action at this time.
0 commit comments