Skip to content

Commit

Permalink
Fixing src/copies.rs and src/entries.rs by using ExprBlock(block) = t…
Browse files Browse the repository at this point in the history
…hen.node
  • Loading branch information
ensch committed Mar 31, 2017
1 parent 8f9fb97 commit 8297c19
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
22 changes: 11 additions & 11 deletions clippy_lints/src/copies.rs
Expand Up @@ -223,13 +223,15 @@ fn lint_match_arms(cx: &LateContext, expr: &Expr) {
/// `if a { c } else if b { d } else { e }`.
fn if_sequence(mut expr: &Expr) -> (SmallVector<&Expr>, SmallVector<&Block>) {
let mut conds = SmallVector::new();
let mut blocks = SmallVector::new();
let mut blocks : SmallVector<&Block> = SmallVector::new();

while let ExprIf(ref cond, ref then_expr, ref else_expr) = expr.node {
conds.push(&**cond);
//FIXME
//blocks.push(&**then_expr);
//FIXME
if let ExprBlock(ref block) = then_expr.node {
blocks.push(&block);
} else {
panic!("ExprIf node is not an ExprBlock");
}

if let Some(ref else_expr) = *else_expr {
expr = else_expr;
Expand All @@ -241,9 +243,7 @@ fn if_sequence(mut expr: &Expr) -> (SmallVector<&Expr>, SmallVector<&Block>) {
// final `else {..}`
if !blocks.is_empty() {
if let ExprBlock(ref block) = expr.node {
//FIXME
//blocks.push(&**block);
//FIXME
blocks.push(&**block);
}
}

Expand Down Expand Up @@ -315,10 +315,10 @@ fn search_same<T, Hash, Eq>(exprs: &[T], hash: Hash, eq: Eq) -> Option<(&T, &T)>
return None;
} else if exprs.len() == 2 {
return if eq(&exprs[0], &exprs[1]) {
Some((&exprs[0], &exprs[1]))
} else {
None
};
Some((&exprs[0], &exprs[1]))
} else {
None
};
}

let mut map: HashMap<_, Vec<&_>> = HashMap::with_capacity(exprs.len());
Expand Down
9 changes: 8 additions & 1 deletion clippy_lints/src/entry.rs
Expand Up @@ -46,7 +46,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HashMapLint {
if let Some((ty, map, key)) = check_cond(cx, check) {
// in case of `if !m.contains_key(&k) { m.insert(k, v); }`
// we can give a better error message
let sole_expr = else_block.is_none();
let sole_expr = {
else_block.is_none() &&
if let ExprBlock(ref then_block) = then_block.node {
(then_block.expr.is_some() as usize) + then_block.stmts.len() == 1
} else {
true
}
};

let mut visitor = InsertVisitor {
cx: cx,
Expand Down
6 changes: 4 additions & 2 deletions clippy_lints/src/let_if_seq.rs
Expand Up @@ -69,7 +69,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
let hir::StmtExpr(ref if_, _) = expr.node,
let hir::ExprIf(ref cond, ref then, ref else_) = if_.node,
!used_in_expr(cx, def_id, cond),
!used_in_expr(cx, def_id, &**then),
!used_in_expr(cx, def_id, &*then),
let hir::ExprBlock(ref then) = then.node,
let Some(value) = check_assign(cx, def_id, &*then),
], {
let span = Span { lo: stmt.span.lo, hi: if_.span.hi, ctxt: NO_EXPANSION };

Expand Down Expand Up @@ -104,7 +106,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
mut=mutability,
name=name.node,
cond=snippet(cx, cond.span, "_"),
then={ "" },
then=if then.stmts.len() > 1 { " ..;" } else { "" },
else=if default_multi_stmts { " ..;" } else { "" },
value=snippet(cx, then.span, "<value>"),
default=snippet(cx, default.span, "<default>"),
Expand Down

0 comments on commit 8297c19

Please sign in to comment.