@@ -24,7 +24,7 @@ use std::fmt;
2424
2525use base_db:: { AnchoredPathBuf , FileId , FileRange } ;
2626use either:: Either ;
27- use hir:: { AsAssocItem , FieldSource , HasSource , InFile , ModuleSource , Semantics } ;
27+ use hir:: { FieldSource , HasSource , InFile , ModuleSource , Semantics } ;
2828use stdx:: never;
2929use syntax:: {
3030 ast:: { self , HasName } ,
@@ -37,6 +37,7 @@ use crate::{
3737 search:: FileReference ,
3838 source_change:: { FileSystemEdit , SourceChange } ,
3939 syntax_helpers:: node_ext:: expr_as_name_ref,
40+ traits:: convert_to_def_in_trait,
4041 RootDatabase ,
4142} ;
4243
@@ -271,7 +272,7 @@ fn rename_reference(
271272 }
272273 }
273274
274- let def = convert_to_def_in_trait ( def , sema ) ;
275+ let def = convert_to_def_in_trait ( sema . db , def ) ;
275276 let usages = def. usages ( sema) . all ( ) ;
276277
277278 if !usages. is_empty ( ) && ident_kind == IdentifierKind :: Underscore {
@@ -298,47 +299,6 @@ fn rename_reference(
298299 Ok ( source_change)
299300}
300301
301- pub ( crate ) fn convert_to_def_in_trait (
302- def : Definition ,
303- sema : & Semantics < RootDatabase > ,
304- ) -> Definition {
305- // HACK: resolve trait impl items to the item def of the trait definition
306- // so that we properly resolve all trait item references
307- let assoc_item = match def {
308- Definition :: Function ( it) => it. as_assoc_item ( sema. db ) ,
309- Definition :: TypeAlias ( it) => it. as_assoc_item ( sema. db ) ,
310- Definition :: Const ( it) => it. as_assoc_item ( sema. db ) ,
311- _ => None ,
312- } ;
313- match assoc_item {
314- Some ( assoc) => assoc
315- . containing_trait_impl ( sema. db )
316- . and_then ( |trait_| {
317- trait_. items ( sema. db ) . into_iter ( ) . find_map ( |it| match ( it, assoc) {
318- ( hir:: AssocItem :: Function ( trait_func) , hir:: AssocItem :: Function ( func) )
319- if trait_func. name ( sema. db ) == func. name ( sema. db ) =>
320- {
321- Some ( Definition :: Function ( trait_func) )
322- }
323- ( hir:: AssocItem :: Const ( trait_konst) , hir:: AssocItem :: Const ( konst) )
324- if trait_konst. name ( sema. db ) == konst. name ( sema. db ) =>
325- {
326- Some ( Definition :: Const ( trait_konst) )
327- }
328- (
329- hir:: AssocItem :: TypeAlias ( trait_type_alias) ,
330- hir:: AssocItem :: TypeAlias ( type_alias) ,
331- ) if trait_type_alias. name ( sema. db ) == type_alias. name ( sema. db ) => {
332- Some ( Definition :: TypeAlias ( trait_type_alias) )
333- }
334- _ => None ,
335- } )
336- } )
337- . unwrap_or ( def) ,
338- None => def,
339- }
340- }
341-
342302pub fn source_edit_from_references (
343303 references : & [ FileReference ] ,
344304 def : Definition ,
0 commit comments