Uh oh!
There was an error while loading. Please reload this page.
rustdoc: set the default edition when pre-parsing a doctest - #60065
Conversation
This comment has been minimized.
This comment has been minimized.
QuietMisdreavus
commented
Apr 18, 2019
Turns out, i guessed the wrong failing test. The r? @rust-lang/rustdoc |
This comment has been minimized.
This comment has been minimized.
8961f20 to
186d063Compare
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
We tend to prefer .unwrap_or_else. ;)
There was a problem hiding this comment.
This was existing code that i moved for this PR, but i can fix it.
GuillaumeGomez
commented
Apr 18, 2019
Just a small nit but everything else looks good. r=me once nit fixed and CI passed. |
ollie27
commented
Apr 18, 2019
I don't think that this completely fixes #59313 because rustdoc will still fail while looking for It should output: |
QuietMisdreavus
commented
Apr 19, 2019
@ollie27 That's a valid point. To solve that, i think we'd have to change this line in rust/src/libsyntax/parse/parser.rs Lines 791 to 792 in 22fa4bb That |
ollie27
commented
Apr 19, 2019
How about wrapping the code looking for |
Zoxc
commented
Apr 19, 2019
This PR seems to have quite a lot of overlap with #59742, which may fix the same issue as a side effect. |
QuietMisdreavus
commented
Apr 19, 2019
@Zoxc Oh yeah, you do seem to make a lot of the same changes! I gave your branch a try, and it does make the doctest pass under 2018, but it doesn't solve the issue that @ollie27 mentioned - there is still no output for the failure under 2015. I'd like to fold my work into your PR somehow and have someone check out the (On a side note, it strikes me as odd that we have a |
QuietMisdreavus
commented
May 2, 2019
Looks like the issue @ollie27 mentioned will get fixed by #60220, and @Zoxc's PR does almost the same thing this one does. (This one goes farther in spreading the edition-passing through rustdoc's code itself, so it's not the same, but fixes the same issue in the end.) @Zoxc Should we land this PR so you can use the other rustdoc changes in your PR? |
Zoxc
commented
May 2, 2019
@QuietMisdreavus Don't block on my PR |
estebank
commented
May 2, 2019
@QuietMisdreavus that hard failure is there because we want to avoid spamming the user with errors caused by error recovery, in other words, spurious errors. It should be possible to make this configurable on the |
bors
commented
May 3, 2019
☔ The latest upstream changes (presumably #60510) made this pull request unmergeable. Please resolve the merge conflicts. |
f4bf9af to
76b4900CompareQuietMisdreavus
commented
May 6, 2019
GuillaumeGomez
commented
May 7, 2019
Looks good to me. Just waiting for @ollie27 confirmation. |
Zoxc
commented
May 19, 2019
What is this PR waiting on now? |
ollie27
commented
May 19, 2019
My bad, lets get this in. @bors r+ |
bors
commented
May 19, 2019
📌 Commit 76b4900 has been approved by |
bors
commented
May 19, 2019
rustdoc: set the default edition when pre-parsing a doctest Fixes#59313 (possibly more? i think we've had issues with parsing edition-specific syntax in doctests at some point) When handling a doctest, rustdoc needs to parse it beforehand, so that it can see whether it declares a `fn main` or `extern crate my_crate` explicitly. However, while doing this, rustdoc doesn't set the "default edition" used by the parser like the regular compilation runs do. This caused a problem when parsing a doctest with an `async move` block in it, since it was expecting the `move` keyword to start a closure, not a block. This PR changes the `rustdoc::test::make_test` function to set the parser's default edition while looking for a main function and `extern crate` statement. However, to do this, `make_test` needs to know what edition to set. Since this is also used during the HTML rendering process (to make playground URLs), now the HTML renderer needs to know about the default edition. Upshot: rendering standalone markdown files can now accept a "default edition" for their doctests with the `--edition` flag! (I'm pretty sure i waffled around how to set that a long time ago when we first added the `--edition` flag... `>_>`) I'm posting this before i stop for the night so that i can write this description while it's still in my head, but before this merges i want to make sure that (1) the `rustdoc-ui/failed-doctest-output` test still works (i expect it doesn't), and (2) i add a test with the sample from the linked issue.
bors
commented
May 19, 2019
☀️ Test successful - checks-travis, status-appveyor |
Fixes#59313 (possibly more? i think we've had issues with parsing edition-specific syntax in doctests at some point)
When handling a doctest, rustdoc needs to parse it beforehand, so that it can see whether it declares a
fn mainorextern crate my_crateexplicitly. However, while doing this, rustdoc doesn't set the "default edition" used by the parser like the regular compilation runs do. This caused a problem when parsing a doctest with anasync moveblock in it, since it was expecting themovekeyword to start a closure, not a block.This PR changes the
rustdoc::test::make_testfunction to set the parser's default edition while looking for a main function andextern cratestatement. However, to do this,make_testneeds to know what edition to set. Since this is also used during the HTML rendering process (to make playground URLs), now the HTML renderer needs to know about the default edition. Upshot: rendering standalone markdown files can now accept a "default edition" for their doctests with the--editionflag! (I'm pretty sure i waffled around how to set that a long time ago when we first added the--editionflag...>_>)I'm posting this before i stop for the night so that i can write this description while it's still in my head, but before this merges i want to make sure that (1) the
rustdoc-ui/failed-doctest-outputtest still works (i expect it doesn't), and (2) i add a test with the sample from the linked issue.