[rustdoc] Do not take doc(cfg()) into account when filtering doctests - #159014
[rustdoc] Do not take doc(cfg()) into account when filtering doctests#159014GuillaumeGomez wants to merge 3 commits into
doc(cfg()) into account when filtering doctests#159014Conversation
This comment has been minimized.
This comment has been minimized.
|
And now it fails because we (doc) inlined some functions. Fixing that then. :) |
This comment has been minimized.
This comment has been minimized.
f5059c8 to
062cfea
Compare
This comment has been minimized.
This comment has been minimized.
062cfea to
1d5692c
Compare
|
Fixed CI \o/ |
1d5692c to
a0bf3c9
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
Reverted changes I made to |
This comment has been minimized.
This comment has been minimized.
|
Ah, new stuff gets added. |
a0bf3c9 to
59a72c3
Compare
|
cc @Amanieu, @folkertdev, @sayantn |
59a72c3 to
885af7e
Compare
This comment has been minimized.
This comment has been minimized.
885af7e to
21e8051
Compare
|
Seems like CI is happy now. |
|
Setting a new reviewer as fmease seems busy. r? @Urgau |
There was a problem hiding this comment.
Can't this test be made a regular UI test with two revisions for the editions?
//@ revisions: e2015 e2024
//@[e0215] edition: 2015
//@[e0215] edition: 2024
There was a problem hiding this comment.
Yes but I wanted to enforce the output, which cannot be done with ui-tests sadly. I want to be absolutely sure that we have 2 passed.
There was a problem hiding this comment.
I think that can be done with //@ regex-error-pattern: 2 passed.
There was a problem hiding this comment.
Did you look at using regex-error-pattern? The UI test would have the advantage of checking the whole output, even if we are not asserting something.
If not, I'm fine approving it without it.
There was a problem hiding this comment.
error in revision `e2015`: error pattern 'running 2 tests' not found!
error in revision `e2024`: error pattern 'running 2 tests' not found!
It doesn't check stdout as far as I can see.
There was a problem hiding this comment.
For reference, tested with:
//@ revisions: e2015 e2024
//@[e0215] edition: 2015
//@[e0215] edition: 2024
//@ compile-flags: --test
//@ regex-error-pattern: running 2 tests
//@ regex-error-pattern: test .+/doc-cfg-filter.rs - f (line 3) \.\.\. ok
//@ regex-error-pattern: test .+/doc-cfg-filter.rs - dummy::f2 \(line 11\) \.\.\. ok
//@ regex-error-pattern: test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out;
//@ check-pass
#![feature(doc_cfg)]
/// ```
/// assert!(true);
/// ```
#[doc(cfg(spec))]
fn f() {}
#[doc(cfg(false))]
mod dummy {
/// ```
/// assert!(true);
/// ```
fn f2() {}
}There was a problem hiding this comment.
It doesn't check
stdoutas far as I can see.
Ah, nevermind then.
21e8051 to
329ac5f
Compare
|
Thanks for the review, updated! |
There was a problem hiding this comment.
Sorry, I wasn't really available for the last 3 weeks. I haven't looked at your latest implementation, I'll let Urgau do the reviewing, I'm just chiming in for some comments.
IMO, we (probably I) should definitely tackle #[target_feature(enable = …)] again next since I don't want the two drifting apart behavior-wise (thereby fully fixing #147033). Of course, that'd involve crater & an FCP.
| #[cfg_attr(target_os = "macos", doc = "```no_run")] | ||
| #[cfg_attr(not(target_os = "macos"), doc = "```ignore (needs macos)")] |
There was a problem hiding this comment.
All these changes to libcore etc. make me question whether this change is actually desired / my bug report #147033 is valid ^^' Please instill certainty that it is :'D
Clearly, the user code is worse: We have to give up on the doc comments, check the cfg condition again despite being in a module that only gets compiled on macOS or doc.
Since this looks like a common code pattern I wish there was an official way to express this, don't y'all think? Unfortunately, ignore-* code block attributes won't help here. We'd need
/// ```no_run,only-macos
or arbitrary cfg exprs
/// ```no_run,ignore2-not(macos)
unfortunately, #[doc(test(attr(cfg(…))))] won't help either since it just butchers the generated test harness code. If that had worked that would've been beyond awesome :'(
There was a problem hiding this comment.
unfortunately,
#[doc(test(attr(cfg(…))))]won't help either since it just butchers the generated test harness code. If that had worked that would've been beyond awesome :'(
What's the problem exactly with that approach?
There was a problem hiding this comment.
#![doc(test(attr(cfg(false))))]
//! ```
//! assert!(true);
//! ```
running 1 test
test q.rs - (line 2) ... FAILED
failures:
---- q.rs - (line 2) stdout ----
error[E0601]: `main` function not found in crate `rust_out`
--> q.rs:4:29
|
4 | } _doctest_main_q_rs_2_0() }
| ^ consider adding a `main` function to `q.rs`
<12 lines omitted>
#![doc(test(attr(cfg(false))))]
//! ```
//! fn main() {
//! assert!(true);
//! }
//! ```
running 1 test
test q.rs - (line 2) ... FAILED
failures:
---- q.rs - (line 2) stdout ----
error[E0601]: `main` function not found in crate `rust_out`
--> q.rs:5:2
|
5 | }
| ^ consider adding a `main` function to `q.rs`
<12 lines omitted>
There was a problem hiding this comment.
I think it's up to the users to ensure their doctest is run under the right conditions. The way core/std are making all items available might not be the best one. ^^'
There was a problem hiding this comment.
error[E0601]: `main` function not found in crate `rust_out` --> q.rs:5:2 | 5 | } | ^ consider adding a `main` function to `q.rs` <12 lines omitted>
Hum, seems like we are not taking into account cfgs and are blanket applying to the whole doctest crate. I wonder if we should do something about it.
There was a problem hiding this comment.
We are, otherwise we would see all items, whatever their cfg.
44fe1ed to
329ac5f
Compare
So I'll remove my last commit. |
This comment was marked as resolved.
This comment was marked as resolved.
|
Restarted flaky CI and now it passed. @rustbot ready |
|
@bors r+ |
…est, r=Urgau [rustdoc] Do not take `doc(cfg())` into account when filtering doctests Part of rust-lang#147033. Because it was using the `extract_cfg_from_attrs` common function, it was taking into account the `doc(cfg())` attributes the same as if they were a `cfg`. I didn't mark this PR as "fix" because I didn't handle the case of the doctest not being marked as ignored because I'm not sure if we should revisit the fact that we ignore these doctests or if we should just mark them as ignored (because of `target_feature(enable = "...")`). Setting @fmease as reviewer as they are likely the only one with context about this issue. 😆 r? @fmease
Rollup of 17 pull requests Successful merges: - #159014 ([rustdoc] Do not take `doc(cfg())` into account when filtering doctests) - #159130 (a bit optimize four-digit chunks in integer formatting) - #159592 (core: implement bounded random sampling) - #159898 (Add intrinsic-test alias and set sample rate) - #158247 (hermit/fs: Return `unsupported()` instead of `from_raw_os_error(22)`) - #158649 (Hermit: fix `readdir()` ) - #159049 (Avoid ICE in From/TryFrom cast suggestion when encountering HRTBs) - #160053 (test: add test suite for the 85681 issue) - #160087 (Add regression test for nested associated-type projection ICE) - #160090 (rustc_resolve: Further reduce mutability in resolver) - #160099 (Resolver: split module resolutions into local and external resolutions) - #160106 (Add suggestions for `must_implement_one_of`) - #160117 (Remove unnecessary format usage) - #160134 (Work around Wine bug 60084 by calling WSAStartup at most once) - #160142 (bootstrap: remove use-lld config alias) - #160148 (Rename `errors.rs` file to `diagnostics.rs` (15/N)) - #160151 (Mark a doctest as requiring unwinding)
|
This pull request was unapproved. This PR was contained in a rollup (#160168), which was unapproved. |
View all comments
Part of #147033.
Because it was using the
extract_cfg_from_attrscommon function, it was taking into account thedoc(cfg())attributes the same as if they were acfg.I didn't mark this PR as "fix" because I didn't handle the case of the doctest not being marked as ignored because I'm not sure if we should revisit the fact that we ignore these doctests or if we should just mark them as ignored (because of
target_feature(enable = "...")).Setting @fmease as reviewer as they are likely the only one with context about this issue. 😆
r? @fmease