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?
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.