Less lifetines: derive SemanticsScope in place

This commit is contained in:
Kirill Bulatov
2021-03-08 00:25:45 +02:00
parent db61d4ea13
commit dccbb38d2e
7 changed files with 49 additions and 50 deletions

View File

@@ -112,9 +112,7 @@ pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
Some(())
}
pub(super) fn find_importable_node<'a>(
ctx: &'a AssistContext,
) -> Option<(ImportAssets<'a>, SyntaxNode)> {
pub(super) fn find_importable_node(ctx: &AssistContext) -> Option<(ImportAssets, SyntaxNode)> {
if let Some(path_under_caret) = ctx.find_node_at_offset_with_descend::<ast::Path>() {
ImportAssets::for_exact_path(&path_under_caret, &ctx.sema)
.zip(Some(path_under_caret.syntax().clone()))

View File

@@ -65,23 +65,20 @@ pub(crate) fn replace_derive_with_manual_impl(
let current_module = ctx.sema.scope(annotated_name.syntax()).module()?;
let current_crate = current_module.krate();
let found_traits = items_locator::with_for_exact_name(
&ctx.sema,
current_crate,
trait_token.text().to_string(),
)
.into_iter()
.filter_map(|item| match ModuleDef::from(item.as_module_def_id()?) {
ModuleDef::Trait(trait_) => Some(trait_),
_ => None,
})
.flat_map(|trait_| {
current_module
.find_use_path(ctx.sema.db, hir::ModuleDef::Trait(trait_))
.as_ref()
.map(mod_path_to_ast)
.zip(Some(trait_))
});
let found_traits =
items_locator::with_exact_name(&ctx.sema, current_crate, trait_token.text().to_string())
.into_iter()
.filter_map(|item| match ModuleDef::from(item.as_module_def_id()?) {
ModuleDef::Trait(trait_) => Some(trait_),
_ => None,
})
.flat_map(|trait_| {
current_module
.find_use_path(ctx.sema.db, hir::ModuleDef::Trait(trait_))
.as_ref()
.map(mod_path_to_ast)
.zip(Some(trait_))
});
let mut no_traits_found = true;
for (trait_path, trait_) in found_traits.inspect(|_| no_traits_found = false) {