-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Prevent rustdoc feature doctests #64741
Prevent rustdoc feature doctests #64741
Conversation
7e7ab2b
to
bf41529
Compare
src/librustdoc/test.rs
Outdated
let mut test_args = options.test_args.clone(); | ||
let mut test_args = options.test_args | ||
.iter() | ||
.filter_map(|arg| { |
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.
.filter(..).cloned()
seems cleaner 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.
I continue to be deeply confused why we're altering test_args here.
test_args is the array of arguments that's passed to test::test_main -- that's way too late for cfg
to matter, I believe, and test_main certainly is not a compiler.
Can you at least check manually that this works? A comment that explains how this works (e.g., why is this applying to cfg, despite not mentioning cfg at all?) would also be good.
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 just thought about it when you said something was wrong in this implementation the other day: it's incorrect since I don't check the cfg
. However, test_args
are passed to each code sample rustdoc compiles and run. Therefore, it seems accurate to me to have this check here. However I need to fix it.
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.
But... they're not? These are not the arguments to rustc. These are the arguments to the test 'binary'. I would expect you to never find a --cfg
in these arguments; they're not (AFAICT) used at all for compilation. Right now the code is removing a test filter for rustdoc -- not a cfg gate or anything like that.
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.
Then I completely misunderstood this part of the code... I'll take a step back and check what I missed...
d19f3f3
to
b69ae4a
Compare
Indeed, I wasn't looking at the good place at all... Thanks a lot for catching up my error @Mark-Simulacrum ! |
src/librustdoc/test.rs
Outdated
@@ -251,7 +251,9 @@ fn run_test( | |||
let mut compiler = Command::new(std::env::current_exe().unwrap().with_file_name("rustc")); | |||
compiler.arg("--crate-type").arg("bin"); | |||
for cfg in &options.cfgs { | |||
compiler.arg("--cfg").arg(&cfg); | |||
if cfg != "rustdoc" { |
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 also feels like the wrong place :)
I would expect us to not add the rustdoc cfg ourselves -- looking at it, I guess here -- not remove it later on. We don't want to remove it if the user has passed it.
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.
That's a good point I didn't think about... Checking more globally why we even need to do this. However, I think we need it at some point to check for the documentation build (not the tests build). I'm looking around to confirm it.
b69ae4a
to
e4e674b
Compare
@Mark-Simulacrum Just like you suggested, instead of adding it into the options directly, I removed it from there and add it before the doc build. Sorry about all the fuss... |
ping @Mark-Simulacrum |
@bors r+ |
📌 Commit e4e674bec91e364f290ab8b708d960a292d2678a has been approved by |
Shouldn't Line 67 in bf8491e
@bors r- We need tests for this, a // build-pass
// compile-flags:--test
// normalize-stdout-test: "src/test/rustdoc-ui" -> "$$DIR"
#![feature(doc_cfg)]
// Make sure `cfg(rustdoc)` is set when finding doctests but not inside the doctests.
/// ```
/// #![feature(doc_cfg)]
/// assert!(!cfg!(rustdoc));
/// ```
#[cfg(rustdoc)]
pub struct Foo; |
r? @ollie27 I assumed that setting it in core would've done that... |
I did as well since we use this one for it. Adding the test. |
e4e674b
to
57faf0f
Compare
@ollie27 It seems like the test passed whereas I didn't change the code. Did we misunderstood your message? |
If you look at the stdout it shows that it didn't actually run the doctest. It should say "running 1 test". |
Oh I see! Indeed, good catch! |
57faf0f
to
366fdeb
Compare
Now we have it as well. |
📌 Commit 366fdeb has been approved by |
…ure-doctests, r=QuietMisdreavus Prevent rustdoc feature doctests Part of rust-lang#61351 cc @ollie27
…ure-doctests, r=QuietMisdreavus Prevent rustdoc feature doctests Part of rust-lang#61351 cc @ollie27
…ure-doctests, r=QuietMisdreavus Prevent rustdoc feature doctests Part of rust-lang#61351 cc @ollie27
…ure-doctests, r=QuietMisdreavus Prevent rustdoc feature doctests Part of rust-lang#61351 cc @ollie27
Rollup of 11 pull requests Successful merges: - #61879 (Stabilize todo macro) - #64675 (Deprecate `#![plugin]` & `#[plugin_registrar]`) - #64690 (proc_macro API: Expose `macro_rules` hygiene) - #64706 (add regression test for #60218) - #64741 (Prevent rustdoc feature doctests) - #64842 (Disallow Self in type param defaults of ADTs) - #65004 (Replace mentions of IRC with Discord) - #65018 (Set RUST_BACKTRACE=0 in tests that include a backtrace in stderr) - #65055 (Add long error explanation for E0556) - #65056 (Make visit projection iterative) - #65057 (typo: fix typo in E0392) Failed merges: r? @ghost
Part of #61351
cc @ollie27