Skip to content

confusing error message when format strings end in % #158216

@jendrikw

Description

@jendrikw

Code

pub fn f(x: f64){
    println!("{x:>8.2}%", "foo");
}

Current output

error: argument never used
 --> src/lib.rs:2:27
  |
2 |     println!("{x:>8.2}%", "foo");
  |                           ^^^^^ argument never used
  |
note: format specifiers use curly braces, and the conversion specifier `
      ` is unknown or unsupported
 --> src/lib.rs:2:23
  |
2 |     println!("{x:>8.2}%", "foo");
  |                       ^^
  = note: printf formatting is not supported; see the documentation for `std::fmt`

Desired output

error: argument never used
 --> src/lib.rs:2:27
  |
2 |     println!("{x:>8.2}%", "foo");
  |                           ^^^^^ argument never used
  |

Rationale and extra context

I think it is quite common to format a float as a percentage.

The error message tries very hard to explain that rust doesn't use %d for users coming from C, but i think that diagnostics should be suppressed when the formatting string ends in "%", because it screws up the "note: " formatting (the empty string gets converted to a newline somewhere).

Other cases

Rust Version

rustc 1.96.0 (ac68faa20 2026-05-25)
binary: rustc
commit-hash: ac68faa20c58cbccd01ee7208bf3b6e93a7d7f96
commit-date: 2026-05-25
host: x86_64-unknown-linux-gnu
release: 1.96.0
LLVM version: 22.1.2

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    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