-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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: set the default edition when pre-parsing a doctest #60065
Conversation
This comment has been minimized.
This comment has been minimized.
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
186d063
Compare
This comment has been minimized.
This comment has been minimized.
src/librustdoc/config.rs
Outdated
@@ -383,27 +383,28 @@ impl Options { | |||
} | |||
} | |||
|
|||
let edition = matches.opt_str("edition").unwrap_or("2015".to_string()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We tend to prefer .unwrap_or_else
. ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was existing code that i moved for this PR, but i can fix it.
Just a small nit but everything else looks good. r=me once nit fixed and CI passed. |
I don't think that this completely fixes #59313 because rustdoc will still fail while looking for
It should output:
|
@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 |
How about wrapping the code looking for |
This PR seems to have quite a lot of overlap with #59742, which may fix the same issue as a side effect. |
@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 |
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? |
@QuietMisdreavus Don't block on my PR |
@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 |
☔ The latest upstream changes (presumably #60510) made this pull request unmergeable. Please resolve the merge conflicts. |
f4bf9af
to
76b4900
Compare
Looks good to me. Just waiting for @ollie27 confirmation. |
What is this PR waiting on now? |
My bad, lets get this in. @bors r+ |
📌 Commit 76b4900 has been approved by |
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.
☀️ 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 main
orextern 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 anasync move
block in it, since it was expecting themove
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 andextern 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.