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

Index out of bounds panic in cargo doc --open when building crate with no documentation #10194

Closed
5225225 opened this issue Dec 12, 2021 · 2 comments · Fixed by #10204
Closed
Assignees
Labels
C-bug Category: bug Command-doc E-easy Experience: Easy

Comments

@5225225
Copy link
Contributor

5225225 commented Dec 12, 2021

Problem

cargo doc --open panics when ran in a crate without any crates with documentation.

thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', src/tools/cargo/src/cargo/ops/cargo_doc.rs:23:21
stack backtrace:
   0: rust_begin_unwind
             at /rustc/928783de663bd855a96f14b2d38c1061603587c6/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/928783de663bd855a96f14b2d38c1061603587c6/library/core/src/panicking.rs:107:14
   2: core::panicking::panic_bounds_check
             at /rustc/928783de663bd855a96f14b2d38c1061603587c6/library/core/src/panicking.rs:75:5
   3: cargo::ops::cargo_doc::doc
   4: cargo::commands::doc::exec
   5: cargo::cli::execute_subcommand
   6: cargo::cli::main
   7: cargo::main

Steps

  1. Make a crate with cargo init --lib
  2. Add the following to the Cargo.toml
[lib]
doc = false
  1. Run cargo doc --open

Possible Solution(s)

Cargo doc should print an error about not having any crates with documentation

Notes

It also errors with a crate with a binary with no docs, but I assume fixing one will fix the other.

Version

cargo 1.58.0-nightly (40dc28175 2021-12-06)
release: 1.58.0
commit-hash: 40dc281755137ee804bc9b3b08e782773b726e44
commit-date: 2021-12-06
host: x86_64-unknown-linux-gnu
libgit2: 1.3.0 (sys:0.13.23 vendored)
libcurl: 7.80.0-DEV (sys:0.4.51+curl-7.80.0 vendored ssl:OpenSSL/1.1.1l)
os: Arch Linux Rolling Release [64-bit]
@5225225 5225225 added the C-bug Category: bug label Dec 12, 2021
@ehuss ehuss added Command-doc E-easy Experience: Easy labels Dec 12, 2021
@Eh2406
Copy link
Contributor

Eh2406 commented Dec 12, 2021

Indeed https://github.com/rust-lang/cargo/blob/master/src/cargo/ops/cargo_doc.rs#L23 should probably be a get that converts None to an error message.

@Rustin170506
Copy link
Member

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug Command-doc E-easy Experience: Easy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants