Auto merge of #101030 - woppopo:const_location, r=scottmcm
Constify `Location` methods Tracking issue: #102911 Example: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=4789884c2f16ec4fb0e0405d86b794f5
This commit is contained in:
commit
bf15a9e526
@ -123,8 +123,9 @@ pub const fn caller() -> &'static Location<'static> {
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[stable(feature = "panic_hooks", since = "1.10.0")]
|
||||
#[rustc_const_unstable(feature = "const_location_fields", issue = "102911")]
|
||||
#[inline]
|
||||
pub fn file(&self) -> &str {
|
||||
pub const fn file(&self) -> &str {
|
||||
self.file
|
||||
}
|
||||
|
||||
@ -147,8 +148,9 @@ pub fn file(&self) -> &str {
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[stable(feature = "panic_hooks", since = "1.10.0")]
|
||||
#[rustc_const_unstable(feature = "const_location_fields", issue = "102911")]
|
||||
#[inline]
|
||||
pub fn line(&self) -> u32 {
|
||||
pub const fn line(&self) -> u32 {
|
||||
self.line
|
||||
}
|
||||
|
||||
@ -171,8 +173,9 @@ pub fn line(&self) -> u32 {
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[stable(feature = "panic_col", since = "1.25.0")]
|
||||
#[rustc_const_unstable(feature = "const_location_fields", issue = "102911")]
|
||||
#[inline]
|
||||
pub fn column(&self) -> u32 {
|
||||
pub const fn column(&self) -> u32 {
|
||||
self.col
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
#![feature(const_assume)]
|
||||
#![feature(const_black_box)]
|
||||
#![feature(const_bool_to_option)]
|
||||
#![feature(const_caller_location)]
|
||||
#![feature(const_cell_into_inner)]
|
||||
#![feature(const_convert)]
|
||||
#![feature(const_heap)]
|
||||
@ -20,6 +21,7 @@
|
||||
#![feature(const_ptr_write)]
|
||||
#![feature(const_trait_impl)]
|
||||
#![feature(const_likely)]
|
||||
#![feature(const_location_fields)]
|
||||
#![feature(core_intrinsics)]
|
||||
#![feature(core_private_bignum)]
|
||||
#![feature(core_private_diy_float)]
|
||||
@ -131,6 +133,7 @@
|
||||
mod num;
|
||||
mod ops;
|
||||
mod option;
|
||||
mod panic;
|
||||
mod pattern;
|
||||
mod pin;
|
||||
mod pin_macro;
|
||||
|
1
library/core/tests/panic.rs
Normal file
1
library/core/tests/panic.rs
Normal file
@ -0,0 +1 @@
|
||||
mod location;
|
31
library/core/tests/panic/location.rs
Normal file
31
library/core/tests/panic/location.rs
Normal file
@ -0,0 +1,31 @@
|
||||
use core::panic::Location;
|
||||
|
||||
// Note: Some of the following tests depend on the source location,
|
||||
// so please be careful when editing this file.
|
||||
|
||||
#[test]
|
||||
fn location_const_caller() {
|
||||
const _CALLER_REFERENCE: &Location<'static> = Location::caller();
|
||||
const _CALLER: Location<'static> = *Location::caller();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn location_const_file() {
|
||||
const CALLER: &Location<'static> = Location::caller();
|
||||
const FILE: &str = CALLER.file();
|
||||
assert_eq!(FILE, file!());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn location_const_line() {
|
||||
const CALLER: &Location<'static> = Location::caller();
|
||||
const LINE: u32 = CALLER.line();
|
||||
assert_eq!(LINE, 21);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn location_const_column() {
|
||||
const CALLER: &Location<'static> = Location::caller();
|
||||
const COLUMN: u32 = CALLER.column();
|
||||
assert_eq!(COLUMN, 40);
|
||||
}
|
Loading…
Reference in New Issue
Block a user