Skip to content

Suggest enclosing {:?}/{:#?}/{} in "" when used as a format argument #155508

@makai410

Description

@makai410

Code

#[derive(Debug)]
enum UwU {
    QwQ, AwA, QAQ,
}

fn main() {
    println!({:?}, UwU::QwQ)
}

Current output

error: expected expression, found `:`
 --> src/main.rs:7:15
  |
7 |     println!({:?}, UwU::QwQ)
  |               ^ expected expression
  |
help: maybe write a path separator here
  |
7 |     println!({::?}, UwU::QwQ)
  |                +

error: format argument must be a string literal
 --> src/main.rs:7:14
  |
7 |     println!({:?}, UwU::QwQ)
  |              ^^^^
  |
help: you might be missing a string literal to format with
  |
7 |     println!("{} {}", {:?}, UwU::QwQ)
  |              ++++++++

error: could not compile `playground` (bin "playground") due to 2 previous errors

Desired output

error: expected expression, found `:`
 --> src/main.rs:7:15
  |
7 |     println!({:?}, UwU::QwQ)
  |               ^ expected expression
  |
help: maybe write a path separator here
  |
7 |     println!({::?}, UwU::QwQ)
  |                +

error: format argument must be a string literal
 --> src/main.rs:7:14
  |
7 |     println!({:?}, UwU::QwQ)
  |              ^^^^
  |
help: you might be missing a string literal to format with
  |
7 |     println!("{} {}", {:?}, UwU::QwQ)
  |              ++++++++
help: you might want to enclose `{:?}` in `""`
  |
7 |     println!("{:?}", UwU::QwQ)
  |              ++++++

error: could not compile `playground` (bin "playground") due to 2 previous errors

Rationale and extra context

I think this is most likely what users intended when writing something like {}, {:?} or {:#?} in this context, and usually the slight difference between "{:?}" and {:?} is easy to miss at a glance, so I think this suggestion could be helpful.

Other cases

Rust Version

playground 1.97.0-nightly

(2026-04-18 0febdbab2720dc0360cd)

Anything else?

No response

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions