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;
"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)
- }
-
- fn name(&self) -> &'static str {
- "UselessVec"
- }
-}
-
-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! {
// 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);
}
}
);
}
-/// 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)