-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
rustdoc: module flag to prevent code blocks without a lang item from counting as rust #59867
Comments
I'm not a big fan of the idea... |
Can you say more about why not? Keeping in mind that that I'm not asking for it to be a default, just to have it be available as something that a person can turn on if they want to turn it on. |
Because unless stated as non-rust code block, a code block should always be tested. |
If I explicitly type out an attribute flag at the top of a module, that says "ignore all code blocks in here that lack a language marker", perhaps something like #![rustdoc::only_doctest_code_blocks_with_rust_lang] Then that seems fairly clearly "stated" to me. |
Like I said, I don't like the idea. But if other @rust-lang/rustdoc people are okay with it, I'll add it. We'll also need to check if |
Taking a quick look at |
Speaking about the request generally, i'm of the opinion that we should allow the marker attribute that @Lokathor suggested. Accidental doc tests from indented code blocks were one of the biggest false positives when we initially migrated to pulldown, and in this kind of situation with generated code, it's worth providing an out. If we can add the check to make it only ignore indented code blocks, i'd say that's even better. |
I'm running into this same problem trying to build a sys crate for There is already a cargo config |
I'm also affected by this. We're generating code from protobuf types (using prost). The protobuf comments, sometimes containing indented markdown blocks, are converted to rustdoc comments. Unfortunately Rust's doctests try to interpret all those markdown blocks as Rust code (and in some occasions fail to do so with a compile-time error message when running In this case I can adjust the protocol specifications to satisfy Rust, but it would be fantastic if there were a way to disable rust doctest processing within a certain module. |
So, I've got some code being generated by
bindgen
. The C source hasdoxygen
doc comments in it, whichbindgen
faithfully converts over into doc comments. However, some of thedoxygen
content is indented with spaces (numbered lists and the like), so when converted into rustdoc it becomes a code block. These code blocks are picked up as "doctests" bycargo test
, which then of course fail to build because they're not Rust code at all.I'm told that, internally, this is all just code block elements by the time rustdoc sees it, you can't tell which code block was made via a backtick fence and which was made via indentation. However, you can tell if a lang was declared on the code block.
So what I need is an opt-in flag that you can declare module-wide (and children modules and such) so that any code block without a declared language is not treated as rust code by default, so then it won't become a doctest.
The text was updated successfully, but these errors were encountered: