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

Dev-dependencies are not provided when running cargo rustdoc on benches and examples #9198

Closed
Nemo157 opened this issue Feb 23, 2021 · 2 comments · Fixed by #10341
Closed
Labels

Comments

@Nemo157
Copy link
Member

Nemo157 commented Feb 23, 2021

Steps

Setup:

> cargo new foo && cd foo
     Created binary (application) `foo` package
> cargo add --dev serde
    Updating 'https://github.com/rust-lang/crates.io-index' index
      Adding serde v1.0.123 to dev-dependencies
> mkdir examples
> echo 'use serde; fn main() {}' > examples/bar.rs
> mkdir benches
> echo 'use serde; fn main() {}' > benches/bar.rs

Building works:

> cargo build --bench bar --example bar
   Compiling serde v1.0.123
   Compiling foo v0.1.0 (/tmp/tmp.zlGcSI2CHo/foo)
warning: unused import: `serde`
 --> examples/bar.rs:1:5
  |
1 | use serde; fn main() {}
  |     ^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: unused import: `serde`
 --> benches/bar.rs:1:5
  |
1 | use serde; fn main() {}
  |     ^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: 1 warning emitted

warning: 1 warning emitted

    Finished dev [unoptimized + debuginfo] target(s) in 4.60s

Documenting fails:

> cargo rustdoc --example bar
 Documenting foo v0.1.0 (/tmp/tmp.zlGcSI2CHo/foo)
error[E0432]: unresolved import `serde`
 --> examples/bar.rs:1:5
  |
1 | use serde; fn main() {}
  |     ^^^^^ no external crate `serde`

error: Compilation failed, aborting rustdoc

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0432`.
error: could not document `foo`

Caused by:
  process didn't exit successfully: `rustdoc --edition=2018 --crate-type bin --crate-name bar examples/bar.rs -o /tmp/tmp.zlGcSI2CHo/foo/target/doc --error-format=json --json=diagnostic-rendered-ansi -L dependency=/tmp/tmp.zlGcSI2CHo/foo/target/debug/deps --crate-version 0.1.0` (exit code: 1)


> cargo rustdoc --bench bar
 Documenting foo v0.1.0 (/tmp/tmp.zlGcSI2CHo/foo)
error[E0432]: unresolved import `serde`
 --> benches/bar.rs:1:5
  |
1 | use serde; fn main() {}
  |     ^^^^^ no external crate `serde`

error: Compilation failed, aborting rustdoc

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0432`.
error: could not document `foo`

Caused by:
  process didn't exit successfully: `rustdoc --edition=2018 --crate-type bin --crate-name bar benches/bar.rs -o /tmp/tmp.zlGcSI2CHo/foo/target/doc --error-format=json --json=diagnostic-rendered-ansi -L dependency=/tmp/tmp.zlGcSI2CHo/foo/target/debug/deps --crate-version 0.1.0` (exit code: 1)

Notes

Output of cargo version: cargo 1.50.0-nightly (63d0fe4 2020-12-02)

@Nemo157 Nemo157 added the C-bug Category: bug label Feb 23, 2021
@willcrichton
Copy link
Contributor

This seems to be fixed by including dev-dependencies when generating UnitDeps. willcrichton@b973cce

willcrichton added a commit to willcrichton/cargo that referenced this issue Oct 8, 2021
@daxpedda
Copy link
Contributor

This issue affects the new cargo doc --examples too.

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

Successfully merging a pull request may close this issue.

4 participants