Skip to content

Incorrect span used for doctests defined using #[doc(include)] or #[doc = include_str!("...")] #81070

Open
@lambda-fairy

Description

@lambda-fairy

Given these two files:

ducks.rs

#![feature(extended_key_value_attributes)]
#[doc = include_str!("ducks.md")]
fn ducks() {}

ducks.md

test
test
test
test
test
test
test
test
test
test

```rust
invalid syntax
```

When I run rustdoc --test ducks.rs, I get an error:

error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `syntax`
 --> ducks.rs:14:9
  |
3 | invalid syntax
  |         ^^^^^^ expected one of 8 possible tokens

error: aborting due to previous error

The error message is correct. However, the position (ducks.rs:14:9) is invalid. I would expect it to reference either the original include_str! call, or (preferred) the snippet in the Markdown file.

Meta

rustc --version --verbose:

rustc 1.51.0-nightly (bc39d4d9c 2021-01-15)
binary: rustc
commit-hash: bc39d4d9c514e5fdb40a5782e6ca08924f979c35
commit-date: 2021-01-15
host: x86_64-unknown-linux-gnu
release: 1.51.0-nightly
LLVM version: 11.0

cc #78835

Metadata

Metadata

Assignees

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

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions