-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected semilocon makes rustdoc to produce false negatives #91014
Labels
A-doctests
Area: Documentation tests, run by rustdoc
C-bug
Category: This is a bug.
T-rustdoc
Relevant to the rustdoc team, which will review and decide on the PR/issue.
Comments
jyn514
added
A-doctests
Area: Documentation tests, run by rustdoc
T-rustdoc
Relevant to the rustdoc team, which will review and decide on the PR/issue.
labels
Nov 18, 2021
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Nov 19, 2021
…-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.
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Nov 19, 2021
…-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.
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Nov 19, 2021
…-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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-doctests
Area: Documentation tests, run by rustdoc
C-bug
Category: This is a bug.
T-rustdoc
Relevant to the rustdoc team, which will review and decide on the PR/issue.
I tried this code:
I expected to see this happen:
Instead, this happened:
Meta
rustc --version --verbose
:Also, reproduces on playground (1.56.1 / 1.57.0-beta.3 / 1.58.0-nightly)
Putting struct def after the
main
function makes rustdoc to behave as expected:Implicit
main
function does the assertion correctly.The text was updated successfully, but these errors were encountered: