Skip to content

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented May 3, 2025

Alternate title: Ignore "a global default trace dispatcher has already been set" error in Rustdoc

By consecutively initializing tracing and rustc_log, Rustdoc assumes that these involve 2 different tracing crates.

I would like to be able to build rustdoc against the same tracing crate that rustc_log is also built against. Previously this arrangement would crash rustdoc:

thread 'main' panicked at rust/compiler/rustc_log/src/lib.rs:142:65:
called `Result::unwrap()` on an `Err` value: SetGlobalDefaultError("a global default trace dispatcher has already been set")
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::result::unwrap_failed
   3: rustc_log::init_logger
   4: rustc_driver_impl::init_logger
   5: rustdoc::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-rustdoc&template=ice.md

note: please make sure that you have updated to the latest nightly

query stack during panic:
end of query stack

By consecutively initializing `tracing` and `rustc_log`, Rustdoc assumes
that these involve 2 different tracing crates.

I would like to be able to build rustdoc against the same tracing crate
that rustc_log is also built against. Previously this arrangement would
crash rustdoc:

    thread 'main' panicked at rust/compiler/rustc_log/src/lib.rs:142:65:
    called `Result::unwrap()` on an `Err` value: SetGlobalDefaultError("a global default trace dispatcher has already been set")
    stack backtrace:
       0: rust_begin_unwind
       1: core::panicking::panic_fmt
       2: core::result::unwrap_failed
       3: rustc_log::init_logger
       4: rustc_driver_impl::init_logger
       5: rustdoc::main
    note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

    error: the compiler unexpectedly panicked. this is a bug.

    note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-rustdoc&template=ice.md

    note: please make sure that you have updated to the latest nightly

    query stack during panic:
    end of query stack
@rustbot
Copy link
Collaborator

rustbot commented May 3, 2025

r? @GuillaumeGomez

rustbot has assigned @GuillaumeGomez.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels May 3, 2025
@GuillaumeGomez
Copy link
Member

Do you have a regression test by any chance?

@dtolnay
Copy link
Member Author

dtolnay commented May 4, 2025

This is not something Cargo can do. But I invited you to https://github.com/dtolnay/buck2-rustc-bootstrap where it's used.

@GuillaumeGomez
Copy link
Member

It's mostly that we'd have a regression test to prevent this bug from happening again. Nothing that can be tested with run-make tests?

@dtolnay
Copy link
Member Author

dtolnay commented May 4, 2025

It can but would require maintaining a non-Cargo build of librustdoc, which is hundreds to thousands of lines of makefile code because of its big dependency graph. I don't think the cost/benefit justifies that.

@dtolnay
Copy link
Member Author

dtolnay commented May 4, 2025

Even if we move rustdoc's tracing initialization out of librustdoc into a small separate crate and test that together with rustc_log, that still would require a non-Cargo build of all these crates:

autocfg v1.4.0
cfg-if v1.0.0
lazy_static v1.5.0
libc v0.2.172
lock_api v0.4.12
log v0.4.27
matchers v0.1.0
nu-ansi-term v0.50.1
once_cell v1.21.3
overload v0.1.1
parking_lot v0.12.3
parking_lot_core v0.9.10
pin-project-lite v0.2.16
proc-macro2 v1.0.94
quote v1.0.40
regex v1.11.1
regex-automata v0.1.10
regex-automata v0.4.9
regex-syntax v0.6.29
regex-syntax v0.8.5
scopeguard v1.2.0
sharded-slab v0.1.7
smallvec v1.15.0
syn v2.0.100
thread_local v1.1.8
tracing v0.1.37
tracing-attributes v0.1.28
tracing-core v0.1.30
tracing-log v0.2.0
tracing-subscriber v0.3.18
tracing-tree v0.3.1
unicode-ident v1.0.18

And reducing the bug any smaller than that ceases to be useful as a regression test.

@GuillaumeGomez
Copy link
Member

Indeed. It's a shame but not much we can do sadly...

Thanks!

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented May 4, 2025

📌 Commit 00d3fdc has been approved by GuillaumeGomez

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 4, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request May 4, 2025
Rollup of 6 pull requests

Successful merges:

 - rust-lang#137280 (stabilize ptr::swap_nonoverlapping in const)
 - rust-lang#140457 (Use target-cpu=z13 on s390x codegen const vector test)
 - rust-lang#140619 (Small adjustments to `check_attribute_safety` to make the logic more obvious)
 - rust-lang#140625 (Suggest `retain_mut` over `retain` as `Vec::extract_if` alternative)
 - rust-lang#140627 (Allow linking rustc and rustdoc against the same single tracing crate)
 - rust-lang#140630 (Async drop source info fix for proxy-drop-coroutine)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 5b3de49 into rust-lang:master May 5, 2025
6 checks passed
@rustbot rustbot added this to the 1.88.0 milestone May 5, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 5, 2025
Rollup merge of rust-lang#140627 - dtolnay:rustdoctracing, r=GuillaumeGomez

Allow linking rustc and rustdoc against the same single tracing crate

Alternate title: _Ignore "a global default trace dispatcher has already been set" error in Rustdoc_

By consecutively initializing `tracing` and `rustc_log`, Rustdoc assumes that these involve 2 different tracing crates.

I would like to be able to build rustdoc against the same tracing crate that rustc_log is also built against. Previously this arrangement would crash rustdoc:

```console
thread 'main' panicked at rust/compiler/rustc_log/src/lib.rs:142:65:
called `Result::unwrap()` on an `Err` value: SetGlobalDefaultError("a global default trace dispatcher has already been set")
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::result::unwrap_failed
   3: rustc_log::init_logger
   4: rustc_driver_impl::init_logger
   5: rustdoc::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-rustdoc&template=ice.md

note: please make sure that you have updated to the latest nightly

query stack during panic:
end of query stack
```
@dtolnay dtolnay deleted the rustdoctracing branch May 6, 2025 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants