Skip to content

Commit 72e126f

Browse files
authored
Unrolled build for #142373
Rollup merge of #142373 - m-ou-se:debug-for-location, r=tgross35 Fix Debug for Location Fixes #142279
2 parents d9ca9bd + 5ac1cd9 commit 72e126f

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

library/core/src/panic/location.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::fmt;
3030
/// Files are compared as strings, not `Path`, which could be unexpected.
3131
/// See [`Location::file`]'s documentation for more discussion.
3232
#[lang = "panic_location"]
33-
#[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
33+
#[derive(Copy, Clone, Eq, Hash, Ord, PartialEq, PartialOrd)]
3434
#[stable(feature = "panic_hooks", since = "1.10.0")]
3535
pub struct Location<'a> {
3636
// Note: this filename will have exactly one nul byte at its end, but otherwise
@@ -43,6 +43,17 @@ pub struct Location<'a> {
4343
col: u32,
4444
}
4545

46+
#[stable(feature = "panic_hooks", since = "1.10.0")]
47+
impl fmt::Debug for Location<'_> {
48+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
49+
f.debug_struct("Location")
50+
.field("file", &self.file())
51+
.field("line", &self.line)
52+
.field("column", &self.col)
53+
.finish()
54+
}
55+
}
56+
4657
impl<'a> Location<'a> {
4758
/// Returns the source location of the caller of this function. If that function's caller is
4859
/// annotated then its call location will be returned, and so on up the stack to the first call

library/coretests/tests/panic/location.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,11 @@ fn location_const_column() {
2929
const COLUMN: u32 = CALLER.column();
3030
assert_eq!(COLUMN, 40);
3131
}
32+
33+
#[test]
34+
fn location_debug() {
35+
let f = format!("{:?}", Location::caller());
36+
assert!(f.contains(&format!("{:?}", file!())));
37+
assert!(f.contains("35"));
38+
assert!(f.contains("29"));
39+
}

0 commit comments

Comments
 (0)