From 259c42f00e2e85594c7373166bc8467ce375a045 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 13 Dec 2019 21:43:53 +0100 Subject: Add macros for known names and paths --- crates/ra_hir_ty/src/autoderef.rs | 4 ++-- crates/ra_hir_ty/src/infer.rs | 12 ++++++------ crates/ra_hir_ty/src/infer/expr.rs | 4 ++-- crates/ra_hir_ty/src/traits/builtin.rs | 6 +++--- crates/ra_hir_ty/src/utils.rs | 6 ++---- 5 files changed, 15 insertions(+), 17 deletions(-) (limited to 'crates/ra_hir_ty/src') diff --git a/crates/ra_hir_ty/src/autoderef.rs b/crates/ra_hir_ty/src/autoderef.rs index d557962b4..04822d56e 100644 --- a/crates/ra_hir_ty/src/autoderef.rs +++ b/crates/ra_hir_ty/src/autoderef.rs @@ -6,7 +6,7 @@ use std::iter::successors; use hir_def::lang_item::LangItemTarget; -use hir_expand::name; +use hir_expand::name::N; use log::{info, warn}; use ra_db::CrateId; @@ -52,7 +52,7 @@ fn deref_by_trait( LangItemTarget::TraitId(it) => it, _ => return None, }; - let target = db.trait_data(deref_trait).associated_type_by_name(&name::TARGET_TYPE)?; + let target = db.trait_data(deref_trait).associated_type_by_name(&N![Target])?; let generic_params = generics(db, target.into()); if generic_params.len() != 1 { diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs index a1201b3e4..bb366bb8b 100644 --- a/crates/ra_hir_ty/src/infer.rs +++ b/crates/ra_hir_ty/src/infer.rs @@ -29,7 +29,7 @@ use hir_def::{ type_ref::{Mutability, TypeRef}, AdtId, AssocItemId, DefWithBodyId, FunctionId, StructFieldId, TypeAliasId, VariantId, }; -use hir_expand::{diagnostics::DiagnosticSink, name}; +use hir_expand::{diagnostics::DiagnosticSink, name::N}; use ra_arena::map::ArenaMap; use ra_prof::profile; @@ -424,31 +424,31 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { fn resolve_into_iter_item(&self) -> Option { let path = known::std_iter_into_iterator(); let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; - self.db.trait_data(trait_).associated_type_by_name(&name::ITEM_TYPE) + self.db.trait_data(trait_).associated_type_by_name(&N![Item]) } fn resolve_ops_try_ok(&self) -> Option { let path = known::std_ops_try(); let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; - self.db.trait_data(trait_).associated_type_by_name(&name::OK_TYPE) + self.db.trait_data(trait_).associated_type_by_name(&N![Ok]) } fn resolve_ops_neg_output(&self) -> Option { let path = known::std_ops_neg(); let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; - self.db.trait_data(trait_).associated_type_by_name(&name::OUTPUT_TYPE) + self.db.trait_data(trait_).associated_type_by_name(&N![Output]) } fn resolve_ops_not_output(&self) -> Option { let path = known::std_ops_not(); let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; - self.db.trait_data(trait_).associated_type_by_name(&name::OUTPUT_TYPE) + self.db.trait_data(trait_).associated_type_by_name(&N![Output]) } fn resolve_future_future_output(&self) -> Option { let path = known::std_future_future(); let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; - self.db.trait_data(trait_).associated_type_by_name(&name::OUTPUT_TYPE) + self.db.trait_data(trait_).associated_type_by_name(&N![Output]) } fn resolve_boxed_box(&self) -> Option { diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index f8c00a7b4..a6f5c6ec3 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs @@ -10,7 +10,7 @@ use hir_def::{ resolver::resolver_for_expr, AdtId, ContainerId, Lookup, StructFieldId, }; -use hir_expand::name::{self, Name}; +use hir_expand::name::{Name, N}; use ra_syntax::ast::RangeOp; use crate::{ @@ -631,7 +631,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { // Parent arguments are unknown, except for the receiver type if let Some(parent_generics) = def_generics.as_ref().map(|p| p.iter_parent()) { for (_id, param) in parent_generics { - if param.name == name::SELF_TYPE { + if param.name == N![Self] { substs.push(receiver_ty.clone()); } else { substs.push(Ty::Unknown); diff --git a/crates/ra_hir_ty/src/traits/builtin.rs b/crates/ra_hir_ty/src/traits/builtin.rs index 598fd81e3..27c475a3c 100644 --- a/crates/ra_hir_ty/src/traits/builtin.rs +++ b/crates/ra_hir_ty/src/traits/builtin.rs @@ -1,7 +1,7 @@ //! This module provides the built-in trait implementations, e.g. to make //! closures implement `Fn`. use hir_def::{expr::Expr, lang_item::LangItemTarget, TraitId, TypeAliasId}; -use hir_expand::name; +use hir_expand::name::N; use ra_db::CrateId; use super::{AssocTyValue, Impl}; @@ -79,7 +79,7 @@ fn closure_fn_trait_impl_datum( // and don't want to return a valid value only to find out later that FnOnce // is broken let fn_once_trait = get_fn_trait(db, krate, super::FnTrait::FnOnce)?; - let _output = db.trait_data(fn_once_trait).associated_type_by_name(&name::OUTPUT_TYPE)?; + let _output = db.trait_data(fn_once_trait).associated_type_by_name(&N![Output])?; let num_args: u16 = match &db.body(data.def.into())[data.expr] { Expr::Lambda { args, .. } => args.len() as u16, @@ -137,7 +137,7 @@ fn closure_fn_trait_output_assoc_ty_value( let output_ty_id = db .trait_data(fn_once_trait) - .associated_type_by_name(&name::OUTPUT_TYPE) + .associated_type_by_name(&N![Output]) .expect("assoc ty value should not exist"); BuiltinImplAssocTyValueData { diff --git a/crates/ra_hir_ty/src/utils.rs b/crates/ra_hir_ty/src/utils.rs index aeb211a91..fabf45b53 100644 --- a/crates/ra_hir_ty/src/utils.rs +++ b/crates/ra_hir_ty/src/utils.rs @@ -10,10 +10,8 @@ use hir_def::{ type_ref::TypeRef, ContainerId, GenericDefId, Lookup, TraitId, TypeAliasId, TypeParamId, VariantId, }; -use hir_expand::name::{self, Name}; +use hir_expand::name::{Name, N}; -// FIXME: this is wrong, b/c it can't express `trait T: PartialEq<()>`. -// We should return a `TraitREf` here. fn direct_super_traits(db: &impl DefDatabase, trait_: TraitId) -> Vec { let resolver = trait_.resolver(db); // returning the iterator directly doesn't easily work because of @@ -24,7 +22,7 @@ fn direct_super_traits(db: &impl DefDatabase, trait_: TraitId) -> Vec { .where_predicates .iter() .filter_map(|pred| match &pred.type_ref { - TypeRef::Path(p) if p.as_ident() == Some(&name::SELF_TYPE) => pred.bound.as_path(), + TypeRef::Path(p) if p.as_ident() == Some(&N![Self]) => pred.bound.as_path(), _ => None, }) .filter_map(|path| match resolver.resolve_path_in_type_ns_fully(db, path) { -- cgit v1.2.3 From 6911bc89a784ce72b4dfd8e0ba72bd22ce898395 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 13 Dec 2019 22:01:06 +0100 Subject: Rename N! to name! --- crates/ra_hir_ty/src/autoderef.rs | 4 ++-- crates/ra_hir_ty/src/infer.rs | 12 ++++++------ crates/ra_hir_ty/src/infer/expr.rs | 4 ++-- crates/ra_hir_ty/src/traits/builtin.rs | 6 +++--- crates/ra_hir_ty/src/utils.rs | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-) (limited to 'crates/ra_hir_ty/src') diff --git a/crates/ra_hir_ty/src/autoderef.rs b/crates/ra_hir_ty/src/autoderef.rs index 04822d56e..ee48fa537 100644 --- a/crates/ra_hir_ty/src/autoderef.rs +++ b/crates/ra_hir_ty/src/autoderef.rs @@ -6,7 +6,7 @@ use std::iter::successors; use hir_def::lang_item::LangItemTarget; -use hir_expand::name::N; +use hir_expand::name::name; use log::{info, warn}; use ra_db::CrateId; @@ -52,7 +52,7 @@ fn deref_by_trait( LangItemTarget::TraitId(it) => it, _ => return None, }; - let target = db.trait_data(deref_trait).associated_type_by_name(&N![Target])?; + let target = db.trait_data(deref_trait).associated_type_by_name(&name![Target])?; let generic_params = generics(db, target.into()); if generic_params.len() != 1 { diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs index bb366bb8b..edf4e69ba 100644 --- a/crates/ra_hir_ty/src/infer.rs +++ b/crates/ra_hir_ty/src/infer.rs @@ -29,7 +29,7 @@ use hir_def::{ type_ref::{Mutability, TypeRef}, AdtId, AssocItemId, DefWithBodyId, FunctionId, StructFieldId, TypeAliasId, VariantId, }; -use hir_expand::{diagnostics::DiagnosticSink, name::N}; +use hir_expand::{diagnostics::DiagnosticSink, name::name}; use ra_arena::map::ArenaMap; use ra_prof::profile; @@ -424,31 +424,31 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { fn resolve_into_iter_item(&self) -> Option { let path = known::std_iter_into_iterator(); let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; - self.db.trait_data(trait_).associated_type_by_name(&N![Item]) + self.db.trait_data(trait_).associated_type_by_name(&name![Item]) } fn resolve_ops_try_ok(&self) -> Option { let path = known::std_ops_try(); let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; - self.db.trait_data(trait_).associated_type_by_name(&N![Ok]) + self.db.trait_data(trait_).associated_type_by_name(&name![Ok]) } fn resolve_ops_neg_output(&self) -> Option { let path = known::std_ops_neg(); let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; - self.db.trait_data(trait_).associated_type_by_name(&N![Output]) + self.db.trait_data(trait_).associated_type_by_name(&name![Output]) } fn resolve_ops_not_output(&self) -> Option { let path = known::std_ops_not(); let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; - self.db.trait_data(trait_).associated_type_by_name(&N![Output]) + self.db.trait_data(trait_).associated_type_by_name(&name![Output]) } fn resolve_future_future_output(&self) -> Option { let path = known::std_future_future(); let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; - self.db.trait_data(trait_).associated_type_by_name(&N![Output]) + self.db.trait_data(trait_).associated_type_by_name(&name![Output]) } fn resolve_boxed_box(&self) -> Option { diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index a6f5c6ec3..2e3cdd53a 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs @@ -10,7 +10,7 @@ use hir_def::{ resolver::resolver_for_expr, AdtId, ContainerId, Lookup, StructFieldId, }; -use hir_expand::name::{Name, N}; +use hir_expand::name::{name, Name}; use ra_syntax::ast::RangeOp; use crate::{ @@ -631,7 +631,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { // Parent arguments are unknown, except for the receiver type if let Some(parent_generics) = def_generics.as_ref().map(|p| p.iter_parent()) { for (_id, param) in parent_generics { - if param.name == N![Self] { + if param.name == name![Self] { substs.push(receiver_ty.clone()); } else { substs.push(Ty::Unknown); diff --git a/crates/ra_hir_ty/src/traits/builtin.rs b/crates/ra_hir_ty/src/traits/builtin.rs index 27c475a3c..cd587a338 100644 --- a/crates/ra_hir_ty/src/traits/builtin.rs +++ b/crates/ra_hir_ty/src/traits/builtin.rs @@ -1,7 +1,7 @@ //! This module provides the built-in trait implementations, e.g. to make //! closures implement `Fn`. use hir_def::{expr::Expr, lang_item::LangItemTarget, TraitId, TypeAliasId}; -use hir_expand::name::N; +use hir_expand::name::name; use ra_db::CrateId; use super::{AssocTyValue, Impl}; @@ -79,7 +79,7 @@ fn closure_fn_trait_impl_datum( // and don't want to return a valid value only to find out later that FnOnce // is broken let fn_once_trait = get_fn_trait(db, krate, super::FnTrait::FnOnce)?; - let _output = db.trait_data(fn_once_trait).associated_type_by_name(&N![Output])?; + let _output = db.trait_data(fn_once_trait).associated_type_by_name(&name![Output])?; let num_args: u16 = match &db.body(data.def.into())[data.expr] { Expr::Lambda { args, .. } => args.len() as u16, @@ -137,7 +137,7 @@ fn closure_fn_trait_output_assoc_ty_value( let output_ty_id = db .trait_data(fn_once_trait) - .associated_type_by_name(&N![Output]) + .associated_type_by_name(&name![Output]) .expect("assoc ty value should not exist"); BuiltinImplAssocTyValueData { diff --git a/crates/ra_hir_ty/src/utils.rs b/crates/ra_hir_ty/src/utils.rs index fabf45b53..0049d3c6f 100644 --- a/crates/ra_hir_ty/src/utils.rs +++ b/crates/ra_hir_ty/src/utils.rs @@ -10,7 +10,7 @@ use hir_def::{ type_ref::TypeRef, ContainerId, GenericDefId, Lookup, TraitId, TypeAliasId, TypeParamId, VariantId, }; -use hir_expand::name::{Name, N}; +use hir_expand::name::{name, Name}; fn direct_super_traits(db: &impl DefDatabase, trait_: TraitId) -> Vec { let resolver = trait_.resolver(db); @@ -22,7 +22,7 @@ fn direct_super_traits(db: &impl DefDatabase, trait_: TraitId) -> Vec { .where_predicates .iter() .filter_map(|pred| match &pred.type_ref { - TypeRef::Path(p) if p.as_ident() == Some(&N![Self]) => pred.bound.as_path(), + TypeRef::Path(p) if p.as_ident() == Some(&name![Self]) => pred.bound.as_path(), _ => None, }) .filter_map(|path| match resolver.resolve_path_in_type_ns_fully(db, path) { -- cgit v1.2.3 From f02fcc16444fcd18ccd51b43fa01bf0233e044fa Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 13 Dec 2019 22:32:44 +0100 Subject: Use path macro --- crates/ra_hir_ty/src/expr.rs | 4 ++-- crates/ra_hir_ty/src/infer.rs | 26 +++++++++++++------------- 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'crates/ra_hir_ty/src') diff --git a/crates/ra_hir_ty/src/expr.rs b/crates/ra_hir_ty/src/expr.rs index d2bd64e5c..f752a9f09 100644 --- a/crates/ra_hir_ty/src/expr.rs +++ b/crates/ra_hir_ty/src/expr.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use hir_def::{ - path::{known, Path}, + path::{path, Path}, resolver::HasResolver, AdtId, FunctionId, }; @@ -124,7 +124,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { None => return, }; - let std_result_path = known::std_result_result(); + let std_result_path = path![std::result::Result]; let resolver = self.func.resolver(db); let std_result_enum = match resolver.resolve_known_enum(db, &std_result_path) { diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs index edf4e69ba..f1b7e9442 100644 --- a/crates/ra_hir_ty/src/infer.rs +++ b/crates/ra_hir_ty/src/infer.rs @@ -24,7 +24,7 @@ use hir_def::{ body::Body, data::{ConstData, FunctionData}, expr::{BindingAnnotation, ExprId, PatId}, - path::{known, Path}, + path::{path, Path}, resolver::{HasResolver, Resolver, TypeNs}, type_ref::{Mutability, TypeRef}, AdtId, AssocItemId, DefWithBodyId, FunctionId, StructFieldId, TypeAliasId, VariantId, @@ -422,73 +422,73 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } fn resolve_into_iter_item(&self) -> Option { - let path = known::std_iter_into_iterator(); + let path = path![std::iter::IntoIterator]; let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; self.db.trait_data(trait_).associated_type_by_name(&name![Item]) } fn resolve_ops_try_ok(&self) -> Option { - let path = known::std_ops_try(); + let path = path![std::ops::Try]; let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; self.db.trait_data(trait_).associated_type_by_name(&name![Ok]) } fn resolve_ops_neg_output(&self) -> Option { - let path = known::std_ops_neg(); + let path = path![std::ops::Neg]; let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; self.db.trait_data(trait_).associated_type_by_name(&name![Output]) } fn resolve_ops_not_output(&self) -> Option { - let path = known::std_ops_not(); + let path = path![std::ops::Not]; let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; self.db.trait_data(trait_).associated_type_by_name(&name![Output]) } fn resolve_future_future_output(&self) -> Option { - let path = known::std_future_future(); + let path = path![std::future::Future]; let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; self.db.trait_data(trait_).associated_type_by_name(&name![Output]) } fn resolve_boxed_box(&self) -> Option { - let path = known::std_boxed_box(); + let path = path![std::boxed::Box]; let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; Some(struct_.into()) } fn resolve_range_full(&self) -> Option { - let path = known::std_ops_range_full(); + let path = path![std::ops::RangeFull]; let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; Some(struct_.into()) } fn resolve_range(&self) -> Option { - let path = known::std_ops_range(); + let path = path![std::ops::Range]; let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; Some(struct_.into()) } fn resolve_range_inclusive(&self) -> Option { - let path = known::std_ops_range_inclusive(); + let path = path![std::ops::RangeInclusive]; let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; Some(struct_.into()) } fn resolve_range_from(&self) -> Option { - let path = known::std_ops_range_from(); + let path = path![std::ops::RangeFrom]; let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; Some(struct_.into()) } fn resolve_range_to(&self) -> Option { - let path = known::std_ops_range_to(); + let path = path![std::ops::RangeTo]; let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; Some(struct_.into()) } fn resolve_range_to_inclusive(&self) -> Option { - let path = known::std_ops_range_to_inclusive(); + let path = path![std::ops::RangeToInclusive]; let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; Some(struct_.into()) } -- cgit v1.2.3