From 7ed3be32916facf3b709d5277381408cd3ec134a Mon Sep 17 00:00:00 2001 From: uHOOCCOOHu Date: Sun, 15 Sep 2019 20:14:33 +0800 Subject: Define known paths and group names --- crates/ra_hir/src/ty/autoderef.rs | 2 +- crates/ra_hir/src/ty/infer.rs | 37 ++++++++++++------------------------- 2 files changed, 13 insertions(+), 26 deletions(-) (limited to 'crates/ra_hir/src/ty') diff --git a/crates/ra_hir/src/ty/autoderef.rs b/crates/ra_hir/src/ty/autoderef.rs index 5ba7cf2e0..94f8ecdc9 100644 --- a/crates/ra_hir/src/ty/autoderef.rs +++ b/crates/ra_hir/src/ty/autoderef.rs @@ -42,7 +42,7 @@ fn deref_by_trait( crate::lang_item::LangItemTarget::Trait(t) => t, _ => return None, }; - let target = deref_trait.associated_type_by_name(db, &name::TARGET)?; + let target = deref_trait.associated_type_by_name(db, &name::TARGET_TYPE)?; if target.generic_params(db).count_params_including_parent() != 1 { // the Target type + Deref trait should only have one generic parameter, diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 3981de829..785499f77 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -44,7 +44,7 @@ use crate::{ generics::{GenericParams, HasGenericParams}, name, nameres::Namespace, - path::{GenericArg, GenericArgs, PathKind}, + path::{known, GenericArg, GenericArgs}, resolve::{ResolveValueResult, Resolver, TypeNs, ValueNs}, ty::infer::diagnostics::InferenceDiagnostic, type_ref::{Mutability, TypeRef}, @@ -1442,39 +1442,26 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } fn resolve_into_iter_item(&self) -> Option { - let into_iter_path = Path::from_simple_segments( - PathKind::Abs, - vec![name::STD, name::ITER, name::INTO_ITERATOR], - ); - - let trait_ = self.resolver.resolve_known_trait(self.db, &into_iter_path)?; - trait_.associated_type_by_name(self.db, &name::ITEM) + let path = known::std_iter_into_iterator(); + let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; + trait_.associated_type_by_name(self.db, &name::ITEM_TYPE) } fn resolve_ops_try_ok(&self) -> Option { - let ops_try_path = - Path::from_simple_segments(PathKind::Abs, vec![name::STD, name::OPS, name::TRY]); - - let trait_ = self.resolver.resolve_known_trait(self.db, &ops_try_path)?; - trait_.associated_type_by_name(self.db, &name::OK) + let path = known::std_ops_try(); + let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; + trait_.associated_type_by_name(self.db, &name::OK_TYPE) } fn resolve_future_future_output(&self) -> Option { - let future_future_path = Path::from_simple_segments( - PathKind::Abs, - vec![name::STD, name::FUTURE_MOD, name::FUTURE_TYPE], - ); - - let trait_ = self.resolver.resolve_known_trait(self.db, &future_future_path)?; - trait_.associated_type_by_name(self.db, &name::OUTPUT) + let path = known::std_future_future(); + let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; + trait_.associated_type_by_name(self.db, &name::OUTPUT_TYPE) } fn resolve_boxed_box(&self) -> Option { - let boxed_box_path = Path::from_simple_segments( - PathKind::Abs, - vec![name::STD, name::BOXED_MOD, name::BOX_TYPE], - ); - let struct_ = self.resolver.resolve_known_struct(self.db, &boxed_box_path)?; + let path = known::std_boxed_box(); + let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; Some(Adt::Struct(struct_)) } } -- cgit v1.2.3