rust icon indicating copy to clipboard operation
rust copied to clipboard

Stabilize `const_location_fields`

Open lilasta opened this issue 1 year ago • 1 comments

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;
}

lilasta avatar Mar 10 '24 13:03 lilasta

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

rustbot avatar Mar 10 '24 13:03 rustbot

This still needs FCP.

jhpratt avatar Mar 11 '24 07:03 jhpratt

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

lilasta avatar Mar 12 '24 14:03 lilasta

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.

Amanieu avatar Mar 19 '24 16:03 Amanieu

FCP started in #76156.

Amanieu avatar Mar 22 '24 08:03 Amanieu

FCP has finished, this PR should be changed to also stabilize const_caller_location.

Amanieu avatar Apr 02 '24 16:04 Amanieu

Isn't it already included in the PR?

slanterns avatar Apr 03 '24 08:04 slanterns

@bors r+

dtolnay avatar Apr 05 '24 22:04 dtolnay

:pushpin: Commit d324d6de0e9a0c3f2413b75de71b175e74057b59 has been approved by dtolnay

It is now in the queue for this repository.

bors avatar Apr 05 '24 22:04 bors