Skip to content

Commit bf46804

Browse files
mdibaieeMark-Simulacrum
authored andcommitted
rustdoc: fix intra-link for generic trait impls
1 parent 9fc25ab commit bf46804

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
@@ -888,7 +888,18 @@ fn traits_implemented_by<'a>(
888888
ty
889889
);
890890
// Fast path: if this is a primitive simple `==` will work
891-
let saw_impl = impl_type == ty;
891+
// NOTE: the `match` is necessary; see #92662.
892+
// this allows us to ignore generics because the user input
893+
// may not include the generic placeholders
894+
// e.g. this allows us to match Foo (user comment) with Foo<T> (actual type)
895+
let saw_impl = impl_type == ty
896+
|| match (impl_type.kind(), ty.kind()) {
897+
(ty::Adt(impl_def, _), ty::Adt(ty_def, _)) => {
898+
debug!("impl def_id: {:?}, ty def_id: {:?}", impl_def.did, ty_def.did);
899+
impl_def.did == ty_def.did
900+
}
901+
_ => false,
902+
};
892903

893904
if saw_impl { Some(trait_) } else { None }
894905
})
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)