aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/tests.rs
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-02-23 11:32:25 +0000
committerFlorian Diebold <[email protected]>2019-02-23 11:37:29 +0000
commit6a04d1f292f14744c6b747fa39f1d1c1c20db0ee (patch)
tree5efa93cfd5c474d70b850ab24cd9b1e90ff79bd0 /crates/ra_hir/src/ty/tests.rs
parent3d8a0982a12f3aa4b8c193a841f864b15c3cb66e (diff)
Fix resolution of associated method calls across crates
I think it'll be better to make the path resolution the number of unresolved segments, not the first unresolved index; then this error could simply not have happened. But I'll do that separately.
Diffstat (limited to 'crates/ra_hir/src/ty/tests.rs')
-rw-r--r--crates/ra_hir/src/ty/tests.rs41
1 files changed, 39 insertions, 2 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index f04e9109c..77aeca669 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -1,8 +1,8 @@
1use std::sync::Arc; 1use std::sync::Arc;
2use std::fmt::Write; 2use std::fmt::Write;
3 3
4use ra_db::{SourceDatabase, salsa::Database}; 4use ra_db::{SourceDatabase, salsa::Database, FilePosition};
5use ra_syntax::ast::{self, AstNode}; 5use ra_syntax::{algo, ast::{self, AstNode}};
6use test_utils::covers; 6use test_utils::covers;
7 7
8use crate::{ 8use crate::{
@@ -946,6 +946,43 @@ fn test<R>(query_response: Canonical<QueryResponse<R>>) {
946 ); 946 );
947} 947}
948 948
949#[test]
950fn cross_crate_associated_method_call() {
951 let (mut db, pos) = MockDatabase::with_position(
952 r#"
953//- /main.rs
954fn test() {
955 let x = other_crate::foo::S::thing();
956 x<|>;
957}
958
959//- /lib.rs
960mod foo {
961 struct S;
962 impl S {
963 fn thing() -> i128 {}
964 }
965}
966"#,
967 );
968 db.set_crate_graph_from_fixture(crate_graph! {
969 "main": ("/main.rs", ["other_crate"]),
970 "other_crate": ("/lib.rs", []),
971 });
972 assert_eq!("i128", type_at_pos(&db, pos));
973}
974
975fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String {
976 let func = source_binder::function_from_position(db, pos).unwrap();
977 let body_syntax_mapping = func.body_syntax_mapping(db);
978 let inference_result = func.infer(db);
979 let (_, syntax) = func.source(db);
980 let node = algo::find_node_at_offset::<ast::Expr>(syntax.syntax(), pos.offset).unwrap();
981 let expr = body_syntax_mapping.node_expr(node).unwrap();
982 let ty = &inference_result[expr];
983 ty.to_string()
984}
985
949fn infer(content: &str) -> String { 986fn infer(content: &str) -> String {
950 let (db, _, file_id) = MockDatabase::with_single_file(content); 987 let (db, _, file_id) = MockDatabase::with_single_file(content);
951 let source_file = db.parse(file_id); 988 let source_file = db.parse(file_id);