-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Oh rust doctest lints, where art þou? (Add a way to run clippy on doctests) #56232
Comments
It seems like having |
@QuietMisdreavus @GuillaumeGomez any idea how we could coax rustdoc into extracting the doctests for us to lint? |
Well, we already extract the doctest but just for compilation/run at the moment. The only question I have is: what interface do you want rustdoc to provide to do so? Running specifically clippy on the returned code samples or something more generic? And if so, then what would it look like? |
I think there might be interest in running both |
So something more generic. I see a few different possibilities. Like providing a Rust file like |
That's not really useful for tooling, tooling shouldn't have to add new files to the tree to be able to run tests. |
I don't have other ideas to do this nicely. But if you have any, please tell so! :) |
@GuillaumeGomez we have a custom driver (as has cargo check, IIRC), so the most elegant solution in terms of UI would be giving an expansion of the doctests with the respective spans in the code to our custom driver. |
Actually I think this should wait until Ultimately clippy behaves just like another rustc binary, and we're slowly consolidating all of the actual cargo logic in cargo itself. |
Fine by me! |
@Manishearth currently examples are tested by running Since |
Vaguely related to #73314 |
I think the proper way to do this is something like this:
How does that sound? I wonder if this is large enough to need an rfc ... |
This would be very very helpful for rust-analyzer as well, I think. Currently when writing non-trivial example code, I have no inline errors in my editor which reduces my productivity a bunch. |
I finally got round to writing a little script that manages to run clippy against doctests using the currently available (unstable) options: https://github.com/Nemo157/dotfiles/blob/master/bin/cargo-rustdoc-clippy I haven't tested it very widely, and it doesn't have the greatest output because you still see all the rustdoc test-runner output, but it works quite well on the few crates I've tried it on. |
stumbled upon this while digging in rustdoc for an unrelated issue, what's the status on this ? Or how would one go about potentially contributing something ? |
- Updated hyperlink format in `HyperKZG` module documentation. - CI should be testing this when rust-lang/rust#56232 resolves.
- Updated hyperlink format in `HyperKZG` module documentation. - CI should be testing this when rust-lang/rust#56232 resolves.
- Updated hyperlink format in `HyperKZG` module documentation. - CI should be testing this when rust-lang/rust#56232 resolves.
* Improve rustdoc - Updated references in documentation comments, changing from Kotlin-style to rustdoc style. - Corrected the use of brackets to backticks for proper Rust code referencing in the comments in the `lib.rs` and `r1cs/mod.rs` files. - The changes made were purely stylistic and cosmetic. No modifications were made to the actual code logic or implementation. * doc: fix Rustdoc - Updated hyperlink format in `HyperKZG` module documentation. - CI should be testing this when rust-lang/rust#56232 resolves.
This is great! For others who stumble on this issue, the script above has moved to https://github.com/Nemo157/dotfiles/blob/74d54412ccb705551ef0c8d928d64bc9e6de69de/packages/cargo-rustdoc-clippy After copying it to somewhere in your cargo +nightly rustdoc-clippy |
This comment has been minimized.
This comment has been minimized.
Building on #56232 (comment) you can actually achieve the same effect with a plain cargo command (here less configurable, but seems like a good enough baseline, at least for us): RUSTDOCFLAGS="--no-run --nocapture --test-builder clippy-driver -Z unstable-options" cargo +nightly test --doc
Edit: actually seems warning is not enough so there may still be a need for an intermediate script to forward the clippy flags Edit2: simpler more "hard coded" construct: clippy_driver.sh #!/usr/bin/env bash
set -eu
exec clippy-driver ${CLIPPYFLAGS} $@ CLIPPYFLAGS="-D warnings" RUSTDOCFLAGS="--no-run --nocapture --test-builder ./clippy_driver.sh -Z unstable-options" cargo +nightly test --doc |
Btw, as described in https://doc.rust-lang.org/rustdoc/write-documentation/documentation-tests.html#showing-warnings-in-doctests, some With clippy, they are still disabled by default while more "sophisticated" lints are enabled. They can be reenabled globally by using |
Currently, doctests benefit from being code in numerous ways, such as being tested. However, this unfortunately does not (yet?) apply to clippy lints. For (an atmittedly contrived) example:
Running
cargo clippy
shows no lint.To solve this, we'd need to be able to hook into the test code generation and present the resulting AST and HIR to our lints. I am unsure where to put this issue, but as clippy is not the only source of custom lints, I think solving it within rust/rustdoc makes sense.
cc @Manishearth @oli-obk
The text was updated successfully, but these errors were encountered: