]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/utils/internal_lints.rs
Fix build
[rust.git] / clippy_lints / src / utils / internal_lints.rs
index cf9e90d62bd4fa2e2760a90d6293f0025350d7a0..226817c8e51f0f140835f9c3f2fb09926b303cd6 100644 (file)
@@ -1,11 +1,13 @@
 use rustc::lint::*;
+use rustc::{declare_lint, lint_array};
 use rustc::hir::*;
-use rustc::hir::intravisit::{Visitor, walk_expr, NestedVisitorMap};
-use utils::{paths, match_path, span_lint};
-use syntax::symbol::InternedString;
-use syntax::ast::{Name, NodeId, ItemKind, Crate as AstCrate};
+use rustc::hir;
+use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
+use crate::utils::{match_qpath, paths, span_lint};
+use syntax::symbol::LocalInternedString;
+use syntax::ast::{Crate as AstCrate, ItemKind, Name};
 use syntax::codemap::Span;
-use std::collections::{HashSet, HashMap};
+use std::collections::{HashMap, HashSet};
 
 
 /// **What it does:** Checks for various things we like to keep tidy in clippy.
@@ -15,9 +17,9 @@
 /// **Known problems:** None.
 ///
 /// **Example:** Wrong ordering of the util::paths constants.
-declare_lint! {
+declare_clippy_lint! {
     pub CLIPPY_LINTS_INTERNAL,
-    Allow,
+    internal,
     "various things that will negatively affect your clippy experience"
 }
 
@@ -45,9 +47,9 @@
 ///     }
 /// }
 /// ```
-declare_lint! {
+declare_clippy_lint! {
     pub LINT_WITHOUT_LINT_PASS,
-    Warn,
+    internal,
     "declaring a lint without associating it in a LintPass"
 }
 
@@ -62,21 +64,32 @@ fn get_lints(&self) -> LintArray {
 }
 
 impl EarlyLintPass for Clippy {
-    fn check_crate(&mut self, cx: &EarlyContext, krate: &AstCrate) {
-        if let Some(utils) = krate.module.items.iter().find(|item| item.ident.name == "utils") {
+    fn check_crate(&mut self, cx: &EarlyContext<'_>, krate: &AstCrate) {
+        if let Some(utils) = krate
+            .module
+            .items
+            .iter()
+            .find(|item| item.ident.name == "utils")
+        {
             if let ItemKind::Mod(ref utils_mod) = utils.node {
-                if let Some(paths) = utils_mod.items.iter().find(|item| item.ident.name == "paths") {
+                if let Some(paths) = utils_mod
+                    .items
+                    .iter()
+                    .find(|item| item.ident.name == "paths")
+                {
                     if let ItemKind::Mod(ref paths_mod) = paths.node {
-                        let mut last_name: Option<InternedString> = None;
+                        let mut last_name: Option<LocalInternedString> = None;
                         for item in &paths_mod.items {
-                            let name = item.ident.name.as_str();
+                            let name = item.ident.as_str();
                             if let Some(ref last_name) = last_name {
                                 if **last_name > *name {
-                                    span_lint(cx,
-                                              CLIPPY_LINTS_INTERNAL,
-                                              item.span,
-                                              "this constant should be before the previous constant due to lexical \
-                                               ordering");
+                                    span_lint(
+                                        cx,
+                                        CLIPPY_LINTS_INTERNAL,
+                                        item.span,
+                                        "this constant should be before the previous constant due to lexical \
+                                         ordering",
+                                    );
                                 }
                             }
                             last_name = Some(name);
@@ -106,15 +119,17 @@ fn get_lints(&self) -> LintArray {
 
 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LintWithoutLintPass {
     fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
-        if let ItemStatic(ref ty, MutImmutable, ref expr) = item.node {
+        if let hir::ItemKind::Static(ref ty, MutImmutable, body_id) = item.node {
             if is_lint_ref_type(ty) {
                 self.declared_lints.insert(item.name, item.span);
-            } else if is_lint_array_type(ty) && item.vis == Visibility::Inherited && item.name == "ARRAY" {
-                let mut collector = LintCollector {
-                    output: &mut self.registered_lints,
-                    cx: cx,
-                };
-                collector.visit_expr(expr);
+            } else if is_lint_array_type(ty) && item.name == "ARRAY" {
+                if let VisibilityKind::Inherited = item.vis.node {
+                    let mut collector = LintCollector {
+                        output: &mut self.registered_lints,
+                        cx,
+                    };
+                    collector.visit_expr(&cx.tcx.hir.body(body_id).value);
+                }
             }
         }
     }
@@ -128,13 +143,20 @@ fn check_crate_post(&mut self, cx: &LateContext<'a, 'tcx>, _: &'tcx Crate) {
             // not able to capture the error.
             // Therefore, we need to climb the macro expansion tree and find the
             // actual span that invoked `declare_lint!`:
-            let lint_span = cx.sess().codemap().source_callsite(lint_span);
+            let lint_span = lint_span
+                .ctxt()
+                .outer()
+                .expn_info()
+                .map(|ei| ei.call_site)
+                .expect("unable to get call_site");
 
             if !self.registered_lints.contains(lint_name) {
-                span_lint(cx,
-                          LINT_WITHOUT_LINT_PASS,
-                          lint_span,
-                          &format!("the lint `{}` is not added to any `LintPass`", lint_name));
+                span_lint(
+                    cx,
+                    LINT_WITHOUT_LINT_PASS,
+                    lint_span,
+                    &format!("the lint `{}` is not added to any `LintPass`", lint_name),
+                );
             }
         }
     }
@@ -142,9 +164,16 @@ fn check_crate_post(&mut self, cx: &LateContext<'a, 'tcx>, _: &'tcx Crate) {
 
 
 fn is_lint_ref_type(ty: &Ty) -> bool {
-    if let TyRptr(Some(_), MutTy { ty: ref inner, mutbl: MutImmutable }) = ty.node {
-        if let TyPath(ref path) = inner.node {
-            return match_path(path, &paths::LINT);
+    if let TyKind::Rptr(
+        _,
+        MutTy {
+            ty: ref inner,
+            mutbl: MutImmutable,
+        },
+    ) = ty.node
+    {
+        if let TyKind::Path(ref path) = inner.node {
+            return match_qpath(path, &paths::LINT);
         }
     }
     false
@@ -152,8 +181,8 @@ fn is_lint_ref_type(ty: &Ty) -> bool {
 
 
 fn is_lint_array_type(ty: &Ty) -> bool {
-    if let TyPath(ref path) = ty.node {
-        match_path(path, &paths::LINT_ARRAY)
+    if let TyKind::Path(ref path) = ty.node {
+        match_qpath(path, &paths::LINT_ARRAY)
     } else {
         false
     }
@@ -169,12 +198,12 @@ fn visit_expr(&mut self, expr: &'tcx Expr) {
         walk_expr(self, expr);
     }
 
-    fn visit_path(&mut self, path: &'tcx Path, _: NodeId) {
+    fn visit_path(&mut self, path: &'tcx Path, _: HirId) {
         if path.segments.len() == 1 {
-            self.output.insert(path.segments[0].name);
+            self.output.insert(path.segments[0].ident.name);
         }
     }
     fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
-        NestedVisitorMap::All(&self.cx.tcx.map)
+        NestedVisitorMap::All(&self.cx.tcx.hir)
     }
 }