Skip to content

doctests: Assertion panic message is escaped and is unreadable terrible on 2024 edition. #137970

Closed
@aDotInTheVoid

Description

@aDotInTheVoid

I tried this code:

//! ```rust
//! assert_eq!(2 + 2, 5);
//! ```

Running the doctests gives a terrible error message:

gh-aDotInTheVoid@dev-desktop-eu-1:~/tmp$ rustdoc +nightly --test ./mcve.rs --edition=2024

running 1 test
test ./mcve.rs - (line 1) ... FAILED

failures:

---- ./mcve.rs - (line 1) stdout ----
Error: "\nthread 'main' panicked at /tmp/rustdoctestKogNj0/doctest_2024.rs:11:1:\nassertion `left == right` failed\n  left: 4\n right: 5\nnote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\n"


failures:
    ./mcve.rs - (line 1)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

It should instead format the assertion error well, like it does on edition=2015

$ rustdoc +nightly --test ./mcve.rs --edition=2015

running 1 test
test ./mcve.rs - (line 1) ... FAILED

failures:

---- ./mcve.rs - (line 1) stdout ----
Test executable failed (exit status: 101).

stderr:

thread 'main' panicked at ./mcve.rs:3:1:
assertion `left == right` failed
  left: 4
 right: 5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace



failures:
    ./mcve.rs - (line 1)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.16s
It works as expected on beta/stable
gh-aDotInTheVoid@dev-desktop-eu-1:~/tmp$ rustdoc +beta --test ./mcve.rs --edition=2015

running 1 test
test ./mcve.rs - (line 1) ... FAILED

failures:

---- ./mcve.rs - (line 1) stdout ----
Test executable failed (exit status: 101).

stderr:

thread 'main' panicked at ./mcve.rs:3:1:
assertion `left == right` failed
  left: 4
 right: 5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace



failures:
    ./mcve.rs - (line 1)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.16s

gh-aDotInTheVoid@dev-desktop-eu-1:~/tmp$ rustdoc +beta --test ./mcve.rs --edition=2024

running 1 test
test ./mcve.rs - (line 1) ... FAILED

failures:

---- ./mcve.rs - (line 1) stdout ----
Test executable failed (exit status: 101).

stderr:

thread 'main' panicked at ./mcve.rs:3:1:
assertion `left == right` failed
  left: 4
 right: 5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace



failures:
    ./mcve.rs - (line 1)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.16s

gh-aDotInTheVoid@dev-desktop-eu-1:~/tmp$ rustdoc +stable --test ./mcve.rs --edition=2015

running 1 test
test ./mcve.rs - (line 1) ... FAILED

failures:

---- ./mcve.rs - (line 1) stdout ----
Test executable failed (exit status: 101).

stderr:

thread 'main' panicked at ./mcve.rs:3:1:
assertion `left == right` failed
  left: 4
 right: 5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace



failures:
    ./mcve.rs - (line 1)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.18s

gh-aDotInTheVoid@dev-desktop-eu-1:~/tmp$ rustdoc +stable --test ./mcve.rs --edition=2024

running 1 test
test ./mcve.rs - (line 1) ... FAILED

failures:

---- ./mcve.rs - (line 1) stdout ----
Test executable failed (exit status: 101).

stderr:

thread 'main' panicked at ./mcve.rs:3:1:
assertion `left == right` failed
  left: 4
 right: 5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace



failures:
    ./mcve.rs - (line 1)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.18s

Possibly releated: https://users.rust-lang.org/t/question-about-doctest-speedup-in-rust-2024-edition/126431 / #137898

CC @notriddle @GuillaumeGomez

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-doctestsArea: Documentation tests, run by rustdocA-edition-2024Area: The 2024 editionA-panicArea: Panicking machineryC-bugCategory: This is a bug.I-edition-triagedIssue: This issue has been reviewed and triaged by the Edition team.P-highHigh priorityT-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

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions