diff options
author | Mikhail Rakhmanov <[email protected]> | 2020-06-13 07:42:15 +0100 |
---|---|---|
committer | Mikhail Rakhmanov <[email protected]> | 2020-06-13 07:42:15 +0100 |
commit | 16bbf4ab7f132e6e5e5318dccdef9a5d71afdd7f (patch) | |
tree | 4b79fa8c046be56b02427ba843e70cdf3ac05767 /crates/ra_hir_ty/src/tests/traits.rs | |
parent | eeb8b9e236796da8734ba81a49164864497f7226 (diff) | |
parent | b56ad148db0c69eb279c225f45d324b4e80e7367 (diff) |
Merge branch 'master' into keyword_completion
# Conflicts:
# docs/user/generated_features.adoc
Diffstat (limited to 'crates/ra_hir_ty/src/tests/traits.rs')
-rw-r--r-- | crates/ra_hir_ty/src/tests/traits.rs | 174 |
1 files changed, 132 insertions, 42 deletions
diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index e8778d419..e81193a3c 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs | |||
@@ -10,7 +10,7 @@ use super::{infer, infer_with_mismatches, type_at, type_at_pos}; | |||
10 | fn infer_await() { | 10 | fn infer_await() { |
11 | let (db, pos) = TestDB::with_position( | 11 | let (db, pos) = TestDB::with_position( |
12 | r#" | 12 | r#" |
13 | //- /main.rs crate:main deps:std | 13 | //- /main.rs crate:main deps:core |
14 | 14 | ||
15 | struct IntFuture; | 15 | struct IntFuture; |
16 | 16 | ||
@@ -24,7 +24,7 @@ fn test() { | |||
24 | v<|>; | 24 | v<|>; |
25 | } | 25 | } |
26 | 26 | ||
27 | //- /std.rs crate:std | 27 | //- /core.rs crate:core |
28 | #[prelude_import] use future::*; | 28 | #[prelude_import] use future::*; |
29 | mod future { | 29 | mod future { |
30 | #[lang = "future_trait"] | 30 | #[lang = "future_trait"] |
@@ -42,7 +42,7 @@ mod future { | |||
42 | fn infer_async() { | 42 | fn infer_async() { |
43 | let (db, pos) = TestDB::with_position( | 43 | let (db, pos) = TestDB::with_position( |
44 | r#" | 44 | r#" |
45 | //- /main.rs crate:main deps:std | 45 | //- /main.rs crate:main deps:core |
46 | 46 | ||
47 | async fn foo() -> u64 { | 47 | async fn foo() -> u64 { |
48 | 128 | 48 | 128 |
@@ -54,7 +54,7 @@ fn test() { | |||
54 | v<|>; | 54 | v<|>; |
55 | } | 55 | } |
56 | 56 | ||
57 | //- /std.rs crate:std | 57 | //- /core.rs crate:core |
58 | #[prelude_import] use future::*; | 58 | #[prelude_import] use future::*; |
59 | mod future { | 59 | mod future { |
60 | #[lang = "future_trait"] | 60 | #[lang = "future_trait"] |
@@ -72,7 +72,7 @@ mod future { | |||
72 | fn infer_desugar_async() { | 72 | fn infer_desugar_async() { |
73 | let (db, pos) = TestDB::with_position( | 73 | let (db, pos) = TestDB::with_position( |
74 | r#" | 74 | r#" |
75 | //- /main.rs crate:main deps:std | 75 | //- /main.rs crate:main deps:core |
76 | 76 | ||
77 | async fn foo() -> u64 { | 77 | async fn foo() -> u64 { |
78 | 128 | 78 | 128 |
@@ -83,7 +83,7 @@ fn test() { | |||
83 | r<|>; | 83 | r<|>; |
84 | } | 84 | } |
85 | 85 | ||
86 | //- /std.rs crate:std | 86 | //- /core.rs crate:core |
87 | #[prelude_import] use future::*; | 87 | #[prelude_import] use future::*; |
88 | mod future { | 88 | mod future { |
89 | trait Future { | 89 | trait Future { |
@@ -100,7 +100,7 @@ mod future { | |||
100 | fn infer_try() { | 100 | fn infer_try() { |
101 | let (db, pos) = TestDB::with_position( | 101 | let (db, pos) = TestDB::with_position( |
102 | r#" | 102 | r#" |
103 | //- /main.rs crate:main deps:std | 103 | //- /main.rs crate:main deps:core |
104 | 104 | ||
105 | fn test() { | 105 | fn test() { |
106 | let r: Result<i32, u64> = Result::Ok(1); | 106 | let r: Result<i32, u64> = Result::Ok(1); |
@@ -108,7 +108,7 @@ fn test() { | |||
108 | v<|>; | 108 | v<|>; |
109 | } | 109 | } |
110 | 110 | ||
111 | //- /std.rs crate:std | 111 | //- /core.rs crate:core |
112 | 112 | ||
113 | #[prelude_import] use ops::*; | 113 | #[prelude_import] use ops::*; |
114 | mod ops { | 114 | mod ops { |
@@ -140,9 +140,9 @@ mod result { | |||
140 | fn infer_for_loop() { | 140 | fn infer_for_loop() { |
141 | let (db, pos) = TestDB::with_position( | 141 | let (db, pos) = TestDB::with_position( |
142 | r#" | 142 | r#" |
143 | //- /main.rs crate:main deps:std | 143 | //- /main.rs crate:main deps:core,alloc |
144 | 144 | ||
145 | use std::collections::Vec; | 145 | use alloc::collections::Vec; |
146 | 146 | ||
147 | fn test() { | 147 | fn test() { |
148 | let v = Vec::new(); | 148 | let v = Vec::new(); |
@@ -152,7 +152,7 @@ fn test() { | |||
152 | } | 152 | } |
153 | } | 153 | } |
154 | 154 | ||
155 | //- /std.rs crate:std | 155 | //- /core.rs crate:core |
156 | 156 | ||
157 | #[prelude_import] use iter::*; | 157 | #[prelude_import] use iter::*; |
158 | mod iter { | 158 | mod iter { |
@@ -161,6 +161,8 @@ mod iter { | |||
161 | } | 161 | } |
162 | } | 162 | } |
163 | 163 | ||
164 | //- /alloc.rs crate:alloc deps:core | ||
165 | |||
164 | mod collections { | 166 | mod collections { |
165 | struct Vec<T> {} | 167 | struct Vec<T> {} |
166 | impl<T> Vec<T> { | 168 | impl<T> Vec<T> { |
@@ -168,7 +170,7 @@ mod collections { | |||
168 | fn push(&mut self, t: T) { } | 170 | fn push(&mut self, t: T) { } |
169 | } | 171 | } |
170 | 172 | ||
171 | impl<T> crate::iter::IntoIterator for Vec<T> { | 173 | impl<T> IntoIterator for Vec<T> { |
172 | type Item=T; | 174 | type Item=T; |
173 | } | 175 | } |
174 | } | 176 | } |
@@ -1110,7 +1112,6 @@ fn test() { | |||
1110 | } | 1112 | } |
1111 | 1113 | ||
1112 | #[test] | 1114 | #[test] |
1113 | #[ignore] | ||
1114 | fn impl_trait() { | 1115 | fn impl_trait() { |
1115 | assert_snapshot!( | 1116 | assert_snapshot!( |
1116 | infer(r#" | 1117 | infer(r#" |
@@ -1161,6 +1162,95 @@ fn test(x: impl Trait<u64>, y: &impl Trait<u64>) { | |||
1161 | } | 1162 | } |
1162 | 1163 | ||
1163 | #[test] | 1164 | #[test] |
1165 | fn simple_return_pos_impl_trait() { | ||
1166 | mark::check!(lower_rpit); | ||
1167 | assert_snapshot!( | ||
1168 | infer(r#" | ||
1169 | trait Trait<T> { | ||
1170 | fn foo(&self) -> T; | ||
1171 | } | ||
1172 | fn bar() -> impl Trait<u64> { loop {} } | ||
1173 | |||
1174 | fn test() { | ||
1175 | let a = bar(); | ||
1176 | a.foo(); | ||
1177 | } | ||
1178 | "#), | ||
1179 | @r###" | ||
1180 | 30..34 'self': &Self | ||
1181 | 72..83 '{ loop {} }': ! | ||
1182 | 74..81 'loop {}': ! | ||
1183 | 79..81 '{}': () | ||
1184 | 95..130 '{ ...o(); }': () | ||
1185 | 105..106 'a': impl Trait<u64> | ||
1186 | 109..112 'bar': fn bar() -> impl Trait<u64> | ||
1187 | 109..114 'bar()': impl Trait<u64> | ||
1188 | 120..121 'a': impl Trait<u64> | ||
1189 | 120..127 'a.foo()': u64 | ||
1190 | "### | ||
1191 | ); | ||
1192 | } | ||
1193 | |||
1194 | #[test] | ||
1195 | fn more_return_pos_impl_trait() { | ||
1196 | assert_snapshot!( | ||
1197 | infer(r#" | ||
1198 | trait Iterator { | ||
1199 | type Item; | ||
1200 | fn next(&mut self) -> Self::Item; | ||
1201 | } | ||
1202 | trait Trait<T> { | ||
1203 | fn foo(&self) -> T; | ||
1204 | } | ||
1205 | fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>) { loop {} } | ||
1206 | fn baz<T>(t: T) -> (impl Iterator<Item = impl Trait<T>>, impl Trait<T>) { loop {} } | ||
1207 | |||
1208 | fn test() { | ||
1209 | let (a, b) = bar(); | ||
1210 | a.next().foo(); | ||
1211 | b.foo(); | ||
1212 | let (c, d) = baz(1u128); | ||
1213 | c.next().foo(); | ||
1214 | d.foo(); | ||
1215 | } | ||
1216 | "#), | ||
1217 | @r###" | ||
1218 | 50..54 'self': &mut Self | ||
1219 | 102..106 'self': &Self | ||
1220 | 185..196 '{ loop {} }': ({unknown}, {unknown}) | ||
1221 | 187..194 'loop {}': ! | ||
1222 | 192..194 '{}': () | ||
1223 | 207..208 't': T | ||
1224 | 269..280 '{ loop {} }': ({unknown}, {unknown}) | ||
1225 | 271..278 'loop {}': ! | ||
1226 | 276..278 '{}': () | ||
1227 | 292..414 '{ ...o(); }': () | ||
1228 | 302..308 '(a, b)': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>) | ||
1229 | 303..304 'a': impl Iterator<Item = impl Trait<u32>> | ||
1230 | 306..307 'b': impl Trait<u64> | ||
1231 | 311..314 'bar': fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>) | ||
1232 | 311..316 'bar()': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>) | ||
1233 | 322..323 'a': impl Iterator<Item = impl Trait<u32>> | ||
1234 | 322..330 'a.next()': impl Trait<u32> | ||
1235 | 322..336 'a.next().foo()': u32 | ||
1236 | 342..343 'b': impl Trait<u64> | ||
1237 | 342..349 'b.foo()': u64 | ||
1238 | 359..365 '(c, d)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>) | ||
1239 | 360..361 'c': impl Iterator<Item = impl Trait<u128>> | ||
1240 | 363..364 'd': impl Trait<u128> | ||
1241 | 368..371 'baz': fn baz<u128>(u128) -> (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>) | ||
1242 | 368..378 'baz(1u128)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>) | ||
1243 | 372..377 '1u128': u128 | ||
1244 | 384..385 'c': impl Iterator<Item = impl Trait<u128>> | ||
1245 | 384..392 'c.next()': impl Trait<u128> | ||
1246 | 384..398 'c.next().foo()': u128 | ||
1247 | 404..405 'd': impl Trait<u128> | ||
1248 | 404..411 'd.foo()': u128 | ||
1249 | "### | ||
1250 | ); | ||
1251 | } | ||
1252 | |||
1253 | #[test] | ||
1164 | fn dyn_trait() { | 1254 | fn dyn_trait() { |
1165 | assert_snapshot!( | 1255 | assert_snapshot!( |
1166 | infer(r#" | 1256 | infer(r#" |
@@ -1718,33 +1808,33 @@ fn test() { | |||
1718 | } | 1808 | } |
1719 | "#), | 1809 | "#), |
1720 | @r###" | 1810 | @r###" |
1721 | 65..69 'self': &Self | 1811 | 65..69 'self': &Self |
1722 | 166..170 'self': Self | 1812 | 166..170 'self': Self |
1723 | 172..176 'args': Args | 1813 | 172..176 'args': Args |
1724 | 240..244 'self': &Foo | 1814 | 240..244 'self': &Foo |
1725 | 255..257 '{}': () | 1815 | 255..257 '{}': () |
1726 | 335..336 'f': F | 1816 | 335..336 'f': F |
1727 | 355..357 '{}': () | 1817 | 355..357 '{}': () |
1728 | 444..690 '{ ...o(); }': () | 1818 | 444..690 '{ ...o(); }': () |
1729 | 454..459 'lazy1': Lazy<Foo, fn() -> T> | 1819 | 454..459 'lazy1': Lazy<Foo, || -> Foo> |
1730 | 476..485 'Lazy::new': fn new<Foo, fn() -> T>(fn() -> T) -> Lazy<Foo, fn() -> T> | 1820 | 476..485 'Lazy::new': fn new<Foo, || -> Foo>(|| -> Foo) -> Lazy<Foo, || -> Foo> |
1731 | 476..493 'Lazy::...| Foo)': Lazy<Foo, fn() -> T> | 1821 | 476..493 'Lazy::...| Foo)': Lazy<Foo, || -> Foo> |
1732 | 486..492 '|| Foo': || -> T | 1822 | 486..492 '|| Foo': || -> Foo |
1733 | 489..492 'Foo': Foo | 1823 | 489..492 'Foo': Foo |
1734 | 503..505 'r1': {unknown} | 1824 | 503..505 'r1': usize |
1735 | 508..513 'lazy1': Lazy<Foo, fn() -> T> | 1825 | 508..513 'lazy1': Lazy<Foo, || -> Foo> |
1736 | 508..519 'lazy1.foo()': {unknown} | 1826 | 508..519 'lazy1.foo()': usize |
1737 | 561..576 'make_foo_fn_ptr': fn() -> Foo | 1827 | 561..576 'make_foo_fn_ptr': fn() -> Foo |
1738 | 592..603 'make_foo_fn': fn make_foo_fn() -> Foo | 1828 | 592..603 'make_foo_fn': fn make_foo_fn() -> Foo |
1739 | 613..618 'lazy2': Lazy<Foo, fn() -> T> | 1829 | 613..618 'lazy2': Lazy<Foo, fn() -> Foo> |
1740 | 635..644 'Lazy::new': fn new<Foo, fn() -> T>(fn() -> T) -> Lazy<Foo, fn() -> T> | 1830 | 635..644 'Lazy::new': fn new<Foo, fn() -> Foo>(fn() -> Foo) -> Lazy<Foo, fn() -> Foo> |
1741 | 635..661 'Lazy::...n_ptr)': Lazy<Foo, fn() -> T> | 1831 | 635..661 'Lazy::...n_ptr)': Lazy<Foo, fn() -> Foo> |
1742 | 645..660 'make_foo_fn_ptr': fn() -> Foo | 1832 | 645..660 'make_foo_fn_ptr': fn() -> Foo |
1743 | 671..673 'r2': {unknown} | 1833 | 671..673 'r2': {unknown} |
1744 | 676..681 'lazy2': Lazy<Foo, fn() -> T> | 1834 | 676..681 'lazy2': Lazy<Foo, fn() -> Foo> |
1745 | 676..687 'lazy2.foo()': {unknown} | 1835 | 676..687 'lazy2.foo()': {unknown} |
1746 | 550..552 '{}': () | 1836 | 550..552 '{}': () |
1747 | "### | 1837 | "### |
1748 | ); | 1838 | ); |
1749 | } | 1839 | } |
1750 | 1840 | ||
@@ -2758,12 +2848,12 @@ fn test() { | |||
2758 | fn integer_range_iterate() { | 2848 | fn integer_range_iterate() { |
2759 | let t = type_at( | 2849 | let t = type_at( |
2760 | r#" | 2850 | r#" |
2761 | //- /main.rs crate:main deps:std | 2851 | //- /main.rs crate:main deps:core |
2762 | fn test() { | 2852 | fn test() { |
2763 | for x in 0..100 { x<|>; } | 2853 | for x in 0..100 { x<|>; } |
2764 | } | 2854 | } |
2765 | 2855 | ||
2766 | //- /std.rs crate:std | 2856 | //- /core.rs crate:core |
2767 | pub mod ops { | 2857 | pub mod ops { |
2768 | pub struct Range<Idx> { | 2858 | pub struct Range<Idx> { |
2769 | pub start: Idx, | 2859 | pub start: Idx, |