-
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
rustdoc fails on ignore
'd code
#30032
Comments
I took a look at this and it seems like your char literal contains another (apparently invisible) code point, which means it is no valid Rust code. The problem seems to be that rustdoc tries to highlight the code regardless of the ignore annotation, as it only ignores the snippet when running tests. And AFAIK rustdoc uses While the error is confusing (because there is no visible additional code point), I think the behavior of Finally this code should work with
|
Yes. That's why it's in
Or maybe not syntax highlight code that's ignored? |
I think it would still make sense to have an annotation which excludes the code from the tests but highlights it in the docs, e.g. for nice looking example code, which does not have to include every little detail to make it compile. If one would like to include code that should not be highlighted and not be used when testing, wouldn't it be possible to just add it as normal text, not in a code block? |
Currently, the libsyntax lexer panics on invalid source, which makes rustdoc panic when trying to highlight it. I assume there are efforts underway to make the lexer panic-free, but until this is done this should be an acceptable workaround. Note that the panic is still printed like normal as "thread X panicked, run with RUST_BACKTRACE=1 ...", so I added the printout below to make it seem less like a fatal error. I didn't touch `render_inner_with_highlighting` below, as it is currently unused. It returns a Result whose Err type would have to be changed if it was to support lexer errors. Fixes: rust-lang#30032
Currently, the libsyntax lexer panics on invalid source, which makes rustdoc panic when trying to highlight it. I assume there are efforts underway to make the lexer panic-free, but until this is done this should be an acceptable workaround. Note that the panic is still printed like normal as "thread X panicked, run with RUST_BACKTRACE=1 ...", so I added the printout below to make it seem less like a fatal error. I didn't touch `render_inner_with_highlighting` below, as it is currently unused. It returns a Result whose Err type would have to be changed if it was to support lexer errors. Fixes: rust-lang#30032
Triage: looks like #33510 didn't happen |
I ran into this today. I use I'm surprised this issue hasn't had any responses since 2016, so either this is already solved and I'm hitting some other issue, or people don't really put non-Rust code blocks in their documentation. Here's part of the documentation that currently fails. |
FYI: changing this from using |
…deblock-warn, r=jyn514 Add suggestion for "ignore" doc code block Part of rust-lang#30032. This PR adds a suggestion to help users when they have a "ignore" doc code block which is invalid rust code. r? `@jyn514`
Triage: rustdoc outputs this:
but in the generated docs, it uses correct syntax highlighting on the broken code. I think that's pretty optimal. If I understand correctly, this issue was filed because rustdoc used to abort doc-generation on encountering something like this? |
I believe so, but to be honest, that diagnostic output looks great to me, and there's a path to having incorrect things be documented, so as far as I'm concerned, I don't personally feel this is an issue anymore, so happy to close it, regardless of whatever historical behavior may or may not have been happening way back then. |
This doc example:
compiles and passes with
rustdoc --test
, but not just generating documentation.The text was updated successfully, but these errors were encountered: