Stabilize `const_location_fields`
Closes #102911.
tests: library/core/tests/panic/location.rs
API:
// core::panic::location
impl Location {
pub const fn file(&self) -> &str;
pub const fn line(&self) -> u32;
pub const fn column(&self) -> u32;
}
r? @Mark-Simulacrum
rustbot has assigned @Mark-Simulacrum. They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.
Use r? to explicitly pick a reviewer
This still needs FCP.
I've written a stabilization report. Is the content sufficient to request the initiation of FCP? (I apologize as it's my first time submitting a stabilization PR)
Stabilization Report
Summary
The const_location_fields feature enables the utilization of the file, line, and column fields of core::location::Location in a const context.
use core::panic::Location;
const LOCATION: &Location<'static> = Location::caller();
const FILE: &str = LOCATION.file();
const LINE: u32 = LOCATION.line();
const COLUMN: u32 = LOCATION.column();
This feature is used in conjunction with Location::caller (tracked in const_caller_location #76156). It has the potential to be useful for embedding debug information during compilation.
Location::{file, line, column} simply returns the fields of the struct as they are, so it can be safely made const.
Tests
We discussed this in the libs-api meeting today. We are happy to const-stabilize these methods, but this should happen alongside the const-stabilization of Location::caller, not separately.
FCP started in #76156.
FCP has finished, this PR should be changed to also stabilize const_caller_location.
Isn't it already included in the PR?
@bors r+
:pushpin: Commit d324d6de0e9a0c3f2413b75de71b175e74057b59 has been approved by dtolnay
It is now in the queue for this repository.