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: doctest compilation failure for item without code block #101405

Closed
epbuennig opened this issue Sep 4, 2022 · 1 comment
Closed

rustdoc: doctest compilation failure for item without code block #101405

epbuennig opened this issue Sep 4, 2022 · 1 comment
Labels
C-bug Category: This is a bug.

Comments

@epbuennig
Copy link

rustdoc will attempt to compile a doc test for the following code, resulting in a failed doctest compilation:
I encountered this while writing verbatim docs for options using the clap derive API.

Steps to reproduce:

  1. Add this to src/lib.rs
/// Show more output
///
/// * -q    - show only required output
/// *       - show changes
/// * -v    - show intermediate steps
/// * -vv   - show filter logs
/// * -vvv  - show pattern preprocessing logs
/// * -vvvv - show internal logs
pub fn main() {}
  1. Run cargo t --doc

Expected result: no doctest is compiled for fn main, as it has not code blocks
Actual result: a doctest failure

Meta

rustc --version --verbose:

rustc 1.65.0-nightly (0b79f758c 2022-08-18)
binary: rustc
commit-hash: 0b79f758c9aa6646606662a6d623a0752286cd17
commit-date: 2022-08-18
host: x86_64-unknown-linux-gnu
release: 1.65.0-nightly
LLVM version: 15.0.0

This also happens on stable, rustc +stable --version --verbose:

rustc 1.63.0 (4b91a6ea7 2022-08-08)
binary: rustc
commit-hash: 4b91a6ea7258a947e59c6522cd5898e7c0a6a88f
commit-date: 2022-08-08
host: x86_64-unknown-linux-gnu
release: 1.63.0
LLVM version: 14.0.
Backtrace

    Finished test [unoptimized + debuginfo] target(s) in 0.00s
   Doc-tests playground

running 1 test
test src/lib.rs - main (line 4) ... FAILED

failures:

---- src/lib.rs - main (line 4) stdout ----
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `changes`
 --> src/lib.rs:5:8
  |
3 | - show changes
  |        ^^^^^^^ expected one of 8 possible tokens

error: aborting due to previous error

Couldn't compile the test.

failures:
    src/lib.rs - main (line 4)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.02s

error: test failed, to rerun pass '--doc'

@epbuennig epbuennig added the C-bug Category: This is a bug. label Sep 4, 2022
@ehuss
Copy link
Contributor

ehuss commented Sep 4, 2022

Unfortunately this is a known issue. The line * - show changes is an indendent code block according to commonmark rules. All code blocks are treated as rust code blocks, and all rust code blocks get tested. I don't think in this case you'll be able to indent the text to line up visually. You could perhaps use nbsp whitespace or something like that, but that might not render well in an editor.

I'm going to close as a duplicate of several other issues:

@ehuss ehuss closed this as not planned Won't fix, can't repro, duplicate, stale Sep 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants