Skip to content

Commit e0c04b6

Browse files
authored
Rollup merge of rust-lang#92792 - mdibaiee:92662/fix-intra-doc-generics, r=camelid
rustdoc: fix intra-link for generic trait impls fixes rust-lang#92662 r? `@camelid`
2 parents f7e7dbb + ae20500 commit e0c04b6

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,18 @@ fn traits_implemented_by<'a>(
939939
ty
940940
);
941941
// Fast path: if this is a primitive simple `==` will work
942-
let saw_impl = impl_type == ty;
942+
// NOTE: the `match` is necessary; see #92662.
943+
// this allows us to ignore generics because the user input
944+
// may not include the generic placeholders
945+
// e.g. this allows us to match Foo (user comment) with Foo<T> (actual type)
946+
let saw_impl = impl_type == ty
947+
|| match (impl_type.kind(), ty.kind()) {
948+
(ty::Adt(impl_def, _), ty::Adt(ty_def, _)) => {
949+
debug!("impl def_id: {:?}, ty def_id: {:?}", impl_def.did, ty_def.did);
950+
impl_def.did == ty_def.did
951+
}
952+
_ => false,
953+
};
943954

944955
if saw_impl { Some(trait_) } else { None }
945956
})

src/test/rustdoc/intra-doc/extern-type.rs

+22-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,34 @@ extern {
44
pub type ExternType;
55
}
66

7+
pub trait T {
8+
fn test(&self) {}
9+
}
10+
11+
pub trait G<N> {
12+
fn g(&self, n: N) {}
13+
}
14+
715
impl ExternType {
8-
pub fn f(&self) {
16+
pub fn f(&self) {}
17+
}
918

10-
}
19+
impl T for ExternType {
20+
fn test(&self) {}
21+
}
22+
23+
impl G<usize> for ExternType {
24+
fn g(&self, n: usize) {}
1125
}
1226

1327
// @has 'extern_type/foreigntype.ExternType.html'
1428
// @has 'extern_type/fn.links_to_extern_type.html' \
1529
// 'href="foreigntype.ExternType.html#method.f"'
30+
// @has 'extern_type/fn.links_to_extern_type.html' \
31+
// 'href="foreigntype.ExternType.html#method.test"'
32+
// @has 'extern_type/fn.links_to_extern_type.html' \
33+
// 'href="foreigntype.ExternType.html#method.g"'
1634
/// See also [ExternType::f]
35+
/// See also [ExternType::test]
36+
/// See also [ExternType::g]
1737
pub fn links_to_extern_type() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![deny(rustdoc::broken_intra_doc_links)]
2+
3+
// Test intra-doc links on trait implementations with generics
4+
// regression test for issue #92662
5+
6+
use std::marker::PhantomData;
7+
8+
pub trait Bar<T> {
9+
fn bar(&self);
10+
}
11+
12+
pub struct Foo<U>(PhantomData<U>);
13+
14+
impl<T, U> Bar<T> for Foo<U> {
15+
fn bar(&self) {}
16+
}
17+
18+
// @has generic_trait_impl/fn.main.html '//a[@href="struct.Foo.html#method.bar"]' 'Foo::bar'
19+
/// link to [`Foo::bar`]
20+
pub fn main() {}

0 commit comments

Comments
 (0)