Skip to content

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

Closed

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

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Apr 19, 2026
  2. cclfmht commented on Apr 23, 2026

    @cclfmht
    Contributor

    Hi, I think this would be very helpful and I want to work on this issue.
    @rustbot claim

  3. added 3 commits that reference this issue on Apr 26, 2026
  4. added a commit that references this issue on Apr 26, 2026
  5. makai410 commented on Jun 25, 2026

    @makai410
    MemberAuthor

    Hi! @cclfmht Thanks for working on this! I was wondering what's the current status of this issue? Can we close this?

  6. cclfmht commented on Jun 25, 2026

    @cclfmht
    Contributor

    Hi! @cclfmht Thanks for working on this! I was wondering what's the current status of this issue? Can we close this?

    The issue has been implemented into rustc, so I think it's OK to close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions