From 4e3b9ed337d8088e58ad0aaad503000556b5684b Mon Sep 17 00:00:00 2001 From: woppopo Date: Fri, 26 Aug 2022 18:14:12 +0900 Subject: [PATCH 1/7] constify `Location` methods --- library/core/src/panic/location.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/library/core/src/panic/location.rs b/library/core/src/panic/location.rs index 8eefd9ff20db2..26a410365568c 100644 --- a/library/core/src/panic/location.rs +++ b/library/core/src/panic/location.rs @@ -123,8 +123,9 @@ impl<'a> Location<'a> { /// ``` #[must_use] #[stable(feature = "panic_hooks", since = "1.10.0")] + #[rustc_const_unstable(feature = "const_caller_location", issue = "76156")] #[inline] - pub fn file(&self) -> &str { + pub const fn file(&self) -> &str { self.file } @@ -147,8 +148,9 @@ impl<'a> Location<'a> { /// ``` #[must_use] #[stable(feature = "panic_hooks", since = "1.10.0")] + #[rustc_const_unstable(feature = "const_caller_location", issue = "76156")] #[inline] - pub fn line(&self) -> u32 { + pub const fn line(&self) -> u32 { self.line } @@ -171,8 +173,9 @@ impl<'a> Location<'a> { /// ``` #[must_use] #[stable(feature = "panic_col", since = "1.25.0")] + #[rustc_const_unstable(feature = "const_caller_location", issue = "76156")] #[inline] - pub fn column(&self) -> u32 { + pub const fn column(&self) -> u32 { self.col } } From 834cab724441b1c538f5a84b0fef8f0052714137 Mon Sep 17 00:00:00 2001 From: woppopo Date: Tue, 27 Sep 2022 19:09:32 +0000 Subject: [PATCH 2/7] Add test cases for const `Location` --- library/core/tests/lib.rs | 2 ++ library/core/tests/panic.rs | 1 + library/core/tests/panic/location.rs | 31 ++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 library/core/tests/panic.rs create mode 100644 library/core/tests/panic/location.rs diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 59510d3cc2ae0..548c1884ecd3f 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -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)] @@ -131,6 +132,7 @@ mod num; mod ops; mod option; mod pattern; +mod panic; mod pin; mod pin_macro; mod ptr; diff --git a/library/core/tests/panic.rs b/library/core/tests/panic.rs new file mode 100644 index 0000000000000..b7056bdf36ed7 --- /dev/null +++ b/library/core/tests/panic.rs @@ -0,0 +1 @@ +mod location; \ No newline at end of file diff --git a/library/core/tests/panic/location.rs b/library/core/tests/panic/location.rs new file mode 100644 index 0000000000000..ba066bfbc5398 --- /dev/null +++ b/library/core/tests/panic/location.rs @@ -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, "library/core/tests/panic/location.rs"); +} + +#[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, 39); +} \ No newline at end of file From 767a7771c72f37004be36e1656d4f7b724f495c6 Mon Sep 17 00:00:00 2001 From: woppopo Date: Tue, 27 Sep 2022 19:23:52 +0000 Subject: [PATCH 3/7] Add newlines --- library/core/tests/panic.rs | 2 +- library/core/tests/panic/location.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/tests/panic.rs b/library/core/tests/panic.rs index b7056bdf36ed7..24b6c56b35691 100644 --- a/library/core/tests/panic.rs +++ b/library/core/tests/panic.rs @@ -1 +1 @@ -mod location; \ No newline at end of file +mod location; diff --git a/library/core/tests/panic/location.rs b/library/core/tests/panic/location.rs index ba066bfbc5398..9d7b912458a7b 100644 --- a/library/core/tests/panic/location.rs +++ b/library/core/tests/panic/location.rs @@ -28,4 +28,4 @@ fn location_const_column() { const CALLER: &Location<'static> = Location::caller(); const COLUMN: u32 = CALLER.column(); assert_eq!(COLUMN, 39); -} \ No newline at end of file +} From ca55a881612d90554eedec9a8999db890f63cfc6 Mon Sep 17 00:00:00 2001 From: woppopo Date: Tue, 27 Sep 2022 19:40:53 +0000 Subject: [PATCH 4/7] Fix indent --- library/core/tests/panic/location.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/library/core/tests/panic/location.rs b/library/core/tests/panic/location.rs index 9d7b912458a7b..9df626a8326ce 100644 --- a/library/core/tests/panic/location.rs +++ b/library/core/tests/panic/location.rs @@ -5,27 +5,27 @@ use core::panic::Location; #[test] fn location_const_caller() { - const _CALLER_REFERENCE: &Location<'static> = Location::caller(); - const _CALLER: Location<'static> = *Location::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, "library/core/tests/panic/location.rs"); + const CALLER: &Location<'static> = Location::caller(); + const FILE: &str = CALLER.file(); + assert_eq!(FILE, "library/core/tests/panic/location.rs"); } #[test] fn location_const_line() { - const CALLER: &Location<'static> = Location::caller(); - const LINE: u32 = CALLER.line(); - assert_eq!(LINE, 21); + 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, 39); + const CALLER: &Location<'static> = Location::caller(); + const COLUMN: u32 = CALLER.column(); + assert_eq!(COLUMN, 40); } From 7b993885d0d998006a352dcf93cdd319ba36a6ab Mon Sep 17 00:00:00 2001 From: woppopo Date: Tue, 27 Sep 2022 19:53:58 +0000 Subject: [PATCH 5/7] Sort mod --- library/core/tests/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 548c1884ecd3f..7cf2c0dcefc98 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -131,8 +131,8 @@ mod nonzero; mod num; mod ops; mod option; -mod pattern; mod panic; +mod pattern; mod pin; mod pin_macro; mod ptr; From f0b8167a4e7150aa77a3da8072b1b019f2c52d5d Mon Sep 17 00:00:00 2001 From: woppopo Date: Sat, 8 Oct 2022 11:48:53 +0000 Subject: [PATCH 6/7] Fix test (location_const_file) --- library/core/tests/panic/location.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/tests/panic/location.rs b/library/core/tests/panic/location.rs index 9df626a8326ce..d20241d838001 100644 --- a/library/core/tests/panic/location.rs +++ b/library/core/tests/panic/location.rs @@ -13,7 +13,7 @@ fn location_const_caller() { fn location_const_file() { const CALLER: &Location<'static> = Location::caller(); const FILE: &str = CALLER.file(); - assert_eq!(FILE, "library/core/tests/panic/location.rs"); + assert_eq!(FILE, file!()); } #[test] From a53e3acca914a1f6897c451ba35636ee1f72c0e7 Mon Sep 17 00:00:00 2001 From: woppopo Date: Tue, 11 Oct 2022 06:40:37 +0000 Subject: [PATCH 7/7] Change tracking issue from #76156 to #102911 --- library/core/src/panic/location.rs | 6 +++--- library/core/tests/lib.rs | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/library/core/src/panic/location.rs b/library/core/src/panic/location.rs index 26a410365568c..6dcf23dde87c7 100644 --- a/library/core/src/panic/location.rs +++ b/library/core/src/panic/location.rs @@ -123,7 +123,7 @@ impl<'a> Location<'a> { /// ``` #[must_use] #[stable(feature = "panic_hooks", since = "1.10.0")] - #[rustc_const_unstable(feature = "const_caller_location", issue = "76156")] + #[rustc_const_unstable(feature = "const_location_fields", issue = "102911")] #[inline] pub const fn file(&self) -> &str { self.file @@ -148,7 +148,7 @@ impl<'a> Location<'a> { /// ``` #[must_use] #[stable(feature = "panic_hooks", since = "1.10.0")] - #[rustc_const_unstable(feature = "const_caller_location", issue = "76156")] + #[rustc_const_unstable(feature = "const_location_fields", issue = "102911")] #[inline] pub const fn line(&self) -> u32 { self.line @@ -173,7 +173,7 @@ impl<'a> Location<'a> { /// ``` #[must_use] #[stable(feature = "panic_col", since = "1.25.0")] - #[rustc_const_unstable(feature = "const_caller_location", issue = "76156")] + #[rustc_const_unstable(feature = "const_location_fields", issue = "102911")] #[inline] pub const fn column(&self) -> u32 { self.col diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 7cf2c0dcefc98..534f92d3d8ecb 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -21,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)]