Skip to content

Commit

Permalink
Rollup merge of rust-lang#74452 - Manishearth:module-type-ns, r=jyn514
Browse files Browse the repository at this point in the history
intra-doc links: resolve modules in the type namespace

Fixes rust-lang#62830

Modules actually live in the type namespace, not all three, and it's not possible to clash a type with a module.
  • Loading branch information
Manishearth authored Jul 17, 2020
2 parents ff1c53f + 69dab50 commit c587386
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
23 changes: 8 additions & 15 deletions src/librustdoc/passes/collect_intra_doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
18 changes: 18 additions & 0 deletions src/test/rustdoc/intra-doc-link-mod-ambiguity.rs
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit c587386

Please sign in to comment.