-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
add no_compile
doctest attribute
#96573
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
no_compile doctest attribute
no_compile
doctest attribute
The test for this would live in src/test/rustdoc-ui. |
UI test has been added. |
This comment has been minimized.
This comment has been minimized.
Okay tidy, I'm trying to unblock stopping using |
Some interesting stats on
(I definitely missed a some, I got to clippy in the github.dev search and bailed) |
I'm not sure to understand the use case here. It means you'd want to have a rust code example that can never be checked. It's a strange use case. Why do you need this? Also, just like for |
So, fundamentally, I believe the current usage of
This is demonstrably not how Examples in this repoSome of these should maybe be made to compile, but most want rust/compiler/rustc_ast/src/ast.rs Lines 1479 to 1487 in 879fb42
rust/compiler/rustc_ast/src/ast.rs Lines 2705 to 2714 in 879fb42
rust/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs Lines 509 to 518 in 879fb42
rust/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs Lines 522 to 534 in 879fb42
rust/compiler/rustc_hir/src/hir.rs Lines 1978 to 1984 in 879fb42
rust/compiler/rustc_hir/src/hir.rs Lines 3287 to 3292 in 879fb42
rust/compiler/rustc_macros/src/diagnostics/mod.rs Lines 15 to 35 in 879fb42
rust/compiler/rustc_macros/src/diagnostics/mod.rs Lines 46 to 54 in 879fb42
rust/compiler/rustc_macros/src/diagnostics/mod.rs Lines 70 to 95 in 879fb42
rust/compiler/rustc_macros/src/diagnostics/mod.rs Lines 107 to 111 in 879fb42
rust/compiler/rustc_macros/src/diagnostics/utils.rs Lines 134 to 143 in 879fb42
rust/compiler/rustc_macros/src/diagnostics/utils.rs Lines 148 to 150 in 879fb42
rust/compiler/rustc_middle/src/query/mod.rs Lines 107 to 117 in 879fb42
rust/compiler/rustc_middle/src/query/mod.rs Lines 195 to 200 in 879fb42
rust/compiler/rustc_middle/src/ty/context.rs Lines 345 to 351 in 879fb42
rust/compiler/rustc_middle/src/ty/mod.rs Lines 1078 to 1083 in 879fb42
... you get the point, just do a code search for The use of The behavior I would like to see is that in edition 2024 Flag for stop interpreting code blocks as doctests #63193, No way to run
Agreed, I'm going to look into fixing that this week. |
Ok, now I understand the problem. It seems super weird that /// ```ignore
/// kawakunga
/// ```
pub use ::std as x; If I run running 1 test
test foo.rs - x (line 1) ... ignored
test result: ok. 0 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in 0.00s So maybe the documentation itself is wrong? Needs to be checked more in detail. |
The docs aren't super clear but for rustdoc I believe you need something like this to run ignored tests:
|
Some clarification would be appreciated... So in any case, with this in mind, I don't see why |
@ChrisDenton is correct. With The current status of things is explained by the following table:
The point of
giving an option for documentation blocks which should be highlighted as Rust code in the documentation but should not be considered tests — they should not be tested with Looking further forwardIn edition 2024, I would like to change the table to
to improve the experience of passing A different table that's fully backwards compatible would be
instead making |
See also some discussion in zulip |
Ok, now I see the problem. I'm not used at using Anyway, what do you think about this @rust-lang/rustdoc ? |
To be clear, the default is to ignore the tests:
|
Then again I don't see the need for |
Because you do want to run ignored tests in general. They may all be too slow or too janky to run by default but you do want some way to run them as a group. They're opt-in when you know what you're doing. But there are also some code in doc comments which you never ever ever want to run. Because it's not really rust code (but you want the same syntax highlighting) or it's just for illustrative purposes or whatever. The first group you definitely do want to run at some point. The second group you don't want to be compiled ever at all. These are both currently using the same |
The point is that running
Similarly, there's desire to suppress the
It's my position that such uses should use
I'll also quote @thomcc's motivation from #87586:
@jonhoo @jyn514 it'd be helpful if you could explain your position here as well that you alluded to in #82715. cc also @thomcc from #87586 |
I don't want to be involved in this, sorry. |
So I'm in favor of this in general, but before we go forward with this can we have a doc or something talking about the different options that currently exist (there's The reason I say this is that this space is kinda complicated already, and I would rather not have people confused about which option to pick. If we can pick a name that's clear and document it well, I'd be in favor of this. I am a little skeptical about A pretty major use case for non-compiling code is writing snippets, rustdoc does let you "fill in" the snippets with Fundamentally the distinction being drawn here seems to be "this will not compile, this will never compile, never try" ( |
I'm pretty sure that belongs here, in the rustdoc book. |
Here's a draft of a replacement for the Attributes section of the documentation tests part of the rustdoc book, both one for clarity on the current situation and one for my "ideal future": TodayCode blocks can be annotated with attributes that help
/// ```compile_fail
/// let x = 5;
/// x += 2; // shouldn't compile!
/// ```
/// ```no_run
/// loop {
/// println!("Hello, world");
/// }
/// ```
/// ```should_panic
/// assert!(false);
/// ```
If the test is ignored by the test runner, /// ```ignore
/// fn foo() {
/// ```
/// Only compiles in the 2015 edition.
///
/// ```edition2015
/// try!(Result::<(), std::io::Error>::Ok(()));
/// Ok::<(), std::io::Error>(())
/// ``` Future(replacing the previous, starting at
/// This test requires user interaction.
///
/// ```ignore
/// assert!(show_yes_no_dialog("Should this test succeed?"));
/// ```
/// The syntax of a function declaration is
///
/// ```no_compile
/// $vis $(unsafe)? $(extern $($literal)?)? fn $ident( $( $pat : $ty ),* $(,)? ) $(-> $ty)? {
/// $($stmt)*
/// $($expr)?
/// }
/// ``` (return to the previous, starting at |
☔ The latest upstream changes (presumably #97239) made this pull request unmergeable. Please resolve the merge conflicts. |
@rfcbot reviewed This addition seems good to me. I hadn't realized that @Manishearth it looks like rfcbot didn't recognize |
@rfcbot resolved stablization-report |
@rfcbot resolved feature-gate |
Weird... the |
@rfcbot resolved feature-gate |
I think this might be an rfcbot glitch. Asked on Zulip. |
@rfcbot resolved feature-gate We should have a feature gate for this attribute |
only the original author can mark their concern as resolved? cc @Manishearth |
@rfcbot resolved feature-gate We should have a feature gate for this attribute |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
I have a comment about the "shiny future" presented -- I don't like For the instant issue, no complaints! |
less important detailsFWIW: the reason for I don't have any idea the best way to handle this -- it might be just to disable The important thing imho is that HOWEVER, something apparently has changed between 1.65.0-beta.2 and 1.66.0-nightly-2022-10-03: nightly
Investigating a bit, it looks like this is probably a bugfix, as #63193 is asking for (That said, what makes @rfcbot concern does-the-cargo-behavior-change-make-this-unnecessary |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
Any information about #96573 (comment) @CAD97 ? |
@CAD97 @GuillaumeGomez ping from triage. Have you come to a conclusion on whether this is necessary? |
Can I maintain the formatting using rust-analyser while using Is it possible to include conditional triggers in I encountered some issues on CI where the documentation examples were running with This tool is very helpful, and I would like to know if it's possible to make it conditional while still performing format checks. |
You can hide lines in code examples by starting them with |
☔ The latest upstream changes (presumably #110800) made this pull request unmergeable. Please resolve the merge conflicts. |
(Sorry for the delay; life happened) I've come to the eventual conclusion that The normal test harness has the advantage that tests have names, so it's possible (even if not necessarily nice) to run a subset of ignored tests that actually work in the current environment. Doctests don't really have that affordance. If the test runner ever gets more interesting (e.g. As such, closing this. If someone else thinks this is a valuable addition, feel free to take the code and make your argument for it. |
This makes it possible to write a doctest
which is detected as and highlighted as rust code, but is not compiled.
ignore
kind of serves this purpose, but is still compiled and run when--include-ignored
or--ignored
is used.Maybe should be feature gated / limited to working on the nightly channel (but I personally think this is simple and obviously correct enough that it could potentially just ride the release train).
Fixes #63193, Fixes (kinda) #87586
Big Picture View
https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/Cleaning.20up.20docblock.20attributes
We currently have
--ignored
--ignored
--ignored
I want to clean up this to be
--ignored
This does the simple part of adding
no_compile
. Afterno_compile
is available, it becomes possible to tell current uses ofignore
for does-not-compile rust code to useno_compile
instead, and move towardsignore
always compiling the code in the next edition.