mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-18 10:48:36 +00:00
Format if_chain
invocations in clippy_utils
This commit is contained in:
parent
7ceffdee9b
commit
e7922f745d
4 changed files with 25 additions and 29 deletions
|
@ -340,8 +340,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
|
|||
_ => return None,
|
||||
};
|
||||
Some(Constant::Int(value))
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
|
@ -284,8 +284,7 @@ impl<'a> VecArgs<'a> {
|
|||
return if match_def_path(cx, fun_def_id, &paths::VEC_FROM_ELEM) && args.len() == 2 {
|
||||
// `vec![elem; size]` case
|
||||
Some(VecArgs::Repeat(&args[0], &args[1]))
|
||||
}
|
||||
else if match_def_path(cx, fun_def_id, &paths::SLICE_INTO_VEC) && args.len() == 1 {
|
||||
} else if match_def_path(cx, fun_def_id, &paths::SLICE_INTO_VEC) && args.len() == 1 {
|
||||
// `vec![a, b, c]` case
|
||||
if_chain! {
|
||||
if let hir::ExprKind::Box(boxed) = args[0].kind;
|
||||
|
@ -296,11 +295,9 @@ impl<'a> VecArgs<'a> {
|
|||
}
|
||||
|
||||
None
|
||||
}
|
||||
else if match_def_path(cx, fun_def_id, &paths::VEC_NEW) && args.is_empty() {
|
||||
} else if match_def_path(cx, fun_def_id, &paths::VEC_NEW) && args.is_empty() {
|
||||
Some(VecArgs::Vec(&[]))
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
None
|
||||
};
|
||||
}
|
||||
|
@ -456,7 +453,7 @@ pub fn get_vec_init_kind<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -
|
|||
if let ExprKind::Lit(lit) = &arg.kind;
|
||||
if let LitKind::Int(num, _) = lit.node;
|
||||
then {
|
||||
return Some(VecInitKind::WithLiteralCapacity(num.try_into().ok()?))
|
||||
return Some(VecInitKind::WithLiteralCapacity(num.try_into().ok()?));
|
||||
}
|
||||
}
|
||||
return Some(VecInitKind::WithExprCapacity(arg.hir_id));
|
||||
|
|
|
@ -603,7 +603,9 @@ pub fn trait_ref_of_method<'tcx>(cx: &LateContext<'tcx>, def_id: LocalDefId) ->
|
|||
if parent_impl != CRATE_DEF_ID;
|
||||
if let hir::Node::Item(item) = cx.tcx.hir().get_by_def_id(parent_impl);
|
||||
if let hir::ItemKind::Impl(impl_) = &item.kind;
|
||||
then { return impl_.of_trait.as_ref(); }
|
||||
then {
|
||||
return impl_.of_trait.as_ref();
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
@ -713,12 +715,7 @@ pub fn is_default_equivalent_call(cx: &LateContext<'_>, repl_func: &Expr<'_>) ->
|
|||
if let Some(repl_def_id) = cx.qpath_res(repl_func_qpath, repl_func.hir_id).opt_def_id();
|
||||
if is_diag_trait_item(cx, repl_def_id, sym::Default)
|
||||
|| is_default_equivalent_ctor(cx, repl_def_id, repl_func_qpath);
|
||||
then {
|
||||
true
|
||||
}
|
||||
else {
|
||||
false
|
||||
}
|
||||
then { true } else { false }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1553,8 +1550,7 @@ pub fn is_try<'tcx>(cx: &LateContext<'_>, expr: &'tcx Expr<'tcx>) -> Option<&'tc
|
|||
if arms.len() == 2;
|
||||
if arms[0].guard.is_none();
|
||||
if arms[1].guard.is_none();
|
||||
if (is_ok(cx, &arms[0]) && is_err(cx, &arms[1])) ||
|
||||
(is_ok(cx, &arms[1]) && is_err(cx, &arms[0]));
|
||||
if (is_ok(cx, &arms[0]) && is_err(cx, &arms[1])) || (is_ok(cx, &arms[1]) && is_err(cx, &arms[0]));
|
||||
then {
|
||||
return Some(expr);
|
||||
}
|
||||
|
@ -1644,7 +1640,7 @@ pub fn match_function_call<'tcx>(
|
|||
if let Some(fun_def_id) = cx.qpath_res(qpath, fun.hir_id).opt_def_id();
|
||||
if match_def_path(cx, fun_def_id, path);
|
||||
then {
|
||||
return Some(args)
|
||||
return Some(args);
|
||||
}
|
||||
};
|
||||
None
|
||||
|
|
|
@ -452,7 +452,11 @@ impl<'tcx> FormatArgsExpn<'tcx> {
|
|||
if let Ok(i) = usize::try_from(position);
|
||||
if let Some(&(j, format_trait)) = self.formatters.get(i);
|
||||
then {
|
||||
Some(FormatArgsArg { value: self.value_args[j], format_trait, spec: Some(spec) })
|
||||
Some(FormatArgsArg {
|
||||
value: self.value_args[j],
|
||||
format_trait,
|
||||
spec: Some(spec),
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue