diff options
Diffstat (limited to 'crates/ra_hir_ty/src/tests.rs')
-rw-r--r-- | crates/ra_hir_ty/src/tests.rs | 106 |
1 files changed, 96 insertions, 10 deletions
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs index 3766ab981..a3cc5cf95 100644 --- a/crates/ra_hir_ty/src/tests.rs +++ b/crates/ra_hir_ty/src/tests.rs | |||
@@ -222,6 +222,56 @@ mod collections { | |||
222 | } | 222 | } |
223 | 223 | ||
224 | #[test] | 224 | #[test] |
225 | fn infer_ranges() { | ||
226 | let (db, pos) = TestDB::with_position( | ||
227 | r#" | ||
228 | //- /main.rs crate:main deps:std | ||
229 | fn test() { | ||
230 | let a = ..; | ||
231 | let b = 1..; | ||
232 | let c = ..2u32; | ||
233 | let d = 1..2usize; | ||
234 | let e = ..=10; | ||
235 | let f = 'a'..='z'; | ||
236 | |||
237 | let t = (a, b, c, d, e, f); | ||
238 | t<|>; | ||
239 | } | ||
240 | |||
241 | //- /std.rs crate:std | ||
242 | #[prelude_import] use prelude::*; | ||
243 | mod prelude {} | ||
244 | |||
245 | pub mod ops { | ||
246 | pub struct Range<Idx> { | ||
247 | pub start: Idx, | ||
248 | pub end: Idx, | ||
249 | } | ||
250 | pub struct RangeFrom<Idx> { | ||
251 | pub start: Idx, | ||
252 | } | ||
253 | struct RangeFull; | ||
254 | pub struct RangeInclusive<Idx> { | ||
255 | start: Idx, | ||
256 | end: Idx, | ||
257 | is_empty: u8, | ||
258 | } | ||
259 | pub struct RangeTo<Idx> { | ||
260 | pub end: Idx, | ||
261 | } | ||
262 | pub struct RangeToInclusive<Idx> { | ||
263 | pub end: Idx, | ||
264 | } | ||
265 | } | ||
266 | "#, | ||
267 | ); | ||
268 | assert_eq!( | ||
269 | "(RangeFull, RangeFrom<i32>, RangeTo<u32>, Range<usize>, RangeToInclusive<i32>, RangeInclusive<char>)", | ||
270 | type_at_pos(&db, pos), | ||
271 | ); | ||
272 | } | ||
273 | |||
274 | #[test] | ||
225 | fn infer_while_let() { | 275 | fn infer_while_let() { |
226 | let (db, pos) = TestDB::with_position( | 276 | let (db, pos) = TestDB::with_position( |
227 | r#" | 277 | r#" |
@@ -2104,7 +2154,6 @@ fn test(x: Foo, y: Bar<&str>, z: Baz<i8, u8>) { | |||
2104 | } | 2154 | } |
2105 | 2155 | ||
2106 | #[test] | 2156 | #[test] |
2107 | #[should_panic] // we currently can't handle this | ||
2108 | fn recursive_type_alias() { | 2157 | fn recursive_type_alias() { |
2109 | assert_snapshot!( | 2158 | assert_snapshot!( |
2110 | infer(r#" | 2159 | infer(r#" |
@@ -2113,7 +2162,10 @@ type Foo = Foo; | |||
2113 | type Bar = A<Bar>; | 2162 | type Bar = A<Bar>; |
2114 | fn test(x: Foo) {} | 2163 | fn test(x: Foo) {} |
2115 | "#), | 2164 | "#), |
2116 | @"" | 2165 | @r###" |
2166 | [59; 60) 'x': {unknown} | ||
2167 | [67; 69) '{}': () | ||
2168 | "### | ||
2117 | ) | 2169 | ) |
2118 | } | 2170 | } |
2119 | 2171 | ||
@@ -4662,10 +4714,48 @@ fn test<T, U>() where T::Item: Trait2, T: Trait<U::Item>, U: Trait<()> { | |||
4662 | } | 4714 | } |
4663 | 4715 | ||
4664 | #[test] | 4716 | #[test] |
4665 | // FIXME this is currently a Salsa panic; it would be nicer if it just returned | 4717 | fn trait_impl_self_ty() { |
4666 | // in Unknown, and we should be able to do that once Salsa allows us to handle | 4718 | let t = type_at( |
4667 | // the cycle. But at least it doesn't overflow for now. | 4719 | r#" |
4668 | #[should_panic] | 4720 | //- /main.rs |
4721 | trait Trait<T> { | ||
4722 | fn foo(&self); | ||
4723 | } | ||
4724 | |||
4725 | struct S; | ||
4726 | |||
4727 | impl Trait<Self> for S {} | ||
4728 | |||
4729 | fn test() { | ||
4730 | S.foo()<|>; | ||
4731 | } | ||
4732 | "#, | ||
4733 | ); | ||
4734 | assert_eq!(t, "()"); | ||
4735 | } | ||
4736 | |||
4737 | #[test] | ||
4738 | fn trait_impl_self_ty_cycle() { | ||
4739 | let t = type_at( | ||
4740 | r#" | ||
4741 | //- /main.rs | ||
4742 | trait Trait { | ||
4743 | fn foo(&self); | ||
4744 | } | ||
4745 | |||
4746 | struct S<T>; | ||
4747 | |||
4748 | impl Trait for S<Self> {} | ||
4749 | |||
4750 | fn test() { | ||
4751 | S.foo()<|>; | ||
4752 | } | ||
4753 | "#, | ||
4754 | ); | ||
4755 | assert_eq!(t, "{unknown}"); | ||
4756 | } | ||
4757 | |||
4758 | #[test] | ||
4669 | fn unselected_projection_in_trait_env_cycle_1() { | 4759 | fn unselected_projection_in_trait_env_cycle_1() { |
4670 | let t = type_at( | 4760 | let t = type_at( |
4671 | r#" | 4761 | r#" |
@@ -4686,10 +4776,6 @@ fn test<T: Trait>() where T: Trait2<T::Item> { | |||
4686 | } | 4776 | } |
4687 | 4777 | ||
4688 | #[test] | 4778 | #[test] |
4689 | // FIXME this is currently a Salsa panic; it would be nicer if it just returned | ||
4690 | // in Unknown, and we should be able to do that once Salsa allows us to handle | ||
4691 | // the cycle. But at least it doesn't overflow for now. | ||
4692 | #[should_panic] | ||
4693 | fn unselected_projection_in_trait_env_cycle_2() { | 4779 | fn unselected_projection_in_trait_env_cycle_2() { |
4694 | let t = type_at( | 4780 | let t = type_at( |
4695 | r#" | 4781 | r#" |