Skip to content

doctests: print_merged_doctests_times() crashes JUnit formatter #149436

@ilammy

Description

@ilammy

When unstable --format=junit is used, crates with doctests panic.

Code

/// ```
/// assert_eq!(2 + 2, 4);
/// ```
pub fn foo() {}
cargo test --doc -- -Z unstable-options --format=junit

Meta

rustc --version --verbose:

rustc 1.92.0-nightly (6501e64fc 2025-10-23)
binary: rustc
commit-hash: 6501e64fcb02d22b49d6e59d10a7692ec8095619
commit-date: 2025-10-23
host: aarch64-apple-darwin
release: 1.92.0-nightly
LLVM version: 21.1.3

Error output

thread 'main' (59091947) panicked at library/test/src/formatters/junit.rs:22:9:
assertion failed: !s.contains('\n')
Backtrace

stack backtrace:
   0:        0x1117b9284 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::heca2c53e567951af
   1:        0x10ebfc128 - core::fmt::write::hfd392e77bbd0a117
   2:        0x1117722f4 - std::io::Write::write_fmt::h2e5d5d3b14293b5d
   3:        0x1117844a8 - std::sys::backtrace::BacktraceLock::print::haf2c31c8f0b66728
   4:        0x11178ad2c - std::panicking::default_hook::{{closure}}::hb6a1626dcc9d638e
   5:        0x11178a9cc - std::panicking::default_hook::he558bb5633d06dd3
   6:        0x10f7a6c2c - std[31820d8d119d2b1a]::panicking::update_hook::<alloc[c98364d87502df1f]::boxed::Box<rustc_driver_impl[741f0d247cd92ffe]::install_ice_hook::{closure#1}>>::{closure#0}
   7:        0x11178b254 - std::panicking::panic_with_hook::h9fbd4402ab35bb12
   8:        0x11178aedc - std::panicking::panic_handler::{{closure}}::hdc508ac937b59f80
   9:        0x1117845c0 - std::sys::backtrace::__rust_end_short_backtrace::h1152a0393351b73f
  10:        0x111768a7c - __rustc[4683036c762297f9]::rust_begin_unwind
  11:        0x1144f1d6c - core::panicking::panic_fmt::hd6f40ed356ee47b2
  12:        0x1144f1d4c - core::panicking::panic::h2db8414143ce2846
  13:        0x102e9e5b4 - <test::formatters::junit::JunitFormatter<T> as test::formatters::OutputFormatter>::write_merged_doctests_times::ha74d38c005789c1e
  14:        0x102eb526c - test::print_merged_doctests_times::hdcdf0fdad92fc855
  15:        0x102d665e0 - rustdoc[fc49a747f52601b2]::doctest::run_tests
  16:        0x102d62720 - rustdoc[fc49a747f52601b2]::doctest::run
  17:        0x102ca505c - rustdoc[fc49a747f52601b2]::main_args
  18:        0x102ca0a74 - rustdoc[fc49a747f52601b2]::main
  19:        0x102e86fc4 - std[31820d8d119d2b1a]::sys::backtrace::__rust_begin_short_backtrace::<fn(), ()>
  20:        0x102e86fdc - std[31820d8d119d2b1a]::rt::lang_start::<()>::{closure#0}
  21:        0x1117750fc - std::rt::lang_start_internal::h8bc1be803cf24ab7
  22:        0x102e8703c - _main

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-libtestArea: `#[test]` / the `test` libraryC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions