Skip to content

Commit 1ede08a

Browse files
committed
Refactorings: use ranges instead of skip/take, use and_then instead of flatten
1 parent fdbd0c4 commit 1ede08a

1 file changed

Lines changed: 7 additions & 12 deletions

File tree

compiler/rustc_hir_analysis/src/delegation.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -290,21 +290,18 @@ pub(crate) fn get_delegation_self_ty<'tcx>(
290290
.iter()
291291
.skip_while(|a| a.as_region().is_some())
292292
.next()
293-
.map(|a| a.as_type())
294-
.flatten()
293+
.and_then(|a| a.as_type())
295294
}
296295
SelfPositionKind::Zero => ty::GenericArgs::identity_for_item(tcx, delegation_id)
297296
.first()
298-
.map(|a| a.as_type())
299-
.flatten(),
297+
.and_then(|a| a.as_type()),
300298
}
301299
}
302300

303301
(FnKind::AssocTraitImpl, FnKind::AssocTrait) => {
304302
create_trait_impl_to_trait_parent_args(tcx, delegation_id)
305303
.first()
306-
.map(|a| a.as_type())
307-
.flatten()
304+
.and_then(|a| a.as_type())
308305
}
309306

310307
(FnKind::AssocInherentImpl, FnKind::AssocTrait) => {
@@ -397,13 +394,13 @@ fn create_generic_args<'tcx>(
397394

398395
match self_pos_kind {
399396
SelfPositionKind::AfterLifetimes => {
400-
new_args.extend(parent_args.iter().skip(1).take(parent_args_lifetimes_count));
397+
new_args.extend(&parent_args[1..1 + parent_args_lifetimes_count]);
401398

402399
lifetimes_end_pos = parent_args_lifetimes_count;
403400

404401
new_args.push(parent_args[0]);
405402

406-
new_args.extend(parent_args.iter().skip(1 + parent_args_lifetimes_count));
403+
new_args.extend(&parent_args[1 + parent_args_lifetimes_count..]);
407404
}
408405
SelfPositionKind::Zero => {
409406
lifetimes_end_pos = 1 /* Self */ + parent_args_lifetimes_count;
@@ -423,10 +420,8 @@ fn create_generic_args<'tcx>(
423420

424421
lifetimes_end_pos = self_impact
425422
+ deleg_parent_args_without_self_count
426-
+ args
423+
+ &args[self_impact + deleg_parent_args_without_self_count..]
427424
.iter()
428-
.skip(self_impact)
429-
.skip(deleg_parent_args_without_self_count)
430425
.filter(|a| a.as_region().is_some())
431426
.count();
432427

@@ -453,7 +448,7 @@ fn create_generic_args<'tcx>(
453448
}
454449

455450
let skip_self = matches!(self_pos_kind, SelfPositionKind::AfterLifetimes);
456-
new_args.extend(child_args.iter().skip(child_lifetimes_count).skip(skip_self as usize));
451+
new_args.extend(&child_args[child_lifetimes_count + skip_self as usize..]);
457452
}
458453
}
459454

0 commit comments

Comments
 (0)