Skip to content

feat: make unused_format_specs catch width issues#16542

Merged
llogiq merged 1 commit intorust-lang:masterfrom
nyurik:format_width_ignored
Apr 24, 2026
Merged

feat: make unused_format_specs catch width issues#16542
llogiq merged 1 commit intorust-lang:masterfrom
nyurik:format_width_ignored

Conversation

@nyurik
Copy link
Copy Markdown
Contributor

@nyurik nyurik commented Feb 9, 2026

implements #15039

Improve [unused_format_specs] lint to detect format width that is below the minimum output size for certain format traits (e.g. {:#02x} outputs "0x1", so width 2 is ignored). The lint suggests removing the width or increasing it above the minimum.

error: format width has no effect on the output for this format trait
  --> tests/ui/unused_format_specs_width.rs:9:15
   |
LL |     println!("{:#02X}", 1u8);
   |               ^^^^^^^
   |
   = help: consider removing the width or increasing it to at least 4
   = note: `-D clippy::unused-format-specs` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(clippy::unused_format_specs)]`

changelog: [unused_format_specs]: detect format width below minimum output size for #x/#o/#b, exponent, and pointer

@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? @llogiq

rustbot has assigned @llogiq.
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

@oscargus
Copy link
Copy Markdown

increasing it above 3 so increasing it to at least 4? Maybe the latter is more clear? (Or maybe it should be at least 3?)

@nyurik nyurik force-pushed the format_width_ignored branch from de64518 to 0ec3cda Compare February 19, 2026 17:50
@rustbot

This comment has been minimized.

@nyurik
Copy link
Copy Markdown
Contributor Author

nyurik commented Feb 19, 2026

Thanks, fixed

@nyurik nyurik force-pushed the format_width_ignored branch from 0ec3cda to c186148 Compare February 19, 2026 18:00
@llogiq llogiq changed the title feat: add format_width_ignored lint feat: add useless_format_width lint Feb 22, 2026
@llogiq
Copy link
Copy Markdown
Contributor

llogiq commented Feb 22, 2026

I think adding this to the unused_format_specs lint would be acceptable. I doubt that anyone wants one but not the other.

@nyurik nyurik force-pushed the format_width_ignored branch from c186148 to f37caa7 Compare February 23, 2026 06:00
@rustbot

This comment has been minimized.

@nyurik nyurik changed the title feat: add useless_format_width lint feat: make unused_format_specs catch width issues Feb 23, 2026
@nyurik
Copy link
Copy Markdown
Contributor Author

nyurik commented Feb 23, 2026

@llogiq i modified it to be part of unused_format_specs. Note that I also made #16540 - which catches similar issue, and it may make sense to also make part of this lint. What do you think?

@rustbot

This comment has been minimized.

@nyurik nyurik force-pushed the format_width_ignored branch from f37caa7 to 1565ae2 Compare April 17, 2026 03:56
@rustbot

This comment has been minimized.

@nyurik
Copy link
Copy Markdown
Contributor Author

nyurik commented Apr 17, 2026

r? @samueltardieu

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 17, 2026

Error: Parsing assign command in comment failed: ...'' | error: specify user to assign to at >| ''...

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip.

@rustbot rustbot assigned samueltardieu and unassigned llogiq Apr 17, 2026
@rustbot

This comment has been minimized.

Warn when a format width is less than the minimum output size for the
format trait (e.g. `{:#02x}` yields "0x1", so width 2 is ignored).
Help suggests removing the width or increasing it above the minimum.
@nyurik nyurik force-pushed the format_width_ignored branch from 1565ae2 to 10eb2e7 Compare April 19, 2026 08:41
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 19, 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.

@nyurik
Copy link
Copy Markdown
Contributor Author

nyurik commented Apr 21, 2026

@llogiq friendly ping, or do you want someone else to review it?
cc: @samueltardieu

@samueltardieu
Copy link
Copy Markdown
Member

r? @samueltardieu

Please don't target me specifically unless I have manifested an explicit and clear interest in a particular PR. Moreover, I am out of rotation for around two weeks.

r? clippy

@rustbot rustbot assigned ada4a and unassigned samueltardieu Apr 21, 2026
Copy link
Copy Markdown
Contributor

@llogiq llogiq left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thank you!

View changes since this review

@llogiq llogiq added this pull request to the merge queue Apr 24, 2026
Merged via the queue into rust-lang:master with commit 33b28c6 Apr 24, 2026
11 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Apr 24, 2026
@nyurik nyurik deleted the format_width_ignored branch April 24, 2026 13:45
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants