Skip to content

feat: add lint for ignored format precision on non-float types#16540

Open
nyurik wants to merge 1 commit intorust-lang:masterfrom
nyurik:unused_format_precision
Open

feat: add lint for ignored format precision on non-float types#16540
nyurik wants to merge 1 commit intorust-lang:masterfrom
nyurik:unused_format_precision

Conversation

@nyurik
Copy link
Copy Markdown
Contributor

@nyurik nyurik commented Feb 9, 2026

Introduce a new Clippy lint, unused_format_precision, which warns when a precision specifier is used in formatting macros for types where it has no effect, such as integers, bool, char, and pointers. This helps catch misleading or potentially buggy formatting code.

What it does

Detects use of format precision for standard non-float types where it has no effect
(integers, bool, char, pointers). Precision is meaningful for floats, str (truncation), or user types.

Why is this bad?

Specifying precision for these types is misleading and may indicate a bug. The value is ignored by the formatter.

Example

println!("{:.5}", 42);   // precision ignored for integers
println!("{:.3}", true); // precision ignored for bool
println!("{:.2}", 'x');  // precision ignored for char

TODO

  • I am not certain which of the lint groups applies best for this lint. All these seem somewhat appropriate:
    • correctness - code that is outright wrong or useless
    • suspicious - code that is most likely wrong or useless
    • complexity - code that does something simple but in a complex way

changelog: [unused_format_precision]: new lint to catch ignored format precision on non-float types

@rustbot rustbot added needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Feb 9, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Feb 9, 2026

r? @dswij

rustbot has assigned @dswij.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: 7 candidates
  • 7 candidates expanded to 7 candidates
  • Random selection from Jarcho, dswij, llogiq, samueltardieu

Copy link
Copy Markdown
Contributor

@ada4a ada4a left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a reviewer, but LGTM:)

View changes since this review

@rustbot

This comment has been minimized.

@nyurik nyurik force-pushed the unused_format_precision branch from 77edce2 to 3929a88 Compare February 23, 2026 05:30
@rustbot

This comment has been minimized.

@nyurik
Copy link
Copy Markdown
Contributor Author

nyurik commented Feb 23, 2026

Adding @llogiq to this issue because it may make sense to combine this functionality into unused_format_specs as discussed in #16542

r? @llogiq

@rustbot rustbot assigned llogiq and unassigned dswij Feb 23, 2026
@rustbot

This comment has been minimized.

@nyurik nyurik force-pushed the unused_format_precision branch from 3929a88 to c4c7ac8 Compare April 17, 2026 03:50
@rustbot

This comment has been minimized.

@nyurik nyurik force-pushed the unused_format_precision branch from c4c7ac8 to 2a01c10 Compare April 17, 2026 04:13
@rustbot

This comment has been minimized.

@nyurik nyurik force-pushed the unused_format_precision branch from 2a01c10 to cf2c1fd Compare April 19, 2026 08:45
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@nyurik nyurik force-pushed the unused_format_precision branch from cf2c1fd to 7cc6bed Compare April 24, 2026 13:46
@rustbot

This comment has been minimized.

@nyurik nyurik force-pushed the unused_format_precision branch from 7cc6bed to 913a981 Compare May 1, 2026 15:33
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 1, 2026

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

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

Labels

needs-fcp PRs that add, remove, or rename lints and need an FCP S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants