diff options
Diffstat (limited to 'crates/ra_hir/src/ty/tests.rs')
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 59 |
1 files changed, 57 insertions, 2 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index c7d409e6d..0f2172ddf 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -10,6 +10,7 @@ use test_utils::covers; | |||
10 | use crate::{ | 10 | use crate::{ |
11 | source_binder, | 11 | source_binder, |
12 | mock::MockDatabase, | 12 | mock::MockDatabase, |
13 | ty::display::HirDisplay, | ||
13 | }; | 14 | }; |
14 | 15 | ||
15 | // These tests compare the inference results for all expressions in a file | 16 | // These tests compare the inference results for all expressions in a file |
@@ -830,6 +831,60 @@ fn test(x: &i32) { | |||
830 | } | 831 | } |
831 | 832 | ||
832 | #[test] | 833 | #[test] |
834 | fn infer_pattern_match_ergonomics() { | ||
835 | assert_snapshot_matches!( | ||
836 | infer(r#" | ||
837 | struct A<T>(T); | ||
838 | |||
839 | fn test() { | ||
840 | let A(n) = &A(1); | ||
841 | let A(n) = &mut A(1); | ||
842 | } | ||
843 | "#), | ||
844 | @r###" | ||
845 | [28; 79) '{ ...(1); }': () | ||
846 | [38; 42) 'A(n)': A<i32> | ||
847 | [40; 41) 'n': &i32 | ||
848 | [45; 50) '&A(1)': &A<i32> | ||
849 | [46; 47) 'A': A<i32>(T) -> A<T> | ||
850 | [46; 50) 'A(1)': A<i32> | ||
851 | [48; 49) '1': i32 | ||
852 | [60; 64) 'A(n)': A<i32> | ||
853 | [62; 63) 'n': &mut i32 | ||
854 | [67; 76) '&mut A(1)': &mut A<i32> | ||
855 | [72; 73) 'A': A<i32>(T) -> A<T> | ||
856 | [72; 76) 'A(1)': A<i32> | ||
857 | [74; 75) '1': i32"### | ||
858 | ); | ||
859 | } | ||
860 | |||
861 | #[test] | ||
862 | fn infer_pattern_match_ergonomics_ref() { | ||
863 | covers!(match_ergonomics_ref); | ||
864 | assert_snapshot_matches!( | ||
865 | infer(r#" | ||
866 | fn test() { | ||
867 | let v = &(1, &2); | ||
868 | let (_, &w) = v; | ||
869 | } | ||
870 | "#), | ||
871 | @r###" | ||
872 | [11; 57) '{ ...= v; }': () | ||
873 | [21; 22) 'v': &(i32, &i32) | ||
874 | [25; 33) '&(1, &2)': &(i32, &i32) | ||
875 | [26; 33) '(1, &2)': (i32, &i32) | ||
876 | [27; 28) '1': i32 | ||
877 | [30; 32) '&2': &i32 | ||
878 | [31; 32) '2': i32 | ||
879 | [43; 50) '(_, &w)': (i32, &i32) | ||
880 | [44; 45) '_': i32 | ||
881 | [47; 49) '&w': &i32 | ||
882 | [48; 49) 'w': i32 | ||
883 | [53; 54) 'v': &(i32, &i32)"### | ||
884 | ); | ||
885 | } | ||
886 | |||
887 | #[test] | ||
833 | fn infer_adt_pattern() { | 888 | fn infer_adt_pattern() { |
834 | assert_snapshot_matches!( | 889 | assert_snapshot_matches!( |
835 | infer(r#" | 890 | infer(r#" |
@@ -2142,7 +2197,7 @@ fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { | |||
2142 | let node = algo::find_node_at_offset::<ast::Expr>(syntax.syntax(), pos.offset).unwrap(); | 2197 | let node = algo::find_node_at_offset::<ast::Expr>(syntax.syntax(), pos.offset).unwrap(); |
2143 | let expr = body_source_map.node_expr(node).unwrap(); | 2198 | let expr = body_source_map.node_expr(node).unwrap(); |
2144 | let ty = &inference_result[expr]; | 2199 | let ty = &inference_result[expr]; |
2145 | ty.to_string() | 2200 | ty.display(db).to_string() |
2146 | } | 2201 | } |
2147 | 2202 | ||
2148 | fn infer(content: &str) -> String { | 2203 | fn infer(content: &str) -> String { |
@@ -2178,7 +2233,7 @@ fn infer(content: &str) -> String { | |||
2178 | "{} '{}': {}\n", | 2233 | "{} '{}': {}\n", |
2179 | syntax_ptr.range(), | 2234 | syntax_ptr.range(), |
2180 | ellipsize(node.text().to_string().replace("\n", " "), 15), | 2235 | ellipsize(node.text().to_string().replace("\n", " "), 15), |
2181 | ty | 2236 | ty.display(&db) |
2182 | ) | 2237 | ) |
2183 | .unwrap(); | 2238 | .unwrap(); |
2184 | } | 2239 | } |