Skip to content

Rustdoc creates doctests with extern crate mod; #79771

Closed
@Swatinem

Description

@Swatinem

In #79770 I tried to create a new rustdoc-ui testcase that runs doctests. However having the mod substring in a doctest comment injected an invalid extern crate mod; into the code generated for the doctest.

Turns out this here is a bit too aggressive:

if s.contains(cratename) {
prog.push_str(&format!("extern crate {};\n", cratename));

It looks like compiletest actually gave the crate the name mod, perhaps because it was defined in a issue-XXX/mod.rs file, and having a doctest such as this triggers the this auto-injection, resulting in a failed doctest run:

/// ```
/// // ^ mod.rs line 10
/// assert_eq!(1, 1);
/// ```

Metadata

Metadata

Assignees

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