Closed
Description
It seems like cargo doc
fails is there is a dependency that has a panic_impl
and a binary that defines it as well, even if the dependency is never imported.
I ran into this issue when I had >1 no_std bin per crate, where one binary had a custom panic_impl and another used that from a dependency. Minimal reproduction:
crate1 % tree
.
├── Cargo.lock
├── Cargo.toml
└── src
└── main.rs
[package]
name = "crate1"
version = "0.1.0"
edition = "2021"
[dependencies]
# this dependency adds `panic_impl`, but it is never imported or used
flash-algorithm = "0.3.0"
// main.rs
#![no_std]
#![no_main]
#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
loop {}
}
The following works:
cargo c --target thumbv7em-none-eabihf
cargo build --target thumbv7em-none-eabihf
But this fails (also when specifying target)
% cargo doc
Documenting flash-algorithm v0.3.0
Documenting crate1 v0.1.0 (/crate1)
error[E0152]: found duplicate lang item `panic_impl`
--> src/main.rs:5:1
|
5 | fn panic(_: &core::panic::PanicInfo) -> ! {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the lang item is first defined in crate `flash_algorithm`.
= note: first definition in `flash_algorithm` loaded from /crate1/target/debug/deps/libflash_algorithm-53fc8a5d1bd6046f.rmeta
= note: second definition in the local crate (`crate1`)
For more information about this error, try `rustc --explain E0152`.
error: could not document `crate1`
Caused by:
process didn't exit successfully: `rustdoc --edition=2021 --crate-type bin --crate-name crate1 src/main.rs -o /crate1/target/doc --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=147 --document-private-items '-Arustdoc::private-intra-doc-links' -C metadata=90e18e4cce856399 -L dependency=/crate1/target/debug/deps --extern flash_algorithm=/crate1/target/debug/deps/libflash_algorithm-53fc8a5d1bd6046f.rmeta --crate-version 0.1.0` (exit status: 1)
rustc --version --verbose
:
rustc 1.69.0-nightly (1e225413a 2023-01-28)
binary: rustc
commit-hash: 1e225413a21fa69570bd3fefea9eb05e33f8b917
commit-date: 2023-01-28
host: x86_64-apple-darwin
release: 1.69.0-nightly
LLVM version: 15.0.7
@rustbot label +T-rustdoc