Skip to content

align in format! macro does not work with String as Debug #38259

Closed
@ghost

Description

Playground url: https://play.rust-lang.org/?gist=1ff6c43dc1da08b05ad13bc772de070e&version=nightly&backtrace=0

fn main() {
    println!("{0: <10} | {1: <10?} | {2: <10} | {3: <10}",
             "total",
             "blanks",
             "comments",
             "code");
    println!("{0: <10} | {1: <10?} | {2: <10} | {3: <10}", 0, 0, 0, 0);
    println!("{0: <10} | {1: <10} | {2: <10?} | {3: <10}", 77, 0, 3, 74);
    println!("{0: <10?} | {1: <10} | {2: <10} | {3: <10?}",
             460,
             0,
             10,
             1371);
}

Align works properly for other types.

rustc 1.15.0-nightly (daf8c1dfc 2016-12-05)
total      | "blanks" | comments   | code      
0          | 0          | 0          | 0         
77         | 0          | 3          | 74        
460        | 0          | 10         | 1371      
Program ended.

without ?

fn main() {
    println!("{0: <10} | {1: <10} | {2: <10} | {3: <10}",
             "total",
             "blanks",
             "comments",
             "code");
    println!("{0: <10} | {1: <10?} | {2: <10} | {3: <10}", 0, 0, 0, 0);
    println!("{0: <10} | {1: <10} | {2: <10?} | {3: <10}", 77, 0, 3, 74);
    println!("{0: <10?} | {1: <10} | {2: <10} | {3: <10?}",
             460,
             0,
             10,
             1371);
}
rustc 1.15.0-nightly (daf8c1dfc 2016-12-05)
total      | blanks     | comments   | code      
0          | 0          | 0          | 0         
77         | 0          | 3          | 74        
460        | 0          | 10         | 1371      
Program ended.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions