From afc1d18ff3e060a4107d7a17623a5e84f6c6c86e Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Wed, 12 Feb 2020 17:18:29 +0200 Subject: Fix post-rebase issues --- crates/ra_assists/src/handlers/auto_import.rs | 27 +++++++++++++-------------- crates/ra_hir/src/code_model.rs | 23 ++++++++++++----------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/crates/ra_assists/src/handlers/auto_import.rs b/crates/ra_assists/src/handlers/auto_import.rs index 86615d659..950ec7d05 100644 --- a/crates/ra_assists/src/handlers/auto_import.rs +++ b/crates/ra_assists/src/handlers/auto_import.rs @@ -4,8 +4,8 @@ use crate::{ }; use hir::{ db::{DefDatabase, HirDatabase}, - AssocContainerId, AssocItem, Crate, Function, ModPath, Module, ModuleDef, PathResolution, - SourceAnalyzer, Trait, Type, + AsAssocItem, AssocItem, AssocItemContainer, Crate, Function, ModPath, Module, ModuleDef, + PathResolution, SourceAnalyzer, Trait, Type, }; use ra_ide_db::{imports_locator::ImportsLocator, RootDatabase}; use ra_prof::profile; @@ -157,13 +157,12 @@ impl AutoImportAssets { &trait_candidates, None, |_, assoc| { - if let AssocContainerId::TraitId(trait_id) = assoc.container(db) + if let AssocItemContainer::Trait(appropriate_trait) = + assoc.container(db) { applicable_traits.push( - self.module_with_name_to_import.find_use_path( - db, - ModuleDef::Trait(trait_id.into()), - ), + self.module_with_name_to_import + .find_use_path(db, appropriate_trait.into()), ); }; None::<()> @@ -187,15 +186,15 @@ impl AutoImportAssets { current_crate, &trait_candidates, None, - |_, funciton| { - if let AssocContainerId::TraitId(trait_id) = - funciton.container(db) + |_, function| { + if let AssocItemContainer::Trait(appropriate_trait) = function + .as_assoc_item(db) + .expect("Function is an assoc item") + .container(db) { applicable_traits.push( - self.module_with_name_to_import.find_use_path( - db, - ModuleDef::Trait(trait_id.into()), - ), + self.module_with_name_to_import + .find_use_path(db, appropriate_trait.into()), ); }; None::<()> diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 140b3a87f..cf3b04511 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -123,7 +123,7 @@ impl_froms!( ); pub use hir_def::{ - attr::Attrs, item_scope::ItemInNs, visibility::Visibility, AssocContainerId, AssocItemId, + attr::Attrs, item_scope::ItemInNs, visibility::Visibility, AssocItemId, AssocItemLoc, }; use rustc_hash::FxHashSet; @@ -548,10 +548,6 @@ impl Function { let mut validator = ExprValidator::new(self.id, infer, sink); validator.validate_body(db); } - - pub fn container(self, db: &impl DefDatabase) -> AssocContainerId { - self.id.lookup(db).container - } } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -701,11 +697,16 @@ impl AssocItem { } } - pub fn container(self, db: &impl DefDatabase) -> AssocContainerId { - match self { - AssocItem::Function(f) => f.container(db), - AssocItem::Const(c) => c.id.lookup(db).container, - AssocItem::TypeAlias(t) => t.id.lookup(db).container, + pub fn container(self, db: &impl DefDatabase) -> AssocItemContainer { + let container = match self { + AssocItem::Function(it) => it.id.lookup(db).container, + AssocItem::Const(it) => it.id.lookup(db).container, + AssocItem::TypeAlias(it) => it.id.lookup(db).container, + }; + match container { + AssocContainerId::TraitId(id) => AssocItemContainer::Trait(id.into()), + AssocContainerId::ImplId(id) => AssocItemContainer::ImplBlock(id.into()), + AssocContainerId::ContainerId(_) => panic!("invalid AssocItem"), } } } @@ -818,7 +819,7 @@ impl TypeParam { } } -// FIXME: rename to `ImplBlock` +// FIXME: rename from `ImplBlock` to `Impl` #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct ImplBlock { pub(crate) id: ImplId, -- cgit v1.2.3