Skip to content

Commit

Permalink
Rollup merge of rust-lang#122291 - lilasta:stabilize_const_location_f…
Browse files Browse the repository at this point in the history
…ields, r=dtolnay

Stabilize `const_caller_location` and `const_location_fields`

Closes rust-lang#102911. Closes rust-lang#76156.

tests: [library/core/tests/panic/location.rs](https://github.com/rust-lang/rust/blob/3521a2f2f317cb978063842485c7d1bc86ec82b6/library/core/tests/panic/location.rs)

API:
```rust
// core::panic::location
impl Location {
    pub const fn caller() -> &'static Location<'static>;
    pub const fn file(&self) -> &str;
    pub const fn line(&self) -> u32;
    pub const fn column(&self) -> u32;
}
```
  • Loading branch information
matthiaskrgr committed Apr 6, 2024
2 parents 0b2cb6d + d324d6d commit 12c819c
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 @@ -1128,7 +1128,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 @@ -125,7 +125,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 @@ -11,7 +11,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 @@ -25,7 +24,6 @@
#![cfg_attr(not(bootstrap), feature(const_three_way_compare))]
#![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 12c819c

Please sign in to comment.