Skip to content

Commit 43dcc9b

Browse files
committed
Auto merge of #114962 - darklyspaced:debug, r=est31
adds a column number to `dbg!()` this would be very nice to have for a few reasons: 1. the rfc, when deciding not to add column numbers to macro, failed to acknowledge any potential ambiguous cases -- such as the one provided in #114910 -- which do exist 2. would be able to consistently and easily jump directly to the `dbg!()` regardless of the sutation 3. takes up, at a maximum, 3 characters of _horizontal_ screen space fixes #114910
2 parents 6a62871 + b05f211 commit 43dcc9b

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

library/std/src/macros.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -355,15 +355,15 @@ macro_rules! dbg {
355355
// `$val` expression could be a block (`{ .. }`), in which case the `eprintln!`
356356
// will be malformed.
357357
() => {
358-
$crate::eprintln!("[{}:{}]", $crate::file!(), $crate::line!())
358+
$crate::eprintln!("[{}:{}:{}]", $crate::file!(), $crate::line!(), $crate::column!())
359359
};
360360
($val:expr $(,)?) => {
361361
// Use of `match` here is intentional because it affects the lifetimes
362362
// of temporaries - https://stackoverflow.com/a/48732525/1063961
363363
match $val {
364364
tmp => {
365-
$crate::eprintln!("[{}:{}] {} = {:#?}",
366-
$crate::file!(), $crate::line!(), $crate::stringify!($val), &tmp);
365+
$crate::eprintln!("[{}:{}:{}] {} = {:#?}",
366+
$crate::file!(), $crate::line!(), $crate::column!(), $crate::stringify!($val), &tmp);
367367
tmp
368368
}
369369
}
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
[$DIR/dbg-macro-expected-behavior.rs:22] Unit = Unit
2-
[$DIR/dbg-macro-expected-behavior.rs:23] a = Unit
3-
[$DIR/dbg-macro-expected-behavior.rs:29] Point { x: 42, y: 24 } = Point {
1+
[$DIR/dbg-macro-expected-behavior.rs:22:19] Unit = Unit
2+
[$DIR/dbg-macro-expected-behavior.rs:23:19] a = Unit
3+
[$DIR/dbg-macro-expected-behavior.rs:29:24] Point { x: 42, y: 24 } = Point {
44
x: 42,
55
y: 24,
66
}
7-
[$DIR/dbg-macro-expected-behavior.rs:30] b = Point {
7+
[$DIR/dbg-macro-expected-behavior.rs:30:24] b = Point {
88
x: 42,
99
y: 24,
1010
}
11-
[$DIR/dbg-macro-expected-behavior.rs:38]
12-
[$DIR/dbg-macro-expected-behavior.rs:42] &a = NoCopy(
11+
[$DIR/dbg-macro-expected-behavior.rs:38:17]
12+
[$DIR/dbg-macro-expected-behavior.rs:42:27] &a = NoCopy(
1313
1337,
1414
)
15-
[$DIR/dbg-macro-expected-behavior.rs:42] dbg!(&a) = NoCopy(
15+
[$DIR/dbg-macro-expected-behavior.rs:42:22] dbg!(&a) = NoCopy(
1616
1337,
1717
)
18-
[$DIR/dbg-macro-expected-behavior.rs:47] f(&42) = 42
18+
[$DIR/dbg-macro-expected-behavior.rs:47:18] f(&42) = 42
1919
before
20-
[$DIR/dbg-macro-expected-behavior.rs:52] { foo += 1; eprintln!("before"); 7331 } = 7331
21-
[$DIR/dbg-macro-expected-behavior.rs:60] ("Yeah",) = (
20+
[$DIR/dbg-macro-expected-behavior.rs:52:22] { foo += 1; eprintln!("before"); 7331 } = 7331
21+
[$DIR/dbg-macro-expected-behavior.rs:60:27] ("Yeah",) = (
2222
"Yeah",
2323
)
24-
[$DIR/dbg-macro-expected-behavior.rs:63] 1 = 1
25-
[$DIR/dbg-macro-expected-behavior.rs:63] 2 = 2
26-
[$DIR/dbg-macro-expected-behavior.rs:67] 1u8 = 1
27-
[$DIR/dbg-macro-expected-behavior.rs:67] 2u32 = 2
28-
[$DIR/dbg-macro-expected-behavior.rs:67] "Yeah" = "Yeah"
24+
[$DIR/dbg-macro-expected-behavior.rs:63:29] 1 = 1
25+
[$DIR/dbg-macro-expected-behavior.rs:63:29] 2 = 2
26+
[$DIR/dbg-macro-expected-behavior.rs:67:37] 1u8 = 1
27+
[$DIR/dbg-macro-expected-behavior.rs:67:37] 2u32 = 2
28+
[$DIR/dbg-macro-expected-behavior.rs:67:37] "Yeah" = "Yeah"

0 commit comments

Comments
 (0)