aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ty/tests.rs')
-rw-r--r--crates/ra_hir/src/ty/tests.rs71
1 files changed, 62 insertions, 9 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index fe5e89f2d..6aea1fb4a 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -21,19 +21,57 @@ use crate::{
21// update the snapshots. 21// update the snapshots.
22 22
23#[test] 23#[test]
24fn infer_for_loop() { 24fn 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
28struct Vec<T> {} 28
29impl<T> Vec<T> { 29fn test() {
30 fn new() -> Self { Vec {} } 30 let r: Result<i32, u64> = Result::Ok(1);
31 fn push(&mut self, t: T) { } 31 let v = r?;
32 v<|>;
32} 33}
33 34
34impl<T> ::std::iter::IntoIterator for Vec<T> { 35//- /std.rs
35 type Item=T; 36
37#[prelude_import] use ops::*;
38mod ops {
39 trait Try {
40 type Ok;
41 type Error;
42 }
43}
44
45#[prelude_import] use result::*;
46mod 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
58"#,
59 );
60 db.set_crate_graph_from_fixture(crate_graph! {
61 "main": ("/main.rs", ["std"]),
62 "std": ("/std.rs", []),
63 });
64 assert_eq!("i32", type_at_pos(&db, pos));
36} 65}
66
67#[test]
68fn infer_for_loop() {
69 let (mut db, pos) = MockDatabase::with_position(
70 r#"
71//- /main.rs
72
73use std::collections::Vec;
74
37fn test() { 75fn test() {
38 let v = Vec::new(); 76 let v = Vec::new();
39 v.push("foo"); 77 v.push("foo");
@@ -42,20 +80,35 @@ fn test() {
42 } 80 }
43} 81}
44 82
45//- /lib.rs 83//- /std.rs
84
85#[prelude_import] use iter::*;
46mod iter { 86mod iter {
47 trait IntoIterator { 87 trait IntoIterator {
48 type Item; 88 type Item;
49 } 89 }
50} 90}
91
92mod 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}
51"#, 103"#,
52 ); 104 );
53 db.set_crate_graph_from_fixture(crate_graph! { 105 db.set_crate_graph_from_fixture(crate_graph! {
54 "main": ("/main.rs", ["std"]), 106 "main": ("/main.rs", ["std"]),
55 "std": ("/lib.rs", []), 107 "std": ("/std.rs", []),
56 }); 108 });
57 assert_eq!("&str", type_at_pos(&db, pos)); 109 assert_eq!("&str", type_at_pos(&db, pos));
58} 110}
111
59#[test] 112#[test]
60fn infer_basics() { 113fn infer_basics() {
61 assert_snapshot_matches!( 114 assert_snapshot_matches!(