Apply suggestions from code review

Use array slice instead of `Vec` in `find_macro_calls` as suggested by @ebroto

Co-authored-by: Eduardo Broto <ebroto@tutanota.com>
This commit is contained in:
dp304 2020-12-03 23:07:24 +01:00 committed by Eduardo Broto
parent e58c7dd168
commit bdad7900f4
2 changed files with 5 additions and 5 deletions

View File

@ -53,7 +53,7 @@ fn check_fn(
fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, body: &'tcx hir::Body<'tcx>) { fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, body: &'tcx hir::Body<'tcx>) {
let panics = find_macro_calls( let panics = find_macro_calls(
vec![ &[
"unimplemented", "unimplemented",
"unreachable", "unreachable",
"panic", "panic",

View File

@ -603,12 +603,12 @@ fn nested_visit_map(&mut self) -> hir::intravisit::NestedVisitorMap<Self::Map> {
visitor.found visitor.found
} }
struct FindMacroCalls<'a> { struct FindMacroCalls<'a, 'b> {
names: Vec<&'a str>, names: &'a [&'b str],
result: Vec<Span>, 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>; type Map = Map<'tcx>;
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { 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. /// 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 { let mut fmc = FindMacroCalls {
names, names,
result: Vec::new(), result: Vec::new(),