aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorJosh Mcguigan <[email protected]>2020-04-05 20:42:24 +0100
committerJosh Mcguigan <[email protected]>2020-04-07 13:12:08 +0100
commit5fe608fb31430f43a404312e284a71d6f7cfa038 (patch)
tree092a0898d9bea176099fd07e3ff8c8ee290052d0 /crates
parent5b4316377b9897f064b213a52a7efe8622d48487 (diff)
handle match auto-deref
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir_ty/src/_match.rs35
-rw-r--r--crates/ra_hir_ty/src/expr.rs11
2 files changed, 45 insertions, 1 deletions
diff --git a/crates/ra_hir_ty/src/_match.rs b/crates/ra_hir_ty/src/_match.rs
index 8b9bdb7cd..f502a9208 100644
--- a/crates/ra_hir_ty/src/_match.rs
+++ b/crates/ra_hir_ty/src/_match.rs
@@ -866,6 +866,41 @@ mod tests {
866 } 866 }
867 867
868 #[test] 868 #[test]
869 fn enum_ref_missing_arms() {
870 let content = r"
871 enum Either {
872 A,
873 B,
874 }
875 fn test_fn() {
876 match &Either::B {
877 Either::A => {},
878 }
879 }
880 ";
881
882 check_diagnostic_with_no_fix(content);
883 }
884
885 #[test]
886 fn enum_ref_no_diagnostic() {
887 let content = r"
888 enum Either {
889 A,
890 B,
891 }
892 fn test_fn() {
893 match &Either::B {
894 Either::A => {},
895 Either::B => {},
896 }
897 }
898 ";
899
900 check_no_diagnostic(content);
901 }
902
903 #[test]
869 fn enum_containing_bool_no_arms() { 904 fn enum_containing_bool_no_arms() {
870 let content = r" 905 let content = r"
871 enum Either { 906 enum Either {
diff --git a/crates/ra_hir_ty/src/expr.rs b/crates/ra_hir_ty/src/expr.rs
index 8c7d1a98e..6efed6f9e 100644
--- a/crates/ra_hir_ty/src/expr.rs
+++ b/crates/ra_hir_ty/src/expr.rs
@@ -93,7 +93,16 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
93 // of the match expression. If we had a InvalidMatchArmPattern 93 // of the match expression. If we had a InvalidMatchArmPattern
94 // diagnostic or similar we could raise that in an else 94 // diagnostic or similar we could raise that in an else
95 // block here. 95 // block here.
96 if pat_ty == match_expr_ty { 96 //
97 // When comparing the types, we also have to consider that rustc
98 // will automatically de-reference the match expression type if
99 // necessary.
100 if pat_ty == match_expr_ty
101 || match_expr_ty
102 .as_reference()
103 .map(|(match_expr_ty, _)| match_expr_ty == pat_ty)
104 .unwrap_or(false)
105 {
97 // If we had a NotUsefulMatchArm diagnostic, we could 106 // If we had a NotUsefulMatchArm diagnostic, we could
98 // check the usefulness of each pattern as we added it 107 // check the usefulness of each pattern as we added it
99 // to the matrix here. 108 // to the matrix here.