Fix clippy::redundant_clone lint violations (#36558)

This removes around 900 unnecessary clones, ranging from cloning a few
ints all the way to large data structures and images.

A lot of these were fixed using `cargo clippy --fix --workspace
--all-targets`, however it often breaks other lints and needs to be run
again. This was then followed up with some manual fixing.

I understand this is a large diff, but all the changes are pretty
trivial. Rust is doing some heavy lifting here for us. Once I get it up
to speed with main, I'd appreciate this getting merged rather sooner
than later.

Release Notes:

- N/A
This commit is contained in:
tidely 2025-08-20 13:20:13 +03:00 committed by GitHub
parent cf7c64d77f
commit 7bdc99abc1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
306 changed files with 805 additions and 1102 deletions

View file

@ -1648,7 +1648,7 @@ impl OnMatchingLines {
});
window.dispatch_action(action, cx);
cx.defer_in(window, move |editor, window, cx| {
let newest = editor.selections.newest::<Point>(cx).clone();
let newest = editor.selections.newest::<Point>(cx);
editor.change_selections(
SelectionEffects::no_scroll(),
window,

View file

@ -74,11 +74,7 @@ impl ModeIndicator {
.map(|count| format!("{}", count)),
)
.chain(vim.selected_register.map(|reg| format!("\"{reg}")))
.chain(
vim.operator_stack
.iter()
.map(|item| item.status().to_string()),
)
.chain(vim.operator_stack.iter().map(|item| item.status()))
.chain(
cx.global::<VimGlobals>()
.post_count

View file

@ -719,21 +719,14 @@ impl Vim {
target: Some(SurroundsType::Motion(motion)),
});
} else {
self.normal_motion(
motion.clone(),
active_operator.clone(),
count,
forced_motion,
window,
cx,
)
self.normal_motion(motion, active_operator, count, forced_motion, window, cx)
}
}
Mode::Visual | Mode::VisualLine | Mode::VisualBlock => {
self.visual_motion(motion.clone(), count, window, cx)
self.visual_motion(motion, count, window, cx)
}
Mode::HelixNormal => self.helix_normal_motion(motion.clone(), count, window, cx),
Mode::HelixNormal => self.helix_normal_motion(motion, count, window, cx),
}
self.clear_operator(window, cx);
if let Some(operator) = waiting_operator {
@ -1327,7 +1320,7 @@ impl Motion {
pub fn range(
&self,
map: &DisplaySnapshot,
selection: Selection<DisplayPoint>,
mut selection: Selection<DisplayPoint>,
times: Option<usize>,
text_layout_details: &TextLayoutDetails,
forced_motion: bool,
@ -1372,7 +1365,6 @@ impl Motion {
(None, true) => Some((selection.head(), selection.goal)),
}?;
let mut selection = selection.clone();
selection.set_head(new_head, goal);
let mut kind = match (self.default_kind(), forced_motion) {
@ -2401,9 +2393,7 @@ fn matching(map: &DisplaySnapshot, display_point: DisplayPoint) -> DisplayPoint
let line_range = map.prev_line_boundary(point).0..line_end;
let visible_line_range =
line_range.start..Point::new(line_range.end.row, line_range.end.column.saturating_sub(1));
let ranges = map
.buffer_snapshot
.bracket_ranges(visible_line_range.clone());
let ranges = map.buffer_snapshot.bracket_ranges(visible_line_range);
if let Some(ranges) = ranges {
let line_range = line_range.start.to_offset(&map.buffer_snapshot)
..line_range.end.to_offset(&map.buffer_snapshot);

View file

@ -474,8 +474,7 @@ mod test {
Mode::Normal,
);
assert_eq!(
cx.read_from_clipboard()
.map(|item| item.text().unwrap().to_string()),
cx.read_from_clipboard().map(|item| item.text().unwrap()),
Some("jumps".into())
);
cx.simulate_keystrokes("d d p");
@ -487,8 +486,7 @@ mod test {
Mode::Normal,
);
assert_eq!(
cx.read_from_clipboard()
.map(|item| item.text().unwrap().to_string()),
cx.read_from_clipboard().map(|item| item.text().unwrap()),
Some("jumps".into())
);
cx.write_to_clipboard(ClipboardItem::new_string("test-copy".to_string()));

View file

@ -187,9 +187,7 @@ fn find_mini_delimiters(
};
// Try to find delimiters in visible range first
let ranges = map
.buffer_snapshot
.bracket_ranges(visible_line_range.clone());
let ranges = map.buffer_snapshot.bracket_ranges(visible_line_range);
if let Some(candidate) = cover_or_next(ranges, display_point, map, Some(&bracket_filter)) {
return Some(
DelimiterRange {

View file

@ -400,7 +400,7 @@ impl MarksState {
} else {
HashMap::default()
};
let old_points = self.serialized_marks.get(&path.clone());
let old_points = self.serialized_marks.get(&path);
if old_points == Some(&new_points) {
return;
}
@ -543,7 +543,7 @@ impl MarksState {
.insert(name.clone(), anchors);
if self.is_global_mark(&name) {
self.global_marks
.insert(name.clone(), MarkLocation::Buffer(multibuffer.entity_id()));
.insert(name, MarkLocation::Buffer(multibuffer.entity_id()));
}
if let Some(buffer) = buffer {
let buffer_id = buffer.read(cx).remote_id();
@ -559,7 +559,7 @@ impl MarksState {
let buffer_id = buffer.read(cx).remote_id();
self.buffer_marks.entry(buffer_id).or_default().insert(
name.clone(),
name,
anchors
.into_iter()
.map(|anchor| anchor.text_anchor)
@ -654,9 +654,9 @@ impl MarksState {
return;
}
};
self.global_marks.remove(&mark_name.clone());
self.global_marks.remove(&mark_name);
self.serialized_marks
.get_mut(&path.clone())
.get_mut(&path)
.map(|m| m.remove(&mark_name.clone()));
if let Some(workspace_id) = self.workspace_id(cx) {
cx.background_spawn(async move { DB.delete_mark(workspace_id, path, mark_name).await })
@ -1282,7 +1282,7 @@ impl RegistersView {
if let Some(register) = register {
matches.push(RegisterMatch {
name: '%',
contents: register.text.clone(),
contents: register.text,
})
}
}
@ -1374,7 +1374,7 @@ impl PickerDelegate for MarksViewDelegate {
_: &mut Window,
cx: &mut Context<Picker<Self>>,
) -> gpui::Task<()> {
let Some(workspace) = self.workspace.upgrade().clone() else {
let Some(workspace) = self.workspace.upgrade() else {
return Task::ready(());
};
cx.spawn(async move |picker, cx| {

View file

@ -292,12 +292,7 @@ impl NeovimBackedTestContext {
register: '"',
state: self.shared_state().await,
neovim: self.neovim.read_register('"').await,
editor: self
.read_from_clipboard()
.unwrap()
.text()
.unwrap()
.to_owned(),
editor: self.read_from_clipboard().unwrap().text().unwrap(),
}
}

View file

@ -453,7 +453,7 @@ impl NeovimConnection {
};
if self.data.back() != Some(&state) {
self.data.push_back(state.clone());
self.data.push_back(state);
}
(mode, ranges)

View file

@ -225,7 +225,7 @@ impl VimTestContext {
VimClipboard {
editor: self
.read_from_clipboard()
.map(|item| item.text().unwrap().to_string())
.map(|item| item.text().unwrap())
.unwrap_or_default(),
}
}

View file

@ -1693,7 +1693,7 @@ impl Vim {
}) {
editor.do_paste(
&register.text.to_string(),
register.clipboard_selections.clone(),
register.clipboard_selections,
false,
window,
cx,

View file

@ -1203,7 +1203,7 @@ mod test {
the lazy dog"});
assert_eq!(
cx.read_from_clipboard()
.map(|item| item.text().unwrap().to_string())
.map(|item| item.text().unwrap())
.unwrap(),
"The q"
);