]> git.lizzy.rs Git - rust.git/commitdiff
Apply suggestions from code review
authordp304 <34493835+dp304@users.noreply.github.com>
Thu, 3 Dec 2020 22:07:24 +0000 (23:07 +0100)
committerEduardo Broto <ebroto@tutanota.com>
Mon, 7 Dec 2020 23:10:39 +0000 (00:10 +0100)
Use array slice instead of `Vec` in `find_macro_calls` as suggested by @ebroto

Co-authored-by: Eduardo Broto <ebroto@tutanota.com>
clippy_lints/src/panic_in_result_fn.rs
clippy_lints/src/utils/mod.rs

index cdabb0d0dd6ef0437c94794165458fa4a7ce23f2..37e2b50def17a389b7473a280f59527f6ed2785b 100644 (file)
@@ -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",
index e47d71aac996e51ecc658f9d92b23815323c3f1f..e83371f8b99a4c3007641b1661fbc6745e318e6b 100644 (file)
@@ -603,12 +603,12 @@ fn nested_visit_map(&mut self) -> hir::intravisit::NestedVisitorMap<Self::Map> {
     visitor.found
 }
 
-struct FindMacroCalls<'a> {
-    names: Vec<&'a str>,
+struct FindMacroCalls<'a, 'b> {
+    names: &'a [&'b str],
     result: Vec<Span>,
 }
 
-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<Self::Map> {
 }
 
 /// Finds calls of the specified macros in a function body.
-pub fn find_macro_calls(names: Vec<&str>, body: &'tcx Body<'tcx>) -> Vec<Span> {
+pub fn find_macro_calls(names: &[&str], body: &Body<'_>) -> Vec<Span> {
     let mut fmc = FindMacroCalls {
         names,
         result: Vec::new(),