Skip to content

Rewrite min_ident_chars#17362

Open
Jarcho wants to merge 1 commit into
rust-lang:masterfrom
Jarcho:min_ident_chars
Open

Rewrite min_ident_chars#17362
Jarcho wants to merge 1 commit into
rust-lang:masterfrom
Jarcho:min_ident_chars

Conversation

@Jarcho

@Jarcho Jarcho commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Changes:

  • Directly access the identifiers instead of using a visitor.
  • Don't lint functions with linking related attributes (e.g. no_mangle).
  • Delay checking for external macros.
  • Check the length in code-points and not bytes.
  • Only walk up the HIR tree if we need to check for trait impl function parameters.
  • State the number of missing characters in the lint message.

changelog: none

* Directly access the identifiers instead of using a visitor.
* Don't lint functions with linking related attributes (e.g. `no_mangle`).
* Delay checking for external macros.
* Check the length in code-points and not bytes.
* Only walk up the HIR tree if we need to check for trait impl function parameters.
* State the number of missing characters in the lint message.
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 5, 2026
@rustbot

rustbot commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator

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: 8 candidates
  • 8 candidates expanded to 8 candidates
  • Random selection from llogiq, samueltardieu

@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

Lintcheck changes for b1ba9dd

Lint Added Removed Changed
clippy::min_ident_chars 9 202 15331

This comment will be updated if you push new changes

@Jarcho Jarcho added the G-performance-project Goal: For issues and PRs related to the Clippy Performance Project label Jul 6, 2026
pub struct MinIdentChars {
allowed_idents_below_min_chars: FxHashSet<String>,
min_ident_chars_threshold: u64,
min_chars_threshold: u64,

@samueltardieu samueltardieu Jul 6, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not store it directly as a usize? It is always used as such.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Really the config shouldn't be a u64. It's even one of those times where a u8 would be reasonable.

fn emit(&self, cx: &LateContext<'_>, ident: Ident, missing: NonZero<usize>) {
if !ident.span.in_external_macro(cx.tcx.sess.source_map()) && !is_from_proc_macro(cx, &ident) {
span_lint_and_then(cx, MIN_IDENT_CHARS, ident.span, self.lint_msg(missing), |diag| {
diag.note_once(format!("the configured threshold is {}", self.min_chars_threshold));

@samueltardieu samueltardieu Jul 6, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This note feels a bit weird when combined with "consists of only a single character". It looks like the lint only prevents one letter identifiers in this case (which it does), so it is not obvious which threshold this is about.

Maybe "the configured threshold for unsuitable identifier length is {}"?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I thought the default was zero, but it turns out it's one. The message is probably better not emitted in this case.

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

Labels

G-performance-project Goal: For issues and PRs related to the Clippy Performance Project 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.

4 participants