Skip to content

Commit 9aea2f5

Browse files
committed
misc: destruct args directly
avoids bounds checks
1 parent 123bc5e commit 9aea2f5

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

clippy_utils/src/higher.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,22 +288,22 @@ impl<'a> VecArgs<'a> {
288288
&& is_expn_of(fun.span, sym::vec).is_some()
289289
&& let Some(fun_def_id) = cx.qpath_res(qpath, fun.hir_id).opt_def_id()
290290
{
291-
return match (cx.tcx.get_diagnostic_name(fun_def_id), args.len()) {
292-
(Some(sym::vec_from_elem), 2) => {
291+
return match (cx.tcx.get_diagnostic_name(fun_def_id), args) {
292+
(Some(sym::vec_from_elem), [elem, size]) => {
293293
// `vec![elem; size]` case
294-
Some(VecArgs::Repeat(&args[0], &args[1]))
294+
Some(VecArgs::Repeat(elem, size))
295295
},
296-
(Some(sym::slice_into_vec), 1) => {
296+
(Some(sym::slice_into_vec), [slice]) => {
297297
// `vec![a, b, c]` case
298-
if let ExprKind::Call(_, [arg]) = &args[0].kind
298+
if let ExprKind::Call(_, [arg]) = slice.kind
299299
&& let ExprKind::Array(args) = arg.kind
300300
{
301301
Some(VecArgs::Vec(args))
302302
} else {
303303
None
304304
}
305305
},
306-
(Some(sym::vec_new), 0) => Some(VecArgs::Vec(&[])),
306+
(Some(sym::vec_new), []) => Some(VecArgs::Vec(&[])),
307307
_ => None,
308308
};
309309
}

0 commit comments

Comments
 (0)