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 16:15:12 -07:00
|
|
|
|
|
|
|
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
|
2024-07-06 03:07:46 +00:00
|
|
|
| ^
|
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 16:15:12 -07:00
|
|
|
|
|
|
|
|
= help: braced struct declarations are not followed by a semicolon
|
2024-07-06 03:07:46 +00:00
|
|
|
help: remove this semicolon
|
|
|
|
|
|
|
|
|
LL - struct S {}; // unexpected semicolon after struct def
|
|
|
|
LL + struct S {} // unexpected semicolon after struct def
|
|
|
|
|
|
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 16:15:12 -07:00
|
|
|
|
2023-11-21 16:44:51 +00:00
|
|
|
error: aborting due to 1 previous error
|
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 16:15:12 -07:00
|
|
|
|
|
|
|
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
|
|
|
|
|