Skip to content

Commit

Permalink
dbg macro: align line number to 4 digits
Browse files Browse the repository at this point in the history
  • Loading branch information
hellow554 committed Feb 26, 2019
1 parent ea43c3c commit a057c2d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
24 changes: 12 additions & 12 deletions src/libstd/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ macro_rules! eprintln {
/// ```rust
/// let a = 2;
/// let b = dbg!(a * 2) + 1;
/// // ^-- prints: [src/main.rs:2] a * 2 = 4
/// // ^-- prints: [src/main.rs:0002] a * 2 = 4
/// assert_eq!(b, 5);
/// ```
///
Expand Down Expand Up @@ -267,7 +267,7 @@ macro_rules! eprintln {
/// This prints to [stderr]:
///
/// ```text,ignore
/// [src/main.rs:4] n.checked_sub(4) = None
/// [src/main.rs:0004] n.checked_sub(4) = None
/// ```
///
/// Naive factorial implementation:
Expand All @@ -287,15 +287,15 @@ macro_rules! eprintln {
/// This prints to [stderr]:
///
/// ```text,ignore
/// [src/main.rs:3] n <= 1 = false
/// [src/main.rs:3] n <= 1 = false
/// [src/main.rs:3] n <= 1 = false
/// [src/main.rs:3] n <= 1 = true
/// [src/main.rs:4] 1 = 1
/// [src/main.rs:5] n * factorial(n - 1) = 2
/// [src/main.rs:5] n * factorial(n - 1) = 6
/// [src/main.rs:5] n * factorial(n - 1) = 24
/// [src/main.rs:11] factorial(4) = 24
/// [src/main.rs:0003] n <= 1 = false
/// [src/main.rs:0003] n <= 1 = false
/// [src/main.rs:0003] n <= 1 = false
/// [src/main.rs:0003] n <= 1 = true
/// [src/main.rs:0004] 1 = 1
/// [src/main.rs:0005] n * factorial(n - 1) = 2
/// [src/main.rs:0005] n * factorial(n - 1) = 6
/// [src/main.rs:0005] n * factorial(n - 1) = 24
/// [src/main.rs:0011] factorial(4) = 24
/// ```
///
/// The `dbg!(..)` macro moves the input:
Expand All @@ -319,7 +319,7 @@ macro_rules! dbg {
// of temporaries - https://stackoverflow.com/a/48732525/1063961
match $val {
tmp => {
eprintln!("[{}:{}] {} = {:#?}",
eprintln!("[{}:{:04}] {} = {:#?}",
file!(), line!(), stringify!($val), &tmp);
tmp
}
Expand Down
16 changes: 8 additions & 8 deletions src/test/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,31 @@ fn test() {

fn validate_stderr(stderr: Vec<String>) {
assert_eq!(stderr, &[
":21] Unit = Unit",
":0021] Unit = Unit",

":22] a = Unit",
":0022] a = Unit",

":28] Point{x: 42, y: 24,} = Point {",
":0028] Point{x: 42, y: 24,} = Point {",
" x: 42,",
" y: 24",
"}",

":29] b = Point {",
":0029] b = Point {",
" x: 42,",
" y: 24",
"}",

":38] &a = NoCopy(",
":0038] &a = NoCopy(",
" 1337",
")",

":38] dbg!(& a) = NoCopy(",
":0038] dbg!(& a) = NoCopy(",
" 1337",
")",
":43] f(&42) = 42",
":0043] f(&42) = 42",

"before",
":48] { foo += 1; eprintln!(\"before\"); 7331 } = 7331",
":0048] { foo += 1; eprintln!(\"before\"); 7331 } = 7331",
]);
}

Expand Down

0 comments on commit a057c2d

Please sign in to comment.