You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
intra-doc links: crate means something different when an item is re-exported #77193
changed the title [-]Relative intra-rustdoc links are not resolved when documenting re-exported types[/-][+]Relative intra-rustdoc links are not resolved when documenting re-exported items[/+]on Sep 25, 2020
Ok, I found the issue: rustdoc and resolve disagree about which crate this is in 🤦
Sep 25 13:38:39.133 DEBUG rustdoc::passes::collect_intra_doc_links: resolving with_code as a macro in the module DefId(5:3806 ~ alloc[e7ed]::string[0])
Sep 25 13:38:39.133 DEBUG rustdoc::passes::collect_intra_doc_links: with_code resolved to Err(()) in namespace ValueNS
Sep 25 13:38:39.133 DEBUG rustdoc::passes::collect_intra_doc_links: resolving crate::with_code as a macro in the module DefId(5:3806 ~ alloc[e7ed]::string[0])
Sep 25 13:38:39.133 DEBUG rustdoc::passes::collect_intra_doc_links: crate::with_code resolved to Ok((Path { span: re-export.rs:1:1: 1:1 (#0), segments: [PathSegment { ident: crate#0, id: NodeId(28), args: None }, PathSegment { ident: with_code#0, id: NodeId(29), args: None }], tokens: None }, Def(Fn, DefId(0:4 ~ re_export[8787]::with_code[0])))) in namespace ValueNS
Sep 25 13:38:39.133 DEBUG rustdoc::passes::collect_intra_doc_links: intra-doc link to crate::with_code resolved to Def(Fn, DefId(0:4 ~ re_export[8787]::with_code[0]))
For with_code, rustdoc passes the original module of String, alloc::string, and resolve correctly says there's no item named alloc::string::with_code. But for crate::with_code, resolve thinks that crate refers to the current crate, not to alloc.
This explains a lot of other broken links I've been seeing actually: anything that has crate:: will be wrong. So you were actually correct to start that this was the same issue as #76106 ;)
The fix will be a little tricky ... there's no 'change crate' button for resolve. There are a few things rustdoc can do:
Resolve links in lexical scope: the original docs get resolved in the original module; the new docs get resolved in the module with the re-export. This is the ideal fix but somewhat hard to do because rustdoc doesn't distinguish between the two internally.
A possible way to implement 2. is by stripping crate:: wherever we see it and resolving relative to the crate root instead of the current module. This is slightly hacky but should work fairly reliably.
changed the title [-]Relative intra-rustdoc links are not resolved when documenting re-exported items[/-][+]intra-doc links: `crate` means something different when an item is re-exported[/+]on Sep 25, 2020
Activity
[-]Relative intra-rustdoc links are not resolved when documenting re-exported types[/-][+]Relative intra-rustdoc links are not resolved when documenting re-exported items[/+]jyn514 commentedon Sep 25, 2020
All of this was wrong, I forgot to use +nightly
This isn't related to scopes, rustdoc will also fail to resolve these links:
Something about the re-export itself is messing it up.
jyn514 commentedon Sep 25, 2020
The good news is this is unrelated to proc-macros. Here's what I found:
This is really strange. I would have expected it to resolve relative to
std::string, not relative to the current crate.jyn514 commentedon Sep 25, 2020
Ok, I found the issue: rustdoc and resolve disagree about which crate this is in 🤦
For
with_code, rustdoc passes the original module of String,alloc::string, and resolve correctly says there's no item namedalloc::string::with_code. But forcrate::with_code, resolve thinks thatcraterefers to the current crate, not to alloc.This explains a lot of other broken links I've been seeing actually: anything that has
crate::will be wrong. So you were actually correct to start that this was the same issue as #76106 ;)The fix will be a little tricky ... there's no 'change
crate' button for resolve. There are a few things rustdoc can do:A possible way to implement 2. is by stripping
crate::wherever we see it and resolving relative to the crate root instead of the current module. This is slightly hacky but should work fairly reliably.[-]Relative intra-rustdoc links are not resolved when documenting re-exported items[/-][+]intra-doc links: `crate` means something different when an item is re-exported[/+]jyn514 commentedon Sep 25, 2020
Marking as P-high after discussing with @GuillaumeGomez ; it would be unfortunate to still have this bug on the first release after stabilization.
Rollup merge of rust-lang#77253 - jyn514:crate-link, r=Manishearth
Auto merge of rust-lang#77253 - jyn514:crate-link, r=Manishearth