Skip to content

Conversation

@Veykril
Copy link
Member

@Veykril Veykril commented Nov 3, 2020

When we find at least one trait with the same name as the derive accessible from the current module we now generate a qualified path to that trait in the generated impl.
If we don't find any we just do what was done before and emit the trait name in the generated impl.

Comment on lines +57 to +69
let found_traits = imports_locator::find_imports(&ctx.sema, current_crate, trait_token.text())
.into_iter()
.filter_map(|candidate: either::Either<hir::ModuleDef, hir::MacroDef>| match candidate {
either::Either::Left(hir::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_))
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it makes sense to move this search into the edit phase of an assist? That way, we won't need to run somewhat costly find imports infra only to check if we should show a 💡.

Otoh, that means that we'd have to get by with a single assist....

Yeah, I guess it's better to use this logic, the applicability is narrow anyway

bors r+

@bors
Copy link
Contributor

bors bot commented Nov 4, 2020

@bors bors bot merged commit 99a8e59 into rust-lang:master Nov 4, 2020
@Veykril Veykril deleted the add-custom-impl branch November 27, 2020 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants