Skip to content

Unexpected semilocon makes rustdoc to produce false negatives #91014

@xDarksome

Description

@xDarksome

I tried this code:

/// ```rust
/// struct S {}; // unexpected semicolon after struct def
///
/// fn main() {
///    assert_eq!(0, 1);
/// }
/// ```
mod m {}
cargo test

I expected to see this happen:

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s


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

failures:

---- src/lib.rs - m (line 1) stdout ----
error: expected item, found `;`
 --> src/lib.rs:6:12
  |
2 | struct S {};
  |            ^ help: remove this semicolon
  |
  = help: braced struct declarations are not followed by a semicolon

error: aborting due to previous error

Couldn't compile the test.

failures:
    src/lib.rs - m (line 1)

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

Instead, this happened:

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s


running 1 test
test src/lib.rs - m (line 1) ... ok

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

Meta

rustc --version --verbose:

binary: rustc
commit-hash: c8dfcfe046a7680554bf4eb612bad840e7631c4b
commit-date: 2021-09-06
host: x86_64-unknown-linux-gnu
release: 1.55.0
LLVM version: 12.0.1

Also, reproduces on playground (1.56.1 / 1.57.0-beta.3 / 1.58.0-nightly)

Putting struct def after the main function makes rustdoc to behave as expected:

/// ```rust
/// fn main() {
///    assert_eq!(0, 1);
/// }
///
/// struct S {}; // unexpected semicolon after struct def
/// ```
mod m {}

Implicit main function does the assertion correctly.

/// ```rust
/// struct S {}; // semicolon is OK here
/// assert_eq!(0, 1);
/// ```
mod m {}

Activity

added
A-doctestsArea: Documentation tests, run by rustdoc
T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
on Nov 18, 2021
added 4 commits that reference this issue on Nov 19, 2021
3e04549
f9d7064
b01e807
a9858ce
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-doctestsArea: Documentation tests, run by rustdocC-bugCategory: This is a bug.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @xDarksome@jyn514

      Issue actions

        Unexpected semilocon makes rustdoc to produce false negatives · Issue #91014 · rust-lang/rust