From 6b076f1931d7dc324d7bbbc4c1df9f7c1c1db8b7 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 26 Jan 2019 22:52:04 +0100 Subject: Use new Resolver API in type inference --- crates/ra_hir/src/ty/method_resolution.rs | 30 +++++++--------------- .../snapshots/tests__infer_function_generics.snap | 8 +++--- .../ty/snapshots/tests__infer_generic_chain.snap | 8 +++--- .../src/ty/snapshots/tests__infer_type_param.snap | 14 +++++----- 4 files changed, 24 insertions(+), 36 deletions(-) (limited to 'crates/ra_hir/src/ty') diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs index e857d6856..2282286b0 100644 --- a/crates/ra_hir/src/ty/method_resolution.rs +++ b/crates/ra_hir/src/ty/method_resolution.rs @@ -7,12 +7,10 @@ use std::sync::Arc; use rustc_hash::FxHashMap; use crate::{ - HirDatabase, module_tree::ModuleId, Module, ModuleDef, Crate, Name, Function, Trait, + HirDatabase, module_tree::ModuleId, Module, Crate, Name, Function, Trait, ids::TraitId, impl_block::{ImplId, ImplBlock, ImplItem}, - generics::GenericParams, ty::{AdtDef, Ty}, - type_ref::TypeRef, }; /// This is used as a key for indexing impls. @@ -85,17 +83,10 @@ impl CrateImplBlocks { fn collect_recursive(&mut self, db: &impl HirDatabase, module: &Module) { let module_impl_blocks = db.impls_in_module(module.clone()); - for (impl_id, impl_data) in module_impl_blocks.impls.iter() { + for (impl_id, _) in module_impl_blocks.impls.iter() { let impl_block = ImplBlock::from_id(Arc::clone(&module_impl_blocks), impl_id); - // TODO provide generics of impl - let generics = GenericParams::default(); - let target_ty = Ty::from_hir( - db, - &module, - Some(&impl_block), - &generics, - impl_data.target_type(), - ); + + let target_ty = impl_block.target_ty(db); if let Some(target_ty_fp) = TyFingerprint::for_impl(&target_ty) { self.impls @@ -104,14 +95,11 @@ impl CrateImplBlocks { .push((module.module_id, impl_id)); } - if let Some(TypeRef::Path(path)) = impl_data.target_trait() { - let perns = module.resolve_path(db, path); - if let Some(ModuleDef::Trait(tr)) = perns.take_types() { - self.impls_by_trait - .entry(tr.id) - .or_insert_with(Vec::new) - .push((module.module_id, impl_id)); - } + if let Some(tr) = impl_block.target_trait(db) { + self.impls_by_trait + .entry(tr.id) + .or_insert_with(Vec::new) + .push((module.module_id, impl_id)); } } diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_function_generics.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_function_generics.snap index 8ff6e55a6..91c48897c 100644 --- a/crates/ra_hir/src/ty/snapshots/tests__infer_function_generics.snap +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_function_generics.snap @@ -1,12 +1,12 @@ --- -created: "2019-01-26T18:16:16.530712344+00:00" +created: "2019-01-27T14:52:29.934503829+00:00" creator: insta@0.5.2 expression: "&result" source: crates/ra_hir/src/ty/tests.rs --- -[10; 11) 't': [unknown] -[21; 26) '{ t }': [unknown] -[23; 24) 't': [unknown] +[10; 11) 't': T +[21; 26) '{ t }': T +[23; 24) 't': T [38; 98) '{ ...(1); }': () [44; 46) 'id': fn id(T) -> T [44; 52) 'id(1u32)': u32 diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_generic_chain.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_generic_chain.snap index f21bffa75..626f31252 100644 --- a/crates/ra_hir/src/ty/snapshots/tests__infer_generic_chain.snap +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_generic_chain.snap @@ -1,5 +1,5 @@ --- -created: "2019-01-26T17:46:03.866825843+00:00" +created: "2019-01-27T14:52:29.938713255+00:00" creator: insta@0.5.2 expression: "&result" source: crates/ra_hir/src/ty/tests.rs @@ -8,9 +8,9 @@ source: crates/ra_hir/src/ty/tests.rs [65; 87) '{ ... }': [unknown] [75; 79) 'self': A<[unknown]> [75; 81) 'self.x': [unknown] -[99; 100) 't': [unknown] -[110; 115) '{ t }': [unknown] -[112; 113) 't': [unknown] +[99; 100) 't': T +[110; 115) '{ t }': T +[112; 113) 't': T [135; 261) '{ ....x() }': i128 [146; 147) 'x': i32 [150; 151) '1': i32 diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_type_param.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_type_param.snap index a99323264..216d1e41f 100644 --- a/crates/ra_hir/src/ty/snapshots/tests__infer_type_param.snap +++ b/crates/ra_hir/src/ty/snapshots/tests__infer_type_param.snap @@ -1,15 +1,15 @@ --- -created: "2019-01-27T16:54:18.368427685+00:00" +created: "2019-01-27T20:38:32.153717698+00:00" creator: insta@0.5.2 expression: "&result" source: crates/ra_hir/src/ty/tests.rs --- -[10; 11) 'x': [unknown] -[21; 30) '{ x }': [unknown] -[27; 28) 'x': [unknown] -[44; 45) 'x': &[unknown] -[56; 65) '{ x }': &[unknown] -[62; 63) 'x': &[unknown] +[10; 11) 'x': T +[21; 30) '{ x }': T +[27; 28) 'x': T +[44; 45) 'x': &T +[56; 65) '{ x }': &T +[62; 63) 'x': &T [77; 157) '{ ...(1); }': () [87; 88) 'y': u32 [91; 96) '10u32': u32 -- cgit v1.2.3