Fix iterator related clippy style lint violations (#36437)

Release Notes:

- N/A
This commit is contained in:
tidely 2025-08-19 11:06:35 +03:00 committed by GitHub
parent 176c445817
commit 1fbb318714
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 21 additions and 33 deletions

View file

@ -820,6 +820,11 @@ single_range_in_vec_init = "allow"
style = { level = "allow", priority = -1 } style = { level = "allow", priority = -1 }
# Temporary list of style lints that we've fixed so far. # Temporary list of style lints that we've fixed so far.
iter_cloned_collect = "warn"
iter_next_slice = "warn"
iter_nth = "warn"
iter_nth_zero = "warn"
iter_skip_next = "warn"
module_inception = { level = "deny" } module_inception = { level = "deny" }
question_mark = { level = "deny" } question_mark = { level = "deny" }
redundant_closure = { level = "deny" } redundant_closure = { level = "deny" }

View file

@ -503,8 +503,7 @@ fn update_editor_selection(
&[last_kept_hunk_end..editor::Anchor::max()], &[last_kept_hunk_end..editor::Anchor::max()],
buffer_snapshot, buffer_snapshot,
) )
.skip(1) .nth(1)
.next()
}) })
.or_else(|| { .or_else(|| {
let first_kept_hunk = diff_hunks.first()?; let first_kept_hunk = diff_hunks.first()?;

View file

@ -690,11 +690,7 @@ impl MessageEditor {
.as_ref() .as_ref()
.map(|model| { .map(|model| {
self.incompatible_tools_state.update(cx, |state, cx| { self.incompatible_tools_state.update(cx, |state, cx| {
state state.incompatible_tools(&model.model, cx).to_vec()
.incompatible_tools(&model.model, cx)
.iter()
.cloned()
.collect::<Vec<_>>()
}) })
}) })
.unwrap_or_default(); .unwrap_or_default();

View file

@ -747,11 +747,7 @@ impl TextThreadEditor {
self.context.read(cx).invoked_slash_command(&command_id) self.context.read(cx).invoked_slash_command(&command_id)
{ {
if let InvokedSlashCommandStatus::Finished = invoked_slash_command.status { if let InvokedSlashCommandStatus::Finished = invoked_slash_command.status {
let run_commands_in_ranges = invoked_slash_command let run_commands_in_ranges = invoked_slash_command.run_commands_in_ranges.clone();
.run_commands_in_ranges
.iter()
.cloned()
.collect::<Vec<_>>();
for range in run_commands_in_ranges { for range in run_commands_in_ranges {
let commands = self.context.update(cx, |context, cx| { let commands = self.context.update(cx, |context, cx| {
context.reparse(cx); context.reparse(cx);

View file

@ -272,7 +272,7 @@ impl VariableList {
let mut entries = vec![]; let mut entries = vec![];
let scopes: Vec<_> = self.session.update(cx, |session, cx| { let scopes: Vec<_> = self.session.update(cx, |session, cx| {
session.scopes(stack_frame_id, cx).iter().cloned().collect() session.scopes(stack_frame_id, cx).to_vec()
}); });
let mut contains_local_scope = false; let mut contains_local_scope = false;

View file

@ -20932,7 +20932,7 @@ impl Editor {
let existing_pending = self let existing_pending = self
.text_highlights::<PendingInput>(cx) .text_highlights::<PendingInput>(cx)
.map(|(_, ranges)| ranges.iter().cloned().collect::<Vec<_>>()); .map(|(_, ranges)| ranges.to_vec());
if existing_pending.is_none() && pending.is_empty() { if existing_pending.is_none() && pending.is_empty() {
return; return;
} }

View file

@ -2756,7 +2756,7 @@ impl GitPanel {
for pending in self.pending.iter() { for pending in self.pending.iter() {
if pending.target_status == TargetStatus::Staged { if pending.target_status == TargetStatus::Staged {
pending_staged_count += pending.entries.len(); pending_staged_count += pending.entries.len();
last_pending_staged = pending.entries.iter().next().cloned(); last_pending_staged = pending.entries.first().cloned();
} }
if let Some(single_staged) = &single_staged_entry { if let Some(single_staged) = &single_staged_entry {
if pending if pending
@ -5261,7 +5261,7 @@ mod tests {
project project
.read(cx) .read(cx)
.worktrees(cx) .worktrees(cx)
.nth(0) .next()
.unwrap() .unwrap()
.read(cx) .read(cx)
.as_local() .as_local()
@ -5386,7 +5386,7 @@ mod tests {
project project
.read(cx) .read(cx)
.worktrees(cx) .worktrees(cx)
.nth(0) .next()
.unwrap() .unwrap()
.read(cx) .read(cx)
.as_local() .as_local()
@ -5437,7 +5437,7 @@ mod tests {
project project
.read(cx) .read(cx)
.worktrees(cx) .worktrees(cx)
.nth(0) .next()
.unwrap() .unwrap()
.read(cx) .read(cx)
.as_local() .as_local()
@ -5486,7 +5486,7 @@ mod tests {
project project
.read(cx) .read(cx)
.worktrees(cx) .worktrees(cx)
.nth(0) .next()
.unwrap() .unwrap()
.read(cx) .read(cx)
.as_local() .as_local()

View file

@ -280,7 +280,7 @@ impl ProjectDiff {
fn button_states(&self, cx: &App) -> ButtonStates { fn button_states(&self, cx: &App) -> ButtonStates {
let editor = self.editor.read(cx); let editor = self.editor.read(cx);
let snapshot = self.multibuffer.read(cx).snapshot(cx); let snapshot = self.multibuffer.read(cx).snapshot(cx);
let prev_next = snapshot.diff_hunks().skip(1).next().is_some(); let prev_next = snapshot.diff_hunks().nth(1).is_some();
let mut selection = true; let mut selection = true;
let mut ranges = editor let mut ranges = editor

View file

@ -86,7 +86,7 @@ pub fn serialize_operation(operation: &crate::Operation) -> proto::Operation {
proto::operation::UpdateCompletionTriggers { proto::operation::UpdateCompletionTriggers {
replica_id: lamport_timestamp.replica_id as u32, replica_id: lamport_timestamp.replica_id as u32,
lamport_timestamp: lamport_timestamp.value, lamport_timestamp: lamport_timestamp.value,
triggers: triggers.iter().cloned().collect(), triggers: triggers.clone(),
language_server_id: server_id.to_proto(), language_server_id: server_id.to_proto(),
}, },
), ),

View file

@ -98,9 +98,7 @@ impl KeyContextView {
cx.notify(); cx.notify();
}); });
let sub2 = cx.observe_pending_input(window, |this, window, cx| { let sub2 = cx.observe_pending_input(window, |this, window, cx| {
this.pending_keystrokes = window this.pending_keystrokes = window.pending_input_keystrokes().map(|k| k.to_vec());
.pending_input_keystrokes()
.map(|k| k.iter().cloned().collect());
if this.pending_keystrokes.is_some() { if this.pending_keystrokes.is_some() {
this.last_keystrokes.take(); this.last_keystrokes.take();
} }

View file

@ -472,13 +472,7 @@ impl KeymapEditor {
fn current_keystroke_query(&self, cx: &App) -> Vec<Keystroke> { fn current_keystroke_query(&self, cx: &App) -> Vec<Keystroke> {
match self.search_mode { match self.search_mode {
SearchMode::KeyStroke { .. } => self SearchMode::KeyStroke { .. } => self.keystroke_editor.read(cx).keystrokes().to_vec(),
.keystroke_editor
.read(cx)
.keystrokes()
.iter()
.cloned()
.collect(),
SearchMode::Normal => Default::default(), SearchMode::Normal => Default::default(),
} }
} }

View file

@ -601,7 +601,7 @@ fn pick_default_screen(cx: &App) -> Task<anyhow::Result<Option<Rc<dyn ScreenCapt
.metadata() .metadata()
.is_ok_and(|meta| meta.is_main.unwrap_or_default()) .is_ok_and(|meta| meta.is_main.unwrap_or_default())
}) })
.or_else(|| available_sources.iter().next()) .or_else(|| available_sources.first())
.cloned()) .cloned())
}) })
} }

View file

@ -221,7 +221,7 @@ pub(crate) fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
return; return;
}; };
let anchors = last_change.iter().cloned().collect::<Vec<_>>(); let anchors = last_change.to_vec();
let mut last_row = None; let mut last_row = None;
let ranges: Vec<_> = anchors let ranges: Vec<_> = anchors
.iter() .iter()