]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/misc.rs
update to the rust-PR that unblocks clippy
[rust.git] / clippy_lints / src / misc.rs
index 854a8d144d688abaf10c2a6fb98716686def926c..0680f6b41a16257185a23ace4b2dac94e7cc5c17 100644 (file)
@@ -10,7 +10,7 @@
 use syntax::codemap::{Span, Spanned, ExpnFormat};
 use utils::{
     get_item_name, get_parent_expr, implements_trait, in_macro, is_integer_literal, match_path,
-    snippet, span_lint, span_lint_and_then, walk_ptrs_ty
+    snippet, span_lint, span_lint_and_then, walk_ptrs_ty, last_path_segment
 };
 use utils::sugg::Sugg;
 
@@ -166,8 +166,8 @@ fn get_lints(&self) -> LintArray {
     }
 }
 
-impl LateLintPass for Pass {
-    fn check_fn(&mut self, cx: &LateContext, k: FnKind, decl: &FnDecl, _: &Expr, _: Span, _: NodeId) {
+impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
+    fn check_fn(&mut self, cx: &LateContext<'a, 'tcx>, k: FnKind<'tcx>, decl: &'tcx FnDecl, _: &'tcx Expr, _: Span, _: NodeId) {
         if let FnKind::Closure(_) = k {
             // Does not apply to closures
             return;
@@ -182,7 +182,7 @@ fn check_fn(&mut self, cx: &LateContext, k: FnKind, decl: &FnDecl, _: &Expr, _:
         }
     }
 
-    fn check_stmt(&mut self, cx: &LateContext, s: &Stmt) {
+    fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, s: &'tcx Stmt) {
         if_let_chain! {[
             let StmtDecl(ref d, _) = s.node,
             let DeclLocal(ref l) = d.node,
@@ -216,7 +216,7 @@ fn check_stmt(&mut self, cx: &LateContext, s: &Stmt) {
         }}
     }
 
-    fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
+    fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
         if let ExprBinary(ref cmp, ref left, ref right) = expr.node {
             let op = cmp.node;
             if op.is_comparison() {
@@ -263,22 +263,14 @@ fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
         }
         let binding = match expr.node {
             ExprPath(ref qpath) => {
-                if let QPath::Resolved(_, ref path) = *qpath {
-                    let binding = path.segments
-                        .last()
-                        .expect("path should always have at least one segment")
-                        .name
-                        .as_str();
-                    if binding.starts_with('_') &&
-                        !binding.starts_with("__") &&
-                        &*binding != "_result" && // FIXME: #944
-                        is_used(cx, expr) &&
-                        // don't lint if the declaration is in a macro
-                        non_macro_local(cx, &cx.tcx.tables().qpath_def(qpath, expr.id)) {
-                        Some(binding)
-                    } else {
-                        None
-                    }
+                let binding = last_path_segment(qpath).name.as_str();
+                if binding.starts_with('_') &&
+                    !binding.starts_with("__") &&
+                    &*binding != "_result" && // FIXME: #944
+                    is_used(cx, expr) &&
+                    // don't lint if the declaration is in a macro
+                    non_macro_local(cx, &cx.tcx.tables().qpath_def(qpath, expr.id)) {
+                    Some(binding)
                 } else {
                     None
                 }
@@ -302,7 +294,7 @@ fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
         }
     }
 
-    fn check_pat(&mut self, cx: &LateContext, pat: &Pat) {
+    fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {
         if let PatKind::Binding(_, _, ref ident, Some(ref right)) = pat.node {
             if right.node == PatKind::Wild {
                 span_lint(cx,
@@ -448,9 +440,7 @@ fn in_attributes_expansion(cx: &LateContext, expr: &Expr) -> bool {
 fn non_macro_local(cx: &LateContext, def: &def::Def) -> bool {
     match *def {
         def::Def::Local(id) | def::Def::Upvar(id, _, _) => {
-            let id = cx.tcx.map.as_local_node_id(id).expect("That DefId should be valid");
-
-            if let Some(span) = cx.tcx.map.opt_span(id) {
+            if let Some(span) = cx.tcx.map.span_if_local(id) {
                 !in_macro(cx, span)
             } else {
                 true