From fe98de2a8e3941bb33d1149c3717d8ea0744e39c Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Fri, 17 Jul 2020 11:04:31 -0700 Subject: [PATCH 1/2] intra-doc links: Resolve modules in type namespace --- .../passes/collect_intra_doc_links.rs | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index b1db1328392e7..e187b9251f71e 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -584,25 +584,18 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> { let (res, fragment) = { let mut kind = None; let mut disambiguator = None; - path_str = if let Some(prefix) = ["struct@", "enum@", "type@", "trait@", "union@"] - .iter() - .find(|p| link.starts_with(**p)) + path_str = if let Some(prefix) = + ["struct@", "enum@", "type@", "trait@", "union@", "module@", "mod@"] + .iter() + .find(|p| link.starts_with(**p)) { kind = Some(TypeNS); disambiguator = Some(&prefix[..prefix.len() - 1]); link.trim_start_matches(prefix) - } else if let Some(prefix) = [ - "const@", - "static@", - "value@", - "function@", - "mod@", - "fn@", - "module@", - "method@", - ] - .iter() - .find(|p| link.starts_with(**p)) + } else if let Some(prefix) = + ["const@", "static@", "value@", "function@", "fn@", "method@"] + .iter() + .find(|p| link.starts_with(**p)) { kind = Some(ValueNS); disambiguator = Some(&prefix[..prefix.len() - 1]); From 69dab507620aada3085b45ccd0189de3bf8c8734 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Fri, 17 Jul 2020 11:33:49 -0700 Subject: [PATCH 2/2] Add test for module ambiguity --- .../rustdoc/intra-doc-link-mod-ambiguity.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/test/rustdoc/intra-doc-link-mod-ambiguity.rs diff --git a/src/test/rustdoc/intra-doc-link-mod-ambiguity.rs b/src/test/rustdoc/intra-doc-link-mod-ambiguity.rs new file mode 100644 index 0000000000000..65187f48539a4 --- /dev/null +++ b/src/test/rustdoc/intra-doc-link-mod-ambiguity.rs @@ -0,0 +1,18 @@ +// ignore-tidy-linelength + +#![deny(intra_doc_link_resolution_failure)] + + +pub fn foo() { + +} + +pub mod foo {} +// @has intra_doc_link_mod_ambiguity/struct.A.html '//a/@href' '../intra_doc_link_mod_ambiguity/foo/index.html' +/// Module is [`module@foo`] +pub struct A; + + +// @has intra_doc_link_mod_ambiguity/struct.B.html '//a/@href' '../intra_doc_link_mod_ambiguity/fn.foo.html' +/// Function is [`fn@foo`] +pub struct B;