1
Fork 0

rustdoc: fix intra-link for generic trait impls

This commit is contained in:
Mahdi Dibaiee 2022-01-11 22:20:01 +00:00
parent 1409c015b4
commit 9ff8ae097e
No known key found for this signature in database
GPG key ID: BABA115BDF0C598A
2 changed files with 31 additions and 1 deletions

View file

@ -903,7 +903,18 @@ fn traits_implemented_by<'a>(
ty
);
// Fast path: if this is a primitive simple `==` will work
let saw_impl = impl_type == ty;
// NOTE: the `match` is necessary; see #92662.
// this allows us to ignore generics because the user input
// may not include the generic placeholders
// e.g. this allows us to match Foo (user comment) with Foo<T> (actual type)
let saw_impl = impl_type == ty
|| match (impl_type.kind(), ty.kind()) {
(ty::Adt(impl_def, _), ty::Adt(ty_def, _)) => {
debug!("impl def_id: {:?}, ty def_id: {:?}", impl_def.did, ty_def.did);
impl_def.did == ty_def.did
}
_ => false,
};
if saw_impl { Some(trait_) } else { None }
})

View file

@ -0,0 +1,19 @@
#![deny(rustdoc::broken_intra_doc_links)]
// Test intra-doc links on trait implementations with generics
use std::marker::PhantomData;
pub trait Bar<T> {
fn bar(&self);
}
pub struct Foo<U>(PhantomData<U>);
impl<T, U> Bar<T> for Foo<U> {
fn bar(&self) {}
}
// @has generic_trait_impl/fn.main.html '//a[@href="struct.Foo.html#method.bar"]' 'Foo::bar'
/// link to [`Foo::bar`]
pub fn main() {}