From 1d15a9cf7874f34ff3e091fd48a4ed691290a20e Mon Sep 17 00:00:00 2001 From: Marcel Hellwig Date: Mon, 21 Oct 2019 19:27:04 +0200 Subject: [PATCH] fix suggestions --- clippy_lints/src/mutable_debug_assertion.rs | 22 ++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/clippy_lints/src/mutable_debug_assertion.rs b/clippy_lints/src/mutable_debug_assertion.rs index d5e51edbe107..1184db0587b9 100644 --- a/clippy_lints/src/mutable_debug_assertion.rs +++ b/clippy_lints/src/mutable_debug_assertion.rs @@ -65,7 +65,9 @@ fn extract_call<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, e: &'tcx Expr) -> Optio if let ExprKind::Unary(UnOp::UnNot, ref condition) = droptmp.kind; then { // debug_assert - return MutArgVisitor::go(cx, condition); + let mut visitor = MutArgVisitor::new(cx); + visitor.visit_expr(condition); + return visitor.expr_span(); } else { // debug_assert_{eq,ne} if_chain! { @@ -76,12 +78,16 @@ fn extract_call<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, e: &'tcx Expr) -> Optio if conditions.len() == 2; then { if let ExprKind::AddrOf(_, ref lhs) = conditions[0].kind { - if let Some(span) = MutArgVisitor::go(cx, lhs) { + let mut visitor = MutArgVisitor::new(cx); + visitor.visit_expr(lhs); + if let Some(span) = visitor.expr_span() { return Some(span); } } if let ExprKind::AddrOf(_, ref rhs) = conditions[1].kind { - if let Some(span) = MutArgVisitor::go(cx, rhs) { + let mut visitor = MutArgVisitor::new(cx); + visitor.visit_expr(rhs); + if let Some(span) = visitor.expr_span() { return Some(span); } } @@ -110,19 +116,13 @@ impl<'a, 'tcx> MutArgVisitor<'a, 'tcx> { } } - fn get_span(&self) -> Option { + fn expr_span(&self) -> Option { if self.found { self.expr_span } else { None } } - - fn go(cx: &'a LateContext<'a, 'tcx>, start: &'tcx Expr) -> Option { - let mut s = Self::new(cx); - s.visit_expr(start); - s.get_span() - } } impl<'a, 'tcx> Visitor<'tcx> for MutArgVisitor<'a, 'tcx> { @@ -150,6 +150,6 @@ impl<'a, 'tcx> Visitor<'tcx> for MutArgVisitor<'a, 'tcx> { } fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> { - NestedVisitorMap::All(&self.cx.tcx.hir()) + NestedVisitorMap::OnlyBodies(&self.cx.tcx.hir()) } }