]> git.lizzy.rs Git - rust.git/commitdiff
Merge branch 'pr-482'
authorManish Goregaokar <manishsmail@gmail.com>
Mon, 7 Dec 2015 12:23:52 +0000 (07:23 -0500)
committerManish Goregaokar <manishsmail@gmail.com>
Mon, 7 Dec 2015 12:23:52 +0000 (07:23 -0500)
README.md
src/lib.rs
src/misc_early.rs [new file with mode: 0644]
src/mut_mut.rs
src/mut_reference.rs
src/open_options.rs
src/shadow.rs
src/utils.rs

index e19ab474c5e35b017e5cf4445df11d7f461f392b..7e8c60e78e5ad3195f411f59367c5536a8dc70db 100644 (file)
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@ A collection of lints to catch common mistakes and improve your Rust code.
 [Jump to usage instructions](#usage)
 
 ##Lints
-There are 81 lints included in this crate:
+There are 82 lints included in this crate:
 
 name                                                                                                     | default | meaning
 ---------------------------------------------------------------------------------------------------------|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@@ -81,6 +81,7 @@ name
 [unicode_not_nfc](https://github.com/Manishearth/rust-clippy/wiki#unicode_not_nfc)                       | allow   | using a unicode literal not in NFC normal form (see http://www.unicode.org/reports/tr15/ for further information)
 [unit_cmp](https://github.com/Manishearth/rust-clippy/wiki#unit_cmp)                                     | warn    | comparing unit values (which is always `true` or `false`, respectively)
 [unnecessary_mut_passed](https://github.com/Manishearth/rust-clippy/wiki#unnecessary_mut_passed)         | warn    | an argument is passed as a mutable reference although the function/method only demands an immutable reference
+[unneeded_field_pattern](https://github.com/Manishearth/rust-clippy/wiki#unneeded_field_pattern)         | warn    | Struct fields are bound to a wildcard instead of using `..`
 [unstable_as_mut_slice](https://github.com/Manishearth/rust-clippy/wiki#unstable_as_mut_slice)           | warn    | as_mut_slice is not stable and can be replaced by &mut v[..]see https://github.com/rust-lang/rust/issues/27729
 [unstable_as_slice](https://github.com/Manishearth/rust-clippy/wiki#unstable_as_slice)                   | warn    | as_slice is not stable and can be replaced by & v[..]see https://github.com/rust-lang/rust/issues/27729
 [unused_collect](https://github.com/Manishearth/rust-clippy/wiki#unused_collect)                         | warn    | `collect()`ing an iterator without using the result; this is usually better written as a for loop
index 9ead05b93b2f05c33a63960dba3bb6ed9d1d345d..64dfc24d1efa431442b48167f419c81a48020b2b 100644 (file)
@@ -65,6 +65,7 @@
 pub mod transmute;
 pub mod cyclomatic_complexity;
 pub mod escape;
+pub mod misc_early;
 
 mod reexport {
     pub use syntax::ast::{Name, Ident, NodeId};
@@ -118,6 +119,7 @@ pub fn plugin_registrar(reg: &mut Registry) {
     reg.register_late_lint_pass(box transmute::UselessTransmute);
     reg.register_late_lint_pass(box cyclomatic_complexity::CyclomaticComplexity::new(25));
     reg.register_late_lint_pass(box escape::EscapePass);
+    reg.register_early_lint_pass(box misc_early::MiscEarly);
 
     reg.register_lint_group("clippy_pedantic", vec![
         methods::OPTION_UNWRAP_USED,
@@ -181,6 +183,7 @@ pub fn plugin_registrar(reg: &mut Registry) {
         misc::MODULO_ONE,
         misc::REDUNDANT_PATTERN,
         misc::TOPLEVEL_REF_ARG,
+        misc_early::UNNEEDED_FIELD_PATTERN,
         mut_reference::UNNECESSARY_MUT_PASSED,
         mutex_atomic::MUTEX_ATOMIC,
         needless_bool::NEEDLESS_BOOL,
diff --git a/src/misc_early.rs b/src/misc_early.rs
new file mode 100644 (file)
index 0000000..8adff75
--- /dev/null
@@ -0,0 +1,48 @@
+//use rustc_front::hir::*;
+
+use rustc::lint::*;
+
+use syntax::ast::*;
+
+use utils::span_lint;
+
+declare_lint!(pub UNNEEDED_FIELD_PATTERN, Warn,
+              "Struct fields are bound to a wildcard instead of using `..`");
+
+#[derive(Copy, Clone)]
+pub struct MiscEarly;
+
+impl LintPass for MiscEarly {
+    fn get_lints(&self) -> LintArray {
+        lint_array!(UNNEEDED_FIELD_PATTERN)
+    }
+}
+
+impl EarlyLintPass for MiscEarly {
+    fn check_pat(&mut self, cx: &EarlyContext, pat: &Pat) {
+        if let PatStruct(_, ref pfields, _) = pat.node {
+            let mut wilds = 0;
+
+            for field in pfields {
+                if field.node.pat.node == PatWild {
+                    wilds += 1;
+                }
+            }
+            if !pfields.is_empty() && wilds == pfields.len() {
+                span_lint(cx, UNNEEDED_FIELD_PATTERN, pat.span,
+                          "All the struct fields are matched to a wildcard pattern, \
+                           consider using `..`.");
+                return;
+            }
+            if wilds > 0 {
+                for field in pfields {
+                    if field.node.pat.node == PatWild {
+                        span_lint(cx, UNNEEDED_FIELD_PATTERN, field.span,
+                                  "You matched a field with a wildcard pattern. \
+                                   Consider using `..` instead");
+                    }
+                }
+            }
+        }
+    }
+}
index c361ab2483120a2ab98eef5b28463ea3e4bac044..06f76479c590f310586a0f810680d3196308cbfa 100644 (file)
@@ -41,7 +41,7 @@ fn unwrap_addr(expr: &Expr) -> Option<&Expr> {
     unwrap_addr(expr).map_or((), |e| {
         unwrap_addr(e).map_or_else(
             || {
-                if let TyRef(_, TypeAndMut{ty: _, mutbl: MutMutable}) =
+                if let TyRef(_, TypeAndMut{mutbl: MutMutable, ..}) =
                     cx.tcx.expr_ty(e).sty {
                         span_lint(cx, MUT_MUT, expr.span,
                                   "this expression mutably borrows a mutable reference. \
index e9601e8650f1142395c57944df4bc702102ef7e8..8e089378929a7717c6987339ab27d0fadca5e24a 100644 (file)
@@ -58,8 +58,8 @@ fn check_arguments(cx: &LateContext, arguments: &[P<Expr>], type_definition: &Ty
         let parameters = &fn_type.sig.skip_binder().inputs;
         for (argument, parameter) in arguments.iter().zip(parameters.iter()) {
             match parameter.sty {
-                TypeVariants::TyRef(_, TypeAndMut {ty: _, mutbl: MutImmutable}) |
-                TypeVariants::TyRawPtr(TypeAndMut {ty: _, mutbl: MutImmutable}) => {
+                TypeVariants::TyRef(_, TypeAndMut {mutbl: MutImmutable, ..}) |
+                TypeVariants::TyRawPtr(TypeAndMut {mutbl: MutImmutable, ..}) => {
                     if let ExprAddrOf(MutMutable, _) = argument.node {
                         span_lint(cx, UNNECESSARY_MUT_PASSED, 
                                   argument.span, &format!("The function/method \"{}\" \
index 732852e168657571ab0ed4068c7c0df462ac3f08..dd375d58a6016fefc8a996148621eb33a79b4fb6 100644 (file)
@@ -58,7 +58,7 @@ fn get_open_options(cx: &LateContext, argument: &Expr, options: &mut Vec<(OpenOp
             
             let argument_option = match arguments[1].node {
                 ExprLit(ref span) => {
-                    if let Spanned {node: LitBool(lit), span: _} = **span {
+                    if let Spanned {node: LitBool(lit), ..} = **span {
                         if lit {Argument::True} else {Argument::False}
                     } else {
                         return; // The function is called with a literal
index 2c68667fc32d55bee77d1a8a2ca819d34b49700d..60197fcf9df539f8f3942435949a4d9f15b65457 100644 (file)
@@ -62,7 +62,7 @@ fn check_decl(cx: &LateContext, decl: &Decl, bindings: &mut Vec<(Name, Span)>) {
     if in_external_macro(cx, decl.span) { return; }
     if is_from_for_desugar(decl) { return; }
     if let DeclLocal(ref local) = decl.node {
-        let Local{ ref pat, ref ty, ref init, id: _, span, attrs: _ } = **local;
+        let Local{ ref pat, ref ty, ref init, span, .. } = **local;
         if let Some(ref t) = *ty { check_ty(cx, t, bindings) }
         if let Some(ref o) = *init {
             check_expr(cx, o, bindings);
index a959f7a8f6de782f2e018b2d27eb219dfde279e3..2b38403b63ad3607e2640a01fc88930f5ba2a31b 100644 (file)
@@ -167,8 +167,8 @@ pub fn get_item_name(cx: &LateContext, expr: &Expr) -> Option<Name> {
     let parent_id = cx.tcx.map.get_parent(expr.id);
     match cx.tcx.map.find(parent_id) {
         Some(NodeItem(&Item{ ref name, .. })) |
-        Some(NodeTraitItem(&TraitItem{ id: _, ref name, .. })) |
-        Some(NodeImplItem(&ImplItem{ id: _, ref name, .. })) => {
+        Some(NodeTraitItem(&TraitItem{ ref name, .. })) |
+        Some(NodeImplItem(&ImplItem{ ref name, .. })) => {
             Some(*name)
         }
         _ => None,