diff options
Diffstat (limited to 'crates/ra_hir_ty/src/_match.rs')
-rw-r--r-- | crates/ra_hir_ty/src/_match.rs | 68 |
1 files changed, 35 insertions, 33 deletions
diff --git a/crates/ra_hir_ty/src/_match.rs b/crates/ra_hir_ty/src/_match.rs index de291c1f6..91206adc3 100644 --- a/crates/ra_hir_ty/src/_match.rs +++ b/crates/ra_hir_ty/src/_match.rs | |||
@@ -250,17 +250,13 @@ pub enum Usefulness { | |||
250 | 250 | ||
251 | pub struct MatchCheckCtx<'a> { | 251 | pub struct MatchCheckCtx<'a> { |
252 | pub body: Arc<Body>, | 252 | pub body: Arc<Body>, |
253 | pub match_expr: &'a Expr, | ||
254 | pub infer: Arc<InferenceResult>, | 253 | pub infer: Arc<InferenceResult>, |
255 | pub db: &'a dyn HirDatabase, | 254 | pub db: &'a dyn HirDatabase, |
256 | } | 255 | } |
257 | 256 | ||
258 | // see src/librustc_mir_build/hair/pattern/_match.rs | 257 | /// Given a set of patterns `matrix`, and pattern to consider `v`, determines |
259 | // It seems the rustc version of this method is able to assume that all the match arm | 258 | /// whether `v` is useful. A pattern is useful if it covers cases which were |
260 | // patterns are valid (they are valid given a particular match expression), but I | 259 | /// not previously covered. |
261 | // don't think we can make that assumption here. How should that be handled? | ||
262 | // | ||
263 | // Perhaps check that validity before passing the patterns into this method? | ||
264 | pub(crate) fn is_useful( | 260 | pub(crate) fn is_useful( |
265 | cx: &MatchCheckCtx, | 261 | cx: &MatchCheckCtx, |
266 | matrix: &Matrix, | 262 | matrix: &Matrix, |
@@ -518,6 +514,19 @@ mod tests { | |||
518 | } | 514 | } |
519 | 515 | ||
520 | #[test] | 516 | #[test] |
517 | fn empty_tuple_wild() { | ||
518 | let content = r" | ||
519 | fn test_fn() { | ||
520 | match () { | ||
521 | _ => {} | ||
522 | } | ||
523 | } | ||
524 | "; | ||
525 | |||
526 | check_no_diagnostic(content); | ||
527 | } | ||
528 | |||
529 | #[test] | ||
521 | fn empty_tuple_no_diagnostic() { | 530 | fn empty_tuple_no_diagnostic() { |
522 | let content = r" | 531 | let content = r" |
523 | fn test_fn() { | 532 | fn test_fn() { |
@@ -976,21 +985,6 @@ mod tests { | |||
976 | 985 | ||
977 | check_no_diagnostic(content); | 986 | check_no_diagnostic(content); |
978 | } | 987 | } |
979 | } | ||
980 | |||
981 | #[cfg(test)] | ||
982 | mod false_negatives { | ||
983 | //! The implementation of match checking here is a work in progress. As we roll this out, we | ||
984 | //! prefer false negatives to false positives (ideally there would be no false positives). This | ||
985 | //! test module should document known false negatives. Eventually we will have a complete | ||
986 | //! implementation of match checking and this module will be empty. | ||
987 | //! | ||
988 | //! The reasons for documenting known false negatives: | ||
989 | //! | ||
990 | //! 1. It acts as a backlog of work that can be done to improve the behavior of the system. | ||
991 | //! 2. It ensures the code doesn't panic when handling these cases. | ||
992 | |||
993 | use super::tests::*; | ||
994 | 988 | ||
995 | #[test] | 989 | #[test] |
996 | fn mismatched_types() { | 990 | fn mismatched_types() { |
@@ -1011,10 +1005,8 @@ mod false_negatives { | |||
1011 | } | 1005 | } |
1012 | "; | 1006 | "; |
1013 | 1007 | ||
1014 | // This is a false negative. | 1008 | // Match arms with the incorrect type are filtered out. |
1015 | // We don't currently check that the match arms actually | 1009 | check_diagnostic_with_no_fix(content); |
1016 | // match the type of the match expression. | ||
1017 | check_no_diagnostic(content); | ||
1018 | } | 1010 | } |
1019 | 1011 | ||
1020 | #[test] | 1012 | #[test] |
@@ -1028,14 +1020,24 @@ mod false_negatives { | |||
1028 | } | 1020 | } |
1029 | "; | 1021 | "; |
1030 | 1022 | ||
1031 | // This is a false negative. | 1023 | // Match arms with the incorrect type are filtered out. |
1032 | // We don't currently check that the match arms actually | 1024 | check_diagnostic_with_no_fix(content); |
1033 | // match the type of the match expression. This test | ||
1034 | // checks to ensure we don't panic when the code we are | ||
1035 | // checking is malformed in such a way that the arity of the | ||
1036 | // constructors doesn't match. | ||
1037 | check_no_diagnostic(content); | ||
1038 | } | 1025 | } |
1026 | } | ||
1027 | |||
1028 | #[cfg(test)] | ||
1029 | mod false_negatives { | ||
1030 | //! The implementation of match checking here is a work in progress. As we roll this out, we | ||
1031 | //! prefer false negatives to false positives (ideally there would be no false positives). This | ||
1032 | //! test module should document known false negatives. Eventually we will have a complete | ||
1033 | //! implementation of match checking and this module will be empty. | ||
1034 | //! | ||
1035 | //! The reasons for documenting known false negatives: | ||
1036 | //! | ||
1037 | //! 1. It acts as a backlog of work that can be done to improve the behavior of the system. | ||
1038 | //! 2. It ensures the code doesn't panic when handling these cases. | ||
1039 | |||
1040 | use super::tests::*; | ||
1039 | 1041 | ||
1040 | #[test] | 1042 | #[test] |
1041 | fn integers() { | 1043 | fn integers() { |