Skip to content

Commit fff5fa6

Browse files
committed
Eat collapsible_match dogfood
1 parent 28dec3b commit fff5fa6

17 files changed

+30
-56
lines changed

clippy_lints/src/default.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,7 @@ fn field_reassigned_by_stmt<'tcx>(this: &Stmt<'tcx>, binding_name: Symbol) -> Op
280280
// only take assignments to fields where the left-hand side field is a field of
281281
// the same binding as the previous statement
282282
if let ExprKind::Field(ref binding, field_ident) = assign_lhs.kind;
283-
if let ExprKind::Path(ref qpath) = binding.kind;
284-
if let QPath::Resolved(_, path) = qpath;
283+
if let ExprKind::Path(QPath::Resolved(_, path)) = binding.kind;
285284
if let Some(second_binding_name) = path.segments.last();
286285
if second_binding_name.ident.name == binding_name;
287286
then {

clippy_lints/src/if_let_some_result.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ declare_lint_pass!(OkIfLet => [IF_LET_SOME_RESULT]);
4141
impl<'tcx> LateLintPass<'tcx> for OkIfLet {
4242
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
4343
if_chain! { //begin checking variables
44-
if let ExprKind::Match(ref op, ref body, source) = expr.kind; //test if expr is a match
45-
if let MatchSource::IfLetDesugar { .. } = source; //test if it is an If Let
44+
if let ExprKind::Match(ref op, ref body, MatchSource::IfLetDesugar { .. }) = expr.kind; //test if expr is if let
4645
if let ExprKind::MethodCall(_, ok_span, ref result_types, _) = op.kind; //check is expr.ok() has type Result<T,E>.ok(, _)
4746
if let PatKind::TupleStruct(QPath::Resolved(_, ref x), ref y, _) = body[0].pat.kind; //get operation
4847
if method_chain_args(op, &["ok"]).is_some(); //test to see if using ok() methoduse std::marker::Sized;

clippy_lints/src/implicit_return.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ fn expr_match(cx: &LateContext<'_>, expr: &Expr<'_>) {
6868
if_chain! {
6969
if let StmtKind::Semi(expr, ..) = &stmt.kind;
7070
// make sure it's a break, otherwise we want to skip
71-
if let ExprKind::Break(.., break_expr) = &expr.kind;
72-
if let Some(break_expr) = break_expr;
71+
if let ExprKind::Break(.., Some(break_expr)) = &expr.kind;
7372
then {
7473
lint(cx, expr.span, break_expr.span, LINT_BREAK);
7574
}

clippy_lints/src/implicit_saturating_sub.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingSub {
5959
if let Some(target) = subtracts_one(cx, e);
6060

6161
// Extracting out the variable name
62-
if let ExprKind::Path(ref assign_path) = target.kind;
63-
if let QPath::Resolved(_, ref ares_path) = assign_path;
62+
if let ExprKind::Path(QPath::Resolved(_, ref ares_path)) = target.kind;
6463

6564
then {
6665
// Handle symmetric conditions in the if statement

clippy_lints/src/large_const_arrays.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeConstArrays {
5252
if let ItemKind::Const(hir_ty, _) = &item.kind;
5353
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
5454
if let ty::Array(element_type, cst) = ty.kind();
55-
if let ConstKind::Value(val) = cst.val;
56-
if let ConstValue::Scalar(element_count) = val;
55+
if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.val;
5756
if let Ok(element_count) = element_count.to_machine_usize(&cx.tcx);
5857
if let Ok(element_size) = cx.layout_of(element_type).map(|l| l.size.bytes());
5958
if self.maximum_allowed_size < element_count * element_size;

clippy_lints/src/large_stack_arrays.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeStackArrays {
4343
if_chain! {
4444
if let ExprKind::Repeat(_, _) = expr.kind;
4545
if let ty::Array(element_type, cst) = cx.typeck_results().expr_ty(expr).kind();
46-
if let ConstKind::Value(val) = cst.val;
47-
if let ConstValue::Scalar(element_count) = val;
46+
if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.val;
4847
if let Ok(element_count) = element_count.to_machine_usize(&cx.tcx);
4948
if let Ok(element_size) = cx.layout_of(element_type).map(|l| l.size.bytes());
5049
if self.maximum_allowed_size < element_count * element_size;

clippy_lints/src/loops.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1919,8 +1919,7 @@ fn check_for_single_element_loop<'tcx>(
19191919
if_chain! {
19201920
if let ExprKind::AddrOf(BorrowKind::Ref, _, ref arg_expr) = arg.kind;
19211921
if let PatKind::Binding(.., target, _) = pat.kind;
1922-
if let ExprKind::Array(ref arg_expr_list) = arg_expr.kind;
1923-
if let [arg_expression] = arg_expr_list;
1922+
if let ExprKind::Array([arg_expression]) = arg_expr.kind;
19241923
if let ExprKind::Path(ref list_item) = arg_expression.kind;
19251924
if let Some(list_item_name) = single_segment_path(list_item).map(|ps| ps.ident.name);
19261925
if let ExprKind::Block(ref block, _) = body.kind;
@@ -2025,8 +2024,7 @@ fn check_for_mutability(cx: &LateContext<'_>, bound: &Expr<'_>) -> Option<HirId>
20252024
let node_str = cx.tcx.hir().get(hir_id);
20262025
if_chain! {
20272026
if let Node::Binding(pat) = node_str;
2028-
if let PatKind::Binding(bind_ann, ..) = pat.kind;
2029-
if let BindingAnnotation::Mutable = bind_ann;
2027+
if let PatKind::Binding(BindingAnnotation::Mutable, ..) = pat.kind;
20302028
then {
20312029
return Some(hir_id);
20322030
}

clippy_lints/src/manual_strip.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,7 @@ fn find_stripping<'tcx>(
225225
if is_ref_str(self.cx, ex);
226226
let unref = peel_ref(ex);
227227
if let ExprKind::Index(indexed, index) = &unref.kind;
228-
if let Some(range) = higher::range(index);
229-
if let higher::Range { start, end, .. } = range;
228+
if let Some(higher::Range { start, end, .. }) = higher::range(index);
230229
if let ExprKind::Path(path) = &indexed.kind;
231230
if qpath_res(self.cx, path, ex.hir_id) == self.target;
232231
then {

clippy_lints/src/matches.rs

+10-14
Original file line numberDiff line numberDiff line change
@@ -652,8 +652,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches {
652652
if_chain! {
653653
if !in_external_macro(cx.sess(), pat.span);
654654
if !in_macro(pat.span);
655-
if let PatKind::Struct(ref qpath, fields, true) = pat.kind;
656-
if let QPath::Resolved(_, ref path) = qpath;
655+
if let PatKind::Struct(QPath::Resolved(_, ref path), fields, true) = pat.kind;
657656
if let Some(def_id) = path.res.opt_def_id();
658657
let ty = cx.tcx.type_of(def_id);
659658
if let ty::Adt(def, _) = ty.kind();
@@ -962,16 +961,14 @@ fn check_wild_enum_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>])
962961
if let QPath::Resolved(_, p) = path {
963962
missing_variants.retain(|e| e.ctor_def_id != Some(p.res.def_id()));
964963
}
965-
} else if let PatKind::TupleStruct(ref path, ref patterns, ..) = arm.pat.kind {
966-
if let QPath::Resolved(_, p) = path {
967-
// Some simple checks for exhaustive patterns.
968-
// There is a room for improvements to detect more cases,
969-
// but it can be more expensive to do so.
970-
let is_pattern_exhaustive =
971-
|pat: &&Pat<'_>| matches!(pat.kind, PatKind::Wild | PatKind::Binding(.., None));
972-
if patterns.iter().all(is_pattern_exhaustive) {
973-
missing_variants.retain(|e| e.ctor_def_id != Some(p.res.def_id()));
974-
}
964+
} else if let PatKind::TupleStruct(QPath::Resolved(_, p), ref patterns, ..) = arm.pat.kind {
965+
// Some simple checks for exhaustive patterns.
966+
// There is a room for improvements to detect more cases,
967+
// but it can be more expensive to do so.
968+
let is_pattern_exhaustive =
969+
|pat: &&Pat<'_>| matches!(pat.kind, PatKind::Wild | PatKind::Binding(.., None));
970+
if patterns.iter().all(is_pattern_exhaustive) {
971+
missing_variants.retain(|e| e.ctor_def_id != Some(p.res.def_id()));
975972
}
976973
}
977974
}
@@ -1446,8 +1443,7 @@ fn is_ref_some_arm(arm: &Arm<'_>) -> Option<BindingAnnotation> {
14461443
if let ExprKind::Call(ref e, ref args) = remove_blocks(&arm.body).kind;
14471444
if let ExprKind::Path(ref some_path) = e.kind;
14481445
if match_qpath(some_path, &paths::OPTION_SOME) && args.len() == 1;
1449-
if let ExprKind::Path(ref qpath) = args[0].kind;
1450-
if let &QPath::Resolved(_, ref path2) = qpath;
1446+
if let ExprKind::Path(QPath::Resolved(_, ref path2)) = args[0].kind;
14511447
if path2.segments.len() == 1 && ident.name == path2.segments[0].ident.name;
14521448
then {
14531449
return Some(rb)

clippy_lints/src/methods/manual_saturating_arithmetic.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ fn is_min_or_max<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>) -> Option<M
9090
if_chain! {
9191
if let hir::ExprKind::Call(func, args) = &expr.kind;
9292
if args.is_empty();
93-
if let hir::ExprKind::Path(path) = &func.kind;
94-
if let hir::QPath::TypeRelative(_, segment) = path;
93+
if let hir::ExprKind::Path(hir::QPath::TypeRelative(_, segment)) = &func.kind;
9594
then {
9695
match &*segment.ident.as_str() {
9796
"max_value" => return Some(MinMax::Max),

clippy_lints/src/needless_bool.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::utils::sugg::Sugg;
66
use crate::utils::{
77
higher, is_expn_of, parent_node_is_if_expr, snippet_with_applicability, span_lint, span_lint_and_sugg,
88
};
9-
use if_chain::if_chain;
109
use rustc_ast::ast::LitKind;
1110
use rustc_errors::Applicability;
1211
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, StmtKind, UnOp};
@@ -198,13 +197,9 @@ struct ExpressionInfoWithSpan {
198197
}
199198

200199
fn is_unary_not(e: &Expr<'_>) -> (bool, Span) {
201-
if_chain! {
202-
if let ExprKind::Unary(unop, operand) = e.kind;
203-
if let UnOp::UnNot = unop;
204-
then {
205-
return (true, operand.span);
206-
}
207-
};
200+
if let ExprKind::Unary(UnOp::UnNot, operand) = e.kind {
201+
return (true, operand.span);
202+
}
208203
(false, e.span)
209204
}
210205

clippy_lints/src/question_mark.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,7 @@ impl QuestionMark {
176176
if block.stmts.len() == 1;
177177
if let Some(expr) = block.stmts.iter().last();
178178
if let StmtKind::Semi(ref expr) = expr.kind;
179-
if let ExprKind::Ret(ret_expr) = expr.kind;
180-
if let Some(ret_expr) = ret_expr;
179+
if let ExprKind::Ret(Some(ret_expr)) = expr.kind;
181180

182181
then {
183182
return Some(ret_expr);

clippy_lints/src/strings.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,7 @@ impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes {
222222
if method_names[0] == sym!(as_bytes);
223223

224224
// Check for slicer
225-
if let ExprKind::Struct(ref path, _, _) = right.kind;
226-
if let QPath::LangItem(LangItem::Range, _) = path;
225+
if let ExprKind::Struct(QPath::LangItem(LangItem::Range, _), _, _) = right.kind;
227226

228227
then {
229228
let mut applicability = Applicability::MachineApplicable;

clippy_lints/src/trait_bounds.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,7 @@ fn check_trait_bound_duplication(cx: &LateContext<'_>, gen: &'_ Generics<'_>) {
168168
if_chain! {
169169
if let WherePredicate::BoundPredicate(ref bound_predicate) = predicate;
170170
if !in_macro(bound_predicate.span);
171-
if let TyKind::Path(ref path) = bound_predicate.bounded_ty.kind;
172-
if let QPath::Resolved(_, Path { ref segments, .. }) = path;
171+
if let TyKind::Path(QPath::Resolved(_, Path { ref segments, .. })) = bound_predicate.bounded_ty.kind;
173172
if let Some(segment) = segments.first();
174173
if let Some(trait_resolutions_direct) = map.get(&segment.ident);
175174
then {

clippy_lints/src/transmuting_null.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ impl<'tcx> LateLintPass<'tcx> for TransmutingNull {
4848
if_chain! {
4949
if let ExprKind::Path(ref _qpath) = args[0].kind;
5050
let x = const_eval_context.expr(&args[0]);
51-
if let Some(constant) = x;
52-
if let Constant::RawPtr(0) = constant;
51+
if let Some(Constant::RawPtr(0)) = x;
5352
then {
5453
span_lint(cx, TRANSMUTING_NULL, expr.span, LINT_MSG)
5554
}

clippy_lints/src/types.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -738,8 +738,7 @@ fn is_any_trait(t: &hir::Ty<'_>) -> bool {
738738
fn get_bounds_if_impl_trait<'tcx>(cx: &LateContext<'tcx>, qpath: &QPath<'_>, id: HirId) -> Option<GenericBounds<'tcx>> {
739739
if_chain! {
740740
if let Some(did) = qpath_res(cx, qpath, id).opt_def_id();
741-
if let Some(node) = cx.tcx.hir().get_if_local(did);
742-
if let Node::GenericParam(generic_param) = node;
741+
if let Some(Node::GenericParam(generic_param)) = cx.tcx.hir().get_if_local(did);
743742
if let GenericParamKind::Type { synthetic, .. } = generic_param.kind;
744743
if synthetic == Some(SyntheticTyParamKind::ImplTrait);
745744
then {
@@ -1470,8 +1469,7 @@ fn check_loss_of_sign(cx: &LateContext<'_>, expr: &Expr<'_>, op: &Expr<'_>, cast
14701469
// don't lint for positive constants
14711470
let const_val = constant(cx, &cx.typeck_results(), op);
14721471
if_chain! {
1473-
if let Some((const_val, _)) = const_val;
1474-
if let Constant::Int(n) = const_val;
1472+
if let Some((Constant::Int(n), _)) = const_val;
14751473
if let ty::Int(ity) = *cast_from.kind();
14761474
if sext(cx.tcx, n, ity) >= 0;
14771475
then {

clippy_lints/src/utils/higher.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ pub fn while_loop<'tcx>(expr: &'tcx hir::Expr<'tcx>) -> Option<(&'tcx hir::Expr<
162162
if let hir::Block { expr: Some(expr), .. } = &**block;
163163
if let hir::ExprKind::Match(cond, arms, hir::MatchSource::WhileDesugar) = &expr.kind;
164164
if let hir::ExprKind::DropTemps(cond) = &cond.kind;
165-
if let [arm, ..] = &arms[..];
166-
if let hir::Arm { body, .. } = arm;
165+
if let [hir::Arm { body, .. }, ..] = &arms[..];
167166
then {
168167
return Some((cond, body));
169168
}

0 commit comments

Comments
 (0)