From 226e31dae94f2c72f5cf650564e521b792793629 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Wed, 26 Dec 2018 21:28:05 +0100 Subject: Add test for self type inference --- crates/ra_hir/src/ty/tests.rs | 19 +++++++++++++++++++ crates/ra_hir/src/ty/tests/data/0007_self.txt | 4 ++++ 2 files changed, 23 insertions(+) create mode 100644 crates/ra_hir/src/ty/tests/data/0007_self.txt (limited to 'crates/ra_hir/src/ty') 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 { ); } +#[test] +fn infer_self() { + check_inference( + r#" +struct S; + +impl S { + fn test(&self) { + self; + } + fn test2(self: &Self) { + self; + } +} +"#, + "0007_self.txt", + ); +} + fn infer(content: &str) -> String { let (db, _, file_id) = MockDatabase::with_single_file(content); 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..18cd796c2 --- /dev/null +++ b/crates/ra_hir/src/ty/tests/data/0007_self.txt @@ -0,0 +1,4 @@ +[50; 54) 'self': [unknown] +[40; 61) '{ ... }': () +[88; 109) '{ ... }': () +[98; 102) 'self': [unknown] -- cgit v1.2.3 From 111126ed3c4f6358e0c833f80226e5192778f749 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 29 Dec 2018 21:32:07 +0100 Subject: Type the self parameter --- crates/ra_hir/src/ty/tests/data/0007_self.txt | 2 ++ 1 file changed, 2 insertions(+) (limited to 'crates/ra_hir/src/ty') diff --git a/crates/ra_hir/src/ty/tests/data/0007_self.txt b/crates/ra_hir/src/ty/tests/data/0007_self.txt index 18cd796c2..3d3c8b260 100644 --- a/crates/ra_hir/src/ty/tests/data/0007_self.txt +++ b/crates/ra_hir/src/ty/tests/data/0007_self.txt @@ -1,4 +1,6 @@ [50; 54) 'self': [unknown] +[34; 38) 'self': &S [40; 61) '{ ... }': () [88; 109) '{ ... }': () [98; 102) 'self': [unknown] +[75; 79) 'self': &[unknown] -- cgit v1.2.3 From d4db61b9a151a2a46c4067e61b0a4b1a9e3c73ec Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 29 Dec 2018 22:59:18 +0100 Subject: Resolve the self parameter during type inference --- crates/ra_hir/src/ty/tests/data/0007_self.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir/src/ty') diff --git a/crates/ra_hir/src/ty/tests/data/0007_self.txt b/crates/ra_hir/src/ty/tests/data/0007_self.txt index 3d3c8b260..0dd61da55 100644 --- a/crates/ra_hir/src/ty/tests/data/0007_self.txt +++ b/crates/ra_hir/src/ty/tests/data/0007_self.txt @@ -1,6 +1,6 @@ -[50; 54) 'self': [unknown] +[50; 54) 'self': &S [34; 38) 'self': &S [40; 61) '{ ... }': () [88; 109) '{ ... }': () -[98; 102) 'self': [unknown] +[98; 102) 'self': &[unknown] [75; 79) 'self': &[unknown] -- cgit v1.2.3 From 538147bf94b4c52a945c975b67e8d557998f9052 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 29 Dec 2018 23:20:12 +0100 Subject: Resolve the Self type --- crates/ra_hir/src/ty/tests/data/0007_self.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir/src/ty') diff --git a/crates/ra_hir/src/ty/tests/data/0007_self.txt b/crates/ra_hir/src/ty/tests/data/0007_self.txt index 0dd61da55..db4ba17d0 100644 --- a/crates/ra_hir/src/ty/tests/data/0007_self.txt +++ b/crates/ra_hir/src/ty/tests/data/0007_self.txt @@ -2,5 +2,5 @@ [34; 38) 'self': &S [40; 61) '{ ... }': () [88; 109) '{ ... }': () -[98; 102) 'self': &[unknown] -[75; 79) 'self': &[unknown] +[98; 102) 'self': &S +[75; 79) 'self': &S -- cgit v1.2.3