Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-db/src/rename.rs')
| -rw-r--r-- | crates/ide-db/src/rename.rs | 46 |
1 files changed, 3 insertions, 43 deletions
diff --git a/crates/ide-db/src/rename.rs b/crates/ide-db/src/rename.rs index bade88c578..f114d934e4 100644 --- a/crates/ide-db/src/rename.rs +++ b/crates/ide-db/src/rename.rs @@ -24,7 +24,7 @@ use std::fmt; use base_db::{AnchoredPathBuf, FileId, FileRange}; use either::Either; -use hir::{AsAssocItem, FieldSource, HasSource, InFile, ModuleSource, Semantics}; +use hir::{FieldSource, HasSource, InFile, ModuleSource, Semantics}; use stdx::never; use syntax::{ ast::{self, HasName}, @@ -37,6 +37,7 @@ use crate::{ search::FileReference, source_change::{FileSystemEdit, SourceChange}, syntax_helpers::node_ext::expr_as_name_ref, + traits::convert_to_def_in_trait, RootDatabase, }; @@ -271,7 +272,7 @@ fn rename_reference( } } - let def = convert_to_def_in_trait(def, sema); + let def = convert_to_def_in_trait(sema.db, def); let usages = def.usages(sema).all(); if !usages.is_empty() && ident_kind == IdentifierKind::Underscore { @@ -298,47 +299,6 @@ fn rename_reference( Ok(source_change) } -pub(crate) fn convert_to_def_in_trait( - def: Definition, - sema: &Semantics<RootDatabase>, -) -> Definition { - // HACK: resolve trait impl items to the item def of the trait definition - // so that we properly resolve all trait item references - let assoc_item = match def { - Definition::Function(it) => it.as_assoc_item(sema.db), - Definition::TypeAlias(it) => it.as_assoc_item(sema.db), - Definition::Const(it) => it.as_assoc_item(sema.db), - _ => None, - }; - match assoc_item { - Some(assoc) => assoc - .containing_trait_impl(sema.db) - .and_then(|trait_| { - trait_.items(sema.db).into_iter().find_map(|it| match (it, assoc) { - (hir::AssocItem::Function(trait_func), hir::AssocItem::Function(func)) - if trait_func.name(sema.db) == func.name(sema.db) => - { - Some(Definition::Function(trait_func)) - } - (hir::AssocItem::Const(trait_konst), hir::AssocItem::Const(konst)) - if trait_konst.name(sema.db) == konst.name(sema.db) => - { - Some(Definition::Const(trait_konst)) - } - ( - hir::AssocItem::TypeAlias(trait_type_alias), - hir::AssocItem::TypeAlias(type_alias), - ) if trait_type_alias.name(sema.db) == type_alias.name(sema.db) => { - Some(Definition::TypeAlias(trait_type_alias)) - } - _ => None, - }) - }) - .unwrap_or(def), - None => def, - } -} - pub fn source_edit_from_references( references: &[FileReference], def: Definition, |