forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#101030 - woppopo:const_location, r=scottmcm
Constify `Location` methods Tracking issue: rust-lang#102911 Example: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=4789884c2f16ec4fb0e0405d86b794f5
- Loading branch information
Showing
4 changed files
with
41 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mod location; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |