Closed
Description
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 {}