Skip to content

Commit 3e47f16

Browse files
committed
Fix min_ident_chars: lint on single chars if method only declared not defined
1 parent e7f1499 commit 3e47f16

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

clippy_lints/src/min_ident_chars.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ impl LateLintPass<'_> for MinIdentChars {
8282
return;
8383
}
8484

85+
// If the function is declared but not defined in a trait, check_pat isn't called so we need to
86+
// check this explicitly
87+
if matches!(&item.kind, rustc_hir::TraitItemKind::Fn(_, _)) {
88+
let param_names = cx.tcx.fn_arg_idents(item.owner_id.to_def_id());
89+
for ident in param_names.iter().flatten() {
90+
emit_min_ident_chars(self, cx, ident.as_str(), ident.span);
91+
}
92+
}
93+
8594
walk_trait_item(&mut IdentVisitor { conf: self, cx }, item);
8695
}
8796

tests/ui/min_ident_chars.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl core::fmt::Debug for Issue13396 {
142142

143143
trait D {
144144
//~^ min_ident_chars
145-
fn f(g: i32) {}
145+
fn f(g: i32);
146146
//~^ min_ident_chars
147147
//~| min_ident_chars
148148
}

tests/ui/min_ident_chars.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,16 +206,16 @@ LL | trait D {
206206
| ^
207207

208208
error: this ident consists of a single char
209-
--> tests/ui/min_ident_chars.rs:145:8
209+
--> tests/ui/min_ident_chars.rs:145:10
210210
|
211-
LL | fn f(g: i32) {}
212-
| ^
211+
LL | fn f(g: i32);
212+
| ^
213213

214214
error: this ident consists of a single char
215-
--> tests/ui/min_ident_chars.rs:145:10
215+
--> tests/ui/min_ident_chars.rs:145:8
216216
|
217-
LL | fn f(g: i32) {}
218-
| ^
217+
LL | fn f(g: i32);
218+
| ^
219219

220220
error: aborting due to 36 previous errors
221221

0 commit comments

Comments
 (0)