diff options
Diffstat (limited to 'crates/ide_assists/src')
-rw-r--r-- | crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs b/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs index 88fe2fe90..1a98c51ce 100644 --- a/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs +++ b/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | use hir::ModuleDef; | 1 | use hir::ModuleDef; |
2 | use ide_db::helpers::mod_path_to_ast; | 2 | use ide_db::helpers::{import_assets::NameToImport, mod_path_to_ast}; |
3 | use ide_db::items_locator; | 3 | use ide_db::items_locator; |
4 | use itertools::Itertools; | 4 | use itertools::Itertools; |
5 | use syntax::{ | 5 | use syntax::{ |
@@ -65,20 +65,25 @@ pub(crate) fn replace_derive_with_manual_impl( | |||
65 | let current_module = ctx.sema.scope(annotated_name.syntax()).module()?; | 65 | let current_module = ctx.sema.scope(annotated_name.syntax()).module()?; |
66 | let current_crate = current_module.krate(); | 66 | let current_crate = current_module.krate(); |
67 | 67 | ||
68 | let found_traits = | 68 | let found_traits = items_locator::locate_for_name( |
69 | items_locator::with_exact_name(&ctx.sema, current_crate, trait_token.text().to_string()) | 69 | &ctx.sema, |
70 | .into_iter() | 70 | current_crate, |
71 | .filter_map(|item| match ModuleDef::from(item.as_module_def_id()?) { | 71 | NameToImport::Exact(trait_token.text().to_string()), |
72 | ModuleDef::Trait(trait_) => Some(trait_), | 72 | items_locator::AssocItemSearch::Exclude, |
73 | _ => None, | 73 | None, |
74 | }) | 74 | ) |
75 | .flat_map(|trait_| { | 75 | .into_iter() |
76 | current_module | 76 | .filter_map(|item| match ModuleDef::from(item.as_module_def_id()?) { |
77 | .find_use_path(ctx.sema.db, hir::ModuleDef::Trait(trait_)) | 77 | ModuleDef::Trait(trait_) => Some(trait_), |
78 | .as_ref() | 78 | _ => None, |
79 | .map(mod_path_to_ast) | 79 | }) |
80 | .zip(Some(trait_)) | 80 | .flat_map(|trait_| { |
81 | }); | 81 | current_module |
82 | .find_use_path(ctx.sema.db, hir::ModuleDef::Trait(trait_)) | ||
83 | .as_ref() | ||
84 | .map(mod_path_to_ast) | ||
85 | .zip(Some(trait_)) | ||
86 | }); | ||
82 | 87 | ||
83 | let mut no_traits_found = true; | 88 | let mut no_traits_found = true; |
84 | for (trait_path, trait_) in found_traits.inspect(|_| no_traits_found = false) { | 89 | for (trait_path, trait_) in found_traits.inspect(|_| no_traits_found = false) { |