Skip to content

Commit ff83b3e

Browse files
committed
Fix non_expressive_names
1 parent 3a4ea45 commit ff83b3e

File tree

3 files changed

+55
-15
lines changed

3 files changed

+55
-15
lines changed

clippy_lints/src/non_expressive_names.rs

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -313,21 +313,32 @@ impl<'a, 'tcx> Visitor<'tcx> for SimilarNamesLocalVisitor<'a, 'tcx> {
313313
impl EarlyLintPass for NonExpressiveNames {
314314
fn check_item(&mut self, cx: &EarlyContext, item: &Item) {
315315
if let ItemKind::Fn(ref decl, _, _, _, _, ref blk) = item.node {
316-
if !attr::contains_name(&item.attrs, "test") {
317-
let mut visitor = SimilarNamesLocalVisitor {
318-
names: Vec::new(),
319-
cx: cx,
320-
lint: self,
321-
single_char_names: Vec::new(),
322-
};
323-
// initialize with function arguments
324-
for arg in &decl.inputs {
325-
SimilarNamesNameVisitor(&mut visitor).visit_pat(&arg.pat);
326-
}
327-
// walk all other bindings
328-
walk_block(&mut visitor, blk);
329-
}
316+
do_check(self, cx, &item.attrs, decl, blk);
317+
}
318+
}
319+
320+
fn check_impl_item(&mut self, cx: &EarlyContext, item: &ImplItem) {
321+
if let ImplItemKind::Method(ref sig, ref blk) = item.node {
322+
do_check(self, cx, &item.attrs, &sig.decl, blk);
323+
}
324+
}
325+
326+
}
327+
328+
fn do_check(lint: &mut NonExpressiveNames, cx: &EarlyContext, attrs: &[Attribute], decl: &FnDecl, blk: &Block) {
329+
if !attr::contains_name(attrs, "test") {
330+
let mut visitor = SimilarNamesLocalVisitor {
331+
names: Vec::new(),
332+
cx: cx,
333+
lint: lint,
334+
single_char_names: Vec::new(),
335+
};
336+
// initialize with function arguments
337+
for arg in &decl.inputs {
338+
SimilarNamesNameVisitor(&mut visitor).visit_pat(&arg.pat);
330339
}
340+
// walk all other bindings
341+
walk_block(&mut visitor, blk);
331342
}
332343
}
333344

tests/ui/non_expressive_names.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,14 @@ fn underscores_and_numbers() {
141141
let __1___2 = 12; //~ERROR Consider a more descriptive name
142142
let _1_ok= 1;
143143
}
144+
145+
struct Bar;
146+
147+
impl Bar {
148+
fn bar() {
149+
let _1 = 1;
150+
let ____1 = 1;
151+
let __1___2 = 12;
152+
let _1_ok= 1;
153+
}
154+
}

tests/ui/non_expressive_names.stderr

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,23 @@ error: consider choosing a more descriptive name
149149
141 | let __1___2 = 12; //~ERROR Consider a more descriptive name
150150
| ^^^^^^^
151151

152-
error: aborting due to 14 previous errors
152+
error: consider choosing a more descriptive name
153+
--> $DIR/non_expressive_names.rs:149:13
154+
|
155+
149 | let _1 = 1;
156+
| ^^
157+
158+
error: consider choosing a more descriptive name
159+
--> $DIR/non_expressive_names.rs:150:13
160+
|
161+
150 | let ____1 = 1;
162+
| ^^^^^
163+
164+
error: consider choosing a more descriptive name
165+
--> $DIR/non_expressive_names.rs:151:13
166+
|
167+
151 | let __1___2 = 12;
168+
| ^^^^^^^
169+
170+
error: aborting due to 17 previous errors
153171

0 commit comments

Comments
 (0)