Skip to content

Commit 9ff8ae0

Browse files
committed
rustdoc: fix intra-link for generic trait impls
1 parent 1409c01 commit 9ff8ae0

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,18 @@ fn traits_implemented_by<'a>(
903903
ty
904904
);
905905
// Fast path: if this is a primitive simple `==` will work
906-
let saw_impl = impl_type == ty;
906+
// NOTE: the `match` is necessary; see #92662.
907+
// this allows us to ignore generics because the user input
908+
// may not include the generic placeholders
909+
// e.g. this allows us to match Foo (user comment) with Foo<T> (actual type)
910+
let saw_impl = impl_type == ty
911+
|| match (impl_type.kind(), ty.kind()) {
912+
(ty::Adt(impl_def, _), ty::Adt(ty_def, _)) => {
913+
debug!("impl def_id: {:?}, ty def_id: {:?}", impl_def.did, ty_def.did);
914+
impl_def.did == ty_def.did
915+
}
916+
_ => false,
917+
};
907918

908919
if saw_impl { Some(trait_) } else { None }
909920
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![deny(rustdoc::broken_intra_doc_links)]
2+
3+
// Test intra-doc links on trait implementations with generics
4+
5+
use std::marker::PhantomData;
6+
7+
pub trait Bar<T> {
8+
fn bar(&self);
9+
}
10+
11+
pub struct Foo<U>(PhantomData<U>);
12+
13+
impl<T, U> Bar<T> for Foo<U> {
14+
fn bar(&self) {}
15+
}
16+
17+
// @has generic_trait_impl/fn.main.html '//a[@href="struct.Foo.html#method.bar"]' 'Foo::bar'
18+
/// link to [`Foo::bar`]
19+
pub fn main() {}

0 commit comments

Comments
 (0)