]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/lifetimes.rs
Merge branch 'macro-use' into HEAD
[rust.git] / clippy_lints / src / lifetimes.rs
index 3fbbb4daee822e0c2fba66ed30aeb5857a462c8c..7762c4d1cb589a530aebda5b4c2689e5fcfa3647 100644 (file)
@@ -1,5 +1,7 @@
 use crate::reexport::*;
+use matches::matches;
 use rustc::lint::*;
+use rustc::{declare_lint, lint_array};
 use rustc::hir::def::Def;
 use rustc::hir::*;
 use rustc::hir::intravisit::*;
@@ -59,7 +61,7 @@ fn get_lints(&self) -> LintArray {
 
 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LifetimePass {
     fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
-        if let ItemFn(ref decl, _, ref generics, id) = item.node {
+        if let ItemKind::Fn(ref decl, _, ref generics, id) = item.node {
             check_fn_inner(cx, decl, Some(id), generics, item.span);
         }
     }
@@ -338,22 +340,29 @@ fn visit_lifetime(&mut self, lifetime: &'tcx Lifetime) {
 
     fn visit_ty(&mut self, ty: &'tcx Ty) {
         match ty.node {
-            TyRptr(ref lt, _) if lt.is_elided() => {
+            TyKind::Rptr(ref lt, _) if lt.is_elided() => {
                 self.record(&None);
             },
-            TyPath(ref path) => {
-                self.collect_anonymous_lifetimes(path, ty);
-            },
-            TyImplTraitExistential(exist_ty_id, _, _) => {
-                if let ItemExistential(ref exist_ty) = self.cx.tcx.hir.expect_item(exist_ty_id.id).node {
-                    for bound in &exist_ty.bounds {
-                        if let GenericBound::Outlives(_) = *bound {
-                            self.record(&None);
+            TyKind::Path(ref path) => {
+                if let QPath::Resolved(_, ref path) = *path {
+                    if let Def::Existential(def_id) = path.def {
+                        let node_id = self.cx.tcx.hir.as_local_node_id(def_id).unwrap();
+                        if let ItemKind::Existential(ref exist_ty) = self.cx.tcx.hir.expect_item(node_id).node {
+                            for bound in &exist_ty.bounds {
+                                if let GenericBound::Outlives(_) = *bound {
+                                    self.record(&None);
+                                }
+                            }
+                        } else {
+                            unreachable!()
                         }
+                        walk_ty(self, ty);
+                        return;
                     }
                 }
+                self.collect_anonymous_lifetimes(path, ty);
             }
-            TyTraitObject(ref bounds, ref lt) => {
+            TyKind::TraitObject(ref bounds, ref lt) => {
                 if !lt.is_elided() {
                     self.abort = true;
                 }