aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/diagnostics/match_check.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/diagnostics/match_check.rs')
-rw-r--r--crates/hir_ty/src/diagnostics/match_check.rs37
1 files changed, 17 insertions, 20 deletions
diff --git a/crates/hir_ty/src/diagnostics/match_check.rs b/crates/hir_ty/src/diagnostics/match_check.rs
index fbe760c39..86fee0050 100644
--- a/crates/hir_ty/src/diagnostics/match_check.rs
+++ b/crates/hir_ty/src/diagnostics/match_check.rs
@@ -227,7 +227,7 @@ use hir_def::{
227use la_arena::Idx; 227use la_arena::Idx;
228use smallvec::{smallvec, SmallVec}; 228use smallvec::{smallvec, SmallVec};
229 229
230use crate::{db::HirDatabase, ApplicationTy, InferenceResult, Ty, TypeCtor}; 230use crate::{db::HirDatabase, InferenceResult, Ty};
231 231
232#[derive(Debug, Clone, Copy)] 232#[derive(Debug, Clone, Copy)]
233/// Either a pattern from the source code being analyzed, represented as 233/// Either a pattern from the source code being analyzed, represented as
@@ -627,14 +627,12 @@ pub(super) fn is_useful(
627 // - `!` type 627 // - `!` type
628 // In those cases, no match arm is useful. 628 // In those cases, no match arm is useful.
629 match cx.infer[cx.match_expr].strip_references() { 629 match cx.infer[cx.match_expr].strip_references() {
630 Ty::Apply(ApplicationTy { ctor: TypeCtor::Adt(AdtId::EnumId(enum_id)), .. }) => { 630 Ty::Adt(AdtId::EnumId(enum_id), ..) => {
631 if cx.db.enum_data(*enum_id).variants.is_empty() { 631 if cx.db.enum_data(*enum_id).variants.is_empty() {
632 return Ok(Usefulness::NotUseful); 632 return Ok(Usefulness::NotUseful);
633 } 633 }
634 } 634 }
635 Ty::Apply(ApplicationTy { ctor: TypeCtor::Never, .. }) => { 635 Ty::Never => return Ok(Usefulness::NotUseful),
636 return Ok(Usefulness::NotUseful);
637 }
638 _ => (), 636 _ => (),
639 } 637 }
640 638
@@ -1495,6 +1493,20 @@ fn main(f: Foo) {
1495 ); 1493 );
1496 } 1494 }
1497 1495
1496 #[test]
1497 fn internal_or() {
1498 check_diagnostics(
1499 r#"
1500fn main() {
1501 enum Either { A(bool), B }
1502 match Either::B {
1503 //^^^^^^^^^ Missing match arm
1504 Either::A(true | false) => (),
1505 }
1506}
1507"#,
1508 );
1509 }
1498 mod false_negatives { 1510 mod false_negatives {
1499 //! The implementation of match checking here is a work in progress. As we roll this out, we 1511 //! The implementation of match checking here is a work in progress. As we roll this out, we
1500 //! prefer false negatives to false positives (ideally there would be no false positives). This 1512 //! prefer false negatives to false positives (ideally there would be no false positives). This
@@ -1521,20 +1533,5 @@ fn main() {
1521"#, 1533"#,
1522 ); 1534 );
1523 } 1535 }
1524
1525 #[test]
1526 fn internal_or() {
1527 // We do not currently handle patterns with internal `or`s.
1528 check_diagnostics(
1529 r#"
1530fn main() {
1531 enum Either { A(bool), B }
1532 match Either::B {
1533 Either::A(true | false) => (),
1534 }
1535}
1536"#,
1537 );
1538 }
1539 } 1536 }
1540} 1537}