Skip to content

rustdoc only: duplicate lang item panic_halt #68427

Description

@TimNN

This is a regression from rustdoc 1.40.0 (73528e339 2019-12-16) to rustdoc 1.41.0-beta.3 (fb3056216 2020-01-19).

If rustdoc attempts to document a crate that has at least two dependencies which implement a panic_handler, it fails with an error similar to

error: duplicate lang item in crate `panic_halt` (which `panic2` depends on): `panic_impl`.
  |
  = note: first defined in crate `std` (which `panic2` depends on).

Note that the crate builds fine, it's just documenting that is broken.


Steps to reproduce

  1. Create a new project, e.g. cargo new panic2
  2. Add a dependency on panic-halt = "0.2.0", e.g. cargo add panic-halt
  3. Attempt to document the crate, e.g. cargo doc
An example of the different behavior between `stable`/`beta` and `build`/`doc`.
$ cargo +stable clean

$ cargo +beta clean

$ cargo +stable build
   Compiling panic-halt v0.2.0
   Compiling panic2 v0.1.0 (/Users/logic/Projects/tmp/panic2)
    Finished dev [unoptimized + debuginfo] target(s) in 0.35s

$ cargo +stable doc
 Documenting panic-halt v0.2.0
    Checking panic-halt v0.2.0
 Documenting panic2 v0.1.0 (/Users/logic/Projects/tmp/panic2)
    Finished dev [unoptimized + debuginfo] target(s) in 1.40s

$ cargo +beta build
   Compiling panic-halt v0.2.0
   Compiling panic2 v0.1.0 (/Users/logic/Projects/tmp/panic2)
    Finished dev [unoptimized + debuginfo] target(s) in 0.27s

$ cargo +beta doc
 Documenting panic-halt v0.2.0
    Checking panic-halt v0.2.0
 Documenting panic2 v0.1.0 (/Users/logic/Projects/tmp/panic2)
error: duplicate lang item in crate `panic_halt` (which `panic2` depends on): `panic_impl`.
  |
  = note: first defined in crate `std` (which `panic2` depends on).

error: aborting due to previous error

error: Could not document `panic2`.

Caused by:
  process didn't exit successfully: `rustdoc --edition=2018 --crate-type bin --crate-name panic2 src/main.rs -o /Users/logic/Projects/tmp/panic2/target/doc --error-format=json --json=diagnostic-rendered-ansi --document-private-items -L dependency=/Users/logic/Projects/tmp/panic2/target/debug/deps --extern panic_halt=/Users/logic/Projects/tmp/panic2/target/debug/deps/libpanic_halt-6d0ca720c3c355fb.rmeta` (exit code: 1)

Activity

  1. added
    T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
    on Jan 21, 2020
  2. Mark-Simulacrum commented on Jan 21, 2020

    @Mark-Simulacrum
    Member

    cc @rust-lang/rustdoc

  3. GuillaumeGomez commented on Jan 21, 2020

    @GuillaumeGomez
    Member

    I'll try to take a look in the next days.

  4. emilyalbini commented on Jan 24, 2020

    @emilyalbini
    Member

    Note that the stable release will be prepared on monday, so the patch should be merged by then.

  5. ollie27 commented on Jan 24, 2020

    @ollie27
    Contributor

    It looks like this was triggered by #66211 (cc. @kinnison). rustdoc now seems to load all crates passed by --extern even if they're unused in the code whereas rustc just ignores them. Adding extern crate panic_halt; or use panic_halt; to panic2 causes stable rustdoc and rustc to produce the same error message.

    Is this issue affecting any real world code? It seems weird to list a dependency on panic-halt but not actually use it.

    #66211 was to fix an ICE using the intra-doc-links feature but that's only available on nightly so it should be safe to revert #66211 on beta for now if needed.

  6. TimNN commented on Jan 24, 2020

    @TimNN
    ContributorAuthor

    I guess it is unlikely that this will be triggered in many real world scenarios. I came across this problem because I was experimenting with embedded programming: I had multiple panic implementations in the dependencies and then multiple binaries which were using different panic implementations (to see their different behaviors).

  7. kinnison commented on Jan 25, 2020

    @kinnison
    Contributor

    If there's a way to get the metadata into rustdoc without fully loading the --extern crates then that'd satisfy rustdoc's usecase without causing this. I do not object to backing this out of beta so long as there's some idea of how we'd fix it without entirely backing it out and reintroducing the ICE. @GuillaumeGomez how do you feel about that?

  8. GuillaumeGomez commented on Jan 25, 2020

    @GuillaumeGomez
    Member

    We can revert it on the beta to prevent the crash but we definitely need a way to get the metadata from the crates.

  9. GuillaumeGomez commented on Jan 25, 2020

    @GuillaumeGomez
    Member

    So after a discussion with @eddyb, it appears that @petrochenkov is one of the last person working on this part.

    cc @petrochenkov (at @eddyb's suggestion)

  10. petrochenkov commented on Jan 26, 2020

    @petrochenkov
    Contributor

    If you don't want to resolve all crates passed with --extern (with which I agree), then resolve paths in intra-doc links, the crates will be used on demand then.

    All the paths need to be resolved before the Resolver data is frozen (to_resolver_outputs is called), so rustdoc should organize its passes accordingly.

  11. petrochenkov commented on Jan 26, 2020

    @petrochenkov
    Contributor

    In other words, if you remove Resolver::clone_outputs while keeping rustdoc working, it will fix this issue and some other issues as well.

  12. 7 remaining items

  13. jyn514 commented on Aug 14, 2020

    @jyn514
    Member

    Instead of Resolver having its own copy of cstore, is it possible to pass one in and have Resolver use that instead? I think TyCtxt::cstore() might come from the resolver in the first place so maybe it should be a public field or something so that having a cstore on hand is optional.

  14. jyn514 commented on Aug 14, 2020

    @jyn514
    Member

    Another idea is to store the resolver in the TyCtxt itself so that it never has to be cloned in the first place: #75176 (comment)

  15. petrochenkov commented on Aug 14, 2020

    @petrochenkov
    Contributor

    I already mentioned my preferred solution:

    So, rustdoc should work similarly to rustc and organize its passes in such a way that they perform name resolution early.

    + eddyb's comment - #68427 (comment)

  16. added
    A-intra-doc-linksArea: Intra-doc links, the ability to link to items in docs by name
    A-resolveArea: Name/path resolution done by `rustc_resolve` specifically
    on Dec 12, 2020
  17. added 2 commits that reference this issue on Apr 2, 2021
  18. added a commit that references this issue on Apr 3, 2021
  19. added a commit that references this issue on Jul 2, 2021
  20. jyn514 commented on Jul 4, 2021

    @jyn514
    Member

    #83738 was reverted in #85749.

  21. reopened this on Jul 4, 2021
  22. added a commit that references this issue on Aug 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-intra-doc-linksArea: Intra-doc links, the ability to link to items in docs by nameA-lang-itemArea: Language itemsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-bugCategory: This is a bug.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions