Skip to content

Commit cbbc667

Browse files
committed
Dogfood for future MATCH_SAME_ARMS lint
1 parent 5ddc615 commit cbbc667

File tree

6 files changed

+27
-31
lines changed

6 files changed

+27
-31
lines changed

src/len_zero.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,7 @@ fn check_cmp(cx: &LateContext, span: Span, left: &Expr, right: &Expr, op: &str)
140140
}
141141
}
142142
match (&left.node, &right.node) {
143-
(&ExprLit(ref lit), &ExprMethodCall(ref method, _, ref args)) => {
144-
check_len_zero(cx, span, &method.node, args, lit, op)
145-
}
143+
(&ExprLit(ref lit), &ExprMethodCall(ref method, _, ref args)) |
146144
(&ExprMethodCall(ref method, _, ref args), &ExprLit(ref lit)) => {
147145
check_len_zero(cx, span, &method.node, args, lit, op)
148146
}

src/methods.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -865,24 +865,23 @@ enum SelfKind {
865865
impl SelfKind {
866866
fn matches(&self, slf: &ExplicitSelf_, allow_value_for_ref: bool) -> bool {
867867
match (self, slf) {
868-
(&SelfKind::Value, &SelfValue(_)) => true,
869-
(&SelfKind::Ref, &SelfRegion(_, Mutability::MutImmutable, _)) => true,
870-
(&SelfKind::RefMut, &SelfRegion(_, Mutability::MutMutable, _)) => true,
871-
(&SelfKind::Ref, &SelfValue(_)) => allow_value_for_ref,
872-
(&SelfKind::RefMut, &SelfValue(_)) => allow_value_for_ref,
873-
(&SelfKind::No, &SelfStatic) => true,
868+
(&SelfKind::Value, &SelfValue(_)) |
869+
(&SelfKind::Ref, &SelfRegion(_, Mutability::MutImmutable, _)) |
870+
(&SelfKind::RefMut, &SelfRegion(_, Mutability::MutMutable, _)) |
871+
(&SelfKind::No, &SelfStatic) => true,
872+
(&SelfKind::Ref, &SelfValue(_)) | (&SelfKind::RefMut, &SelfValue(_)) => allow_value_for_ref,
874873
(_, &SelfExplicit(ref ty, _)) => self.matches_explicit_type(ty, allow_value_for_ref),
875874
_ => false,
876875
}
877876
}
878877

879878
fn matches_explicit_type(&self, ty: &Ty, allow_value_for_ref: bool) -> bool {
880879
match (self, &ty.node) {
881-
(&SelfKind::Value, &TyPath(..)) => true,
882-
(&SelfKind::Ref, &TyRptr(_, MutTy { mutbl: Mutability::MutImmutable, .. })) => true,
883-
(&SelfKind::RefMut, &TyRptr(_, MutTy { mutbl: Mutability::MutMutable, .. })) => true,
884-
(&SelfKind::Ref, &TyPath(..)) => allow_value_for_ref,
885-
(&SelfKind::RefMut, &TyPath(..)) => allow_value_for_ref,
880+
(&SelfKind::Value, &TyPath(..)) |
881+
(&SelfKind::Ref, &TyRptr(_, MutTy { mutbl: Mutability::MutImmutable, .. })) |
882+
(&SelfKind::RefMut, &TyRptr(_, MutTy { mutbl: Mutability::MutMutable, .. })) => true,
883+
(&SelfKind::Ref, &TyPath(..)) |
884+
(&SelfKind::RefMut, &TyPath(..)) => allow_value_for_ref,
886885
_ => false,
887886
}
888887
}

src/misc.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,7 @@ impl LateLintPass for UsedUnderscoreBinding {
421421
fn is_used(cx: &LateContext, expr: &Expr) -> bool {
422422
if let Some(ref parent) = get_parent_expr(cx, expr) {
423423
match parent.node {
424-
ExprAssign(_, ref rhs) => **rhs == *expr,
425-
ExprAssignOp(_, _, ref rhs) => **rhs == *expr,
424+
ExprAssign(_, ref rhs) | ExprAssignOp(_, _, ref rhs) => **rhs == *expr,
426425
_ => is_used(cx, &parent),
427426
}
428427
} else {

src/utils/hir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
3838
false
3939
}
4040
}
41-
(&StmtExpr(ref l, _), &StmtExpr(ref r, _)) => self.eq_expr(l, r),
42-
(&StmtSemi(ref l, _), &StmtSemi(ref r, _)) => self.eq_expr(l, r),
41+
(&StmtExpr(ref l, _), &StmtExpr(ref r, _)) |
42+
(&StmtSemi(ref l, _), &StmtSemi(ref r, _)) => self.eq_expr(l, r),
4343
_ => false,
4444
}
4545
}

tests/compile-fail/cyclomatic_complexity.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,15 @@ fn bloo() {
138138
#[cyclomatic_complexity = "0"]
139139
fn baa() { //~ ERROR: the function has a cyclomatic complexity of 2
140140
let x = || match 99 {
141-
0 => true,
142-
1 => false,
143-
2 => true,
144-
4 => true,
145-
6 => true,
146-
9 => true,
147-
_ => false,
141+
0 => 0,
142+
1 => 1,
143+
2 => 2,
144+
4 => 4,
145+
6 => 6,
146+
9 => 9,
147+
_ => 42,
148148
};
149-
if x() {
149+
if x() == 42 {
150150
println!("x");
151151
} else {
152152
println!("not x");

tests/compile-fail/matches.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ fn match_bool() {
101101
let test: bool = true;
102102

103103
match test { //~ ERROR you seem to be trying to match on a boolean expression
104-
true => (),
105-
false => (),
104+
true => 0,
105+
false => 42,
106106
};
107107

108108
let option = 1;
@@ -128,9 +128,9 @@ fn match_bool() {
128128

129129
// Not linted
130130
match option {
131-
1 ... 10 => (),
132-
11 ... 20 => (),
133-
_ => (),
131+
1 ... 10 => 1,
132+
11 ... 20 => 2,
133+
_ => 3,
134134
};
135135
}
136136

0 commit comments

Comments
 (0)