Implement RFC 3503: frontmatters by fee1-dead · Pull Request #140035 · rust-lang/rust (original) (raw)

Discussion (mostly for rustdoc maintainers, and most likely not for this PR): I... I came up with another cursed example. I'm sorry-

Somewhat surprisingly, this works (these are functional rustdoc-ui tests):

//@ check-pass //@ compile-flags: --test --test-args=--test-threads=1 //@ normalize-stdout: "tests/rustdoc-ui" -> "$$DIR" //@ normalize-stdout: "finished in \d+.\d+s" -> "finished in TIME" //@ normalize-stdout: ".rs:\d+:\d+" -> ".rs:$$LINE:$$COL"

/// /// ---hurts_my_head /// --- /// #![feature(frontmatter)] /// fn main() {} /// pub struct ExplicitMain;

But these don't:

Version Test
Implicit main, stmt, inner feature attr //@ check-fail //@ compile-flags: --test --test-args=--test-threads=1 //@ normalize-stdout: "tests/rustdoc-ui" -> "$$DIR" //@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in TIME" //@ normalize-stdout: ".rs:\d+:\d+" -> ".rs:$$LINE:$$COL" // This doesn't work, as one might expect? /// ``` /// ---hurts_my_head /// --- /// #![feature(frontmatter)] /// assert_eq!(1, 1); /// ``` pub struct ImplicitWrapMain;
Implicit main, stmt, outside doctest source crate-level feature attr //@ check-fail //@ compile-flags: --test --test-args=--test-threads=1 //@ normalize-stdout: "tests/rustdoc-ui" -> "$$DIR" //@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in TIME" //@ normalize-stdout: ".rs:\d+:\d+" -> ".rs:$$LINE:$$COL" #![feature(frontmatter)] // This doesn't work either /// ``` /// ---hurts_my_head /// --- /// assert_eq!(1, 1); /// ``` pub struct ImplicitWrapMain;

In the second case, even hoisting the #![feature(frontmatter)] into sources (outside of doctest)
doesn't work, because I want to say it's interpreted as an expression (triple negation...) because
of doctest implicit expr main wrapping behavior? But then the generated doctest binary source file doesn't pass on the frontmatter? Idk

Additionally, I have no idea if 2024 doctest merging behavior can introduce some other obscure edge cases here.

I don't work on rustdoc, but my 2 cents is that we might need to ban frontmatters from doctests.