Skip to content

perform macro-expansion on doctests before checking for fn main #57415

Open
@QuietMisdreavus

Description

@QuietMisdreavus

As discussed in #57019, i'd like to refactor the doctest parsing/execution code in rustdoc so that it checks for fn main and extern crate during compilation, not before. This allows us to take advantage of macro expansion and a proper parsing step to find multi-line attributes or extern crate statements with the #[macro_use] on a separate line.

I believe it's possible to break up the compilation steps in test::run_test like in core::run_core, except this time we'd stop after phase_2 and inspect the crate for our desired items. If the test doesn't have a fn main or the right extern crate statement, then we can modify the crate in-place (or attempt to splice in the right text in the original text and run compilation again) before continuing. I haven't tried it, but i'd like to sketch it out soon.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-doctestsArea: Documentation tests, run by rustdocA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions