Cleanup, use matches! some more

This commit is contained in:
mcarton 2016-06-05 20:46:42 +02:00
parent 7211df5a17
commit 7bc7c675f2
3 changed files with 8 additions and 27 deletions

View file

@ -47,10 +47,7 @@ impl<'v> Visitor<'v> for ExVisitor<'v> {
let complex = { let complex = {
if block.stmts.is_empty() { if block.stmts.is_empty() {
if let Some(ref ex) = block.expr { if let Some(ref ex) = block.expr {
match ex.node { matches!(ex.node, ExprBlock(_))
ExprBlock(_) => true,
_ => false,
}
} else { } else {
false false
} }

View file

@ -1023,11 +1023,7 @@ impl OutType {
(&OutType::Bool, &hir::Return(ref ty)) if is_bool(ty) => true, (&OutType::Bool, &hir::Return(ref ty)) if is_bool(ty) => true,
(&OutType::Any, &hir::Return(ref ty)) if ty.node != hir::TyTup(vec![].into()) => true, (&OutType::Any, &hir::Return(ref ty)) if ty.node != hir::TyTup(vec![].into()) => true,
(&OutType::Ref, &hir::Return(ref ty)) => { (&OutType::Ref, &hir::Return(ref ty)) => {
if let hir::TyRptr(_, _) = ty.node { matches!(ty.node, hir::TyRptr(_, _))
true
} else {
false
}
} }
_ => false, _ => false,
} }
@ -1036,11 +1032,10 @@ impl OutType {
fn is_bool(ty: &hir::Ty) -> bool { fn is_bool(ty: &hir::Ty) -> bool {
if let hir::TyPath(None, ref p) = ty.node { if let hir::TyPath(None, ref p) = ty.node {
if match_path(p, &["bool"]) { match_path(p, &["bool"])
return true; } else {
} false
} }
false
} }
fn is_copy<'a, 'ctx>(cx: &LateContext<'a, 'ctx>, ty: ty::Ty<'ctx>, item: &hir::Item) -> bool { fn is_copy<'a, 'ctx>(cx: &LateContext<'a, 'ctx>, ty: ty::Ty<'ctx>, item: &hir::Item) -> bool {

View file

@ -189,11 +189,7 @@ fn is_allowed(cx: &LateContext, expr: &Expr) -> bool {
} }
fn is_float(cx: &LateContext, expr: &Expr) -> bool { fn is_float(cx: &LateContext, expr: &Expr) -> bool {
if let ty::TyFloat(_) = walk_ptrs_ty(cx.tcx.expr_ty(expr)).sty { matches!(walk_ptrs_ty(cx.tcx.expr_ty(expr)).sty, ty::TyFloat(_))
true
} else {
false
}
} }
/// **What it does:** This lint checks for conversions to owned values just for the sake of a comparison. /// **What it does:** This lint checks for conversions to owned values just for the sake of a comparison.
@ -283,11 +279,7 @@ fn check_to_owned(cx: &LateContext, expr: &Expr, other: &Expr, left: bool, op: S
fn is_str_arg(cx: &LateContext, args: &[P<Expr>]) -> bool { fn is_str_arg(cx: &LateContext, args: &[P<Expr>]) -> bool {
args.len() == 1 && args.len() == 1 &&
if let ty::TyStr = walk_ptrs_ty(cx.tcx.expr_ty(&args[0])).sty { matches!(walk_ptrs_ty(cx.tcx.expr_ty(&args[0])).sty, ty::TyStr)
true
} else {
false
}
} }
/// **What it does:** This lint checks for getting the remainder of a division by one. /// **What it does:** This lint checks for getting the remainder of a division by one.
@ -449,10 +441,7 @@ fn is_used(cx: &LateContext, expr: &Expr) -> bool {
fn in_attributes_expansion(cx: &LateContext, expr: &Expr) -> bool { fn in_attributes_expansion(cx: &LateContext, expr: &Expr) -> bool {
cx.sess().codemap().with_expn_info(expr.span.expn_id, |info_opt| { cx.sess().codemap().with_expn_info(expr.span.expn_id, |info_opt| {
info_opt.map_or(false, |info| { info_opt.map_or(false, |info| {
match info.callee.format { matches!(info.callee.format, ExpnFormat::MacroAttribute(_))
ExpnFormat::MacroAttribute(_) => true,
_ => false,
}
}) })
}) })
} }