Skip to content
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 unhelpful error message on missing whitespace after # #83284

Closed
douweschulte opened this issue Mar 18, 2021 · 2 comments · Fixed by #84445
Closed

Rustdoc unhelpful error message on missing whitespace after # #83284

douweschulte opened this issue Mar 18, 2021 · 2 comments · Fixed by #84445
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-doctests Area: Documentation tests, run by rustdoc C-enhancement Category: An issue proposing an enhancement or a PR with one. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@douweschulte
Copy link
Contributor

I made some documentation tests for my crate, but forgot to add a space after the pound sign (#) like the following example:

//! ...
//! ## Iterating over the PDB Hierarchy
//!
//! ```rust
//! #use pdbtbx;
//! #let (mut pdb, _errors) = pdbtbx::open("example-pdbs/1ubq.pdb", pdbtbx::StrictnessLevel::Medium).unwrap();
//! // Iterating over all levels
//! for model in pdb.models() {
//! ...

I was unaware that there should be a space after the pound sign, so I was quite startled by the resulting error message (other passed tests excluded):

   Doc-tests pdbtbx

running 2 tests
test src\lib.rs - (line 64) ... FAILED
test src\lib.rs - (line 26) ... ok

failures:

---- src\lib.rs - (line 64) stdout ----
error: expected one of `!` or `[`, found keyword `use`
 --> src\lib.rs:65:2
  |
4 | #use pdbtbx;
  |  ^^^ expected one of `!` or `[`

error: aborting due to previous error

After looking up the correct syntax in the rustdoc book I could easily solve it. But I assume this is not the best error message to provide to users.

Meta

rustc --version --verbose:

rustc 1.50.0 (cb75ad5db 2021-02-10)
binary: rustc
commit-hash: cb75ad5db02783e8b0222fee363c5f63f7e2cf5b
commit-date: 2021-02-10
host: x86_64-pc-windows-msvc
release: 1.50.0

I am not entirely sure this is supposed to be a Bug Report but it did not really fit into any of the other categories as well. If I can do anything more to help please let me know.

@douweschulte douweschulte added the C-bug Category: This is a bug. label Mar 18, 2021
@jyn514 jyn514 added 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. labels Mar 19, 2021
@camelid
Copy link
Member

camelid commented Mar 21, 2021

I'm not sure if we can do much about this because the user may be using #![feature(foo)], which starts with a #. (Note that # ![feature(foo)] [with a space] is valid Rust but has a different meaning in doctests.)

I guess we could give a warning if # is followed by anything other than [ or !?

@douweschulte
Copy link
Contributor Author

I totally get that it is hard to do something about this. A warning like the proposed could help. In the best case (disregarding implementation details) the warning given specifically when running code in a doctest, would include the option of having a space after the pound sign. This warning could then possibly link to the different uses of this sign.

But I get that this is quite hard to achieve, and maybe if no-one else makes this mistake it is a misuse of time to build something like this.

@camelid camelid added C-enhancement Category: An issue proposing an enhancement or a PR with one. and removed C-bug Category: This is a bug. labels Mar 21, 2021
@bors bors closed this as completed in 9a35232 Apr 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-doctests Area: Documentation tests, run by rustdoc C-enhancement Category: An issue proposing an enhancement or a PR with one. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants