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

Nearly all compiler/ doctests are broken #95994

Closed
jyn514 opened this issue Apr 13, 2022 · 10 comments · Fixed by #96094
Closed

Nearly all compiler/ doctests are broken #95994

jyn514 opened this issue Apr 13, 2022 · 10 comments · Fixed by #96094
Assignees
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc C-bug Category: This is a bug. E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jyn514
Copy link
Member

jyn514 commented Apr 13, 2022

test-output.log

I haven't tried --stage 2 but I don't expect it to matter; most of these aren't build errors, they're just because the tests aren't valid syntax.

Found while investigating #95515.

@rustbot label +T-compiler +A-testsuite +C-bug

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 13, 2022
@jyn514
Copy link
Member Author

jyn514 commented Apr 13, 2022

The scary thing to me is how long these have been broken - I guess we never run library tests in CI? I think it might be worth considering adding them.

@Mark-Simulacrum
Copy link
Member

We "should" be running them, but it's relatively easy today for us to accidentally stop running tests. I have a long-term project in mind to track all executed tests (and target info) to give us positive presence (tests passing) indication rather than just negative (tests failing) as we have today. But that's a somewhat involved endeavor that I haven't had the time to invest in yet - probably a few weeks work.

@jyn514
Copy link
Member Author

jyn514 commented Apr 13, 2022

Mentoring instructions: For each test, decide whether it's meant to be a test or just a code comment. Then, add ignore to comments or fix the failing test.

For example, this test is just a comment, because it's not meant to be valid syntax:

    /// Desugar `ExprKind::Try` from: `<expr>?` into:
    /// ```
    /// match Try::branch(<expr>) {
    ///     ControlFlow::Continue(val) => #[allow(unreachable_code)] val,,
    ///     ControlFlow::Break(residual) =>
    ///         #[allow(unreachable_code)]
    ///         // If there is an enclosing `try {...}`:
    ///         break 'catch_target Try::from_residual(residual),
    ///         // Otherwise:
    ///         return Try::from_residual(residual),
    /// }
    /// ```
    fn lower_expr_try(&mut self, span: Span, sub_expr: &Expr) -> hir::ExprKind<'hir> {

but this one can easily be a doctest:

#[derive(Clone, Copy, PartialEq)]
enum IndentStyle {
    /// Vertically aligned under whatever column this block begins at.
    ///
    ///     fn demo(arg1: usize,
    ///             arg2: usize);
    Visual,
}

@rustbot label +E-help-wanted +E-mentor

@rustbot rustbot added E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. labels Apr 13, 2022
@Elliot-Roberts
Copy link
Contributor

Hi I could try to do this.
I understand how to find the failing doctests, but for the second example (code that is in a doc-comment but not a code block) is there any good way to find those? And in that particular case, while it could be a made a doctest, it was probably written just as text because it's the style not the function that is relevant. Is it important to have those converted to doctests in all cases?

@Elliot-Roberts
Copy link
Contributor

@rustbot claim

@jyn514
Copy link
Member Author

jyn514 commented Apr 13, 2022

@Elliot-Roberts it already is a doctest. Rustdoc treats any 4-space indented block as a code block. The problem with it is that the test fails - the fix is simple in this case, just change ; to {}. But in general it might not be clear whether a code block should be fixed or just ignored.

@Elliot-Roberts
Copy link
Contributor

Oh I see, thanks for the explanation. Just noticed it in the list of failing tests haha.
It looks like there are ~280 failing doctests in compiler/

@jyn514
Copy link
Member Author

jyn514 commented Apr 14, 2022

@Elliot-Roberts btw you don't need to fix all of them at once, if you get halfway through and it gets tedious that's still super useful :)

@Elliot-Roberts
Copy link
Contributor

