Skip to content

Backport: Merged doctests unused in stable edition 2024 #138418

Open
@notriddle

Description

@notriddle

To do:

What happened

Due to a bug in the implementation, merged doctests did not ship on stable. This is caused by the merged “runner” executable using libtest, so the fallback-to-unmerged behavior kicked in and the promised performance improvement didn’t happen.

Proposed remedy

To backport the fix to a point release, before any code accidentally relies on this behavior.

Possible breakage

Merged doctests work by string concatenating doctests into a wrapper binary that looks roughly like this (except that it uses libtest to report progress, and invokes a separate process for every test case).

mod __test_1 { pub fn main() { … } }
mod __test_2 { pub fn main() { … } }
fn main() { __test_1::main(); __test_2::main(); }

If the merged version fails to compile, we silently and automatically fall back to the old way of running them separately.

However, it is possible to write a doctest that successfully compiles as merged, but fails when run. For example, you can examine the stack trace using std::panic::Location. No automatic fallback happens if a doctest fails at runtime.

When we first developed this feature, we tested it on crater and saw that runtime failures introduced by this change were rare #130285 (the one pattern of failure that we found was caused by tests reading their command-line args, and we fixed that). This is why we consider the potential breakage an acceptable risk.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-releaseRelevant to the release subteam, which will review and decide on the PR/issue.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.regression-untriagedUntriaged performance or correctness regression.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions