Skip to content

specified formatting not applied if format_args() is passed to println!() #97797

Open
@matthiaskrgr

Description

@matthiaskrgr

I tried this code:

use std::fmt;

struct A {}

impl fmt::Debug for A {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "1234567890")
    }
}

pub fn main() {
    println!("{:<.5}", "1234567890");
    let a = A {};
    println!("{:<.5}", format_args!("{:?}", a));
}

playground

I expected to see this happen:
I would expect both lines prints to print the same output.

Instead, this happened:
output is

12345
1234567890

and there is no warning that the second println! completely ignores the formatting directives :<.5 that I passed.

Meta

rustc --version --verbose:

rustc 1.63.0-nightly (a6b8c6954 2022-06-03)
binary: rustc
commit-hash: a6b8c6954829669a5c4fa320c3e6132edf04fcfc
commit-date: 2022-06-03
host: x86_64-unknown-linux-gnu
release: 1.63.0-nightly
LLVM version: 14.0.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-fmtArea: `core::fmt`C-bugCategory: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions