Skip to content

rustdoc: doctests with a manual crate_name attribute cannot run #57317

Closed
@QuietMisdreavus

Description

@QuietMisdreavus
//! ```
//! #![crate_name = "asdf"]
//!
//! println!("yo");
//! ```
$ rustdoc +nightly u.rs --test

running 1 test
test u.rs -  (line 1) ... FAILED

failures:

---- u.rs -  (line 1) stdout ----
thread 'u.rs -  (line 1)' panicked at 'couldn't run the test: No such file or directory (os error 2)', src/librustdoc/test.rs:343:19
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.


failures:
    u.rs -  (line 1)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

Based on investigation in rust-lang/rust-by-example#1137 (comment), rustdoc hardcodes the name of the doctest executable to run, but manually setting a #![crate_name] attribute changes the name of this executable. This causes the above error, because rustdoc is trying to run the wrong executable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-doctestsArea: Documentation tests, run by rustdocC-bugCategory: This is a bug.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions