diff options
author | Dawer <[email protected]> | 2021-05-12 07:04:56 +0100 |
---|---|---|
committer | Dawer <[email protected]> | 2021-05-31 20:49:44 +0100 |
commit | 4cce7a6407821f456741a8d512ae31da3128c84f (patch) | |
tree | e7baddfdf72bcef8477fe20de090590b34932a3c /crates/hir_ty/src/diagnostics/match_check.rs | |
parent | f46a42f73aa92ab66800c70d525ddc7e6529edd6 (diff) |
Box field detection; test #[non-exhaustive] attribute
Diffstat (limited to 'crates/hir_ty/src/diagnostics/match_check.rs')
-rw-r--r-- | crates/hir_ty/src/diagnostics/match_check.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/crates/hir_ty/src/diagnostics/match_check.rs b/crates/hir_ty/src/diagnostics/match_check.rs index 5f0cc4145..061ef754d 100644 --- a/crates/hir_ty/src/diagnostics/match_check.rs +++ b/crates/hir_ty/src/diagnostics/match_check.rs | |||
@@ -1090,6 +1090,42 @@ fn main() { | |||
1090 | ); | 1090 | ); |
1091 | } | 1091 | } |
1092 | 1092 | ||
1093 | #[test] | ||
1094 | fn enum_non_exhaustive() { | ||
1095 | check_diagnostics( | ||
1096 | r#" | ||
1097 | //- /lib.rs crate:lib | ||
1098 | #[non_exhaustive] | ||
1099 | pub enum E { A, B } | ||
1100 | fn _local() { | ||
1101 | match E::A { _ => {} } | ||
1102 | match E::A { | ||
1103 | E::A => {} | ||
1104 | E::B => {} | ||
1105 | } | ||
1106 | match E::A { | ||
1107 | E::A | E::B => {} | ||
1108 | } | ||
1109 | } | ||
1110 | |||
1111 | //- /main.rs crate:main deps:lib | ||
1112 | use lib::E; | ||
1113 | fn main() { | ||
1114 | match E::A { _ => {} } | ||
1115 | match E::A { | ||
1116 | //^^^^ Missing match arm | ||
1117 | E::A => {} | ||
1118 | E::B => {} | ||
1119 | } | ||
1120 | match E::A { | ||
1121 | //^^^^ Missing match arm | ||
1122 | E::A | E::B => {} | ||
1123 | } | ||
1124 | } | ||
1125 | "#, | ||
1126 | ); | ||
1127 | } | ||
1128 | |||
1093 | mod false_negatives { | 1129 | mod false_negatives { |
1094 | //! The implementation of match checking here is a work in progress. As we roll this out, we | 1130 | //! The implementation of match checking here is a work in progress. As we roll this out, we |
1095 | //! prefer false negatives to false positives (ideally there would be no false positives). This | 1131 | //! prefer false negatives to false positives (ideally there would be no false positives). This |