3

I'm making a library in Rust and I've started writing documentation for it. I notice that on e.g. https://doc.rust-lang.org/std/primitive.u128.html, the values of constants such as u128::BITS are hidden, and only pub const BITS: u32 is displayed. However, when I run cargo doc on my computer for my library, the documentation page shows the values of all associated constants for a struct that I have defined. constant documentation image

There are other similar constants which use several lines of code to compute and so look quite ugly like this one. How can I change this so that the value of each constant is hidden?

isaacholt100
  • 388
  • 3
  • 11
  • [On nightly std does show that](https://doc.rust-lang.org/nightly/std/primitive.u128.html) ([and so on beta](https://doc.rust-lang.org/beta/std/primitive.u128.html)). This is strange because the PR to show them was merged back in 2019 AFAICT. – Chayim Friedman Jun 14 '22 at 12:44
  • 1
    [docs.rs](https://docs.rs/rand/latest/rand/struct.Error.html) also doesn't seem to show it. Building documentation locally sometimes behaves different then when it's uploaded to docs.rs. I'd publish an [alpha](https://semver.org/) at some point and then see how the documentation on docs.rs behaves. – Finomnis Jun 14 '22 at 12:45
  • @ChayimFriedman: I suspect it's due to [#95316](https://github.com/rust-lang/rust/pull/95316). There's been some discussion re regression in [#97933](https://github.com/rust-lang/rust/issues/97933). – eggyal Jun 14 '22 at 14:02
  • [@dtolnay's workaround in semver](https://github.com/dtolnay/semver/pull/281/files) may be useful. – eggyal Jun 14 '22 at 14:03
  • @eggyal From just skimming over the issue it sounds like it is only about private fields? So it should not be applicable here. – Chayim Friedman Jun 14 '22 at 21:13

1 Answers1

0

I have now published this library and in the documentation on docs.rs this issue is no longer present, with the values of associated constants being hidden and an underscore displayed instead. So it only appears to be an issue when building documentation locally.

I'm not sure if this is a bug in rustdoc when running locally, or whether it is intentional to display the values of constants in development but hide them in production. However, because obviously the appearance of local documentation isn't so important, this is not really a problem anymore.

isaacholt100
  • 388
  • 3
  • 11