Skip to content

Rustdoc standalone attribute #143943

Open
Open
@TroyKomodo

Description

@TroyKomodo

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

Metadata

Metadata

Assignees

No one assigned

    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