aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-04 19:55:23 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-04 19:55:23 +0000
commit4a3ef8fe63c5eedfbb6d3038e88f0b1349a1c382 (patch)
treea2666ef628451437aea9b99a9e18d27bb54b53e8 /crates/ra_hir/src/ty
parent04e6b26758003550633e41df14fe9bc0ac7f8e4a (diff)
parente6aeabf96f9cf339c81f3e79502d477269d141ed (diff)
Merge #370
370: Self params & type r=matklad a=flodiebold This implements type inference for `self`, so field completion for methods taking `self` works now. - rename `IMPL_ITEM` to `IMPL_BLOCK` -- rustc calls the methods etc. inside an impl `ImplItem`s, and the impl itself doesn't define an item, so I thought this name was clearer. - add HIR for impl blocks -- we collect all impls in a crate at once, so we can go from methods to containing impls, and since we will later also need to find all impls for a certain type (which may be anywhere in the crate, I think?). We could be more lazy here, but I don't know if it's worth the complexity. - resolve `self` and `Self` during type inference - refactor a bit in ty.rs as well Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r--crates/ra_hir/src/ty/tests.rs19
-rw-r--r--crates/ra_hir/src/ty/tests/data/0007_self.txt6
2 files changed, 25 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index 93bf431c4..fb53fcf0b 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -134,6 +134,25 @@ fn test() -> &mut &f64 {
134 ); 134 );
135} 135}
136 136
137#[test]
138fn infer_self() {
139 check_inference(
140 r#"
141struct S;
142
143impl S {
144 fn test(&self) {
145 self;
146 }
147 fn test2(self: &Self) {
148 self;
149 }
150}
151"#,
152 "0007_self.txt",
153 );
154}
155
137fn infer(content: &str) -> String { 156fn infer(content: &str) -> String {
138 let (db, _, file_id) = MockDatabase::with_single_file(content); 157 let (db, _, file_id) = MockDatabase::with_single_file(content);
139 let source_file = db.source_file(file_id); 158 let source_file = db.source_file(file_id);
diff --git a/crates/ra_hir/src/ty/tests/data/0007_self.txt b/crates/ra_hir/src/ty/tests/data/0007_self.txt
new file mode 100644
index 000000000..db4ba17d0
--- /dev/null
+++ b/crates/ra_hir/src/ty/tests/data/0007_self.txt
@@ -0,0 +1,6 @@
1[50; 54) 'self': &S
2[34; 38) 'self': &S
3[40; 61) '{ ... }': ()
4[88; 109) '{ ... }': ()
5[98; 102) 'self': &S
6[75; 79) 'self': &S