Skip to content

Commit 977ba46

Browse files
committed
Test match guards, reference patterns
1 parent 4cce7a6 commit 977ba46

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

crates/hir_ty/src/diagnostics/match_check.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,25 @@ fn main() {
11261126
);
11271127
}
11281128

1129+
#[test]
1130+
fn match_guard() {
1131+
check_diagnostics(
1132+
r#"
1133+
fn main() {
1134+
match true {
1135+
true if false => {}
1136+
true => {}
1137+
false => {}
1138+
}
1139+
match true {
1140+
//^^^^ Missing match arm
1141+
true if false => {}
1142+
false => {}
1143+
}
1144+
"#,
1145+
);
1146+
}
1147+
11291148
mod false_negatives {
11301149
//! The implementation of match checking here is a work in progress. As we roll this out, we
11311150
//! prefer false negatives to false positives (ideally there would be no false positives). This
@@ -1153,5 +1172,37 @@ fn main() {
11531172
"#,
11541173
);
11551174
}
1175+
1176+
#[test]
1177+
fn reference_patterns_at_top_level() {
1178+
check_diagnostics(
1179+
r#"
1180+
fn main() {
1181+
match &false {
1182+
&true => {}
1183+
// ^^^^^ Internal: match check bailed out
1184+
}
1185+
}
1186+
"#,
1187+
);
1188+
}
1189+
1190+
#[test]
1191+
fn reference_patterns_in_fields() {
1192+
check_diagnostics(
1193+
r#"
1194+
fn main() {
1195+
match (&false,) {
1196+
(true,) => {}
1197+
// ^^^^^^^ Internal: match check bailed out
1198+
}
1199+
match (&false,) {
1200+
(&true,) => {}
1201+
// ^^^^^^^^ Internal: match check bailed out
1202+
}
1203+
}
1204+
"#,
1205+
);
1206+
}
11561207
}
11571208
}

0 commit comments

Comments
 (0)