Skip to content

Tracking Issue for NUL-terminated file names with #[track_caller] #141727

Open
@Darksonn

Description

@Darksonn

Feature gate: #![feature(location_file_nul)]

This is a tracking issue for Location::file_with_nul.

This feature allows you to obtain NUL-terminated file names from core::panic::Location when using #[track_caller]. This allows for better error messages in projects performing interop with C/C++.

Public API

// core::panic

pub struct Location;

impl Location {
    pub const fn file_with_nul(&self) -> &CStr;
}

Steps / History

(Remember to update the S-tracking-* label when checking boxes.)

Related PRs:

Unresolved Questions

It's still unresolved whether the above API is preferred over returning a raw pointer:

// core::panic

pub struct Location;

impl Location {
    pub const fn file_ptr(&self) -> *const c_char;
}

Although this solution is less safe to use, it has the advantage that if we change Location to not store the length, then you can call Location::file_ptr without having to invoke strlen to construct a &CStr.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-panicArea: Panicking machineryA-rust-for-linuxRelevant for the Rust-for-Linux projectC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-impl-incompleteStatus: The implementation is incomplete.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API 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