Skip to content

Check trait items in min_ident_chars #12294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions clippy_lints/src/min_ident_chars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use clippy_utils::diagnostics::span_lint;
use clippy_utils::is_from_proc_macro;
use rustc_data_structures::fx::FxHashSet;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit::{walk_item, Visitor};
use rustc_hir::{GenericParamKind, HirId, Item, ItemKind, ItemLocalId, Node, Pat, PatKind, UsePath};
use rustc_hir::intravisit::{walk_item, walk_trait_item, Visitor};
use rustc_hir::{GenericParamKind, HirId, Item, ItemKind, ItemLocalId, Node, Pat, PatKind, TraitItem, UsePath};
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_session::impl_lint_pass;
Expand Down Expand Up @@ -66,6 +66,14 @@ impl LateLintPass<'_> for MinIdentChars {
walk_item(&mut IdentVisitor { conf: self, cx }, item);
}

fn check_trait_item(&mut self, cx: &LateContext<'_>, item: &TraitItem<'_>) {
if self.min_ident_chars_threshold == 0 {
return;
}

walk_trait_item(&mut IdentVisitor { conf: self, cx }, item);
}

// This is necessary as `Node::Pat`s are not visited in `visit_id`. :/
fn check_pat(&mut self, cx: &LateContext<'_>, pat: &Pat<'_>) {
if let PatKind::Binding(_, _, ident, ..) = pat.kind
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/min_ident_chars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ struct Vec4 {

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

trait Trait {
const A: u32 = 0;
type A;
fn a() {}
}

fn main() {
// Allowed idents
let w = 1;
Expand Down
56 changes: 37 additions & 19 deletions tests/ui/min_ident_chars.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -68,112 +68,130 @@ LL | F,
| ^

error: this ident consists of a single char
--> $DIR/min_ident_chars.rs:51:9
--> $DIR/min_ident_chars.rs:41:11
|
LL | const A: u32 = 0;
| ^

error: this ident consists of a single char
--> $DIR/min_ident_chars.rs:42:10
|
LL | type A;
| ^

error: this ident consists of a single char
--> $DIR/min_ident_chars.rs:43:8
|
LL | fn a() {}
| ^

error: this ident consists of a single char
--> $DIR/min_ident_chars.rs:57:9
|
LL | let h = 1;
| ^

error: this ident consists of a single char
--> $DIR/min_ident_chars.rs:52:9
--> $DIR/min_ident_chars.rs:58:9
|
LL | let e = 2;
| ^

error: this ident consists of a single char
--> $DIR/min_ident_chars.rs:53:9
--> $DIR/min_ident_chars.rs:59:9
|
LL | let l = 3;
| ^

error: this ident consists of a single char
--> $DIR/min_ident_chars.rs:54:9
--> $DIR/min_ident_chars.rs:60:9
|
LL | let l = 4;
| ^

error: this ident consists of a single char
--> $DIR/min_ident_chars.rs:55:9
--> $DIR/min_ident_chars.rs:61:9
|
LL | let o = 6;
| ^

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

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

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

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

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

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

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

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

error: this ident consists of a single char
--> $DIR/min_ident_chars.rs:66:9
--> $DIR/min_ident_chars.rs:72:9
|
LL | let o = 1;
| ^

error: this ident consists of a single char
--> $DIR/min_ident_chars.rs:67:9
--> $DIR/min_ident_chars.rs:73:9
|
LL | let o = O { o };
| ^

error: this ident consists of a single char
--> $DIR/min_ident_chars.rs:81:4
--> $DIR/min_ident_chars.rs:87:4
|
LL | fn b() {}
| ^

error: this ident consists of a single char
--> $DIR/min_ident_chars.rs:82:21
--> $DIR/min_ident_chars.rs:88:21
|
LL | fn wrong_pythagoras(a: f32, b: f32) -> f32 {
| ^

error: this ident consists of a single char
--> $DIR/min_ident_chars.rs:82:29
--> $DIR/min_ident_chars.rs:88:29
|
LL | fn wrong_pythagoras(a: f32, b: f32) -> f32 {
| ^

error: aborting due to 29 previous errors
error: aborting due to 32 previous errors