Skip to content

Commit 72a1621

Browse files
committed
Use split_{first,last} in cs_fold1.
It makes the code a little nicer to read.
1 parent ddcbba0 commit 72a1621

File tree

1 file changed

+8
-9
lines changed
  • compiler/rustc_builtin_macros/src/deriving/generic

1 file changed

+8
-9
lines changed

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,22 +1717,21 @@ where
17171717
{
17181718
match *substructure.fields {
17191719
EnumMatching(.., ref all_fields) | Struct(_, ref all_fields) => {
1720-
let (base, all_fields) = match (all_fields.is_empty(), use_foldl) {
1720+
let (base, rest) = match (all_fields.is_empty(), use_foldl) {
17211721
(false, true) => {
1722-
let field = &all_fields[0];
1723-
let args = (field.span, field.self_.clone(), &field.other[..]);
1724-
(b(cx, Some(args)), &all_fields[1..])
1722+
let (first, rest) = all_fields.split_first().unwrap();
1723+
let args = (first.span, first.self_.clone(), &first.other[..]);
1724+
(b(cx, Some(args)), rest)
17251725
}
17261726
(false, false) => {
1727-
let idx = all_fields.len() - 1;
1728-
let field = &all_fields[idx];
1729-
let args = (field.span, field.self_.clone(), &field.other[..]);
1730-
(b(cx, Some(args)), &all_fields[..idx])
1727+
let (last, rest) = all_fields.split_last().unwrap();
1728+
let args = (last.span, last.self_.clone(), &last.other[..]);
1729+
(b(cx, Some(args)), rest)
17311730
}
17321731
(true, _) => (b(cx, None), &all_fields[..]),
17331732
};
17341733

1735-
cs_fold_fields(use_foldl, f, base, cx, all_fields)
1734+
cs_fold_fields(use_foldl, f, base, cx, rest)
17361735
}
17371736
EnumNonMatchingCollapsed(..) => {
17381737
cs_fold_enumnonmatch(enum_nonmatch_f, cx, trait_span, substructure)

0 commit comments

Comments
 (0)