Skip to content
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

rustdoc doctest: detect fn main after an unexpected semicolon #91026

Merged

Commits on Nov 18, 2021

  1. 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.
    notriddle committed Nov 18, 2021
    Configuration menu
    Copy the full SHA
    214ad2f View commit details
    Browse the repository at this point in the history