Skip to content

rustdoc exits with an error on crate-level #![doc(hidden)] #109695

@jotare

Description

@jotare

Problem

Hi, I found a possible bug (or at least, bad error message) while generating documentation for a library with #![doc(hidden)]. The use case is a library with private documentation published to crates.io. The docs page is generated and failing. In the docs page you see all broken but no documentation is intended.

(It's a third party crate so I don't have decision on having no documentation)

The error thrown by cargo doc is somewhat obscure, as hiding docs is intentional:

error: couldn't generate documentation: No such file or directory (os error 2)
  |
  = note: failed to create or modify "/home/.../hidden-docs-bug/target/doc/hidden_docs_bug/all.html"

error: could not document `hidden-docs-bug`

Caused by:
  process didn't exit successfully: `rustdoc --edition=2021 --crate-type lib --crate-name hidden_docs_bug src/lib.rs -o /home/.../hidden-docs-bug/target/doc --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=105 -C metadata=5b17bc2b2d87366d -L dependency=/home/.../hidden-docs-bug/target/debug/deps --crate-version 0.1.0` (exit status: 1)

(Full paths have been trimmed)

I'd expect docs to be generated and either an empty docs page or with a simple message indicating this crate has no/hidden docs.

Steps

  1. Create a new cargo project:
cargo init hidden-docs-bug
  1. Open src/lib.rs and add a #![doc(hidden)] in the beginning of the file.
  2. Generate docs using cargo doc.

Possible Solution(s)

I'd expect something like either generating an empty docs page or with a simple message indicating docs are hidden for this crate.

Notes

No response

Version

cargo 1.68.0 (115f34552 2023-02-26)
release: 1.68.0
commit-hash: 115f34552518a2f9b96d740192addbac1271e7e6
commit-date: 2023-02-26
host: x86_64-unknown-linux-gnu
libgit2: 1.5.0 (sys:0.16.0 vendored)
libcurl: 7.86.0-DEV (sys:0.4.59+curl-7.86.0 vendored ssl:OpenSSL/1.1.1q)
os: Ubuntu 22.04 (jammy) [64-bit]

Activity

transferred this issue fromrust-lang/cargoon Mar 28, 2023
ehuss

ehuss commented on Mar 28, 2023

@ehuss
Contributor

Thanks for the report! This appears to be an issue with rustdoc, and its issue tracker lives here.

added
T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
on Mar 28, 2023
jyn514

jyn514 commented on Mar 28, 2023

@jyn514
Member

Putting doc(hidden) on the entire crate is ... a very strange decision. I am not sure what the semantics of that should be.

The use case is a library with private documentation published to crates.io.

What does this mean? docs.rs intentionally does not have an opt-out mechanism: rust-lang/docs.rs#125

changed the title [-]Library with hidden docs fails on generating them[/-] [+]rustdoc exits with an error on crate-level `!#[doc(hidden)]`[/+] on Mar 28, 2023
changed the title [-]rustdoc exits with an error on crate-level `!#[doc(hidden)]`[/-] [+]rustdoc exits with an error on crate-level `#![doc(hidden)]`[/+] on Mar 28, 2023
jotare

jotare commented on Mar 28, 2023

@jotare
Author

Thanks for the quick reply!

Putting doc(hidden) on the entire crate is ... a very strange decision. I am not sure what the semantics of that should be.

Yes, I also think so. In my opinion, an empty docs page (or something similar) or a better error, both might have sense

What does this mean? docs.rs intentionally does not have an opt-out mechanism: rust-lang/docs.rs#125

I first opened an issue to this crate, so I link to it so you can have more context: taiki-e/cargo-llvm-cov#248

GuillaumeGomez

GuillaumeGomez commented on Mar 29, 2023

@GuillaumeGomez
Member

I personally think it's an acceptable behaviour. It'll just create an empty documentation and that's it. Seems like a weird use case indeed though.

I opened #109726 which fixes the rustdoc crash in the meantime (which therefore generates empty documentation).

added a commit that references this issue on Mar 29, 2023
02cb4da
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-needs-decisionIssue: In need of a decision.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ehuss@GuillaumeGomez@jyn514@jotare

        Issue actions

          rustdoc exits with an error on crate-level `#![doc(hidden)]` · Issue #109695 · rust-lang/rust