Merge #8020
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  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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user