Skip to content

Commit acf8387

Browse files
More iter().last() -> last(), iter().next() -> first()
1 parent b67cd4c commit acf8387

File tree

8 files changed

+10
-11
lines changed

8 files changed

+10
-11
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ impl<'a> AstValidator<'a> {
771771
self.dcx().emit_err(errors::ArgsBeforeConstraint {
772772
arg_spans: arg_spans.clone(),
773773
constraints: constraint_spans[0],
774-
args: *arg_spans.iter().last().unwrap(),
774+
args: *arg_spans.last().unwrap(),
775775
data: data.span,
776776
constraint_spans: errors::EmptyLabelManySpans(constraint_spans),
777777
arg_spans2: errors::EmptyLabelManySpans(arg_spans),

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,10 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
439439
let discr = discr.load_scalar(fx);
440440

441441
let use_bool_opt = switch_ty.kind() == fx.tcx.types.bool.kind()
442-
|| (targets.iter().count() == 1 && targets.iter().next().unwrap().0 == 0);
442+
|| (targets.iter().count() == 1 && targets.first().unwrap().0 == 0);
443443
if use_bool_opt {
444444
assert_eq!(targets.iter().count(), 1);
445-
let (then_value, then_block) = targets.iter().next().unwrap();
445+
let (then_value, then_block) = targets.first().unwrap();
446446
let then_block = fx.get_block(then_block);
447447
let else_block = fx.get_block(targets.otherwise());
448448
let test_zero = match then_value {

compiler/rustc_errors/src/emitter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2497,7 +2497,7 @@ impl HumanEmitter {
24972497
{
24982498
let mut buffer = StyledBuffer::new();
24992499
if !self.short_message {
2500-
if let Some(child) = children.iter().next()
2500+
if let Some(child) = children.first()
25012501
&& child.span.primary_spans().is_empty()
25022502
{
25032503
// We'll continue the vertical bar to point into the next note.

compiler/rustc_mir_build/src/thir/cx/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl<'tcx> ThirBuildCx<'tcx> {
187187
ty::Adt(_, args) => args,
188188
_ => bug!("ReborrowPin with non-Pin type"),
189189
};
190-
let pin_ty = pin_ty_args.iter().next().unwrap().expect_ty();
190+
let pin_ty = pin_ty_args.first().unwrap().expect_ty();
191191
let ptr_target_ty = match pin_ty.kind() {
192192
ty::Ref(_, ty, _) => *ty,
193193
_ => bug!("ReborrowPin with non-Ref type"),

compiler/rustc_parse/src/parser/pat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1671,7 +1671,7 @@ impl<'a> Parser<'a> {
16711671
/// If the user writes `S { ref field: name }` instead of `S { field: ref name }`, we suggest
16721672
/// the correct code.
16731673
fn recover_misplaced_pattern_modifiers(&self, fields: &ThinVec<PatField>, err: &mut Diag<'a>) {
1674-
if let Some(last) = fields.iter().last()
1674+
if let Some(last) = fields.last()
16751675
&& last.is_shorthand
16761676
&& let PatKind::Ident(binding, ident, None) = last.pat.kind
16771677
&& binding != BindingMode::NONE

compiler/rustc_parse/src/parser/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2533,7 +2533,7 @@ fn ttdelim_span() {
25332533
.unwrap();
25342534

25352535
let ast::ExprKind::MacCall(mac) = &expr.kind else { panic!("not a macro") };
2536-
let span = mac.args.tokens.iter().last().unwrap().span();
2536+
let span = mac.args.tokens.last().unwrap().span();
25372537

25382538
match psess.source_map().span_to_snippet(span) {
25392539
Ok(s) => assert_eq!(&s[..], "{ body }"),

compiler/rustc_resolve/src/imports.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
770770

771771
let mut diag = struct_span_code_err!(self.dcx(), span, E0432, "{msg}");
772772

773-
if let Some((_, UnresolvedImportError { note: Some(note), .. })) = errors.iter().last() {
773+
if let Some((_, UnresolvedImportError { note: Some(note), .. })) = errors.last() {
774774
diag.note(note.clone());
775775
}
776776

compiler/rustc_resolve/src/late.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3726,7 +3726,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
37263726
v.could_be_path = false;
37273727
}
37283728
self.report_error(
3729-
*v.origin.iter().next().unwrap(),
3729+
*v.origin.first().unwrap(),
37303730
ResolutionError::VariableNotBoundInPattern(v, self.parent_scope),
37313731
);
37323732
}
@@ -4369,8 +4369,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
43694369
self.resolve_path(&std_path, Some(ns), None, source)
43704370
{
43714371
// Check if we wrote `str::from_utf8` instead of `std::str::from_utf8`
4372-
let item_span =
4373-
path.iter().last().map_or(path_span, |segment| segment.ident.span);
4372+
let item_span = path.last().map_or(path_span, |segment| segment.ident.span);
43744373

43754374
self.r.confused_type_with_std_module.insert(item_span, path_span);
43764375
self.r.confused_type_with_std_module.insert(path_span, path_span);

0 commit comments

Comments
 (0)