diff options
Diffstat (limited to 'crates/ra_hir_ty')
-rw-r--r-- | crates/ra_hir_ty/src/db.rs | 11 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/infer.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/lower.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/regression.rs | 17 |
5 files changed, 31 insertions, 5 deletions
diff --git a/crates/ra_hir_ty/src/db.rs b/crates/ra_hir_ty/src/db.rs index d52f65b83..eb521c7a0 100644 --- a/crates/ra_hir_ty/src/db.rs +++ b/crates/ra_hir_ty/src/db.rs | |||
@@ -7,6 +7,7 @@ use hir_def::{ | |||
7 | }; | 7 | }; |
8 | use ra_arena::map::ArenaMap; | 8 | use ra_arena::map::ArenaMap; |
9 | use ra_db::{salsa, CrateId}; | 9 | use ra_db::{salsa, CrateId}; |
10 | use ra_prof::profile; | ||
10 | 11 | ||
11 | use crate::{ | 12 | use crate::{ |
12 | method_resolution::CrateImplBlocks, | 13 | method_resolution::CrateImplBlocks, |
@@ -18,9 +19,12 @@ use crate::{ | |||
18 | #[salsa::query_group(HirDatabaseStorage)] | 19 | #[salsa::query_group(HirDatabaseStorage)] |
19 | #[salsa::requires(salsa::Database)] | 20 | #[salsa::requires(salsa::Database)] |
20 | pub trait HirDatabase: DefDatabase { | 21 | pub trait HirDatabase: DefDatabase { |
21 | #[salsa::invoke(crate::infer_query)] | 22 | #[salsa::transparent] |
22 | fn infer(&self, def: DefWithBodyId) -> Arc<InferenceResult>; | 23 | fn infer(&self, def: DefWithBodyId) -> Arc<InferenceResult>; |
23 | 24 | ||
25 | #[salsa::invoke(crate::do_infer_query)] | ||
26 | fn do_infer(&self, def: DefWithBodyId) -> Arc<InferenceResult>; | ||
27 | |||
24 | #[salsa::invoke(crate::lower::ty_query)] | 28 | #[salsa::invoke(crate::lower::ty_query)] |
25 | #[salsa::cycle(crate::lower::ty_recover)] | 29 | #[salsa::cycle(crate::lower::ty_recover)] |
26 | fn ty(&self, def: TyDefId) -> Ty; | 30 | fn ty(&self, def: TyDefId) -> Ty; |
@@ -104,6 +108,11 @@ pub trait HirDatabase: DefDatabase { | |||
104 | ) -> Option<crate::traits::Solution>; | 108 | ) -> Option<crate::traits::Solution>; |
105 | } | 109 | } |
106 | 110 | ||
111 | fn infer(db: &impl HirDatabase, def: DefWithBodyId) -> Arc<InferenceResult> { | ||
112 | let _p = profile("infer"); | ||
113 | db.do_infer(def) | ||
114 | } | ||
115 | |||
107 | #[test] | 116 | #[test] |
108 | fn hir_database_is_object_safe() { | 117 | fn hir_database_is_object_safe() { |
109 | fn _assert_object_safe(_: &dyn HirDatabase) {} | 118 | fn _assert_object_safe(_: &dyn HirDatabase) {} |
diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs index 37e69599d..e2eda3134 100644 --- a/crates/ra_hir_ty/src/infer.rs +++ b/crates/ra_hir_ty/src/infer.rs | |||
@@ -62,8 +62,8 @@ mod pat; | |||
62 | mod coerce; | 62 | mod coerce; |
63 | 63 | ||
64 | /// The entry point of type inference. | 64 | /// The entry point of type inference. |
65 | pub fn infer_query(db: &impl HirDatabase, def: DefWithBodyId) -> Arc<InferenceResult> { | 65 | pub fn do_infer_query(db: &impl HirDatabase, def: DefWithBodyId) -> Arc<InferenceResult> { |
66 | let _p = profile("infer_query"); | 66 | let _p = profile("do_infer"); |
67 | let resolver = def.resolver(db); | 67 | let resolver = def.resolver(db); |
68 | let mut ctx = InferenceContext::new(db, def, resolver); | 68 | let mut ctx = InferenceContext::new(db, def, resolver); |
69 | 69 | ||
diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs index 55b6dd836..d63f862dc 100644 --- a/crates/ra_hir_ty/src/lib.rs +++ b/crates/ra_hir_ty/src/lib.rs | |||
@@ -58,7 +58,7 @@ use crate::{ | |||
58 | use display::{HirDisplay, HirFormatter}; | 58 | use display::{HirDisplay, HirFormatter}; |
59 | 59 | ||
60 | pub use autoderef::autoderef; | 60 | pub use autoderef::autoderef; |
61 | pub use infer::{infer_query, InferTy, InferenceResult}; | 61 | pub use infer::{do_infer_query, InferTy, InferenceResult}; |
62 | pub use lower::CallableDef; | 62 | pub use lower::CallableDef; |
63 | pub use lower::{callable_item_sig, TyDefId, ValueTyDefId}; | 63 | pub use lower::{callable_item_sig, TyDefId, ValueTyDefId}; |
64 | pub use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment}; | 64 | pub use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment}; |
diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/ra_hir_ty/src/lower.rs index af3db2e1d..2c2ecee9c 100644 --- a/crates/ra_hir_ty/src/lower.rs +++ b/crates/ra_hir_ty/src/lower.rs | |||
@@ -331,7 +331,7 @@ pub(super) fn substs_from_path_segment( | |||
331 | if let Some(generic_args) = &segment.args_and_bindings { | 331 | if let Some(generic_args) = &segment.args_and_bindings { |
332 | // if args are provided, it should be all of them, but we can't rely on that | 332 | // if args are provided, it should be all of them, but we can't rely on that |
333 | let self_param_correction = if add_self_param { 1 } else { 0 }; | 333 | let self_param_correction = if add_self_param { 1 } else { 0 }; |
334 | let child_len = child_len + self_param_correction; | 334 | let child_len = child_len - self_param_correction; |
335 | for arg in generic_args.args.iter().take(child_len) { | 335 | for arg in generic_args.args.iter().take(child_len) { |
336 | match arg { | 336 | match arg { |
337 | GenericArg::Type(type_ref) => { | 337 | GenericArg::Type(type_ref) => { |
diff --git a/crates/ra_hir_ty/src/tests/regression.rs b/crates/ra_hir_ty/src/tests/regression.rs index 8b3aa8564..13c5f62e4 100644 --- a/crates/ra_hir_ty/src/tests/regression.rs +++ b/crates/ra_hir_ty/src/tests/regression.rs | |||
@@ -365,3 +365,20 @@ fn issue_2669() { | |||
365 | "### | 365 | "### |
366 | ) | 366 | ) |
367 | } | 367 | } |
368 | |||
369 | #[test] | ||
370 | fn issue_2705() { | ||
371 | assert_snapshot!( | ||
372 | infer(r#" | ||
373 | trait Trait {} | ||
374 | fn test() { | ||
375 | <Trait<u32>>::foo() | ||
376 | } | ||
377 | "#), | ||
378 | @r###" | ||
379 | [26; 53) '{ ...oo() }': () | ||
380 | [32; 49) '<Trait...>::foo': {unknown} | ||
381 | [32; 51) '<Trait...:foo()': () | ||
382 | "### | ||
383 | ); | ||
384 | } | ||