From a1e18695548b5cd6661f26a985b34c8b105e1896 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 29 Feb 2020 21:24:40 +0100 Subject: Rename ast::ImplBlock -> ast::ImplDef --- crates/ra_hir_ty/src/db.rs | 6 +++--- crates/ra_hir_ty/src/method_resolution.rs | 23 +++++++++++------------ crates/ra_hir_ty/src/tests/macros.rs | 12 ++++++------ crates/ra_hir_ty/src/traits.rs | 6 +++--- crates/ra_hir_ty/src/traits/builtin.rs | 2 +- crates/ra_hir_ty/src/traits/chalk.rs | 8 ++++---- 6 files changed, 28 insertions(+), 29 deletions(-) (limited to 'crates/ra_hir_ty') diff --git a/crates/ra_hir_ty/src/db.rs b/crates/ra_hir_ty/src/db.rs index e9bfcfa17..85d85182f 100644 --- a/crates/ra_hir_ty/src/db.rs +++ b/crates/ra_hir_ty/src/db.rs @@ -11,7 +11,7 @@ use ra_db::{impl_intern_key, salsa, CrateId}; use ra_prof::profile; use crate::{ - method_resolution::CrateImplBlocks, + method_resolution::CrateImplDefs, traits::{chalk, AssocTyValue, Impl}, Binders, CallableDef, GenericPredicate, InferenceResult, PolyFnSig, Substs, TraitRef, Ty, TyDefId, TypeCtor, ValueTyDefId, @@ -59,8 +59,8 @@ pub trait HirDatabase: DefDatabase { #[salsa::invoke(crate::lower::generic_defaults_query)] fn generic_defaults(&self, def: GenericDefId) -> Substs; - #[salsa::invoke(crate::method_resolution::CrateImplBlocks::impls_in_crate_query)] - fn impls_in_crate(&self, krate: CrateId) -> Arc; + #[salsa::invoke(crate::method_resolution::CrateImplDefs::impls_in_crate_query)] + fn impls_in_crate(&self, krate: CrateId) -> Arc; #[salsa::invoke(crate::traits::impls_for_trait_query)] fn impls_for_trait(&self, krate: CrateId, trait_: TraitId) -> Arc<[ImplId]>; diff --git a/crates/ra_hir_ty/src/method_resolution.rs b/crates/ra_hir_ty/src/method_resolution.rs index 988d83af5..df5901835 100644 --- a/crates/ra_hir_ty/src/method_resolution.rs +++ b/crates/ra_hir_ty/src/method_resolution.rs @@ -42,19 +42,19 @@ impl TyFingerprint { } #[derive(Debug, PartialEq, Eq)] -pub struct CrateImplBlocks { +pub struct CrateImplDefs { impls: FxHashMap>, impls_by_trait: FxHashMap>, } -impl CrateImplBlocks { +impl CrateImplDefs { pub(crate) fn impls_in_crate_query( db: &impl HirDatabase, krate: CrateId, - ) -> Arc { + ) -> Arc { let _p = profile("impls_in_crate_query"); let mut res = - CrateImplBlocks { impls: FxHashMap::default(), impls_by_trait: FxHashMap::default() }; + CrateImplDefs { impls: FxHashMap::default(), impls_by_trait: FxHashMap::default() }; let crate_def_map = db.crate_def_map(krate); for (_module_id, module_data) in crate_def_map.modules.iter() { @@ -75,12 +75,12 @@ impl CrateImplBlocks { Arc::new(res) } - pub fn lookup_impl_blocks(&self, ty: &Ty) -> impl Iterator + '_ { + pub fn lookup_impl_defs(&self, ty: &Ty) -> impl Iterator + '_ { let fingerprint = TyFingerprint::for_impl(ty); fingerprint.and_then(|f| self.impls.get(&f)).into_iter().flatten().copied() } - pub fn lookup_impl_blocks_for_trait(&self, tr: TraitId) -> impl Iterator + '_ { + pub fn lookup_impl_defs_for_trait(&self, tr: TraitId) -> impl Iterator + '_ { self.impls_by_trait.get(&tr).into_iter().flatten().copied() } @@ -131,7 +131,7 @@ impl Ty { let res = lang_item_targets .into_iter() .filter_map(|it| match it { - LangItemTarget::ImplBlockId(it) => Some(it), + LangItemTarget::ImplDefId(it) => Some(it), _ => None, }) .map(|it| it.lookup(db).container.module(db).krate) @@ -177,7 +177,7 @@ pub enum LookupMode { } // This would be nicer if it just returned an iterator, but that runs into -// lifetime problems, because we need to borrow temp `CrateImplBlocks`. +// lifetime problems, because we need to borrow temp `CrateImplDefs`. // FIXME add a context type here? pub fn iterate_method_candidates( ty: &Canonical, @@ -425,8 +425,8 @@ fn iterate_inherent_methods( for krate in self_ty.value.def_crates(db, krate)? { let impls = db.impls_in_crate(krate); - for impl_block in impls.lookup_impl_blocks(&self_ty.value) { - for &item in db.impl_data(impl_block).items.iter() { + for impl_def in impls.lookup_impl_defs(&self_ty.value) { + for &item in db.impl_data(impl_def).items.iter() { if !is_valid_candidate(db, name, receiver_ty, item, self_ty) { continue; } @@ -434,8 +434,7 @@ fn iterate_inherent_methods( // that the impl is for. If we have a receiver type, this // already happens in `is_valid_candidate` above; if not, we // check it here - if receiver_ty.is_none() && inherent_impl_substs(db, impl_block, self_ty).is_none() - { + if receiver_ty.is_none() && inherent_impl_substs(db, impl_def, self_ty).is_none() { test_utils::tested_by!(impl_self_type_match_without_receiver); continue; } diff --git a/crates/ra_hir_ty/src/tests/macros.rs b/crates/ra_hir_ty/src/tests/macros.rs index 652420ea8..53cd81d46 100644 --- a/crates/ra_hir_ty/src/tests/macros.rs +++ b/crates/ra_hir_ty/src/tests/macros.rs @@ -4,7 +4,7 @@ use insta::assert_snapshot; use ra_db::fixture::WithFixture; #[test] -fn cfg_impl_block() { +fn cfg_impl_def() { let (db, pos) = TestDB::with_position( r#" //- /main.rs crate:main deps:foo cfg:test @@ -347,17 +347,17 @@ mod m { m::foo!(foo); use foo as bar; fn f() -> bar { 0 } -fn main() { +fn main() { let _a = f(); } "#), @r###" [159; 164) '{ 0 }': u64 [161; 162) '0': u64 - [175; 199) '{ ...f(); }': () - [187; 189) '_a': u64 - [193; 194) 'f': fn f() -> u64 - [193; 196) 'f()': u64 + [175; 197) '{ ...f(); }': () + [185; 187) '_a': u64 + [191; 192) 'f': fn f() -> u64 + [191; 194) 'f()': u64 "### ); } diff --git a/crates/ra_hir_ty/src/traits.rs b/crates/ra_hir_ty/src/traits.rs index 17aef9490..bc6ee2600 100644 --- a/crates/ra_hir_ty/src/traits.rs +++ b/crates/ra_hir_ty/src/traits.rs @@ -131,8 +131,8 @@ pub(crate) fn impls_for_trait_query( for dep in db.crate_graph().dependencies(krate) { impls.extend(db.impls_for_trait(dep.crate_id, trait_).iter()); } - let crate_impl_blocks = db.impls_in_crate(krate); - impls.extend(crate_impl_blocks.lookup_impl_blocks_for_trait(trait_)); + let crate_impl_defs = db.impls_in_crate(krate); + impls.extend(crate_impl_defs.lookup_impl_defs_for_trait(trait_)); impls.into_iter().collect() } @@ -346,7 +346,7 @@ pub struct UnsizeToSuperTraitObjectData { #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum Impl { /// A normal impl from an impl block. - ImplBlock(ImplId), + ImplDef(ImplId), /// Closure types implement the Fn traits synthetically. ClosureFnTraitImpl(ClosureFnTraitImplData), /// [T; n]: Unsize<[T]> diff --git a/crates/ra_hir_ty/src/traits/builtin.rs b/crates/ra_hir_ty/src/traits/builtin.rs index cc0f3eeb4..03f9b4e27 100644 --- a/crates/ra_hir_ty/src/traits/builtin.rs +++ b/crates/ra_hir_ty/src/traits/builtin.rs @@ -96,7 +96,7 @@ fn get_builtin_unsize_impls( pub(super) fn impl_datum(db: &impl HirDatabase, krate: CrateId, impl_: Impl) -> BuiltinImplData { match impl_ { - Impl::ImplBlock(_) => unreachable!(), + Impl::ImplDef(_) => unreachable!(), Impl::ClosureFnTraitImpl(data) => closure_fn_trait_impl_datum(db, krate, data), Impl::UnsizeArray => array_unsize_impl_datum(db, krate), Impl::UnsizeToTraitObject(trait_) => trait_object_unsize_impl_datum(db, krate, trait_), diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs index 5b6c1a62e..4001aa941 100644 --- a/crates/ra_hir_ty/src/traits/chalk.rs +++ b/crates/ra_hir_ty/src/traits/chalk.rs @@ -576,7 +576,7 @@ where .impls_for_trait(self.krate, trait_) .iter() .copied() - .map(Impl::ImplBlock) + .map(Impl::ImplDef) .map(|impl_| impl_.to_chalk(self.db)) .collect(); @@ -712,12 +712,12 @@ pub(crate) fn impl_datum_query( debug!("impl_datum {:?}", impl_id); let impl_: Impl = from_chalk(db, impl_id); match impl_ { - Impl::ImplBlock(impl_block) => impl_block_datum(db, krate, impl_id, impl_block), + Impl::ImplDef(impl_def) => impl_def_datum(db, krate, impl_id, impl_def), _ => Arc::new(builtin::impl_datum(db, krate, impl_).to_chalk(db)), } } -fn impl_block_datum( +fn impl_def_datum( db: &impl HirDatabase, krate: CrateId, chalk_id: ImplId, @@ -815,7 +815,7 @@ fn type_alias_associated_ty_value( let ty = db.ty(type_alias.into()); let value_bound = chalk_rust_ir::AssociatedTyValueBound { ty: ty.value.to_chalk(db) }; let value = chalk_rust_ir::AssociatedTyValue { - impl_id: Impl::ImplBlock(impl_id).to_chalk(db), + impl_id: Impl::ImplDef(impl_id).to_chalk(db), associated_ty_id: assoc_ty.to_chalk(db), value: make_binders(value_bound, ty.num_binders), }; -- cgit v1.2.3