@@ -258,6 +258,8 @@ fn import_on_the_fly(
258258
259259 let import_cfg = ctx. config . import_path_config ( ) ;
260260
261+ let completed_name = ctx. token . to_string ( ) ;
262+
261263 import_assets
262264 . search_for_imports ( & ctx. sema , import_cfg, ctx. config . insert_use . prefix_kind )
263265 . filter ( ns_filter)
@@ -271,7 +273,13 @@ fn import_on_the_fly(
271273 if let ModuleDef :: Trait ( trait_) = import. item_to_import . into_module_def ( ) {
272274 let excluded = ctx. exclude_flyimport_traits . contains ( & trait_) ;
273275 let trait_itself_imported = import. item_to_import == import. original_item ;
274- !excluded || trait_itself_imported
276+ if !excluded || trait_itself_imported {
277+ return true ;
278+ }
279+
280+ let item = import. original_item . into_module_def ( ) ;
281+ // Filter that item out, unless its name matches the name the user wrote exactly - in which case preserve it.
282+ item. name ( ctx. db ) . is_some_and ( |name| name. eq_ident ( & completed_name) )
275283 } else {
276284 true
277285 }
@@ -355,6 +363,8 @@ fn import_on_the_fly_method(
355363
356364 let cfg = ctx. config . import_path_config ( ) ;
357365
366+ let completed_name = ctx. token . to_string ( ) ;
367+
358368 import_assets
359369 . search_for_imports ( & ctx. sema , cfg, ctx. config . insert_use . prefix_kind )
360370 . filter ( |import| {
@@ -363,7 +373,13 @@ fn import_on_the_fly_method(
363373 } )
364374 . filter ( |import| {
365375 if let ModuleDef :: Trait ( trait_) = import. item_to_import . into_module_def ( ) {
366- !ctx. exclude_flyimport_traits . contains ( & trait_)
376+ if !ctx. exclude_flyimport_traits . contains ( & trait_) {
377+ return true ;
378+ }
379+
380+ let item = import. original_item . into_module_def ( ) ;
381+ // Filter that method out, unless its name matches the name the user wrote exactly - in which case preserve it.
382+ item. name ( ctx. db ) . is_some_and ( |name| name. eq_ident ( & completed_name) )
367383 } else {
368384 true
369385 }
0 commit comments