Skip to content

Stabilize core::panic::Location::caller #72448

Closed
@dtolnay

Description

@dtolnay

The lang FCP for #[track_caller] is happening in #72445. This is a libs FCP for https://doc.rust-lang.org/nightly/std/panic/struct.Location.html#method.caller which is under the same feature gate and required for making use of #[track_caller] in library code.

Refer to @anp's stabilization report and the method's example code.

In particular:

  • The return type is &'static Location<'static> which resembles the return type of std::panic::PanicInfo::location (Option<&'a Location<'a>>) but static and non-optional.

  • The location points to the outermost call site not inside of a #[track_caller] function.

#[track_caller]
fn f() -> &'static Location<'static> {
    Location::caller()
}

fn g() -> &'static Location<'static> {
    f() /*
    ^ calling g() gives a location whose file()/line()/column() point to here
        */
}

@rust-lang/libs

Metadata

Metadata

Assignees

No one assigned

    Labels

    F-track_caller`#![feature(track_caller)]`T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions