Cargo panics when documenting `criterion`

I ran cargo doc -p criterion in my project folder, and got the following:

thread 'main' panicked at src/cargo\core\resolver\
activated_features for invalid package: features did not find PackageId { name: "criterion", version: "0.5.1", source: "registry `crates-io`" } NormalOrDev

Am I doing something wrong, or is this a Cargo bug?

It would be nice if you provided your full setup (ideally, a minimally reproducible example, or at least an example project). But taking a guess, you're using criterion the usual way, i.e. for benchmarks. Benchmark dependencies are not included in the usual set of dependencies, i.e. the [dependencies] section of Cargo.toml. Instead, they are part of [dev-dependencies]. cargo doc doesn't try to document dev-dependencies, since those do not affect the downstream usage of your crate. Thus the error, which basically states, as far as I understand, that criterion isn't in your list of dependencies. I'm surprised cargo doc just dumps an internal panic on you, instead of providing a proper error message. It should warrant a diagnostics issue on their github.

As far as I understand, there is no way to use cargo doc to document dev-dependencies or build-dependencies. But what's the point? For public crates, you can already read the relevant documentation on, while for private crates you should already have a workspace defining the crate itself.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.