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

Faulty doctest detection under #[doc] generated OUTER_BLOCK_DOC #107994

Closed
ipaljak-tbtl opened this issue Feb 13, 2023 · 2 comments
Closed

Faulty doctest detection under #[doc] generated OUTER_BLOCK_DOC #107994

ipaljak-tbtl opened this issue Feb 13, 2023 · 2 comments
Labels
C-bug Category: This is a bug.

Comments

@ipaljak-tbtl
Copy link

I've noticed cargo test failing in certain scenarios when using a #[doc] attribute to generate a multi-line rustdoc documentation of some type. I've succeeded to reproduce this issue at the playground on a small example.

I tried to run cargo test on this code (Link to Playground):

#[doc = "A list of items:\n\t- item 1\n\n\t- item 2\n"]
struct SomeStruct {}

fn main() {
    for counter in 0..1 {
        println!("{:?}", counter);
    }
}

I expected to see this happen: cargo test passes, no errors detected.

Instead, this happened: A doctest was detected, and failed with the following error:

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

failures:

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

error: aborting due to previous error

Couldn't compile the test.

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

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

Meta

The same behavior can be observed in stable (1.67.1), beta (1.68.0-beta.4 (2023-02-09 a6d8057f098ab3cebe5a)), and nightly (1.69.0-nightly (2023-02-12 5b8f284536d00ba649ca)) channels within the rust playground.

I've also observed that this error does not occur in some previous releases, for example:

> rustc --version --verbose

rustc 1.66.1 (90743e729 2023-01-10)
binary: rustc
commit-hash: 90743e7298aca107ddaa0c202a4d3604e29bfeb6
commit-date: 2023-01-10
host: x86_64-unknown-linux-gnu
release: 1.66.1
LLVM version: 15.0.2
@ipaljak-tbtl ipaljak-tbtl added the C-bug Category: This is a bug. label Feb 13, 2023
@lukas-code
Copy link
Member

Your doc comment contains an indented code block that is executed as a doc test.

For me this reproduces on 1.66.1 as well.

See also #100225 #88590.

@ipaljak-tbtl
Copy link
Author

Ah, I see, not a bug then 😄

Thanks!

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