Use split_{first,last}
in cs_fold1
.
It makes the code a little nicer to read.
This commit is contained in:
parent
ddcbba036a
commit
72a1621061
1 changed files with 8 additions and 9 deletions
|
@ -1717,22 +1717,21 @@ where
|
||||||
{
|
{
|
||||||
match *substructure.fields {
|
match *substructure.fields {
|
||||||
EnumMatching(.., ref all_fields) | Struct(_, ref all_fields) => {
|
EnumMatching(.., ref all_fields) | Struct(_, ref all_fields) => {
|
||||||
let (base, all_fields) = match (all_fields.is_empty(), use_foldl) {
|
let (base, rest) = match (all_fields.is_empty(), use_foldl) {
|
||||||
(false, true) => {
|
(false, true) => {
|
||||||
let field = &all_fields[0];
|
let (first, rest) = all_fields.split_first().unwrap();
|
||||||
let args = (field.span, field.self_.clone(), &field.other[..]);
|
let args = (first.span, first.self_.clone(), &first.other[..]);
|
||||||
(b(cx, Some(args)), &all_fields[1..])
|
(b(cx, Some(args)), rest)
|
||||||
}
|
}
|
||||||
(false, false) => {
|
(false, false) => {
|
||||||
let idx = all_fields.len() - 1;
|
let (last, rest) = all_fields.split_last().unwrap();
|
||||||
let field = &all_fields[idx];
|
let args = (last.span, last.self_.clone(), &last.other[..]);
|
||||||
let args = (field.span, field.self_.clone(), &field.other[..]);
|
(b(cx, Some(args)), rest)
|
||||||
(b(cx, Some(args)), &all_fields[..idx])
|
|
||||||
}
|
}
|
||||||
(true, _) => (b(cx, None), &all_fields[..]),
|
(true, _) => (b(cx, None), &all_fields[..]),
|
||||||
};
|
};
|
||||||
|
|
||||||
cs_fold_fields(use_foldl, f, base, cx, all_fields)
|
cs_fold_fields(use_foldl, f, base, cx, rest)
|
||||||
}
|
}
|
||||||
EnumNonMatchingCollapsed(..) => {
|
EnumNonMatchingCollapsed(..) => {
|
||||||
cs_fold_enumnonmatch(enum_nonmatch_f, cx, trait_span, substructure)
|
cs_fold_enumnonmatch(enum_nonmatch_f, cx, trait_span, substructure)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue