From bdad7900f4558672ca02b24a0a079b05391acaf9 Mon Sep 17 00:00:00 2001 From: dp304 <34493835+dp304@users.noreply.github.com> Date: Thu, 3 Dec 2020 23:07:24 +0100 Subject: [PATCH] Apply suggestions from code review Use array slice instead of `Vec` in `find_macro_calls` as suggested by @ebroto Co-authored-by: Eduardo Broto --- clippy_lints/src/panic_in_result_fn.rs | 2 +- clippy_lints/src/utils/mod.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/panic_in_result_fn.rs b/clippy_lints/src/panic_in_result_fn.rs index cdabb0d0dd6..37e2b50def1 100644 --- a/clippy_lints/src/panic_in_result_fn.rs +++ b/clippy_lints/src/panic_in_result_fn.rs @@ -53,7 +53,7 @@ fn check_fn( fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, body: &'tcx hir::Body<'tcx>) { let panics = find_macro_calls( - vec![ + &[ "unimplemented", "unreachable", "panic", diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index e47d71aac99..e83371f8b99 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -603,12 +603,12 @@ fn nested_visit_map(&mut self) -> hir::intravisit::NestedVisitorMap { visitor.found } -struct FindMacroCalls<'a> { - names: Vec<&'a str>, +struct FindMacroCalls<'a, 'b> { + names: &'a [&'b str], result: Vec, } -impl<'a, 'tcx> Visitor<'tcx> for FindMacroCalls<'a> { +impl<'a, 'b, 'tcx> Visitor<'tcx> for FindMacroCalls<'a, 'b> { type Map = Map<'tcx>; fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { @@ -625,7 +625,7 @@ fn nested_visit_map(&mut self) -> NestedVisitorMap { } /// Finds calls of the specified macros in a function body. -pub fn find_macro_calls(names: Vec<&str>, body: &'tcx Body<'tcx>) -> Vec { +pub fn find_macro_calls(names: &[&str], body: &Body<'_>) -> Vec { let mut fmc = FindMacroCalls { names, result: Vec::new(),