mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 07:04:18 +00:00
Merge branch 'pr-890'
This commit is contained in:
commit
f6290b622c
4 changed files with 23 additions and 18 deletions
|
@ -129,7 +129,7 @@ name
|
|||
[shadow_same](https://github.com/Manishearth/rust-clippy/wiki#shadow_same) | allow | rebinding a name to itself, e.g. `let mut x = &mut x`
|
||||
[shadow_unrelated](https://github.com/Manishearth/rust-clippy/wiki#shadow_unrelated) | allow | The name is re-bound without even using the original value
|
||||
[should_implement_trait](https://github.com/Manishearth/rust-clippy/wiki#should_implement_trait) | warn | defining a method that should be implementing a std trait
|
||||
[similar_names](https://github.com/Manishearth/rust-clippy/wiki#similar_names) | warn | similarly named items and bindings
|
||||
[similar_names](https://github.com/Manishearth/rust-clippy/wiki#similar_names) | allow | similarly named items and bindings
|
||||
[single_char_pattern](https://github.com/Manishearth/rust-clippy/wiki#single_char_pattern) | warn | using a single-character str where a char could be used, e.g. `_.split("x")`
|
||||
[single_match](https://github.com/Manishearth/rust-clippy/wiki#single_match) | warn | a match statement with a single nontrivial arm (i.e, where the other arm is `_ => {}`) is used; recommends `if let` instead
|
||||
[single_match_else](https://github.com/Manishearth/rust-clippy/wiki#single_match_else) | allow | a match statement with a two arms where the second arm's pattern is a wildcard; recommends `if let` instead
|
||||
|
|
|
@ -266,6 +266,7 @@ pub fn plugin_registrar(reg: &mut Registry) {
|
|||
methods::WRONG_PUB_SELF_CONVENTION,
|
||||
mut_mut::MUT_MUT,
|
||||
mutex_atomic::MUTEX_INTEGER,
|
||||
non_expressive_names::SIMILAR_NAMES,
|
||||
print::PRINT_STDOUT,
|
||||
print::USE_DEBUG,
|
||||
shadow::SHADOW_REUSE,
|
||||
|
@ -368,7 +369,6 @@ pub fn plugin_registrar(reg: &mut Registry) {
|
|||
new_without_default::NEW_WITHOUT_DEFAULT,
|
||||
no_effect::NO_EFFECT,
|
||||
non_expressive_names::MANY_SINGLE_CHAR_NAMES,
|
||||
non_expressive_names::SIMILAR_NAMES,
|
||||
open_options::NONSENSICAL_OPEN_OPTIONS,
|
||||
overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL,
|
||||
panic::PANIC_PARAMS,
|
||||
|
|
|
@ -2,7 +2,8 @@ use rustc::lint::*;
|
|||
use syntax::codemap::Span;
|
||||
use syntax::parse::token::InternedString;
|
||||
use syntax::ast::*;
|
||||
use syntax::visit::{self, FnKind};
|
||||
use syntax::attr;
|
||||
use syntax::visit;
|
||||
use utils::{span_lint_and_then, in_macro, span_lint};
|
||||
|
||||
/// **What it does:** This lint warns about names that are very similar and thus confusing
|
||||
|
@ -14,7 +15,7 @@ use utils::{span_lint_and_then, in_macro, span_lint};
|
|||
/// **Example:** `checked_exp` and `checked_expr`
|
||||
declare_lint! {
|
||||
pub SIMILAR_NAMES,
|
||||
Warn,
|
||||
Allow,
|
||||
"similarly named items and bindings"
|
||||
}
|
||||
|
||||
|
@ -237,24 +238,28 @@ impl<'v, 'a, 'b> visit::Visitor<'v> for SimilarNamesLocalVisitor<'a, 'b> {
|
|||
});
|
||||
}
|
||||
fn visit_item(&mut self, _: &'v Item) {
|
||||
// do nothing
|
||||
// do not recurse into inner items
|
||||
}
|
||||
}
|
||||
|
||||
impl EarlyLintPass for NonExpressiveNames {
|
||||
fn check_fn(&mut self, cx: &EarlyContext, _: FnKind, decl: &FnDecl, blk: &Block, _: Span, _: NodeId) {
|
||||
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 {
|
||||
visit::walk_pat(&mut SimilarNamesNameVisitor(&mut visitor), &arg.pat);
|
||||
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 {
|
||||
visit::walk_pat(&mut SimilarNamesNameVisitor(&mut visitor), &arg.pat);
|
||||
}
|
||||
// walk all other bindings
|
||||
visit::walk_block(&mut visitor, blk);
|
||||
}
|
||||
}
|
||||
// walk all other bindings
|
||||
visit::walk_block(&mut visitor, blk);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#![feature(plugin)]
|
||||
#![plugin(clippy)]
|
||||
#![deny(clippy)]
|
||||
#![deny(clippy,similar_names)]
|
||||
//~^ NOTE: lint level defined here
|
||||
//~| NOTE: lint level defined here
|
||||
//~| NOTE: lint level defined here
|
||||
|
|
Loading…
Reference in a new issue