Skip to content

Commit

Permalink
fix suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
hellow554 committed Oct 21, 2019
1 parent 538c1e8 commit 1d15a9c
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions clippy_lints/src/mutable_debug_assertion.rs
Expand Up @@ -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! {
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -110,19 +116,13 @@ impl<'a, 'tcx> MutArgVisitor<'a, 'tcx> {
}
}

fn get_span(&self) -> Option<Span> {
fn expr_span(&self) -> Option<Span> {
if self.found {
self.expr_span
} else {
None
}
}

fn go(cx: &'a LateContext<'a, 'tcx>, start: &'tcx Expr) -> Option<Span> {
let mut s = Self::new(cx);
s.visit_expr(start);
s.get_span()
}
}

impl<'a, 'tcx> Visitor<'tcx> for MutArgVisitor<'a, 'tcx> {
Expand Down Expand Up @@ -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())
}
}

0 comments on commit 1d15a9c

Please sign in to comment.