Skip to content

Distinguish between fenced and indented code blocks in error message #64162

@lightclient

Description

@lightclient

EDIT: It turns out that the issue I was facing was caused by my doc comment being interpreted as a code block, based on the indented code block rule in markdown.

--

Summary

The following doc comment fails to compile using cargo test --doc:

///
///    \
///x

Example repository here.

Error Output

> cargo test --doc
Finished dev [unoptimized + debuginfo] target(s) in 0.00s
Doc-tests weird

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

failures:

---- src/lib.rs - main (line 2) stdout ----
error: unknown start of token: \
 --> src/lib.rs:3:1
  |
3 | \
  | ^

error: aborting due to previous error

Couldn't compile the test.

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

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

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

What I've Tried

I've found a few things (I'm sure this is not an exhaustive list to describe the problem):

  • There must be an empty line above the backslash
  • There must be a non-empty line below the backslash
  • There must be at least 4 spaces between the backslash and the doc comment ///

Expected

The snippet compiles without issue.

Meta

I've verified the issue is present using 1.37.0 on both x86_64-apple-darwin and x86_64-unknown-linux-gnu.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsA-doctestsArea: Documentation tests, run by rustdocC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions