]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/vec.rs
Auto merge of #4551 - mikerite:fix-ice-reporting, r=llogiq
[rust.git] / clippy_lints / src / vec.rs
index 407722bc66e296f22665a23583a260d781654526..d7709784a3eb4df0c92c50e6b522f982b5a2f338 100644 (file)
@@ -4,37 +4,30 @@
 use rustc::hir::*;
 use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
 use rustc::ty::{self, Ty};
-use rustc::{declare_tool_lint, lint_array};
+use rustc::{declare_lint_pass, declare_tool_lint};
 use rustc_errors::Applicability;
 use syntax::source_map::Span;
 
-/// **What it does:** Checks for usage of `&vec![..]` when using `&[..]` would
-/// be possible.
-///
-/// **Why is this bad?** This is less efficient.
-///
-/// **Known problems:** None.
-///
-/// **Example:**
-/// ```rust,ignore
-/// foo(&vec![1, 2])
-/// ```
 declare_clippy_lint! {
+    /// **What it does:** Checks for usage of `&vec![..]` when using `&[..]` would
+    /// be possible.
+    ///
+    /// **Why is this bad?** This is less efficient.
+    ///
+    /// **Known problems:** None.
+    ///
+    /// **Example:**
+    /// ```rust,ignore
+    /// foo(&vec![1, 2])
+    /// ```
     pub USELESS_VEC,
     perf,
     "useless `vec!`"
 }
 
-#[derive(Copy, Clone, Debug)]
-pub struct Pass;
+declare_lint_pass!(UselessVec => [USELESS_VEC]);
 
-impl LintPass for Pass {
-    fn get_lints(&self) -> LintArray {
-        lint_array!(USELESS_VEC)
-    }
-}
-
-impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
+impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessVec {
     fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
         // search for `&vec![_]` expressions where the adjusted type is `&[_]`
         if_chain! {
@@ -56,10 +49,11 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
                 // report the error around the `vec!` not inside `<std macros>:`
                 let span = arg.span
                     .ctxt()
-                    .outer()
-                    .expn_info()
-                    .map(|info| info.call_site)
-                    .expect("unable to get call_site");
+                    .outer_expn_data()
+                    .call_site
+                    .ctxt()
+                    .outer_expn_data()
+                    .call_site;
                 check_vec_macro(cx, &vec_args, span);
             }
         }
@@ -102,7 +96,7 @@ fn check_vec_macro<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, vec_args: &higher::VecA
     );
 }
 
-/// Return the item type of the vector (ie. the `T` in `Vec<T>`).
+/// Returns the item type of the vector (i.e., the `T` in `Vec<T>`).
 fn vec_type(ty: Ty<'_>) -> Ty<'_> {
     if let ty::Adt(_, substs) = ty.sty {
         substs.type_at(0)