forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#91026 - notriddle:notriddle/rustdoc-doctest…
…-semicolon, r=jyn514 rustdoc doctest: detect `fn main` after an unexpected semicolon Fixes rust-lang#91014 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 PR changes it to do that.
- Loading branch information
Showing
3 changed files
with
49 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/test/rustdoc-ui/failed-doctest-extra-semicolon-on-item.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// 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 | ||
// normalize-stdout-test: "src/test/rustdoc-ui" -> "$$DIR" | ||
// 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 {} |
24 changes: 24 additions & 0 deletions
24
src/test/rustdoc-ui/failed-doctest-extra-semicolon-on-item.stdout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
running 1 test | ||
test $DIR/failed-doctest-extra-semicolon-on-item.rs - m (line 11) ... FAILED | ||
|
||
failures: | ||
|
||
---- $DIR/failed-doctest-extra-semicolon-on-item.rs - m (line 11) stdout ---- | ||
error: expected item, found `;` | ||
--> $DIR/failed-doctest-extra-semicolon-on-item.rs:12:12 | ||
| | ||
LL | struct S {}; // unexpected semicolon after struct def | ||
| ^ help: remove this semicolon | ||
| | ||
= help: braced struct declarations are not followed by a semicolon | ||
|
||
error: aborting due to previous error | ||
|
||
Couldn't compile the test. | ||
|
||
failures: | ||
$DIR/failed-doctest-extra-semicolon-on-item.rs - m (line 11) | ||
|
||
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME | ||
|