diff options
Diffstat (limited to 'crates/ra_hir_ty/src/tests')
-rw-r--r-- | crates/ra_hir_ty/src/tests/method_resolution.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/regression.rs | 36 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/simple.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/traits.rs | 74 |
4 files changed, 114 insertions, 3 deletions
diff --git a/crates/ra_hir_ty/src/tests/method_resolution.rs b/crates/ra_hir_ty/src/tests/method_resolution.rs index 45164c9e9..ce9a06fde 100644 --- a/crates/ra_hir_ty/src/tests/method_resolution.rs +++ b/crates/ra_hir_ty/src/tests/method_resolution.rs | |||
@@ -865,7 +865,7 @@ mod foo { | |||
865 | 865 | ||
866 | #[test] | 866 | #[test] |
867 | fn method_resolution_where_clause_for_unknown_trait() { | 867 | fn method_resolution_where_clause_for_unknown_trait() { |
868 | // The blanket impl shouldn't apply because we can't even resolve UnknownTrait | 868 | // The blanket impl currently applies because we ignore the unresolved where clause |
869 | let t = type_at( | 869 | let t = type_at( |
870 | r#" | 870 | r#" |
871 | //- /main.rs | 871 | //- /main.rs |
@@ -875,7 +875,7 @@ impl<T> Trait for T where T: UnknownTrait {} | |||
875 | fn test() { (&S).foo()<|>; } | 875 | fn test() { (&S).foo()<|>; } |
876 | "#, | 876 | "#, |
877 | ); | 877 | ); |
878 | assert_eq!(t, "{unknown}"); | 878 | assert_eq!(t, "u128"); |
879 | } | 879 | } |
880 | 880 | ||
881 | #[test] | 881 | #[test] |
diff --git a/crates/ra_hir_ty/src/tests/regression.rs b/crates/ra_hir_ty/src/tests/regression.rs index 09d684ac2..8b3aa8564 100644 --- a/crates/ra_hir_ty/src/tests/regression.rs +++ b/crates/ra_hir_ty/src/tests/regression.rs | |||
@@ -1,7 +1,8 @@ | |||
1 | use super::infer; | ||
2 | use insta::assert_snapshot; | 1 | use insta::assert_snapshot; |
3 | use test_utils::covers; | 2 | use test_utils::covers; |
4 | 3 | ||
4 | use super::infer; | ||
5 | |||
5 | #[test] | 6 | #[test] |
6 | fn bug_484() { | 7 | fn bug_484() { |
7 | assert_snapshot!( | 8 | assert_snapshot!( |
@@ -331,3 +332,36 @@ pub fn main_loop() { | |||
331 | "### | 332 | "### |
332 | ); | 333 | ); |
333 | } | 334 | } |
335 | |||
336 | #[test] | ||
337 | fn issue_2669() { | ||
338 | assert_snapshot!( | ||
339 | infer( | ||
340 | r#"trait A {} | ||
341 | trait Write {} | ||
342 | struct Response<T> {} | ||
343 | |||
344 | trait D { | ||
345 | fn foo(); | ||
346 | } | ||
347 | |||
348 | impl<T:A> D for Response<T> { | ||
349 | fn foo() { | ||
350 | end(); | ||
351 | fn end<W: Write>() { | ||
352 | let _x: T = loop {}; | ||
353 | } | ||
354 | } | ||
355 | }"# | ||
356 | ), | ||
357 | @r###" | ||
358 | [147; 262) '{ ... }': () | ||
359 | [161; 164) 'end': fn end<{unknown}>() -> () | ||
360 | [161; 166) 'end()': () | ||
361 | [199; 252) '{ ... }': () | ||
362 | [221; 223) '_x': ! | ||
363 | [230; 237) 'loop {}': ! | ||
364 | [235; 237) '{}': () | ||
365 | "### | ||
366 | ) | ||
367 | } | ||
diff --git a/crates/ra_hir_ty/src/tests/simple.rs b/crates/ra_hir_ty/src/tests/simple.rs index 3e5e163e3..00134c99b 100644 --- a/crates/ra_hir_ty/src/tests/simple.rs +++ b/crates/ra_hir_ty/src/tests/simple.rs | |||
@@ -1518,6 +1518,7 @@ fn test() { | |||
1518 | [167; 179) 'GLOBAL_CONST': u32 | 1518 | [167; 179) 'GLOBAL_CONST': u32 |
1519 | [189; 191) 'id': u32 | 1519 | [189; 191) 'id': u32 |
1520 | [194; 210) 'Foo::A..._CONST': u32 | 1520 | [194; 210) 'Foo::A..._CONST': u32 |
1521 | [126; 128) '99': u32 | ||
1521 | "### | 1522 | "### |
1522 | ); | 1523 | ); |
1523 | } | 1524 | } |
@@ -1549,6 +1550,8 @@ fn test() { | |||
1549 | [233; 246) 'GLOBAL_STATIC': u32 | 1550 | [233; 246) 'GLOBAL_STATIC': u32 |
1550 | [256; 257) 'w': u32 | 1551 | [256; 257) 'w': u32 |
1551 | [260; 277) 'GLOBAL...IC_MUT': u32 | 1552 | [260; 277) 'GLOBAL...IC_MUT': u32 |
1553 | [118; 120) '99': u32 | ||
1554 | [161; 163) '99': u32 | ||
1552 | "### | 1555 | "### |
1553 | ); | 1556 | ); |
1554 | } | 1557 | } |
diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index 76e2198b6..0bc72644a 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs | |||
@@ -38,6 +38,63 @@ mod future { | |||
38 | } | 38 | } |
39 | 39 | ||
40 | #[test] | 40 | #[test] |
41 | fn infer_async() { | ||
42 | let (db, pos) = TestDB::with_position( | ||
43 | r#" | ||
44 | //- /main.rs crate:main deps:std | ||
45 | |||
46 | async fn foo() -> u64 { | ||
47 | 128 | ||
48 | } | ||
49 | |||
50 | fn test() { | ||
51 | let r = foo(); | ||
52 | let v = r.await; | ||
53 | v<|>; | ||
54 | } | ||
55 | |||
56 | //- /std.rs crate:std | ||
57 | #[prelude_import] use future::*; | ||
58 | mod future { | ||
59 | trait Future { | ||
60 | type Output; | ||
61 | } | ||
62 | } | ||
63 | |||
64 | "#, | ||
65 | ); | ||
66 | assert_eq!("u64", type_at_pos(&db, pos)); | ||
67 | } | ||
68 | |||
69 | #[test] | ||
70 | fn infer_desugar_async() { | ||
71 | let (db, pos) = TestDB::with_position( | ||
72 | r#" | ||
73 | //- /main.rs crate:main deps:std | ||
74 | |||
75 | async fn foo() -> u64 { | ||
76 | 128 | ||
77 | } | ||
78 | |||
79 | fn test() { | ||
80 | let r = foo(); | ||
81 | r<|>; | ||
82 | } | ||
83 | |||
84 | //- /std.rs crate:std | ||
85 | #[prelude_import] use future::*; | ||
86 | mod future { | ||
87 | trait Future { | ||
88 | type Output; | ||
89 | } | ||
90 | } | ||
91 | |||
92 | "#, | ||
93 | ); | ||
94 | assert_eq!("impl Future<Output = u64>", type_at_pos(&db, pos)); | ||
95 | } | ||
96 | |||
97 | #[test] | ||
41 | fn infer_try() { | 98 | fn infer_try() { |
42 | let (db, pos) = TestDB::with_position( | 99 | let (db, pos) = TestDB::with_position( |
43 | r#" | 100 | r#" |
@@ -959,6 +1016,23 @@ fn test() { | |||
959 | } | 1016 | } |
960 | 1017 | ||
961 | #[test] | 1018 | #[test] |
1019 | fn error_bound_chalk() { | ||
1020 | let t = type_at( | ||
1021 | r#" | ||
1022 | //- /main.rs | ||
1023 | trait Trait { | ||
1024 | fn foo(&self) -> u32 {} | ||
1025 | } | ||
1026 | |||
1027 | fn test(x: (impl Trait + UnknownTrait)) { | ||
1028 | x.foo()<|>; | ||
1029 | } | ||
1030 | "#, | ||
1031 | ); | ||
1032 | assert_eq!(t, "u32"); | ||
1033 | } | ||
1034 | |||
1035 | #[test] | ||
962 | fn assoc_type_bindings() { | 1036 | fn assoc_type_bindings() { |
963 | assert_snapshot!( | 1037 | assert_snapshot!( |
964 | infer(r#" | 1038 | infer(r#" |