rust-lang / rust-lang/rust

Rustdoc standalone attribute

Open
#143,943 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-docs A-doctests C-enhancement T-rustdoc
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code

According to

https://doc.rust-lang.org/rustdoc/write-documentation/documentation-tests.html#~standalone_crate~:~:text=is%20where%20the-,standalone_crate,-attribute%20comes%20in

//! ```standalone_crate
//! let location = std::panic::Location::caller();
//! assert_eq!(location.line(), 4);
//! ```

not sure where 4 comes from its always 3 for me, however i propose it should be 1

This example can be solved without a standalone crate by using include!

inc.rs


{
    let location = std::panic::Location::caller();
    assert_eq!(location.line(), 3);
}
{let location = std::panic::Location::caller();
assert_eq!(location.line(), 1);}
fn main() {
    include!("inc.rs")
}

Running this passes since it seems that the include! macro forwards panic info to the right file.

Version

rustdoc 1.88.0 (6b00bc388 2025-06-23)
binary: rustdoc
commit-hash: 6b00bc3880198600130e1cf62b8f8a93494488cc
commit-date: 2025-06-23
host: x86_64-unknown-linux-gnu
release: 1.88.0
LLVM version: 20.1.5

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the standalone_crate example from the rustdoc documentation-tests page with the reported Rust 1.88.0 toolchain, then compare its panic line with the include! example. Inspect rustdoc's standalone_crate handling and determine whether the implementation or the documented expected line is wrong. Done means the behavior and documentation agree, with a regression test covering the reported case.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, documentation
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.