Inconsistent format string support for binary and hex representations of arrays
Open
Nobody has claimed this yet.
A-diagnostics
A-fmt
C-bug
D-papercut
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
fn main() {
println!("{:02x?}", [10, 11, 12]);
println!("{:08b?}", [10, 11, 12]);
}
I expected to see this happen:
It prints the given arrays in hexadecimal and in binary.
Instead, this happened:
Hexadecimal works if you comment out the binary line, but binary doesn't work.
Meta
rustc --version --verbose:
rustc 1.74.1 (a28077b28 2023-12-04)
binary: rustc
commit-hash: a28077b28a02b92985b3a3faecf92813155f1ea1
commit-date: 2023-12-04
host: x86_64-unknown-linux-gnu
release: 1.74.1
LLVM version: 17.0.4
rustc 1.75.0-beta.7 (b216e7b0e 2023-12-16)
binary: rustc
commit-hash: b216e7b0e7a2bdf11300a21a614dac6be3e99c5b
commit-date: 2023-12-16
host: x86_64-unknown-linux-gnu
release: 1.75.0-beta.7
LLVM version: 17.0.6
rustc 1.76.0-nightly (3f28fe133 2023-12-18)
binary: rustc
commit-hash: 3f28fe133475ec5faf3413b556bf3cfb0d51336c
commit-date: 2023-12-18
host: x86_64-unknown-linux-gnu
release: 1.76.0-nightly
LLVM version: 17.0.6
Compiling bug v0.1.0 (/home/chaitrex/dev/bug)
error: invalid format string: expected `'}'`, found `'?'`
--> src/main.rs:3:20
|
3 | println!("{:08b?}", [10, 20, 30]);
| - ^ expected `'}'` in format string
| |
| because of this opening brace
|
= note: if you intended to print `{`, you can escape it using `{{`
error: could not compile `bug` (bin "bug") due to previous error
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the println! examples in src/main.rs, comparing the accepted hexadecimal format with the rejected binary format. Trace rustc's format-string handling for {:08b?}; done means both array representations compile and print as expected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100