From ef67581104eb00a0c199f0b2a3b558da8a6f90a2 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 23 Dec 2018 17:13:11 +0100 Subject: Resolve paths to defs (functions currently) during type inference --- crates/ra_hir/src/ty/tests.rs | 7 ++++++- crates/ra_hir/src/ty/tests/data/0003_paths.rs | 10 ++++++++++ crates/ra_hir/src/ty/tests/data/0003_paths.txt | 9 +++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 crates/ra_hir/src/ty/tests/data/0003_paths.rs create mode 100644 crates/ra_hir/src/ty/tests/data/0003_paths.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 0880b51bc..e0458327a 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -1,5 +1,8 @@ use std::fmt::Write; use std::path::{PathBuf}; +use std::sync::Once; + +use flexi_logger::Logger; use ra_db::{SyntaxDatabase}; use ra_syntax::ast::{self, AstNode}; @@ -22,7 +25,7 @@ fn infer_file(content: &str) -> String { let func = source_binder::function_from_source(&db, file_id, fn_def) .unwrap() .unwrap(); - let inference_result = func.infer(&db); + let inference_result = func.infer(&db).unwrap(); for (syntax_ptr, ty) in &inference_result.type_for { let node = syntax_ptr.resolve(&source_file); write!( @@ -58,6 +61,8 @@ fn ellipsize(mut text: String, max_len: usize) -> String { #[test] pub fn infer_tests() { + static INIT: Once = Once::new(); + INIT.call_once(|| Logger::with_env().start().unwrap()); dir_tests(&test_data_dir(), &["."], |text, _path| infer_file(text)); } diff --git a/crates/ra_hir/src/ty/tests/data/0003_paths.rs b/crates/ra_hir/src/ty/tests/data/0003_paths.rs new file mode 100644 index 000000000..e8b11198b --- /dev/null +++ b/crates/ra_hir/src/ty/tests/data/0003_paths.rs @@ -0,0 +1,10 @@ +fn a() -> u32 { 1 } + +mod b { + fn c() -> u32 { 1 } +} + +fn test() { + a(); + b::c(); +} diff --git a/crates/ra_hir/src/ty/tests/data/0003_paths.txt b/crates/ra_hir/src/ty/tests/data/0003_paths.txt new file mode 100644 index 000000000..3a53370a2 --- /dev/null +++ b/crates/ra_hir/src/ty/tests/data/0003_paths.txt @@ -0,0 +1,9 @@ +[16; 17) '1': [unknown] +[14; 19) '{ 1 }': [unknown] +[47; 52) '{ 1 }': [unknown] +[49; 50) '1': [unknown] +[81; 87) 'b::c()': [unknown] +[66; 90) '{ ...c(); }': () +[72; 73) 'a': fn() -> u32 +[72; 75) 'a()': [unknown] +[81; 85) 'b::c': fn() -> u32 -- cgit v1.2.3