Skip to content

Commit e99447f

Browse files
bors[bot]MikailBag
andauthored
Merge #4347
4347: Fix usefulness check for never type r=flodiebold a=MikailBag Co-authored-by: Mikail Bagishov <bagishov.mikail@yandex.ru>
2 parents 1252107 + 7c94fa7 commit e99447f

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

crates/ra_hir_ty/src/_match.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -573,14 +573,20 @@ pub(crate) fn is_useful(
573573
matrix: &Matrix,
574574
v: &PatStack,
575575
) -> MatchCheckResult<Usefulness> {
576-
// Handle the special case of enums with no variants. In that case, no match
577-
// arm is useful.
578-
if let Ty::Apply(ApplicationTy { ctor: TypeCtor::Adt(AdtId::EnumId(enum_id)), .. }) =
579-
cx.infer[cx.match_expr].strip_references()
580-
{
581-
if cx.db.enum_data(*enum_id).variants.is_empty() {
576+
// Handle two special cases:
577+
// - enum with no variants
578+
// - `!` type
579+
// In those cases, no match arm is useful.
580+
match cx.infer[cx.match_expr].strip_references() {
581+
Ty::Apply(ApplicationTy { ctor: TypeCtor::Adt(AdtId::EnumId(enum_id)), .. }) => {
582+
if cx.db.enum_data(*enum_id).variants.is_empty() {
583+
return Ok(Usefulness::NotUseful);
584+
}
585+
}
586+
Ty::Apply(ApplicationTy { ctor: TypeCtor::Never, .. }) => {
582587
return Ok(Usefulness::NotUseful);
583588
}
589+
_ => (),
584590
}
585591

586592
if v.is_empty() {
@@ -1917,6 +1923,17 @@ mod tests {
19171923
check_no_diagnostic(content);
19181924
}
19191925

1926+
#[test]
1927+
fn type_never() {
1928+
let content = r"
1929+
fn test_fn(never: !) {
1930+
match never {}
1931+
}
1932+
";
1933+
1934+
check_no_diagnostic(content);
1935+
}
1936+
19201937
#[test]
19211938
fn enum_never_ref() {
19221939
let content = r"

0 commit comments

Comments
 (0)