aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_assists/src/handlers/auto_import.rs27
-rw-r--r--crates/ra_hir/src/code_model.rs23
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::{
4}; 4};
5use hir::{ 5use hir::{
6 db::{DefDatabase, HirDatabase}, 6 db::{DefDatabase, HirDatabase},
7 AssocContainerId, AssocItem, Crate, Function, ModPath, Module, ModuleDef, PathResolution, 7 AsAssocItem, AssocItem, AssocItemContainer, Crate, Function, ModPath, Module, ModuleDef,
8 SourceAnalyzer, Trait, Type, 8 PathResolution, SourceAnalyzer, Trait, Type,
9}; 9};
10use ra_ide_db::{imports_locator::ImportsLocator, RootDatabase}; 10use ra_ide_db::{imports_locator::ImportsLocator, RootDatabase};
11use ra_prof::profile; 11use ra_prof::profile;
@@ -157,13 +157,12 @@ impl AutoImportAssets {
157 &trait_candidates, 157 &trait_candidates,
158 None, 158 None,
159 |_, assoc| { 159 |_, assoc| {
160 if let AssocContainerId::TraitId(trait_id) = assoc.container(db) 160 if let AssocItemContainer::Trait(appropriate_trait) =
161 assoc.container(db)
161 { 162 {
162 applicable_traits.push( 163 applicable_traits.push(
163 self.module_with_name_to_import.find_use_path( 164 self.module_with_name_to_import
164 db, 165 .find_use_path(db, appropriate_trait.into()),
165 ModuleDef::Trait(trait_id.into()),
166 ),
167 ); 166 );
168 }; 167 };
169 None::<()> 168 None::<()>
@@ -187,15 +186,15 @@ impl AutoImportAssets {
187 current_crate, 186 current_crate,
188 &trait_candidates, 187 &trait_candidates,
189 None, 188 None,
190 |_, funciton| { 189 |_, function| {
191 if let AssocContainerId::TraitId(trait_id) = 190 if let AssocItemContainer::Trait(appropriate_trait) = function
192 funciton.container(db) 191 .as_assoc_item(db)
192 .expect("Function is an assoc item")
193 .container(db)
193 { 194 {
194 applicable_traits.push( 195 applicable_traits.push(
195 self.module_with_name_to_import.find_use_path( 196 self.module_with_name_to_import
196 db, 197 .find_use_path(db, appropriate_trait.into()),
197 ModuleDef::Trait(trait_id.into()),
198 ),
199 ); 198 );
200 }; 199 };
201 None::<()> 200 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!(
123); 123);
124 124
125pub use hir_def::{ 125pub use hir_def::{
126 attr::Attrs, item_scope::ItemInNs, visibility::Visibility, AssocContainerId, AssocItemId, 126 attr::Attrs, item_scope::ItemInNs, visibility::Visibility, AssocItemId, AssocItemLoc,
127}; 127};
128use rustc_hash::FxHashSet; 128use rustc_hash::FxHashSet;
129 129
@@ -548,10 +548,6 @@ impl Function {
548 let mut validator = ExprValidator::new(self.id, infer, sink); 548 let mut validator = ExprValidator::new(self.id, infer, sink);
549 validator.validate_body(db); 549 validator.validate_body(db);
550 } 550 }
551
552 pub fn container(self, db: &impl DefDatabase) -> AssocContainerId {
553 self.id.lookup(db).container
554 }
555} 551}
556 552
557#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 553#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -701,11 +697,16 @@ impl AssocItem {
701 } 697 }
702 } 698 }
703 699
704 pub fn container(self, db: &impl DefDatabase) -> AssocContainerId { 700 pub fn container(self, db: &impl DefDatabase) -> AssocItemContainer {
705 match self { 701 let container = match self {
706 AssocItem::Function(f) => f.container(db), 702 AssocItem::Function(it) => it.id.lookup(db).container,
707 AssocItem::Const(c) => c.id.lookup(db).container, 703 AssocItem::Const(it) => it.id.lookup(db).container,
708 AssocItem::TypeAlias(t) => t.id.lookup(db).container, 704 AssocItem::TypeAlias(it) => it.id.lookup(db).container,
705 };
706 match container {
707 AssocContainerId::TraitId(id) => AssocItemContainer::Trait(id.into()),
708 AssocContainerId::ImplId(id) => AssocItemContainer::ImplBlock(id.into()),
709 AssocContainerId::ContainerId(_) => panic!("invalid AssocItem"),
709 } 710 }
710 } 711 }
711} 712}
@@ -818,7 +819,7 @@ impl TypeParam {
818 } 819 }
819} 820}
820 821
821// FIXME: rename to `ImplBlock` 822// FIXME: rename from `ImplBlock` to `Impl`
822#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 823#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
823pub struct ImplBlock { 824pub struct ImplBlock {
824 pub(crate) id: ImplId, 825 pub(crate) id: ImplId,