diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-23 12:02:06 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-23 12:02:06 +0000 |
commit | 38add103c3f30493e336a37827a76f48a6e7c584 (patch) | |
tree | 5efa93cfd5c474d70b850ab24cd9b1e90ff79bd0 /crates/ra_hir/src/ty | |
parent | 3d8a0982a12f3aa4b8c193a841f864b15c3cb66e (diff) | |
parent | 6a04d1f292f14744c6b747fa39f1d1c1c20db0ee (diff) |
Merge #880
880: Fix resolution of associated method calls across crates r=matklad a=flodiebold
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.
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 41 |
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 @@ | |||
1 | use std::sync::Arc; | 1 | use std::sync::Arc; |
2 | use std::fmt::Write; | 2 | use std::fmt::Write; |
3 | 3 | ||
4 | use ra_db::{SourceDatabase, salsa::Database}; | 4 | use ra_db::{SourceDatabase, salsa::Database, FilePosition}; |
5 | use ra_syntax::ast::{self, AstNode}; | 5 | use ra_syntax::{algo, ast::{self, AstNode}}; |
6 | use test_utils::covers; | 6 | use test_utils::covers; |
7 | 7 | ||
8 | use crate::{ | 8 | use crate::{ |
@@ -946,6 +946,43 @@ fn test<R>(query_response: Canonical<QueryResponse<R>>) { | |||
946 | ); | 946 | ); |
947 | } | 947 | } |
948 | 948 | ||
949 | #[test] | ||
950 | fn cross_crate_associated_method_call() { | ||
951 | let (mut db, pos) = MockDatabase::with_position( | ||
952 | r#" | ||
953 | //- /main.rs | ||
954 | fn test() { | ||
955 | let x = other_crate::foo::S::thing(); | ||
956 | x<|>; | ||
957 | } | ||
958 | |||
959 | //- /lib.rs | ||
960 | mod 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 | |||
975 | fn 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 | |||
949 | fn infer(content: &str) -> String { | 986 | fn 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); |