rustdoc: fix intra-link for generic trait impls
This commit is contained in:
parent
1409c015b4
commit
9ff8ae097e
2 changed files with 31 additions and 1 deletions
|
@ -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 }
|
||||
})
|
||||
|
|
19
src/test/rustdoc/intra-doc/generic-trait-impl.rs
Normal file
19
src/test/rustdoc/intra-doc/generic-trait-impl.rs
Normal 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() {}
|
Loading…
Add table
Add a link
Reference in a new issue