doctests: unhelpful error messages for non-Rust code blocks #88590
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-doctests
Area: Documentation tests, run by rustdoc
T-rustdoc
Relevant to the rustdoc team, which will review and decide on the PR/issue.
I recently added the a docstring to one of my functions that looked similar to this:
When I then ran
cargo test
to execute tests defined in other parts of the project, I got the error messagesIt took me a while to figure out the issue: the list items shouldn't be indented, because the indentation makes them a code block instead of a list. With the indentation, Rust tries to run the list as a doctest, and the error messages are due to the list content not being valid Rust code.
cargo check
didn't yield any insights, either -- in fact it did not produce any warning at all.cargo doc
, on the other hand, produced the following very helpful output:This pointed me directly in the right direction of something being parsed as Rust code.
I know that this is a minor issue, but so far I have been amazed by the incredibly helpful error message in the Rust eco system, and this was one of the few times where the original message was of little help. I don't know anything about how
cargo test
andcargo doc
differ in their parsing, but the helpful output ofcargo doc
shows that a similar message should be possible forcargo test
.This is with Cargo
1.50.0 (f04e7fab7 2021-02-04)
.The text was updated successfully, but these errors were encountered: