-
Couldn't load subscription status.
- Fork 2.7k
Add fallible units for scrape-examples feature #10596
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
Conversation
|
r? @ehuss (rust-highfive has picked a reviewer for you, use r? to override) |
|
☔ The latest upstream changes (presumably #10539) made this pull request unmergeable. Please resolve the merge conflicts. |
20551a8 to
ae509e8
Compare
specific units fail. All Docscrape units now have can_fail = true to avoid stopping Rustdoc if an example fails to scrape.
ae509e8 to
ae0edf7
Compare
|
I've been thinking about this quite a bit and I'm just not convinced that this is something that can unconditionally be enabled by default in the short term. As you identified in #10343 (comment), there are several reasons that a package will fail to build examples, and I don't think this will be sufficient to address those. I'm also concerned about this approach of having fallible units. In my experience, some people get confused when there are error messages displayed which are then later ignored. I'm concerned that this could be a difficult user experience. This also doesn't address the concern that dev-dependencies don't build, which I think is one of the greater issues. I'm also concerned with the depth of changes being made to Cargo to accommodate this. I'd like to consider a different approach, perhaps something along the lines of:
I realize that not enabling by default makes it very unlikely that users will turn it on, making this feature less useful. However, I think this approach gives a short-term stepping stone. For projects without After that has been used on docs.rs for a while (or on stable), and we have more experience with it, we can revisit what more we can do to make it more accessible. Some rough thoughts on what that could look like:
How do you feel about this different approach? |
|
Broadly this policy seems good as a first pass that avoids unexpected breakage, thanks for the careful thought you put into it. My biggest concern is just how complex it is, with the accompanying UX issues in predictability and cliffs. For instance, it feels very weird as a user to change something seemingly unrelated to docs, like adding a dev-dependency, and all of a sudden your scraped examples vanish from documentation. But I suppose this is an unavoidable consequence of the choice to make Rustdoc not rely on dev-dependencies. I think it's reasonable if Cargo has a conservative policy, so all |
What does this PR try to resolve?
As established in rust-lang/rust#73566 and rust-lang/rust#43348, the minimum viable input to Rustdoc only needs to have valid function headers, and not valid function bodies. This is not super common, but must be a valid fallback for some crates.
The scrape examples feature requires checking the bodies of functions in order to find locations of examples. This includes the main library's functions, and functions in any other desired target. Therefore some libraries that are otherwise documentable will fail while scraping.
How should we test and review this PR?
To address this issue, this PR implements a new concept: fallible units. Units can be marked as
can_fail = true, and then their failure does not terminate the Cargo session. A new data structureContext::units_completedtracks which units have completed and whether they succeeded or failed. If a unit fails, then all of its transitive reverse dependencies that also havecan_fail = truewill immediately fail as well.This PR uses this feature to implement the desired behavior for scraping examples. When the user passes
-Z ignore-scrape-failures, then allCompileMode::Docscrapeunits will havecan_fail = true, and thecargo docimplementation will dynamically check which scraped examples have succeeded to determine which*.examplesfiles should be passed to Rustdoc. The idea of the added flag is that it will be used on docs.rs where limiting failure is desirable, while users individually callingcargo docwill be presented terminal compilation failures by default since it's more likely a bug than a feature if a crate's examples don't compile.The added tests
scrape_examples_no_fail_bad_exampleandscrape_examples_no_fail_bad_dependencyshow how this behavior works in practice.Additional information
Some questions / todos:
queue.finishis called to register that the unit is done. Are there other pieces of state that need to get updated in this special case?