`doctest` line number is incorrect if used with #![doc = include_str!()]
Open
Nobody has claimed this yet.
A-doctests
C-bug
T-rustdoc
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
#![doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/README.md"))]
/// ```no_run << line 23
/// panic!("nooo");
/// ```
pub struct XXXXYYYY<A, B> {
...
}
I expected to see this happen: the included doctests show the line number of the include statement.
Instead, this happened:
running 2 tests
test src/lib.rs - XXXXYYYY (line 23) - compile ... ok
test src/lib.rs - (line 23) ... FAILED
Meta
rustc --version --verbose:
rustc 1.81.0-nightly (032be6f7b 2024-07-16)
binary: rustc
commit-hash: 032be6f7bbe091c7dfa29f115e94b9cc9bae1758
commit-date: 2024-07-16
host: aarch64-apple-darwin
release: 1.81.0-nightly
LLVM version: 18.1.7
Backtrace
N/A
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue using the src/lib.rs example and the included README.md doctest, then trace how doctest line numbers are reported for #![doc = include_str!(...)]. Confirm the fix by rerunning the two doctests and verifying that included examples report the include statement's location rather than the README line.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100