8020: Power up goto_implementation r=matklad a=Veykril

by allowing it to be invoked on references of names, now showing all (trait)
implementations of the given type in all crates instead of just the defining
crate as well as including support for builtin types

![image](https://user-images.githubusercontent.com/3757771/111144403-52bb0700-8587-11eb-9205-7a2a5b8b75a3.png)
Example screenshot of `impl`s of Box in `log`, `alloc`, `std` and the current crate. Before you had to invoke it on the definition where it would only show the `impls` in `alloc`.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
bors[bot] 2021-03-15 14:08:26 +00:00 committed by GitHub
commit f2c39d0cdf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 136 additions and 64 deletions

View file

@ -44,7 +44,7 @@ impl TyFingerprint {
/// Creates a TyFingerprint for looking up an impl. Only certain types can
/// have impls: if we have some `struct S`, we can have an `impl S`, but not
/// `impl &S`. Hence, this will return `None` for reference types and such.
pub(crate) fn for_impl(ty: &Ty) -> Option<TyFingerprint> {
pub fn for_impl(ty: &Ty) -> Option<TyFingerprint> {
let fp = match *ty.interned(&Interner) {
TyKind::Str => TyFingerprint::Str,
TyKind::Never => TyFingerprint::Never,
@ -141,6 +141,14 @@ impl TraitImpls {
}
}
/// Queries all trait impls for the given type.
pub fn for_self_ty(&self, fp: TyFingerprint) -> impl Iterator<Item = ImplId> + '_ {
self.map
.values()
.flat_map(move |impls| impls.get(&None).into_iter().chain(impls.get(&Some(fp))))
.flat_map(|it| it.iter().copied())
}
/// Queries all impls of the given trait.
pub fn for_trait(&self, trait_: TraitId) -> impl Iterator<Item = ImplId> + '_ {
self.map