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

cargo doc fails on found duplicate lang item 'panic_impl' dependency issue (no_std) #107918

Closed
tgross35 opened this issue Feb 11, 2023 · 7 comments · Fixed by #108431
Closed

cargo doc fails on found duplicate lang item 'panic_impl' dependency issue (no_std) #107918

tgross35 opened this issue Feb 11, 2023 · 7 comments · Fixed by #108431
Assignees
Labels
C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@tgross35
Copy link
Contributor

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

@tgross35 tgross35 added the C-bug Category: This is a bug. label Feb 11, 2023
@rustbot rustbot added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Feb 11, 2023
@tgross35 tgross35 changed the title cargo doc fails on `found duplicate lang item panic_impl`` dependency issue (no_std`) cargo doc fails on found duplicate lang item 'panic_impl' dependency issue (no_std) Feb 11, 2023
@tgross35
Copy link
Contributor Author

Possibly similar cause: #68427

@tgross35
Copy link
Contributor Author

Seems like this happens even with --no-deps so not really a good workaround, yuck...

@GuillaumeGomez
Copy link
Member

I can't reproduce the bug locally. Do you still have the issue?

@tgross35
Copy link
Contributor Author

Interesting - it looks like it was broken on nightly-2023-01-28 but working on my current rustc 1.69.0-nightly (2d14db321 2023-02-15). Probably not worth bisecting, but maybe a regression test would be good if there isn't one?

% cargo +nightly-2023-01-28 doc   
   Compiling flash-algorithm v0.3.0
 Documenting flash-algorithm v0.3.0
 Documenting testme v0.1.0 (/Users/tmgross/Documents/Projects/testme)
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 /Users/tmgross/Documents/Projects/testme/target/debug/deps/libflash_algorithm-53fc8a5d1bd6046f.rmeta
  = note: second definition in the local crate (`testme`)

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

Caused by:
  process didn't exit successfully: `rustdoc --edition=2021 --crate-type bin --crate-name testme src/main.rs -o /Users/tmgross/Documents/Projects/testme/target/doc --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=181 --document-private-items '-Arustdoc::private-intra-doc-links' -C metadata=179b40203cf7ab78 -L dependency=/Users/tmgross/Documents/Projects/testme/target/debug/deps --extern flash_algorithm=/Users/tmgross/Documents/Projects/testme/target/debug/deps/libflash_algorithm-53fc8a5d1bd6046f.rmeta --crate-version 0.1.0` (exit status: 1)

% cargo doc
 Documenting flash-algorithm v0.3.0
 Documenting testme v0.1.0 (/Users/tmgross/Documents/Projects/testme)
    Finished dev [unoptimized + debuginfo] target(s) in 1.91s

@GuillaumeGomez
Copy link
Member

Agreed, wanna add one? Otherwise I plan to do it in the next hours.

@tgross35
Copy link
Contributor Author

I'm not too familiar with the test patterns for rustdoc, so I'll just leave it to you if you don't mind

@GuillaumeGomez
Copy link
Member

No problem!

@GuillaumeGomez GuillaumeGomez self-assigned this Feb 24, 2023
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Feb 24, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 24, 2023
…-107918, r=notriddle

Add regression test for rust-lang#107918

Fixes rust-lang#107918.

r? `@notriddle`
compiler-errors added a commit to compiler-errors/rust that referenced this issue Feb 25, 2023
…-107918, r=notriddle

Add regression test for rust-lang#107918

Fixes rust-lang#107918.

r? `@notriddle`
compiler-errors added a commit to compiler-errors/rust that referenced this issue Feb 25, 2023
…-107918, r=notriddle

Add regression test for rust-lang#107918

Fixes rust-lang#107918.

r? ``@notriddle``
bors added a commit to rust-lang-ci/rust that referenced this issue Feb 26, 2023
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#107062 (Do some cleanup of doc/index.md)
 - rust-lang#107890 (Lint against `Iterator::map` receiving a callable that returns `()`)
 - rust-lang#108431 (Add regression test for rust-lang#107918)
 - rust-lang#108432 (test: drop unused deps)
 - rust-lang#108436 (make "proc macro panicked" translatable)
 - rust-lang#108444 (docs/test: add UI test and docs for `E0476`)
 - rust-lang#108449 (Do not lint ineffective unstable trait impl for unresolved trait)
 - rust-lang#108456 (Complete migrating `ast_passes` to derive diagnostics)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors closed this as completed in 5196e91 Feb 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants