Doc-test reports “expected item, found keyword let” when the actual problem is a missing semicolon elsewhere
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
To reproduce
/// # Example
///
/// ```
/// use test_lib::add;
///
/// let p = add(3, 2);
///
/// assert_eq!(p, 5);
/// // missing a semicolon next line
/// assert_eq!(add(2, 2), 4)
/// assert_eq!(add(5, 0), 5);
/// ```
pub fn add(left: u64, right: u64) -> u64 {
left + right
}
-
Put the above code in
src/lib.rsof a new cargo project namedtest_lib. -
Run:
cargo test --doc
Actual output
Doc-tests test_lib
running 1 test
test src\lib.rs - add (line 3) ... FAILED
failures:
---- src\lib.rs - add (line 3) stdout ----
error: expected item, found keyword `let`
--> src\lib.rs:6:1
|
3 | let p = add(3, 2);
| ^^^
| `let` cannot be used for global variables
| help: consider using `static` or `const` instead of `let`
|
= note: for a full list of items that can appear in modules, see https://doc.rust-lang.org/reference/items.html
error: aborting due to 1 previous error
Couldn't compile the test.
Expected output
I would expect the error message to be around the actual problematic line, or with an additional hint saying the error is possibly due to a missing semicolon somewhere.
Meta
rustc --version --verbose:
binary: rustc
commit-hash: 17067e9ac6d7ecb70e50f92c1944e545188d2359
commit-date: 2025-05-09
host: x86_64-pc-windows-gnu
release: 1.87.0
LLVM version: 20.1.1
rustdoc --version --verbose:
rustdoc 1.87.0 (17067e9ac 2025-05-09)
binary: rustdoc
commit-hash: 17067e9ac6d7ecb70e50f92c1944e545188d2359
commit-date: 2025-05-09
host: x86_64-pc-windows-gnu
release: 1.87.0
LLVM version: 20.1.1
Also reproducible on nightly.
rustc --version --verbose:
rustc 1.89.0-nightly (573a01569 2025-06-12)
binary: rustc
commit-hash: 573a01569000d395498a5f98f916d6e5305ac81a
commit-date: 2025-06-12
host: x86_64-pc-windows-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5
rustdoc --version --verbose:
rustdoc 1.89.0-nightly (573a01569 2025-06-12)
binary: rustdoc
commit-hash: 573a01569000d395498a5f98f916d6e5305ac81a
commit-date: 2025-06-12
host: x86_64-pc-windows-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5
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 report by placing the example in src/lib.rs of a new Cargo project and running cargo test --doc with the shown rustc and rustdoc versions. Start by tracing how rustdoc compiles doctests and reports the missing-semicolon case. Done means the diagnostic points near the actual problematic line or adds a useful missing-semicolon hint, with the reproduction covered by a test.
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
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100