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

Usage of #![doc(html_root_url)] #185

Closed
jplatte opened this issue Nov 18, 2020 · 12 comments
Closed

Usage of #![doc(html_root_url)] #185

jplatte opened this issue Nov 18, 2020 · 12 comments

Comments

@jplatte
Copy link
Contributor

jplatte commented Nov 18, 2020

@KodrAus @sirwindfield is one of you aware why we have #![doc(html_root_url = "https://docs.rs/env_logger/0.8.1")] at the crate root? I find it a bit annoying to have to bump that when releasing a new version.

@mainrs
Copy link
Contributor

mainrs commented Nov 18, 2020

So that cross crate linking in documentation works.

@jplatte
Copy link
Contributor Author

jplatte commented Nov 18, 2020

How does that work? Can you give an example of where the env_logger docs contain a cross-crate link, or some general docs about #[doc(html_root_url)] w.r.t. cross-crate links on docs.rs?

@mainrs
Copy link
Contributor

mainrs commented Nov 18, 2020

Not sure, I never used it. But it's listed under the API guidelines for Rust: https://rust-lang.github.io/api-guidelines/documentation.html#crate-sets-html_root_url-attribute-c-html-root

I only found this issue: rust-lang/api-guidelines#186

@jplatte
Copy link
Contributor Author

jplatte commented Nov 18, 2020

Okay, so basically a workaround for a docs.rs issue? And even one that we are very unlikely to hit with a lib that's not really meant to be part of other crates' public APIs? @jyn514 can you confirm?

@mainrs
Copy link
Contributor

mainrs commented Nov 18, 2020

To be honest, I don't see any reason to remove it. Who knows who might actually rely on this. Like, some internal documentation for projects might link back to this or so.

It's not a workaround, I think it's the way it's supposed to work. The issue is about having documentation on the style guidelines regarding it in general.

@jplatte
Copy link
Contributor Author

jplatte commented Nov 18, 2020

The reason I'd like to get rid of it is that with it, a release takes longer (even if just a few seconds) and is easier to screw up.

It's not a workaround, I think it's the way it's supposed to work.

This makes no sense to me. There is no information that attribute adds that a tool like docs.rs couldn't theoretically infer.

@jyn514
Copy link

jyn514 commented Nov 18, 2020

I don't like that suggestion on the API guidelines. From the rustdoc documentation:

The #[doc(html_root_url = "…")] attribute value indicates the URL for generating links to external crates. When rustdoc needs to generate a link to an item in an external crate, it will first check if the extern crate has been documented locally on-disk, and if so link directly to it. Failing that, it will use the URL given by the --extern-html-root-url command-line flag if available. If that is not available, then it will use the html_root_url value in the extern crate if it is available. If that is not available, then the extern items will not be linked.

This information has nothing to do with building documentation on docs.rs. This is for when you build locally with doc --no-deps. I agree with @jplatte that it's a workaround, the proper solution would be rust-lang/cargo#8296.

@mainrs
Copy link
Contributor

mainrs commented Nov 18, 2020

My bad then.

@jyn514
Copy link

jyn514 commented Nov 18, 2020

This is for when you build locally with doc --no-deps

To clarify, the scenario where this goes wrong is:

  1. Another downstream crate uses env_logger as a dependency
  2. downstream re-exports or in some other way links to env_logger
  3. A user or developer of downstream builds documentation locally with cargo doc --no-deps (without --extern-html-root-url, because in practice no one but docs.rs does that).

Then the links to env_logger will be broken. But there's a simple fix and the fix is to remove --no-deps.

@jplatte
Copy link
Contributor Author

jplatte commented Nov 18, 2020

Thanks for the clarification!

I don't like that suggestion on the API guidelines.

Do you think it would be worthwhile to try changing this part of the API guidelines?

Either way, I'll remove the attribute from env_logger.

@jplatte jplatte closed this as completed Nov 18, 2020
jplatte added a commit that referenced this issue Nov 18, 2020
See #185 for
justification.
@jyn514
Copy link

jyn514 commented Nov 18, 2020

I only found this issue: rust-lang/api-guidelines#186

That's not really relevant to html_root_url, it's about hand-written links, not the links rustdoc generates automatically.

Do you think it would be worthwhile to try changing this part of the API guidelines?

Sure, I'll look into it.

@mainrs
Copy link
Contributor

mainrs commented Nov 18, 2020

That's not really relevant to html_root_url, it's about hand-written links, not the links rustdoc generates automatically.

I know, should have written it more explicit. I didn't find anything when googling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants