Dogfood for future MATCH_SAME_ARMS lint

This commit is contained in:
mcarton 2016-02-10 00:38:53 +01:00
parent 5ddc615a40
commit cbbc667b1b
6 changed files with 27 additions and 31 deletions

View file

@ -140,9 +140,7 @@ fn check_cmp(cx: &LateContext, span: Span, left: &Expr, right: &Expr, op: &str)
}
}
match (&left.node, &right.node) {
(&ExprLit(ref lit), &ExprMethodCall(ref method, _, ref args)) => {
check_len_zero(cx, span, &method.node, args, lit, op)
}
(&ExprLit(ref lit), &ExprMethodCall(ref method, _, ref args)) |
(&ExprMethodCall(ref method, _, ref args), &ExprLit(ref lit)) => {
check_len_zero(cx, span, &method.node, args, lit, op)
}

View file

@ -865,12 +865,11 @@ enum SelfKind {
impl SelfKind {
fn matches(&self, slf: &ExplicitSelf_, allow_value_for_ref: bool) -> bool {
match (self, slf) {
(&SelfKind::Value, &SelfValue(_)) => true,
(&SelfKind::Ref, &SelfRegion(_, Mutability::MutImmutable, _)) => true,
(&SelfKind::RefMut, &SelfRegion(_, Mutability::MutMutable, _)) => true,
(&SelfKind::Ref, &SelfValue(_)) => allow_value_for_ref,
(&SelfKind::RefMut, &SelfValue(_)) => allow_value_for_ref,
(&SelfKind::Value, &SelfValue(_)) |
(&SelfKind::Ref, &SelfRegion(_, Mutability::MutImmutable, _)) |
(&SelfKind::RefMut, &SelfRegion(_, Mutability::MutMutable, _)) |
(&SelfKind::No, &SelfStatic) => true,
(&SelfKind::Ref, &SelfValue(_)) | (&SelfKind::RefMut, &SelfValue(_)) => allow_value_for_ref,
(_, &SelfExplicit(ref ty, _)) => self.matches_explicit_type(ty, allow_value_for_ref),
_ => false,
}
@ -878,10 +877,10 @@ impl SelfKind {
fn matches_explicit_type(&self, ty: &Ty, allow_value_for_ref: bool) -> bool {
match (self, &ty.node) {
(&SelfKind::Value, &TyPath(..)) => true,
(&SelfKind::Ref, &TyRptr(_, MutTy { mutbl: Mutability::MutImmutable, .. })) => true,
(&SelfKind::Value, &TyPath(..)) |
(&SelfKind::Ref, &TyRptr(_, MutTy { mutbl: Mutability::MutImmutable, .. })) |
(&SelfKind::RefMut, &TyRptr(_, MutTy { mutbl: Mutability::MutMutable, .. })) => true,
(&SelfKind::Ref, &TyPath(..)) => allow_value_for_ref,
(&SelfKind::Ref, &TyPath(..)) |
(&SelfKind::RefMut, &TyPath(..)) => allow_value_for_ref,
_ => false,
}

View file

@ -421,8 +421,7 @@ impl LateLintPass for UsedUnderscoreBinding {
fn is_used(cx: &LateContext, expr: &Expr) -> bool {
if let Some(ref parent) = get_parent_expr(cx, expr) {
match parent.node {
ExprAssign(_, ref rhs) => **rhs == *expr,
ExprAssignOp(_, _, ref rhs) => **rhs == *expr,
ExprAssign(_, ref rhs) | ExprAssignOp(_, _, ref rhs) => **rhs == *expr,
_ => is_used(cx, &parent),
}
} else {

View file

@ -38,7 +38,7 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
false
}
}
(&StmtExpr(ref l, _), &StmtExpr(ref r, _)) => self.eq_expr(l, r),
(&StmtExpr(ref l, _), &StmtExpr(ref r, _)) |
(&StmtSemi(ref l, _), &StmtSemi(ref r, _)) => self.eq_expr(l, r),
_ => false,
}

View file

@ -138,15 +138,15 @@ fn bloo() {
#[cyclomatic_complexity = "0"]
fn baa() { //~ ERROR: the function has a cyclomatic complexity of 2
let x = || match 99 {
0 => true,
1 => false,
2 => true,
4 => true,
6 => true,
9 => true,
_ => false,
0 => 0,
1 => 1,
2 => 2,
4 => 4,
6 => 6,
9 => 9,
_ => 42,
};
if x() {
if x() == 42 {
println!("x");
} else {
println!("not x");

View file

@ -101,8 +101,8 @@ fn match_bool() {
let test: bool = true;
match test { //~ ERROR you seem to be trying to match on a boolean expression
true => (),
false => (),
true => 0,
false => 42,
};
let option = 1;
@ -128,9 +128,9 @@ fn match_bool() {
// Not linted
match option {
1 ... 10 => (),
11 ... 20 => (),
_ => (),
1 ... 10 => 1,
11 ... 20 => 2,
_ => 3,
};
}