Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

format!() sometimes ignores width while formatting Debug #87905

Closed
xpe opened this issue Aug 10, 2021 · 1 comment
Closed

format!() sometimes ignores width while formatting Debug #87905

xpe opened this issue Aug 10, 2021 · 1 comment
Labels
C-bug Category: This is a bug.

Comments

@xpe
Copy link

xpe commented Aug 10, 2021

I tried this code:

// https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=be8ab0a90dce4f0e53f964e41a4ae89e
fn main() {
    println!("'{:5?}'", 1);
    println!("'{:w$?}'", 2, w=5);
    println!("'{:5}'", "3");
    println!("'{:w$}'", "4", w=5);
    println!("'{:5?}'", "5");
    println!("'{:w$?}'", "6", w=5);
}

I expected to see this happen:

'    1'
'    2'
'3    '
'4    '
'"5"  '
'"6"  '

Instead, this happened:

'    1'
'    2'
'3    '
'4    '
'"5"'
'"6"'

To summarize, println!() / format!() ignores width while formatting Debug in some cases but not others.

Meta

rustc --version --verbose:

rustc 1.54.0 (a178d0322 2021-07-26)
binary: rustc
commit-hash: a178d0322ce20e33eac124758e837cbd80a6f633
commit-date: 2021-07-26
host: x86_64-apple-darwin
release: 1.54.0
LLVM version: 12.0.1

I confirmed the unexpected behavior also happens in beta and nightly:

See Also

@oli-obk
Copy link
Contributor

oli-obk commented Sep 17, 2021

closing as duplicate of #30164

@oli-obk oli-obk closed this as completed Sep 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants