Skip to content

Commit 3b36b37

Browse files
committed
Auto merge of rust-lang#12294 - sanxiyn:min_ident_chars-trait-item, r=Jarcho
Check trait items in `min_ident_chars` Fix rust-lang#12237. changelog: [`min_ident_chars`]: check trait items
2 parents 4fb9e12 + 2526765 commit 3b36b37

File tree

3 files changed

+53
-21
lines changed

3 files changed

+53
-21
lines changed

clippy_lints/src/min_ident_chars.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use clippy_utils::diagnostics::span_lint;
22
use clippy_utils::is_from_proc_macro;
33
use rustc_data_structures::fx::FxHashSet;
44
use rustc_hir::def::{DefKind, Res};
5-
use rustc_hir::intravisit::{walk_item, Visitor};
6-
use rustc_hir::{GenericParamKind, HirId, Item, ItemKind, ItemLocalId, Node, Pat, PatKind, UsePath};
5+
use rustc_hir::intravisit::{walk_item, walk_trait_item, Visitor};
6+
use rustc_hir::{GenericParamKind, HirId, Item, ItemKind, ItemLocalId, Node, Pat, PatKind, TraitItem, UsePath};
77
use rustc_lint::{LateContext, LateLintPass, LintContext};
88
use rustc_middle::lint::in_external_macro;
99
use rustc_session::impl_lint_pass;
@@ -66,6 +66,14 @@ impl LateLintPass<'_> for MinIdentChars {
6666
walk_item(&mut IdentVisitor { conf: self, cx }, item);
6767
}
6868

69+
fn check_trait_item(&mut self, cx: &LateContext<'_>, item: &TraitItem<'_>) {
70+
if self.min_ident_chars_threshold == 0 {
71+
return;
72+
}
73+
74+
walk_trait_item(&mut IdentVisitor { conf: self, cx }, item);
75+
}
76+
6977
// This is necessary as `Node::Pat`s are not visited in `visit_id`. :/
7078
fn check_pat(&mut self, cx: &LateContext<'_>, pat: &Pat<'_>) {
7179
if let PatKind::Binding(_, _, ident, ..) = pat.kind

tests/ui/min_ident_chars.rs

+6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ struct Vec4 {
3737

3838
struct AA<T, E>(T, E);
3939

40+
trait Trait {
41+
const A: u32 = 0;
42+
type A;
43+
fn a() {}
44+
}
45+
4046
fn main() {
4147
// Allowed idents
4248
let w = 1;

tests/ui/min_ident_chars.stderr

+37-19
Original file line numberDiff line numberDiff line change
@@ -68,112 +68,130 @@ LL | F,
6868
| ^
6969

7070
error: this ident consists of a single char
71-
--> $DIR/min_ident_chars.rs:51:9
71+
--> $DIR/min_ident_chars.rs:41:11
72+
|
73+
LL | const A: u32 = 0;
74+
| ^
75+
76+
error: this ident consists of a single char
77+
--> $DIR/min_ident_chars.rs:42:10
78+
|
79+
LL | type A;
80+
| ^
81+
82+
error: this ident consists of a single char
83+
--> $DIR/min_ident_chars.rs:43:8
84+
|
85+
LL | fn a() {}
86+
| ^
87+
88+
error: this ident consists of a single char
89+
--> $DIR/min_ident_chars.rs:57:9
7290
|
7391
LL | let h = 1;
7492
| ^
7593

7694
error: this ident consists of a single char
77-
--> $DIR/min_ident_chars.rs:52:9
95+
--> $DIR/min_ident_chars.rs:58:9
7896
|
7997
LL | let e = 2;
8098
| ^
8199

82100
error: this ident consists of a single char
83-
--> $DIR/min_ident_chars.rs:53:9
101+
--> $DIR/min_ident_chars.rs:59:9
84102
|
85103
LL | let l = 3;
86104
| ^
87105

88106
error: this ident consists of a single char
89-
--> $DIR/min_ident_chars.rs:54:9
107+
--> $DIR/min_ident_chars.rs:60:9
90108
|
91109
LL | let l = 4;
92110
| ^
93111

94112
error: this ident consists of a single char
95-
--> $DIR/min_ident_chars.rs:55:9
113+
--> $DIR/min_ident_chars.rs:61:9
96114
|
97115
LL | let o = 6;
98116
| ^
99117

100118
error: this ident consists of a single char
101-
--> $DIR/min_ident_chars.rs:59:10
119+
--> $DIR/min_ident_chars.rs:65:10
102120
|
103121
LL | let (h, o, w) = (1, 2, 3);
104122
| ^
105123

106124
error: this ident consists of a single char
107-
--> $DIR/min_ident_chars.rs:59:13
125+
--> $DIR/min_ident_chars.rs:65:13
108126
|
109127
LL | let (h, o, w) = (1, 2, 3);
110128
| ^
111129

112130
error: this ident consists of a single char
113-
--> $DIR/min_ident_chars.rs:60:10
131+
--> $DIR/min_ident_chars.rs:66:10
114132
|
115133
LL | for (a, (r, e)) in (0..1000).enumerate().enumerate() {}
116134
| ^
117135

118136
error: this ident consists of a single char
119-
--> $DIR/min_ident_chars.rs:60:14
137+
--> $DIR/min_ident_chars.rs:66:14
120138
|
121139
LL | for (a, (r, e)) in (0..1000).enumerate().enumerate() {}
122140
| ^
123141

124142
error: this ident consists of a single char
125-
--> $DIR/min_ident_chars.rs:60:17
143+
--> $DIR/min_ident_chars.rs:66:17
126144
|
127145
LL | for (a, (r, e)) in (0..1000).enumerate().enumerate() {}
128146
| ^
129147

130148
error: this ident consists of a single char
131-
--> $DIR/min_ident_chars.rs:62:16
149+
--> $DIR/min_ident_chars.rs:68:16
132150
|
133151
LL | while let (d, o, _i, n, g) = (true, true, false, false, true) {}
134152
| ^
135153

136154
error: this ident consists of a single char
137-
--> $DIR/min_ident_chars.rs:62:19
155+
--> $DIR/min_ident_chars.rs:68:19
138156
|
139157
LL | while let (d, o, _i, n, g) = (true, true, false, false, true) {}
140158
| ^
141159

142160
error: this ident consists of a single char
143-
--> $DIR/min_ident_chars.rs:62:29
161+
--> $DIR/min_ident_chars.rs:68:29
144162
|
145163
LL | while let (d, o, _i, n, g) = (true, true, false, false, true) {}
146164
| ^
147165

148166
error: this ident consists of a single char
149-
--> $DIR/min_ident_chars.rs:66:9
167+
--> $DIR/min_ident_chars.rs:72:9
150168
|
151169
LL | let o = 1;
152170
| ^
153171

154172
error: this ident consists of a single char
155-
--> $DIR/min_ident_chars.rs:67:9
173+
--> $DIR/min_ident_chars.rs:73:9
156174
|
157175
LL | let o = O { o };
158176
| ^
159177

160178
error: this ident consists of a single char
161-
--> $DIR/min_ident_chars.rs:81:4
179+
--> $DIR/min_ident_chars.rs:87:4
162180
|
163181
LL | fn b() {}
164182
| ^
165183

166184
error: this ident consists of a single char
167-
--> $DIR/min_ident_chars.rs:82:21
185+
--> $DIR/min_ident_chars.rs:88:21
168186
|
169187
LL | fn wrong_pythagoras(a: f32, b: f32) -> f32 {
170188
| ^
171189

172190
error: this ident consists of a single char
173-
--> $DIR/min_ident_chars.rs:82:29
191+
--> $DIR/min_ident_chars.rs:88:29
174192
|
175193
LL | fn wrong_pythagoras(a: f32, b: f32) -> f32 {
176194
| ^
177195

178-
error: aborting due to 29 previous errors
196+
error: aborting due to 32 previous errors
179197

0 commit comments

Comments
 (0)