Skip to content

Commit

Permalink
Stabilize const_caller_location and const_location_fields
Browse files Browse the repository at this point in the history
  • Loading branch information
lilasta committed Mar 21, 2024
1 parent 3521a2f commit d324d6d
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion library/core/src/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ extern "rust-intrinsic" {
/// any safety invariants.
///
/// Consider using [`core::panic::Location::caller`] instead.
#[rustc_const_unstable(feature = "const_caller_location", issue = "76156")]
#[rustc_const_stable(feature = "const_caller_location", since = "CURRENT_RUSTC_VERSION")]
#[rustc_safe_intrinsic]
#[rustc_nounwind]
pub fn caller_location() -> &'static crate::panic::Location<'static>;
Expand Down
1 change: 0 additions & 1 deletion library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@
#![feature(const_array_into_iter_constructors)]
#![feature(const_bigint_helper_methods)]
#![feature(const_black_box)]
#![feature(const_caller_location)]
#![feature(const_cell_into_inner)]
#![feature(const_char_from_u32_unchecked)]
#![feature(const_eval_select)]
Expand Down
8 changes: 4 additions & 4 deletions library/core/src/panic/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl<'a> Location<'a> {
/// ```
#[must_use]
#[stable(feature = "track_caller", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_caller_location", issue = "76156")]
#[rustc_const_stable(feature = "const_caller_location", since = "CURRENT_RUSTC_VERSION")]
#[track_caller]
#[inline]
pub const fn caller() -> &'static Location<'static> {
Expand Down Expand Up @@ -123,7 +123,7 @@ impl<'a> Location<'a> {
/// ```
#[must_use]
#[stable(feature = "panic_hooks", since = "1.10.0")]
#[rustc_const_unstable(feature = "const_location_fields", issue = "102911")]
#[rustc_const_stable(feature = "const_location_fields", since = "CURRENT_RUSTC_VERSION")]
#[inline]
pub const fn file(&self) -> &str {
self.file
Expand All @@ -148,7 +148,7 @@ impl<'a> Location<'a> {
/// ```
#[must_use]
#[stable(feature = "panic_hooks", since = "1.10.0")]
#[rustc_const_unstable(feature = "const_location_fields", issue = "102911")]
#[rustc_const_stable(feature = "const_location_fields", since = "CURRENT_RUSTC_VERSION")]
#[inline]
pub const fn line(&self) -> u32 {
self.line
Expand All @@ -173,7 +173,7 @@ impl<'a> Location<'a> {
/// ```
#[must_use]
#[stable(feature = "panic_col", since = "1.25.0")]
#[rustc_const_unstable(feature = "const_location_fields", issue = "102911")]
#[rustc_const_stable(feature = "const_location_fields", since = "CURRENT_RUSTC_VERSION")]
#[inline]
pub const fn column(&self) -> u32 {
self.col
Expand Down
2 changes: 0 additions & 2 deletions library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#![feature(const_align_offset)]
#![feature(const_align_of_val_raw)]
#![feature(const_black_box)]
#![feature(const_caller_location)]
#![feature(const_cell_into_inner)]
#![feature(const_hash)]
#![feature(const_heap)]
Expand All @@ -22,7 +21,6 @@
#![feature(const_ptr_write)]
#![feature(const_trait_impl)]
#![feature(const_likely)]
#![feature(const_location_fields)]
#![feature(core_intrinsics)]
#![feature(core_io_borrowed_buf)]
#![feature(core_private_bignum)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//@ run-pass
//@ compile-flags: -Z unleash-the-miri-inside-of-you

#![feature(core_intrinsics, const_caller_location)]
#![feature(core_intrinsics)]

type L = &'static std::panic::Location<'static>;

Expand Down
12 changes: 5 additions & 7 deletions tests/ui/rfcs/rfc-2091-track-caller/const-caller-location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
//@ revisions: default mir-opt
//@[mir-opt] compile-flags: -Zmir-opt-level=4

#![feature(const_caller_location)]

use std::panic::Location;

const LOCATION: &Location = Location::caller();

const TRACKED: &Location = tracked();
#[track_caller]
const fn tracked() -> &'static Location <'static> {
const fn tracked() -> &'static Location<'static> {
Location::caller()
}

Expand All @@ -26,18 +24,18 @@ const fn contained() -> &'static Location<'static> {

fn main() {
assert_eq!(LOCATION.file(), file!());
assert_eq!(LOCATION.line(), 9);
assert_eq!(LOCATION.line(), 7);
assert_eq!(LOCATION.column(), 29);

assert_eq!(TRACKED.file(), file!());
assert_eq!(TRACKED.line(), 11);
assert_eq!(TRACKED.line(), 9);
assert_eq!(TRACKED.column(), 28);

assert_eq!(NESTED.file(), file!());
assert_eq!(NESTED.line(), 19);
assert_eq!(NESTED.line(), 17);
assert_eq!(NESTED.column(), 5);

assert_eq!(CONTAINED.file(), file!());
assert_eq!(CONTAINED.line(), 24);
assert_eq!(CONTAINED.line(), 22);
assert_eq!(CONTAINED.column(), 5);
}

0 comments on commit d324d6d

Please sign in to comment.