-
Notifications
You must be signed in to change notification settings - Fork 13.8k
[rustdoc] Correctly handle should_panic
doctest attribute and fix --no-run
test flag on the 2024 edition
#143900
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
base: master
Are you sure you want to change the base?
Conversation
This PR modifies cc @jieyouxu |
This comment has been minimized.
This comment has been minimized.
I... do not see anything like that in the patch? There's two checks for exit code 101. |
Woups, copied/pasted comment from original PR which was outdated after discussion with you (on the previous PR). ^^' EDIT: Updated comment. |
if langstr.should_panic {
if out.status.code() == Some(101) {
return Ok(());
} else if out.status.success() {
return Err(TestFailure::UnexpectedRunPass);
}
}
if !out.status.success() {
return Err(TestFailure::ExecutionFailure(out));
} Do you think something like this would make sense, so that it's easier for the user to differentiate between aborts and panic-less success? |
|
Wouldn't changing |
That wouldn't cover |
I've amended my comment a moment before you replied, apologies. |
Replied too fast then. 😅 The message for |
I think we're talking past each other. I suggest that:
Wouldn't that work? |
I still think it's too general. For end users, |
That makes sense, yeah. Let's delay it until after this PR lands then. |
☔ The latest upstream changes (presumably #144692) made this pull request unmergeable. Please resolve the merge conflicts. |
72aadc6
to
248c61c
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
248c61c
to
c365e6e
Compare
This comment has been minimized.
This comment has been minimized.
…Amanieu Make `libtest::ERROR_EXIT_CODE` const public to not redefine it in rustdoc I think it's better to make this constant public so it can be used by crates using `libtest` as dependency. As a side-note, I will update rust-lang#143900 to make use of this constant once this is current PR is merged.
@bors try jobs=x86_64-gnu-aux |
[rustdoc] Correctly handle `should_panic` doctest attribute and fix `--no-run` test flag on the 2024 edition try-job: x86_64-gnu-aux
This comment has been minimized.
This comment has been minimized.
💔 Test for 75572d4 failed: CI. Failed jobs:
|
Ah, this time a |
This comment has been minimized.
This comment has been minimized.
@bors try jobs=x86_64-gnu-aux,test-various |
This comment has been minimized.
This comment has been minimized.
[rustdoc] Correctly handle `should_panic` doctest attribute and fix `--no-run` test flag on the 2024 edition try-job: x86_64-gnu-aux try-job: test-various
This comment has been minimized.
This comment has been minimized.
4e2c43c
to
b70e20a
Compare
This failure definitely illustrates why I should finish writing the lint in case the merged doctests failed compilation... |
@bors try jobs=x86_64-gnu-aux,test-various |
This comment has been minimized.
This comment has been minimized.
[rustdoc] Correctly handle `should_panic` doctest attribute and fix `--no-run` test flag on the 2024 edition try-job: x86_64-gnu-aux try-job: test-various
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.
Some suggestions and questions. As requested, feel free to r=me once they're all addressed in one way or another.
Although, I've got to admit that I feel slightly uneasy about some of these changes or rather the fact that this will ship "insta-stably". Anyhow, it's probably fine.
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.
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.
While your PR is technically only fixing bugs, at least the should_panic
changes are actually breaking changes (rustdoc never performed these checks before) as can be seen by the modifications that you had to do to the standard library.
Because of that I've now added relnotes
, so users will at least kind of get to know what's up when their doctests "break" which will inevitably happen (I still don't know what the stability policies / guarantees are for rustdoc ^^' they seem to be laxer compared to the language ones).
&& (arch.starts_with("wasm") || os == Some("zkvm")) && os != Some("emscripten") | ||
{ | ||
// We cannot correctly handle `should_panic` in some wasm targets so we exit early. | ||
return (duration, Ok(())); |
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.
So this marks them as OK? Wouldn't it be more ideal to mark them as ignored (somehow)? Does that make any sense? I didn't have the time to refamiliarize myself with these parts of the doctest impl.
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.
They are compiled, so it's not ignore
but no_run
instead. And just like libtest
, no_run
are not marked.
// (cfg!(target_family = "wasm") || cfg!(target_os = "zkvm")) | ||
// && !cfg!(target_os = "emscripten") | ||
// ``` | ||
&& let TargetTuple::TargetTuple(ref s) = rustdoc_options.target |
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 both know that this check is super brittle and icky :D We can ignore that for now I guess ^^'
Okay, so I'm not super familiar with target specifications but ideally this would also handle TargetJson
, right? The user may pass --target=custom.json
which may specify the panic_strategy
(IIUC if that's set to Some(Abort | ImmediateAbort)
then that implies that unwinding panics are not supported?) as well as target_family
and so on.
If what I write makes sense, could you at least leave a FIXME that we should somehow support TargetJson
here, too?
Ideally, we would use some preexisting compiler API for querying this (one that provides a richer representation of the target), maybe there is one we could use?
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 both know that this check is super brittle and icky :D We can ignore that for now I guess ^^'
Yes. T_T
Okay, so I'm not super familiar with target specifications but ideally this would also handle
TargetJson
, right? The user may pass--target=custom.json
which may specify thepanic_strategy
(IIUC if that's set toSome(Abort | ImmediateAbort)
then that implies that unwinding panics are not supported?) as well astarget_family
and so on.If what I write makes sense, could you at least leave a FIXME that we should somehow support
TargetJson
here, too?
Yeah you're right, adding a FIXME.
Ideally, we would use some preexisting compiler API for querying this (one that provides a richer representation of the target), maybe there is one we could use?
Hopefully yes. I'll take time to investigate how to make this all clean afterwards. Adding FIXME comments.
src/librustdoc/doctest.rs
Outdated
// `ZX_TASK_RETCODE_EXCEPTION_KILL`. | ||
#[cfg(target_os = "fuchsia")] | ||
Some(ZX_TASK_RETCODE_EXCEPTION_KILL) => {} | ||
_ => return (duration, Err(TestFailure::UnexpectedRunPass)), |
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.
Could you rename the variant UnexpectedRunPass
to something more appropriate now that it's no longer only used for successful exits but also for "non-panicking" ones?
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.
Yeah good idea.
src/librustdoc/doctest.rs
Outdated
} | ||
TestFailure::UnexpectedRunPass => { | ||
eprint!("Test executable succeeded, but it's marked `should_panic`."); | ||
eprint!("Test didn't panic, but it's marked `should_panic`."); |
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.
It might be worthwhile to print the actual exit code / signal here.
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.
Good idea, adding a regression test as well.
src/librustdoc/doctest.rs
Outdated
Some(test::ERROR_EXIT_CODE) => {} | ||
#[cfg(windows)] | ||
Some(STATUS_FAIL_FAST_EXCEPTION) => {} | ||
#[cfg(unix)] | ||
None if out.status.signal() == Some(SIGABRT) => {} |
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.
I know that you've copied this from libtest
since you've told me but I'm a bit unsure about accepting aborts unconditionally even if -Cpanic=unwind
.
I wondering if it would be more correct to only accept these (SIGABRT, …) if -Cpanic=abort
. Similarly, I'm wondering if under -Cpanic=abort
an exit code of 101 would not be deemed acceptable for should_panic
.
It's 3AM for me, so I can't really judge this right now. I'm just a bit uncomfortable with the idea of immediately shipping these changes given that the scope of this "bug fix" PR has grown in scope. It feels like there are open design questions, I could be wrong tho and I don't want to block this on an FCP.
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.
E.g., in the following examples, all tests pass IINM:
//@ compile-flags: --test -Cpanic=unwind
//! ```should_panic
//! std::process::abort();
//! ```
//@ compile-flags: --test -Cpanic=abort
//! ```should_panic
//! std::process::exit(101);
//! ```
Should they? Feels kinda weird to me tbh but maybe I'm the only one.
Should we document any of these details in the rustdoc book?
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.
To be transparent, I don't know how libtest
's --test -Cpanic=abort -Zpanic_abort_tests
works under the hood & is supposed to work. It seems to be able to detect aborting panic!()
s but also recognize that std::process::abort()
is not a panic! No clue how it does that, I have no time to investigate rn.
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.
I plan to use libtest
directly after this PR is merged because this is a mess currently. ^^'
let duration = instant.elapsed(); | ||
if doctest.no_run { | ||
return (duration, Ok(())); | ||
} else if doctest.langstr.should_panic |
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.
Should we leave a FIXME somewhere that we (probably) don't handle -Cpanic=immediate-abort
correctly (very recently added)?
Maybe we do already? As I've PM'ed you, on master I actually get illegal instruction for panics under this new strategy and I don't know if that's intentional or not.
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.
I believe that's due to llvm lowering core::intrinsics::abort
to ub2 which gets translated to an illegal instruction
Added missing FIXME comments
dfc4264
to
6060bcc
Compare
Let's go again then! @bors r=fmease |
Fixes #143009.
Fixes #143858.
Since it includes fixes from #143453, it's taking it over (commits 2, 3 and 4 are from #143453).
For
--no-run
, we forgot to check the "global" options in the 2024 edition, fixed in the first commit.For
should_panic
fix, the exit code check has been fixed.cc @TroyKomodo (thanks so much for providing such a complete test, made my life a lot easier!)
r? @notriddle