Ok cool. Here's a summary of the different types of failing doctest I've found so far:

  1. Ones intended to fail to compile, which are super easy to fix by just adding compile_fail,[error number] (should I always add the error number?)
  2. Ones that demonstrate rustc internal stuff or unstable features without the necessary #[whatever]. (should I keep those annotations hidden (with # ...)?)
  3. Ones that are pseudo-rust to demonstrate a pattern like your first example. I mark those with ignore (pseudo-rust) instead of text so that we can keep the syntax highlighting.
  4. Ones that are "abbreviated" rust with lots of .. and undeclared types (Foo etc.) to illustrate an idea. In these cases, they likely could be made to run, but it would add clutter such that reading the code without proper rendering to hide lines would be much harder, and possibly reading even with rendering would still be worse. Given that they weren't meant to run in the first place, I'm a bit torn. I've been marking them with ignore (illustrative)
  5. Ones I don't know how to fix (doing fancy type stuff, and also importing things within rustc is confusing me). I've been marking these with ignore HELP and once I start a (maybe draft) PR I'll list their locations and ask you for help.

Please let me know if my described approach to each of those sounds reasonable to you.

@jyn514
Copy link
Member Author

jyn514 commented Apr 15, 2022

That all sounds great! No need to hide the attributes on type 2 tests, I think it's illustrative to show what features they exercise.

For type 5 tests, anything that uses rustc_xxx crates can be ignored, it will be too much of a headache to get bootstrap to give them the proper sysroot with rustc_private available. Happy to help you get the fancy type issues working :)

compiler-errors added a commit to compiler-errors/rust that referenced this issue May 5, 2022
…iler-errors

Begin fixing all the broken doctests in `compiler/`

Begins to fix rust-lang#95994.
All of them pass now but 24 of them I've marked with `ignore HELP (<explanation>)` (asking for help) as I'm unsure how to get them to work / if we should leave them as they are.
There are also a few that I marked `ignore` that could maybe be made to work but seem less important.
Each `ignore` has a rough "reason" for ignoring after it parentheses, with

- `(pseudo-rust)` meaning "mostly rust-like but contains foreign syntax"
- `(illustrative)` a somewhat catchall for either a fragment of rust that doesn't stand on its own (like a lone type), or abbreviated rust with ellipses and undeclared types that would get too cluttered if made compile-worthy.
- `(not-rust)` stuff that isn't rust but benefits from the syntax highlighting, like MIR.
- `(internal)` uses `rustc_*` code which would be difficult to make work with the testing setup.

Those reason notes are a bit inconsistently applied and messy though. If that's important I can go through them again and try a more principled approach. When I run `rg '```ignore \(' .` on the repo, there look to be lots of different conventions other people have used for this sort of thing. I could try unifying them all if that would be helpful.

I'm not sure if there was a better existing way to do this but I wrote my own script to help me run all the doctests and wade through the output. If that would be useful to anyone else, I put it here: https://github.com/Elliot-Roberts/rust_doctest_fixing_tool
compiler-errors added a commit to compiler-errors/rust that referenced this issue May 6, 2022
…iler-errors

Begin fixing all the broken doctests in `compiler/`

Begins to fix rust-lang#95994.
All of them pass now but 24 of them I've marked with `ignore HELP (<explanation>)` (asking for help) as I'm unsure how to get them to work / if we should leave them as they are.
There are also a few that I marked `ignore` that could maybe be made to work but seem less important.
Each `ignore` has a rough "reason" for ignoring after it parentheses, with

- `(pseudo-rust)` meaning "mostly rust-like but contains foreign syntax"
- `(illustrative)` a somewhat catchall for either a fragment of rust that doesn't stand on its own (like a lone type), or abbreviated rust with ellipses and undeclared types that would get too cluttered if made compile-worthy.
- `(not-rust)` stuff that isn't rust but benefits from the syntax highlighting, like MIR.
- `(internal)` uses `rustc_*` code which would be difficult to make work with the testing setup.

Those reason notes are a bit inconsistently applied and messy though. If that's important I can go through them again and try a more principled approach. When I run `rg '```ignore \(' .` on the repo, there look to be lots of different conventions other people have used for this sort of thing. I could try unifying them all if that would be helpful.

I'm not sure if there was a better existing way to do this but I wrote my own script to help me run all the doctests and wade through the output. If that would be useful to anyone else, I put it here: https://github.com/Elliot-Roberts/rust_doctest_fixing_tool
@bors bors closed this as completed in 574830f May 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc C-bug Category: This is a bug. E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants