Skip to content

Commit e020e17

Browse files
committed
Clean existing lint code to match new lint
1 parent cf41785 commit e020e17

18 files changed

+145
-113
lines changed

clippy_lints/src/attrs.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,11 +481,14 @@ fn is_relevant_trait(cx: &LateContext<'_, '_>, item: &TraitItem<'_>) -> bool {
481481
}
482482

483483
fn is_relevant_block(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, block: &Block<'_>) -> bool {
484-
block.stmts.first().map_or(block.expr.as_ref().map_or(false, |e| is_relevant_expr(cx, tables, e)), |stmt| match &stmt.kind {
484+
block.stmts.first().map_or(
485+
block.expr.as_ref().map_or(false, |e| is_relevant_expr(cx, tables, e)),
486+
|stmt| match &stmt.kind {
485487
StmtKind::Local(_) => true,
486488
StmtKind::Expr(expr) | StmtKind::Semi(expr) => is_relevant_expr(cx, tables, expr),
487489
_ => false,
488-
})
490+
},
491+
)
489492
}
490493

491494
fn is_relevant_expr(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, expr: &Expr<'_>) -> bool {
@@ -495,7 +498,10 @@ fn is_relevant_expr(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, exp
495498
ExprKind::Ret(None) | ExprKind::Break(_, None) => false,
496499
ExprKind::Call(path_expr, _) => {
497500
if let ExprKind::Path(qpath) = &path_expr.kind {
498-
tables.qpath_res(qpath, path_expr.hir_id).opt_def_id().map_or(true, |fun_id| !match_def_path(cx, fun_id, &paths::BEGIN_PANIC))
501+
tables
502+
.qpath_res(qpath, path_expr.hir_id)
503+
.opt_def_id()
504+
.map_or(true, |fun_id| !match_def_path(cx, fun_id, &paths::BEGIN_PANIC))
499505
} else {
500506
true
501507
}

clippy_lints/src/if_let_mutex.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ impl<'tcx, 'l> Visitor<'tcx> for ArmVisitor<'tcx, 'l> {
137137

138138
impl<'tcx, 'l> ArmVisitor<'tcx, 'l> {
139139
fn same_mutex(&self, cx: &LateContext<'_, '_>, op_mutex: &Expr<'_>) -> bool {
140-
self.found_mutex.map_or(false, |arm_mutex| SpanlessEq::new(cx).eq_expr(op_mutex, arm_mutex))
140+
self.found_mutex
141+
.map_or(false, |arm_mutex| SpanlessEq::new(cx).eq_expr(op_mutex, arm_mutex))
141142
}
142143
}
143144

clippy_lints/src/len_zero.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,12 @@ fn has_is_empty(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool {
302302

303303
let ty = &walk_ptrs_ty(cx.tables().expr_ty(expr));
304304
match ty.kind {
305-
ty::Dynamic(ref tt, ..) => {
306-
tt.principal().map_or(false, |principal| cx.tcx
307-
.associated_items(principal.def_id())
308-
.in_definition_order()
309-
.any(|item| is_is_empty(cx, &item)))
310-
},
305+
ty::Dynamic(ref tt, ..) => tt.principal().map_or(false, |principal| {
306+
cx.tcx
307+
.associated_items(principal.def_id())
308+
.in_definition_order()
309+
.any(|item| is_is_empty(cx, &item))
310+
}),
311311
ty::Projection(ref proj) => has_is_empty_impl(cx, proj.item_def_id),
312312
ty::Adt(id, _) => has_is_empty_impl(cx, id.did),
313313
ty::Array(..) | ty::Slice(..) | ty::Str => true,

clippy_lints/src/literal_representation.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,12 @@ impl LiteralDigitGrouping {
265265
let (part, mistyped_suffixes, missing_char) = if let Some((_, exponent)) = &mut num_lit.exponent {
266266
(exponent, &["32", "64"][..], 'f')
267267
} else {
268-
num_lit.fraction.as_mut().map_or(
269-
(&mut num_lit.integer, &["8", "16", "32", "64"][..], 'i'),
270-
|fraction| (fraction, &["32", "64"][..], 'f')
271-
)
268+
num_lit
269+
.fraction
270+
.as_mut()
271+
.map_or((&mut num_lit.integer, &["8", "16", "32", "64"][..], 'i'), |fraction| {
272+
(fraction, &["32", "64"][..], 'f')
273+
})
272274
};
273275

274276
let mut split = part.rsplit('_');

clippy_lints/src/loops.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -686,9 +686,9 @@ fn never_loop_expr(expr: &Expr<'_>, main_loop_id: HirId) -> NeverLoopResult {
686686
NeverLoopResult::AlwaysBreak
687687
}
688688
},
689-
ExprKind::Break(_, ref e) | ExprKind::Ret(ref e) => {
690-
e.as_ref().map_or(NeverLoopResult::AlwaysBreak, |e| combine_seq(never_loop_expr(e, main_loop_id), NeverLoopResult::AlwaysBreak))
691-
},
689+
ExprKind::Break(_, ref e) | ExprKind::Ret(ref e) => e.as_ref().map_or(NeverLoopResult::AlwaysBreak, |e| {
690+
combine_seq(never_loop_expr(e, main_loop_id), NeverLoopResult::AlwaysBreak)
691+
}),
692692
ExprKind::InlineAsm(ref asm) => asm
693693
.operands
694694
.iter()
@@ -1877,9 +1877,9 @@ fn is_ref_iterable_type(cx: &LateContext<'_, '_>, e: &Expr<'_>) -> bool {
18771877
fn is_iterable_array<'tcx>(ty: Ty<'tcx>, cx: &LateContext<'_, 'tcx>) -> bool {
18781878
// IntoIterator is currently only implemented for array sizes <= 32 in rustc
18791879
match ty.kind {
1880-
ty::Array(_, n) => {
1881-
n.try_eval_usize(cx.tcx, cx.param_env).map_or(false, |val| (0..=32).contains(&val))
1882-
},
1880+
ty::Array(_, n) => n
1881+
.try_eval_usize(cx.tcx, cx.param_env)
1882+
.map_or(false, |val| (0..=32).contains(&val)),
18831883
_ => false,
18841884
}
18851885
}
@@ -1891,7 +1891,7 @@ fn extract_expr_from_first_stmt<'tcx>(block: &Block<'tcx>) -> Option<&'tcx Expr<
18911891
return None;
18921892
}
18931893
if let StmtKind::Local(ref local) = block.stmts[0].kind {
1894-
local.init.map(|expr| expr)
1894+
local.init //.map(|expr| expr)
18951895
} else {
18961896
None
18971897
}
@@ -2011,11 +2011,13 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
20112011
if let PatKind::Binding(.., ident, _) = local.pat.kind {
20122012
self.name = Some(ident.name);
20132013

2014-
self.state = local.init.as_ref().map_or(VarState::Declared, |init| if is_integer_const(&self.cx, init, 0) {
2014+
self.state = local.init.as_ref().map_or(VarState::Declared, |init| {
2015+
if is_integer_const(&self.cx, init, 0) {
20152016
VarState::Warn
20162017
} else {
20172018
VarState::Declared
2018-
})
2019+
}
2020+
})
20192021
}
20202022
}
20212023
}

clippy_lints/src/methods/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,9 +2469,9 @@ fn derefs_to_slice<'a, 'tcx>(
24692469
ty::Slice(_) => true,
24702470
ty::Adt(def, _) if def.is_box() => may_slice(cx, ty.boxed_ty()),
24712471
ty::Adt(..) => is_type_diagnostic_item(cx, ty, sym!(vec_type)),
2472-
ty::Array(_, size) => {
2473-
size.try_eval_usize(cx.tcx, cx.param_env).map_or(false, |size| size < 32)
2474-
},
2472+
ty::Array(_, size) => size
2473+
.try_eval_usize(cx.tcx, cx.param_env)
2474+
.map_or(false, |size| size < 32),
24752475
ty::Ref(_, inner, _) => may_slice(cx, inner),
24762476
_ => false,
24772477
}

clippy_lints/src/methods/unnecessary_filter_map.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ fn check_expression<'a, 'tcx>(
8181
}
8282
(true, true)
8383
},
84-
hir::ExprKind::Block(ref block, _) => {
85-
block.expr.as_ref().map_or((false, false), |expr| check_expression(cx, arg_id, &expr))
86-
},
84+
hir::ExprKind::Block(ref block, _) => block
85+
.expr
86+
.as_ref()
87+
.map_or((false, false), |expr| check_expression(cx, arg_id, &expr)),
8788
hir::ExprKind::Match(_, arms, _) => {
8889
let mut found_mapping = false;
8990
let mut found_filtering = false;

clippy_lints/src/minmax.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MinMaxPass {
5353
}
5454
}
5555

56-
#[derive(PartialEq, Eq, Debug)]
56+
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
5757
enum MinMax {
5858
Min,
5959
Max,

clippy_lints/src/misc.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -683,11 +683,9 @@ fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr<'_>, other: &Expr<'_>, l
683683
/// of what it means for an expression to be "used".
684684
fn is_used(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool {
685685
get_parent_expr(cx, expr).map_or(true, |parent| match parent.kind {
686-
ExprKind::Assign(_, ref rhs, _) | ExprKind::AssignOp(_, _, ref rhs) => {
687-
SpanlessEq::new(cx).eq_expr(rhs, expr)
688-
},
689-
_ => is_used(cx, parent),
690-
})
686+
ExprKind::Assign(_, ref rhs, _) | ExprKind::AssignOp(_, _, ref rhs) => SpanlessEq::new(cx).eq_expr(rhs, expr),
687+
_ => is_used(cx, parent),
688+
})
691689
}
692690

693691
/// Tests whether an expression is in a macro expansion (e.g., something

clippy_lints/src/option_if_let_else.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OptionIfLetElse {
260260
detection.some_expr,
261261
if detection.wrap_braces { " }" } else { "" },
262262
),
263-
Applicability::MachineApplicable,
263+
Applicability::MaybeIncorrect,
264264
);
265265
}
266266
}

0 commit comments

Comments
 (0)