Cargo doc doesn't recognise removed dependency

I think I noticed this a while ago, and decided it wasn't important, but I think it's a bug, so thought I would raise it here. If I have some dependency in my cargo.toml, for example

mimalloc = { version = "0.1.26", default-features = false }

and I run cargo doc, as expected mimalloc appears in the list of documented crates. However if I comment the dependency out and re-run cargo doc, mimalloc is not removed from the list of documented crates unless I do a Cargo clean operation first. Is this how it is meant to work?

1 Like

Yes. The index of crates shown is all crates the have ever been documented in that target directory. If you share your target directory between different projects then you get all the different crates mixed together.

This is useful because it means when you cargo doc -p foobar it doesn't remove all the other crates from the index; it simply rebuilds the docs for foobar and updates them in-place, leaving the existing docs for other crates alone.

There's AFAIK currently no support for surgically removing the docs of just one crate, but if there were then cargo clean -p mimalloc could plausibly remove it.

Ok, you are saying it's a feature not a bug.

Fair enough, perhaps, but is this behaviour documented anywhere?

I did read through cargo doc - The Cargo Book and I don't see it described ( but I may have missed it ).

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.