@@ -34,7 +34,6 @@ declare_clippy_lint! {
34
34
/// let title = movie.title;
35
35
/// }
36
36
/// ```
37
- /// ```
38
37
#[ clippy:: version = "1.72.0" ]
39
38
pub MIN_IDENT_CHARS ,
40
39
restriction,
@@ -48,6 +47,17 @@ pub struct MinIdentChars {
48
47
pub min_ident_chars_threshold : u64 ,
49
48
}
50
49
50
+ impl MinIdentChars {
51
+ #[ expect( clippy:: cast_possible_truncation) ]
52
+ fn is_ident_too_short ( & self , cx : & LateContext < ' _ > , str : & str , span : Span ) -> bool {
53
+ !in_external_macro ( cx. sess ( ) , span)
54
+ && str. len ( ) <= self . min_ident_chars_threshold as usize
55
+ && !str. starts_with ( '_' )
56
+ && !str. is_empty ( )
57
+ && self . allowed_idents_below_min_chars . get ( & str. to_owned ( ) ) . is_none ( )
58
+ }
59
+ }
60
+
51
61
impl LateLintPass < ' _ > for MinIdentChars {
52
62
fn check_item ( & mut self , cx : & LateContext < ' _ > , item : & Item < ' _ > ) {
53
63
if self . min_ident_chars_threshold == 0 {
@@ -58,15 +68,10 @@ impl LateLintPass<'_> for MinIdentChars {
58
68
}
59
69
60
70
// This is necessary as `Node::Pat`s are not visited in `visit_id`. :/
61
- #[ expect( clippy:: cast_possible_truncation) ]
62
71
fn check_pat ( & mut self , cx : & LateContext < ' _ > , pat : & Pat < ' _ > ) {
63
72
if let PatKind :: Binding ( _, _, ident, ..) = pat. kind
64
73
&& let str = ident. as_str ( )
65
- && !in_external_macro ( cx. sess ( ) , ident. span )
66
- && str. len ( ) <= self . min_ident_chars_threshold as usize
67
- && !str. starts_with ( '_' )
68
- && !str. is_empty ( )
69
- && self . allowed_idents_below_min_chars . get ( & str. to_owned ( ) ) . is_none ( )
74
+ && self . is_ident_too_short ( cx, str, ident. span )
70
75
{
71
76
emit_min_ident_chars ( self , cx, str, ident. span ) ;
72
77
}
@@ -79,12 +84,11 @@ struct IdentVisitor<'cx, 'tcx> {
79
84
}
80
85
81
86
impl Visitor < ' _ > for IdentVisitor < ' _ , ' _ > {
82
- #[ expect( clippy:: cast_possible_truncation) ]
83
87
fn visit_id ( & mut self , hir_id : HirId ) {
84
88
let Self { conf, cx } = * self ;
85
- // Reimplementation of `find`, as it uses indexing, which can (and will in async functions) panic.
86
- // This should probably be fixed on the rustc side, this is just a temporary workaround.
87
- // FIXME: Remove me if/when this is fixed in rustc
89
+ // FIXME(#112534) Reimplementation of `find`, as it uses indexing, which can (and will in
90
+ // async functions, or really anything async) panic. This should probably be fixed on the
91
+ // rustc side, this is just a temporary workaround.
88
92
let node = if hir_id. local_id == ItemLocalId :: from_u32 ( 0 ) {
89
93
// In this case, we can just use `find`, `Owner`'s `node` field is private anyway so we can't
90
94
// reimplement it even if we wanted to
@@ -103,12 +107,7 @@ impl Visitor<'_> for IdentVisitor<'_, '_> {
103
107
} ;
104
108
105
109
let str = ident. as_str ( ) ;
106
- if !in_external_macro ( cx. sess ( ) , ident. span )
107
- && str. len ( ) <= conf. min_ident_chars_threshold as usize
108
- && !str. starts_with ( '_' )
109
- && !str. is_empty ( )
110
- && conf. allowed_idents_below_min_chars . get ( & str. to_owned ( ) ) . is_none ( )
111
- {
110
+ if conf. is_ident_too_short ( cx, str, ident. span ) {
112
111
if let Node :: Item ( item) = node && let ItemKind :: Use ( ..) = item. kind {
113
112
return ;
114
113
}
0 commit comments