diff options
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 56 |
1 files changed, 36 insertions, 20 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index d5c03c4bc..6aea1fb4a 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -25,33 +25,41 @@ fn infer_try() { | |||
25 | let (mut db, pos) = MockDatabase::with_position( | 25 | let (mut db, pos) = MockDatabase::with_position( |
26 | r#" | 26 | r#" |
27 | //- /main.rs | 27 | //- /main.rs |
28 | enum Result<O, E> { | ||
29 | Ok(O), | ||
30 | Err(E) | ||
31 | } | ||
32 | 28 | ||
33 | impl<O, E> ::std::ops::Try for Result<O, E> { | ||
34 | type Ok = O; | ||
35 | type Error = E; | ||
36 | } | ||
37 | fn test() { | 29 | fn test() { |
38 | let r: Result<i32, u64> = Result::Ok(1); | 30 | let r: Result<i32, u64> = Result::Ok(1); |
39 | let v = r?; | 31 | let v = r?; |
40 | v<|>; | 32 | v<|>; |
41 | } | 33 | } |
42 | 34 | ||
43 | //- /lib.rs | 35 | //- /std.rs |
36 | |||
37 | #[prelude_import] use ops::*; | ||
44 | mod ops { | 38 | mod ops { |
45 | trait Try { | 39 | trait Try { |
46 | type Ok; | 40 | type Ok; |
47 | type Error; | 41 | type Error; |
48 | } | 42 | } |
49 | } | 43 | } |
44 | |||
45 | #[prelude_import] use result::*; | ||
46 | mod result { | ||
47 | enum Result<O, E> { | ||
48 | Ok(O), | ||
49 | Err(E) | ||
50 | } | ||
51 | |||
52 | impl<O, E> crate::ops::Try for Result<O, E> { | ||
53 | type Ok = O; | ||
54 | type Error = E; | ||
55 | } | ||
56 | } | ||
57 | |||
50 | "#, | 58 | "#, |
51 | ); | 59 | ); |
52 | db.set_crate_graph_from_fixture(crate_graph! { | 60 | db.set_crate_graph_from_fixture(crate_graph! { |
53 | "main": ("/main.rs", ["std"]), | 61 | "main": ("/main.rs", ["std"]), |
54 | "std": ("/lib.rs", []), | 62 | "std": ("/std.rs", []), |
55 | }); | 63 | }); |
56 | assert_eq!("i32", type_at_pos(&db, pos)); | 64 | assert_eq!("i32", type_at_pos(&db, pos)); |
57 | } | 65 | } |
@@ -61,15 +69,9 @@ fn infer_for_loop() { | |||
61 | let (mut db, pos) = MockDatabase::with_position( | 69 | let (mut db, pos) = MockDatabase::with_position( |
62 | r#" | 70 | r#" |
63 | //- /main.rs | 71 | //- /main.rs |
64 | struct Vec<T> {} | ||
65 | impl<T> Vec<T> { | ||
66 | fn new() -> Self { Vec {} } | ||
67 | fn push(&mut self, t: T) { } | ||
68 | } | ||
69 | 72 | ||
70 | impl<T> ::std::iter::IntoIterator for Vec<T> { | 73 | use std::collections::Vec; |
71 | type Item=T; | 74 | |
72 | } | ||
73 | fn test() { | 75 | fn test() { |
74 | let v = Vec::new(); | 76 | let v = Vec::new(); |
75 | v.push("foo"); | 77 | v.push("foo"); |
@@ -78,17 +80,31 @@ fn test() { | |||
78 | } | 80 | } |
79 | } | 81 | } |
80 | 82 | ||
81 | //- /lib.rs | 83 | //- /std.rs |
84 | |||
85 | #[prelude_import] use iter::*; | ||
82 | mod iter { | 86 | mod iter { |
83 | trait IntoIterator { | 87 | trait IntoIterator { |
84 | type Item; | 88 | type Item; |
85 | } | 89 | } |
86 | } | 90 | } |
91 | |||
92 | mod collections { | ||
93 | struct Vec<T> {} | ||
94 | impl<T> Vec<T> { | ||
95 | fn new() -> Self { Vec {} } | ||
96 | fn push(&mut self, t: T) { } | ||
97 | } | ||
98 | |||
99 | impl<T> crate::iter::IntoIterator for Vec<T> { | ||
100 | type Item=T; | ||
101 | } | ||
102 | } | ||
87 | "#, | 103 | "#, |
88 | ); | 104 | ); |
89 | db.set_crate_graph_from_fixture(crate_graph! { | 105 | db.set_crate_graph_from_fixture(crate_graph! { |
90 | "main": ("/main.rs", ["std"]), | 106 | "main": ("/main.rs", ["std"]), |
91 | "std": ("/lib.rs", []), | 107 | "std": ("/std.rs", []), |
92 | }); | 108 | }); |
93 | assert_eq!("&str", type_at_pos(&db, pos)); | 109 | assert_eq!("&str", type_at_pos(&db, pos)); |
94 | } | 110 | } |