rustdoc doctest: detect `fn main` after an unexpected semicolon
The basic problem with this is that rustdoc, when hunting for `fn main`, will stop
parsing after it reaches a fatal error. This unexpected semicolon was a fatal error,
so in `src/test/rustdoc-ui/failed-doctest-extra-semicolon-on-item.rs`, it would wrap
the doctest in an implied main function, turning it into this:
fn main() {
struct S {};
fn main() {
assert_eq!(0, 1);
}
}
This, as it turns out, is totally valid, and it executes no assertions, so *it passes,*
even though the user wanted it to execute the assertion.
The Rust parser already has the ability to recover from these unexpected semicolons,
but to do so, it needs to use the `parse_mod` function, so this commit changes it to do that.
2021-11-18 17:15:12 -06:00
|
|
|
// FIXME: if/when the output of the test harness can be tested on its own, this test should be
|
|
|
|
// adapted to use that, and that normalize line can go away
|
|
|
|
|
|
|
|
// compile-flags:--test
|
2023-04-29 04:08:33 -05:00
|
|
|
// normalize-stdout-test: "tests/rustdoc-ui/doctest" -> "$$DIR"
|
rustdoc doctest: detect `fn main` after an unexpected semicolon
The basic problem with this is that rustdoc, when hunting for `fn main`, will stop
parsing after it reaches a fatal error. This unexpected semicolon was a fatal error,
so in `src/test/rustdoc-ui/failed-doctest-extra-semicolon-on-item.rs`, it would wrap
the doctest in an implied main function, turning it into this:
fn main() {
struct S {};
fn main() {
assert_eq!(0, 1);
}
}
This, as it turns out, is totally valid, and it executes no assertions, so *it passes,*
even though the user wanted it to execute the assertion.
The Rust parser already has the ability to recover from these unexpected semicolons,
but to do so, it needs to use the `parse_mod` function, so this commit changes it to do that.
2021-11-18 17:15:12 -06:00
|
|
|
// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
|
|
|
|
// failure-status: 101
|
|
|
|
|
|
|
|
/// <https://github.com/rust-lang/rust/issues/91014>
|
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// struct S {}; // unexpected semicolon after struct def
|
|
|
|
///
|
|
|
|
/// fn main() {
|
|
|
|
/// assert_eq!(0, 1);
|
|
|
|
/// }
|
|
|
|
/// ```
|
|
|
|
mod m {}
|