A collection of lints that give helpful tips to newbies and catch oversights.
##Lints
-There are 51 lints included in this crate:
+There are 52 lints included in this crate:
name | default | meaning
-----------------------------------------------------------------------------------------------------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[ptr_arg](https://github.com/Manishearth/rust-clippy/wiki#ptr_arg) | allow | fn arguments of the type `&Vec<...>` or `&String`, suggesting to use `&[...]` or `&str` instead, respectively
[range_step_by_zero](https://github.com/Manishearth/rust-clippy/wiki#range_step_by_zero) | warn | using Range::step_by(0), which produces an infinite iterator
[redundant_closure](https://github.com/Manishearth/rust-clippy/wiki#redundant_closure) | warn | using redundant closures, i.e. `|a| foo(a)` (which can be written as just `foo`)
+[redundant_pattern](https://github.com/Manishearth/rust-clippy/wiki#redundant_pattern) | warn | using `name @ _` in a pattern
[result_unwrap_used](https://github.com/Manishearth/rust-clippy/wiki#result_unwrap_used) | allow | using `Result.unwrap()`, which might be better handled
[shadow_reuse](https://github.com/Manishearth/rust-clippy/wiki#shadow_reuse) | allow | rebinding a name to an expression that re-uses the original value, e.g. `let x = x + 1`
[shadow_same](https://github.com/Manishearth/rust-clippy/wiki#shadow_same) | allow | rebinding a name to itself, e.g. `let mut x = &mut x`
reg.register_lint_pass(box types::CastPass as LintPassObject);
reg.register_lint_pass(box types::TypeComplexityPass as LintPassObject);
reg.register_lint_pass(box matches::MatchPass as LintPassObject);
+ reg.register_lint_pass(box misc::PatternPass as LintPassObject);
reg.register_lint_group("shadow", vec![
shadow::SHADOW_REUSE,
misc::FLOAT_CMP,
misc::MODULO_ONE,
misc::PRECEDENCE,
+ misc::REDUNDANT_PATTERN,
misc::TOPLEVEL_REF_ARG,
mut_mut::MUT_MUT,
needless_bool::NEEDLESS_BOOL,
}
false
}
+
+declare_lint!(pub REDUNDANT_PATTERN, Warn, "using `name @ _` in a pattern");
+
+#[derive(Copy,Clone)]
+pub struct PatternPass;
+
+impl LintPass for PatternPass {
+ fn get_lints(&self) -> LintArray {
+ lint_array!(REDUNDANT_PATTERN)
+ }
+
+ fn check_pat(&mut self, cx: &Context, pat: &Pat) {
+ if let PatIdent(_, ref ident, Some(ref right)) = pat.node {
+ if right.node == PatWild(PatWildSingle) {
+ cx.span_lint(REDUNDANT_PATTERN, pat.span, &format!(
+ "the `{} @ _` pattern can be written as just `{}`",
+ ident.node.name, ident.node.name));
+ }
+ }
+ }
+}
--- /dev/null
+#![feature(plugin)]
+#![plugin(clippy)]
+#![allow(unused)]
+#![deny(clippy)]
+
+fn main() {
+ let v = Some(true);
+ match v {
+ Some(x) => (),
+ y @ _ => (), //~ERROR the `y @ _` pattern can be written as just `y`
+ }
+ match v {
+ Some(x) => (),
+ y @ None => (), // no error
+ }
+}