Rewrite min_ident_chars#17362
Conversation
* 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.
|
r? @llogiq rustbot has assigned @llogiq. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Lintcheck changes for b1ba9dd
This comment will be updated if you push new changes |
| pub struct MinIdentChars { | ||
| allowed_idents_below_min_chars: FxHashSet<String>, | ||
| min_ident_chars_threshold: u64, | ||
| min_chars_threshold: u64, |
There was a problem hiding this comment.
Why not store it directly as a usize? It is always used as such.
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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 {}"?
There was a problem hiding this comment.
I thought the default was zero, but it turns out it's one. The message is probably better not emitted in this case.
Changes:
no_mangle).changelog: none