Skip to content

Unmatched code fences cause panic of doc test compilation #48377

Closed
@elinorbgr

Description

@elinorbgr

Example code for src/lib.rs:

//! This is a doc comment
//!
//! ```rust
//! fn main() {}
//! ```
//!
//! With a trailing code fence
//! ```


/// Some foo function
fn foo() {}

Running doc tests on beta or nightly panics, while stable is ok with that:

$ cargo +beta test --doc
   Compiling lol v0.1.0 (file:///home/levans/test/lol)
warning: function is never used: `foo`
  --> src/lib.rs:12:1
   |
12 | fn foo() {}
   | ^^^^^^^^
   |
   = note: #[warn(dead_code)] on by default

    Finished dev [unoptimized + debuginfo] target(s) in 0.19 secs
   Doc-tests lol
thread '<unnamed>' panicked at 'begin <= end (44 <= 0) when slicing `This is a doc comment

```rust
fn main() {}
```

With a trailing code fence
````', libcore/str/mod.rs:2225:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.
error: test failed, to rerun pass '--doc'

Metadata

Metadata

Labels

C-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

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions