Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional docs on pub re-exports resolve intra-doc links relative to the original module #77254

Closed
jyn514 opened this issue Sep 27, 2020 · 9 comments · Fixed by #77519
Closed
Labels
A-cross-crate-reexports Area: Documentation that has been re-exported from a different crate A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@jyn514
Copy link
Member

jyn514 commented Sep 27, 2020

I tried this code:

/// I want to show [with_code]
pub use std::string::String;

pub fn with_code() {}

I expected to see this happen: Rustdoc links all the original documentation relative to std::string, and all the new documentation relative to the current crate, so with_code resolves properly.

Instead, this happened: Rustdoc links all the original documentation relative to std::string:

Sep 26 22:41:10.388  INFO rustdoc::passes::collect_intra_doc_links: ignoring warning from parent crate: unresolved link to `with_code`

This hits proc-macros especially hard because they're forced to be in a separate crate and can't link to anything in the main crate.

Meta

rustdoc --version: rustdoc 1.48.0-nightly (f68e089 2020-09-19), but also present on master (1ec980d)

@jyn514 jyn514 added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. C-bug Category: This is a bug. A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name labels Sep 27, 2020
@jyn514 jyn514 added the A-cross-crate-reexports Area: Documentation that has been re-exported from a different crate label Sep 27, 2020
@jyn514
Copy link
Member Author

jyn514 commented Sep 27, 2020

Originally I thought this would need pulldown support, but I might be able to hack it by using the span of the BrokenLink pulldown returns.

@jyn514
Copy link
Member Author

jyn514 commented Sep 27, 2020

I'm not sure it's possible to go from a Span to the module it's defined in :/

@jyn514
Copy link
Member Author

jyn514 commented Sep 27, 2020

Another possible approach is to use the DefId of the use statement itself, but that requires fixing #77230 first.

jyn514 added a commit to jyn514/rust that referenced this issue Sep 27, 2020
@jyn514
Copy link
Member Author

jyn514 commented Sep 27, 2020

Originally I thought this would need pulldown support, but I might be able to hack it by using the span of the BrokenLink pulldown returns.

It turns out pulldown already has this support in the form of into_offset_iter.

@jyn514
Copy link
Member Author

jyn514 commented Oct 4, 2020

So I don't forget, this is my current progress:

  • Refactor DocFragments; this was simple and necessary to add the HirId for the docs (Change DocFragments from enum variant fields to structs with a nested enum #77513)
  • Require a HirId for try_inline. This was not too painful but not very useful in itself. It does not currently handle multiple re-exports, I just have an unimplemented!() (not published).
  • Take an optional HirId in merge_attrs. This is necessary but not sufficient for keeping track of the HirId for the attrs.
  • Take an optional HirId in Attributes::from_ast; again, necessary but not sufficient.

The issue I currently have is that attributes are combined before calling from_ast, and I'm not sure how to work merging attrs into from_ast. Maybe it could take attrs: &[ast::Attribute] and other_attrs: &[...], plus a HirId for both? That seems not too painful; I'll need to slightly refactor from_ast to allow doing the same inner actions for two different lists. I have no idea how to generalize this to arbitrary re-exports - maybe Vec<(&[ast::Attribute], HirId)>?

@jyn514
Copy link
Member Author

jyn514 commented Oct 4, 2020

The painful thing is going to be working this into impl Clean<Attributes> for [ast::Attribute] - Clean doesn't allow taking any additional parameters and turning it into a free function instead causes about 30 non-trivial errors.

@jyn514
Copy link
Member Author

jyn514 commented Oct 4, 2020

Actually this might work - the original HirId will always correspond to the DefId, so it can just be none. Then any following attributes will make the HirId mandatory. 🤞

@jyn514
Copy link
Member Author

jyn514 commented Oct 4, 2020

A new problem: collapse_docs turns all attributes into one giant attribute 🤦 @GuillaumeGomez do you know what that's for? Is it safe to just get rid of it and insert newlines between docs instead?

@GuillaumeGomez
Copy link
Member

I think it's to merge both #[doc = "..."] and /// attributes.

@bors bors closed this as completed in 9ba1d21 Oct 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cross-crate-reexports Area: Documentation that has been re-exported from a different crate A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants