diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 5c28ff0afe0e9..1544fae962cb4 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -939,7 +939,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 (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 } }) diff --git a/src/test/rustdoc/intra-doc/extern-type.rs b/src/test/rustdoc/intra-doc/extern-type.rs index f37ae62dde1aa..ab088ab789d43 100644 --- a/src/test/rustdoc/intra-doc/extern-type.rs +++ b/src/test/rustdoc/intra-doc/extern-type.rs @@ -4,14 +4,34 @@ extern { pub type ExternType; } +pub trait T { + fn test(&self) {} +} + +pub trait G { + fn g(&self, n: N) {} +} + impl ExternType { - pub fn f(&self) { + pub fn f(&self) {} +} - } +impl T for ExternType { + fn test(&self) {} +} + +impl G for ExternType { + fn g(&self, n: usize) {} } // @has 'extern_type/foreigntype.ExternType.html' // @has 'extern_type/fn.links_to_extern_type.html' \ // 'href="foreigntype.ExternType.html#method.f"' +// @has 'extern_type/fn.links_to_extern_type.html' \ +// 'href="foreigntype.ExternType.html#method.test"' +// @has 'extern_type/fn.links_to_extern_type.html' \ +// 'href="foreigntype.ExternType.html#method.g"' /// See also [ExternType::f] +/// See also [ExternType::test] +/// See also [ExternType::g] pub fn links_to_extern_type() {} diff --git a/src/test/rustdoc/intra-doc/generic-trait-impl.rs b/src/test/rustdoc/intra-doc/generic-trait-impl.rs new file mode 100644 index 0000000000000..ba8595abfa959 --- /dev/null +++ b/src/test/rustdoc/intra-doc/generic-trait-impl.rs @@ -0,0 +1,20 @@ +#![deny(rustdoc::broken_intra_doc_links)] + +// Test intra-doc links on trait implementations with generics +// regression test for issue #92662 + +use std::marker::PhantomData; + +pub trait Bar { + fn bar(&self); +} + +pub struct Foo(PhantomData); + +impl Bar for Foo { + 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() {}