]> 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/lifetimes.rs
src/misc_early.rs
src/utils.rs
tests/compile-fail/lifetimes.rs

index af4c3e80437cf98ad84db4e99d8b8c8283585be6..7e8c60e78e5ad3195f411f59367c5536a8dc70db 100644 (file)
--- a/README.md
+++ b/README.md
@@ -81,7 +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_binding](https://github.com/Manishearth/rust-clippy/wiki#unneeded_binding)                     | warn    | Type fields are bound when not necessary
+[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 abb3f0425df0dd0798e695e2c9dcbfb146ccfc36..64dfc24d1efa431442b48167f419c81a48020b2b 100644 (file)
@@ -183,7 +183,7 @@ pub fn plugin_registrar(reg: &mut Registry) {
         misc::MODULO_ONE,
         misc::REDUNDANT_PATTERN,
         misc::TOPLEVEL_REF_ARG,
-        misc_early::UNNEEDED_BINDING,
+        misc_early::UNNEEDED_FIELD_PATTERN,
         mut_reference::UNNECESSARY_MUT_PASSED,
         mutex_atomic::MUTEX_ATOMIC,
         needless_bool::NEEDLESS_BOOL,
index 97eb7fa67a354a0bf787736b44bf89a3b07fc3e8..16ba43766e0c06b1d28c6f97e9d156add6153b75 100644 (file)
@@ -3,7 +3,7 @@
 use rustc::lint::*;
 use syntax::codemap::Span;
 use rustc_front::intravisit::{Visitor, walk_ty, walk_ty_param_bound};
-use rustc::middle::def::Def::{DefTy, DefTrait};
+use rustc::middle::def::Def::{DefTy, DefTrait, DefStruct};
 use std::collections::HashSet;
 
 use utils::{in_external_macro, span_lint};
@@ -186,23 +186,22 @@ fn collect_anonymous_lifetimes(&mut self, path: &Path, ty: &Ty) {
         let last_path_segment = path.segments.last().map(|s| &s.parameters);
         if let Some(&AngleBracketedParameters(ref params)) = last_path_segment {
             if params.lifetimes.is_empty() {
-                let def = self.cx.tcx.def_map.borrow().get(&ty.id).map(|r| r.full_def());
-                match def {
-                    Some(DefTy(def_id, _)) => {
-                        if let Some(ty_def) = self.cx.tcx.adt_defs.borrow().get(&def_id) {
-                            let scheme = ty_def.type_scheme(self.cx.tcx);
-                            for _ in scheme.generics.regions.as_slice() {
+                if let Some(def) = self.cx.tcx.def_map.borrow().get(&ty.id).map(|r| r.full_def()) {
+                    match def {
+                        DefTy(def_id, _) | DefStruct(def_id) => {
+                            let type_scheme = self.cx.tcx.lookup_item_type(def_id);
+                            for _ in type_scheme.generics.regions.as_slice() {
                                 self.record(&None);
                             }
-                        }
-                    }
-                    Some(DefTrait(def_id)) => {
-                        let trait_def = self.cx.tcx.trait_defs.borrow()[&def_id];
-                        for _ in &trait_def.generics.regions {
-                            self.record(&None);
-                        }
+                        },
+                        DefTrait(def_id) => {
+                            let trait_def = self.cx.tcx.trait_defs.borrow()[&def_id];
+                            for _ in &trait_def.generics.regions {
+                                self.record(&None);
+                            }
+                        },
+                        _ => {}
                     }
-                    _ => {}
                 }
             }
         }
index 5bec753d3ebd36cd5f7f527f965bb897df012872..8adff7523371cd9e1504f1cf59537a29bc42ad56 100644 (file)
@@ -6,15 +6,15 @@
 
 use utils::span_lint;
 
-declare_lint!(pub UNNEEDED_BINDING, Warn,
-              "Type fields are bound when not necessary");
+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_BINDING)
+        lint_array!(UNNEEDED_FIELD_PATTERN)
     }
 }
 
@@ -29,7 +29,7 @@ fn check_pat(&mut self, cx: &EarlyContext, pat: &Pat) {
                 }
             }
             if !pfields.is_empty() && wilds == pfields.len() {
-                span_lint(cx, UNNEEDED_BINDING, pat.span,
+                span_lint(cx, UNNEEDED_FIELD_PATTERN, pat.span,
                           "All the struct fields are matched to a wildcard pattern, \
                            consider using `..`.");
                 return;
@@ -37,7 +37,7 @@ fn check_pat(&mut self, cx: &EarlyContext, pat: &Pat) {
             if wilds > 0 {
                 for field in pfields {
                     if field.node.pat.node == PatWild {
-                        span_lint(cx, UNNEEDED_BINDING, field.span,
+                        span_lint(cx, UNNEEDED_FIELD_PATTERN, field.span,
                                   "You matched a field with a wildcard pattern. \
                                    Consider using `..` instead");
                     }
index a602902d45fd910428be310c5241dbd9eac7dee1..2b38403b63ad3607e2640a01fc88930f5ba2a31b 100644 (file)
@@ -259,7 +259,6 @@ pub fn get_parent_expr<'c>(cx: &'c LateContext, e: &Expr) -> Option<&'c Expr> {
         if let NodeExpr(parent) = node { Some(parent) } else { None } )
 }
 
-#[allow(needless_lifetimes)] // workaround for https://github.com/Manishearth/rust-clippy/issues/417
 pub fn get_enclosing_block<'c>(cx: &'c LateContext, node: NodeId) -> Option<&'c Block> {
     let map = &cx.tcx.map;
     let enclosing_node = map.get_enclosing_scope(node)
index f5d95aacc9a3659786a0ee5046e8e82a90b4a005..040c3554e89907260bfbaaf22c54ca9aecb3760b 100644 (file)
@@ -106,5 +106,18 @@ fn trait_obj_elided<'a>(_arg: &'a WithLifetime) -> &'a str { unimplemented!() }
 // unambiguous if we elided the lifetime
 fn trait_obj_elided2<'a>(_arg: &'a Drop) -> &'a str { unimplemented!() } //~ERROR explicit lifetimes given
 
+type FooAlias<'a> = Foo<'a>;
+
+fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str { unimplemented!() } //~ERROR explicit lifetimes given
+
+// no warning, two input lifetimes (named on the reference, anonymous on Foo)
+fn alias_with_lt2<'a>(_foo: &'a FooAlias) -> &'a str { unimplemented!() }
+
+// no warning, two input lifetimes (anonymous on the reference, named on Foo)
+fn alias_with_lt3<'a>(_foo: &FooAlias<'a> ) -> &'a str { unimplemented!() }
+
+// no warning, two input lifetimes
+fn alias_with_lt4<'a, 'b>(_foo: &'a FooAlias<'b> ) -> &'a str { unimplemented!() }
+
 fn main() {
 }