Skip to content

More iter().last() -> last(), iter().next() -> first() #145402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ impl<'a> AstValidator<'a> {
self.dcx().emit_err(errors::ArgsBeforeConstraint {
arg_spans: arg_spans.clone(),
constraints: constraint_spans[0],
args: *arg_spans.iter().last().unwrap(),
args: *arg_spans.last().unwrap(),
data: data.span,
constraint_spans: errors::EmptyLabelManySpans(constraint_spans),
arg_spans2: errors::EmptyLabelManySpans(arg_spans),
Expand Down Expand Up @@ -1741,7 +1741,7 @@ fn deny_equality_constraints(
.map(|segment| segment.ident.name)
.zip(poly.trait_ref.path.segments.iter().map(|segment| segment.ident.name))
.all(|(a, b)| a == b)
&& let Some(potential_assoc) = full_path.segments.iter().last()
&& let Some(potential_assoc) = full_path.segments.last()
{
suggest(poly, potential_assoc, predicate);
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_cranelift/src/base.rs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be done in the cg_clif repo instead?

Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,10 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
let discr = discr.load_scalar(fx);

let use_bool_opt = switch_ty.kind() == fx.tcx.types.bool.kind()
|| (targets.iter().count() == 1 && targets.iter().next().unwrap().0 == 0);
|| (targets.iter().count() == 1 && targets.iter().first().unwrap().0 == 0);
if use_bool_opt {
assert_eq!(targets.iter().count(), 1);
let (then_value, then_block) = targets.iter().next().unwrap();
let (then_value, then_block) = targets.iter().first().unwrap();
let then_block = fx.get_block(then_block);
let else_block = fx.get_block(targets.otherwise());
let test_zero = match then_value {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2497,7 +2497,7 @@ impl HumanEmitter {
{
let mut buffer = StyledBuffer::new();
if !self.short_message {
if let Some(child) = children.iter().next()
if let Some(child) = children.first()
&& child.span.primary_spans().is_empty()
{
// We'll continue the vertical bar to point into the next note.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_macros/src/diagnostics/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl<'ty> FieldInnerTy<'ty> {
};

let path = &ty_path.path;
let ty = path.segments.iter().last().unwrap();
let ty = path.segments.last().unwrap();
let syn::PathArguments::AngleBracketed(bracketed) = &ty.arguments else {
panic!("expected bracketed generic arguments");
};
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/thir/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl<'tcx> ThirBuildCx<'tcx> {
ty::Adt(_, args) => args,
_ => bug!("ReborrowPin with non-Pin type"),
};
let pin_ty = pin_ty_args.iter().next().unwrap().expect_ty();
let pin_ty = pin_ty_args.first().unwrap().expect_ty();
let ptr_target_ty = match pin_ty.kind() {
ty::Ref(_, ty, _) => *ty,
_ => bug!("ReborrowPin with non-Ref type"),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1671,7 +1671,7 @@ impl<'a> Parser<'a> {
/// If the user writes `S { ref field: name }` instead of `S { field: ref name }`, we suggest
/// the correct code.
fn recover_misplaced_pattern_modifiers(&self, fields: &ThinVec<PatField>, err: &mut Diag<'a>) {
if let Some(last) = fields.iter().last()
if let Some(last) = fields.last()
&& last.is_shorthand
&& let PatKind::Ident(binding, ident, None) = last.pat.kind
&& binding != BindingMode::NONE
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2533,7 +2533,7 @@ fn ttdelim_span() {
.unwrap();

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

match psess.source_map().span_to_snippet(span) {
Ok(s) => assert_eq!(&s[..], "{ body }"),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

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

if let Some((_, UnresolvedImportError { note: Some(note), .. })) = errors.iter().last() {
if let Some((_, UnresolvedImportError { note: Some(note), .. })) = errors.last() {
diag.note(note.clone());
}

Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3726,7 +3726,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
v.could_be_path = false;
}
self.report_error(
*v.origin.iter().next().unwrap(),
*v.origin.first().unwrap(),
ResolutionError::VariableNotBoundInPattern(v, self.parent_scope),
);
}
Expand Down Expand Up @@ -4369,8 +4369,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
self.resolve_path(&std_path, Some(ns), None, source)
{
// Check if we wrote `str::from_utf8` instead of `std::str::from_utf8`
let item_span =
path.iter().last().map_or(path_span, |segment| segment.ident.span);
let item_span = path.last().map_or(path_span, |segment| segment.ident.span);

self.r.confused_type_with_std_module.insert(item_span, path_span);
self.r.confused_type_with_std_module.insert(path_span, path_span);
Expand Down
Loading