diff options
Diffstat (limited to 'crates/ra_hir_ty/src/tests')
-rw-r--r-- | crates/ra_hir_ty/src/tests/display_source_code.rs | 27 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/simple.rs | 29 |
2 files changed, 56 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/tests/display_source_code.rs b/crates/ra_hir_ty/src/tests/display_source_code.rs index ca1748615..4088b1d22 100644 --- a/crates/ra_hir_ty/src/tests/display_source_code.rs +++ b/crates/ra_hir_ty/src/tests/display_source_code.rs | |||
@@ -21,3 +21,30 @@ fn bar() { | |||
21 | ); | 21 | ); |
22 | assert_eq!("foo::Foo", displayed_source_at_pos(&db, pos)); | 22 | assert_eq!("foo::Foo", displayed_source_at_pos(&db, pos)); |
23 | } | 23 | } |
24 | |||
25 | #[test] | ||
26 | fn omit_default_type_parameters() { | ||
27 | let (db, pos) = TestDB::with_position( | ||
28 | r" | ||
29 | //- /main.rs | ||
30 | struct Foo<T = u8> { t: T } | ||
31 | fn main() { | ||
32 | let foo = Foo { t: 5 }; | ||
33 | foo<|>; | ||
34 | } | ||
35 | ", | ||
36 | ); | ||
37 | assert_eq!("Foo", displayed_source_at_pos(&db, pos)); | ||
38 | |||
39 | let (db, pos) = TestDB::with_position( | ||
40 | r" | ||
41 | //- /main.rs | ||
42 | struct Foo<K, T = u8> { k: K, t: T } | ||
43 | fn main() { | ||
44 | let foo = Foo { k: 400, t: 5 }; | ||
45 | foo<|>; | ||
46 | } | ||
47 | ", | ||
48 | ); | ||
49 | assert_eq!("Foo<i32>", displayed_source_at_pos(&db, pos)); | ||
50 | } | ||
diff --git a/crates/ra_hir_ty/src/tests/simple.rs b/crates/ra_hir_ty/src/tests/simple.rs index 3820175f6..322838f02 100644 --- a/crates/ra_hir_ty/src/tests/simple.rs +++ b/crates/ra_hir_ty/src/tests/simple.rs | |||
@@ -1787,3 +1787,32 @@ fn main() { | |||
1787 | "### | 1787 | "### |
1788 | ) | 1788 | ) |
1789 | } | 1789 | } |
1790 | |||
1791 | #[test] | ||
1792 | fn infer_generic_from_later_assignment() { | ||
1793 | assert_snapshot!( | ||
1794 | infer(r#" | ||
1795 | enum Option<T> { Some(T), None } | ||
1796 | use Option::*; | ||
1797 | |||
1798 | fn test() { | ||
1799 | let mut end = None; | ||
1800 | loop { | ||
1801 | end = Some(true); | ||
1802 | } | ||
1803 | } | ||
1804 | "#), | ||
1805 | @r###" | ||
1806 | 60..130 '{ ... } }': () | ||
1807 | 70..77 'mut end': Option<bool> | ||
1808 | 80..84 'None': Option<bool> | ||
1809 | 90..128 'loop {... }': ! | ||
1810 | 95..128 '{ ... }': () | ||
1811 | 105..108 'end': Option<bool> | ||
1812 | 105..121 'end = ...(true)': () | ||
1813 | 111..115 'Some': Some<bool>(bool) -> Option<bool> | ||
1814 | 111..121 'Some(true)': Option<bool> | ||
1815 | 116..120 'true': bool | ||
1816 | "### | ||
1817 | ); | ||
1818 | } | ||