Fix non_expressive_names
This commit is contained in:
parent
3a4ea45821
commit
ff83b3ecb9
@ -313,22 +313,33 @@ impl<'a, 'tcx> Visitor<'tcx> for SimilarNamesLocalVisitor<'a, 'tcx> {
|
||||
impl EarlyLintPass for NonExpressiveNames {
|
||||
fn check_item(&mut self, cx: &EarlyContext, item: &Item) {
|
||||
if let ItemKind::Fn(ref decl, _, _, _, _, ref blk) = item.node {
|
||||
if !attr::contains_name(&item.attrs, "test") {
|
||||
let mut visitor = SimilarNamesLocalVisitor {
|
||||
names: Vec::new(),
|
||||
cx: cx,
|
||||
lint: self,
|
||||
single_char_names: Vec::new(),
|
||||
};
|
||||
// initialize with function arguments
|
||||
for arg in &decl.inputs {
|
||||
SimilarNamesNameVisitor(&mut visitor).visit_pat(&arg.pat);
|
||||
}
|
||||
// walk all other bindings
|
||||
walk_block(&mut visitor, blk);
|
||||
}
|
||||
do_check(self, cx, &item.attrs, decl, blk);
|
||||
}
|
||||
}
|
||||
|
||||
fn check_impl_item(&mut self, cx: &EarlyContext, item: &ImplItem) {
|
||||
if let ImplItemKind::Method(ref sig, ref blk) = item.node {
|
||||
do_check(self, cx, &item.attrs, &sig.decl, blk);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fn do_check(lint: &mut NonExpressiveNames, cx: &EarlyContext, attrs: &[Attribute], decl: &FnDecl, blk: &Block) {
|
||||
if !attr::contains_name(attrs, "test") {
|
||||
let mut visitor = SimilarNamesLocalVisitor {
|
||||
names: Vec::new(),
|
||||
cx: cx,
|
||||
lint: lint,
|
||||
single_char_names: Vec::new(),
|
||||
};
|
||||
// initialize with function arguments
|
||||
for arg in &decl.inputs {
|
||||
SimilarNamesNameVisitor(&mut visitor).visit_pat(&arg.pat);
|
||||
}
|
||||
// walk all other bindings
|
||||
walk_block(&mut visitor, blk);
|
||||
}
|
||||
}
|
||||
|
||||
/// Precondition: `a_name.chars().count() < b_name.chars().count()`.
|
||||
|
@ -141,3 +141,14 @@ fn underscores_and_numbers() {
|
||||
let __1___2 = 12; //~ERROR Consider a more descriptive name
|
||||
let _1_ok= 1;
|
||||
}
|
||||
|
||||
struct Bar;
|
||||
|
||||
impl Bar {
|
||||
fn bar() {
|
||||
let _1 = 1;
|
||||
let ____1 = 1;
|
||||
let __1___2 = 12;
|
||||
let _1_ok= 1;
|
||||
}
|
||||
}
|
||||
|
@ -149,5 +149,23 @@ error: consider choosing a more descriptive name
|
||||
141 | let __1___2 = 12; //~ERROR Consider a more descriptive name
|
||||
| ^^^^^^^
|
||||
|
||||
error: aborting due to 14 previous errors
|
||||
error: consider choosing a more descriptive name
|
||||
--> $DIR/non_expressive_names.rs:149:13
|
||||
|
|
||||
149 | let _1 = 1;
|
||||
| ^^
|
||||
|
||||
error: consider choosing a more descriptive name
|
||||
--> $DIR/non_expressive_names.rs:150:13
|
||||
|
|
||||
150 | let ____1 = 1;
|
||||
| ^^^^^
|
||||
|
||||
error: consider choosing a more descriptive name
|
||||
--> $DIR/non_expressive_names.rs:151:13
|
||||
|
|
||||
151 | let __1___2 = 12;
|
||||
| ^^^^^^^
|
||||
|
||||
error: aborting due to 17 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user