Skip to content

"the main function must be defined at the crate level" for doc test regression 1.81->1.82 #131893

Closed
@joshka

Description

@joshka

The tokio.rs website tests all the code blocks in markdown files by building up a rust file with code included as doc comments on generated functions. The code is generally wrapped in a function to avoid any main functions being interpreted as a test main function. In 1.81, this worked fine, but 1.82 sees the internal main function and treats it as one which prevents the default test main being created.

Code

I tried this code:

/// ```
/// # fn dox() {
/// fn main() {}
/// # }
/// ```
fn foo() {}

I expected to see this happen: cargo test should succeed

Instead, this happened: cargo test failed

Version it worked on

It most recently worked on: 1.81

rustc --version --verbose:

rustc 1.82.0 (f6e511eec 2024-10-15)
binary: rustc
commit-hash: f6e511eec7342f59a25f7c0534f1dbea00d01b14
commit-date: 2024-10-15
host: aarch64-apple-darwin
release: 1.82.0
LLVM version: 19.1.1

@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged

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.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