Enable clippy::clone_on_copy (#8728)

This PR enables the
[`clippy::clone_on_copy`](https://rust-lang.github.io/rust-clippy/master/index.html#/clone_on_copy)
rule and fixes the outstanding violations.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers
2024-03-02 17:37:48 -05:00
committed by GitHub
parent 5935681c5c
commit 9735912965
42 changed files with 144 additions and 160 deletions
+1 -1
View File
@@ -1291,7 +1291,7 @@ pub mod tests {
let mut cx = EditorTestContext::new(cx).await;
let editor = cx.editor.clone();
let window = cx.window.clone();
let window = cx.window;
_ = cx.update_window(window, |_, cx| {
let text_layout_details =
+10 -10
View File
@@ -884,10 +884,10 @@ impl sum_tree::Item for Fold {
fn summary(&self) -> Self::Summary {
FoldSummary {
start: self.range.start.clone(),
end: self.range.end.clone(),
min_start: self.range.start.clone(),
max_end: self.range.end.clone(),
start: self.range.start,
end: self.range.end,
min_start: self.range.start,
max_end: self.range.end,
count: 1,
}
}
@@ -919,10 +919,10 @@ impl sum_tree::Summary for FoldSummary {
fn add_summary(&mut self, other: &Self, buffer: &Self::Context) {
if other.min_start.cmp(&self.min_start, buffer) == Ordering::Less {
self.min_start = other.min_start.clone();
self.min_start = other.min_start;
}
if other.max_end.cmp(&self.max_end, buffer) == Ordering::Greater {
self.max_end = other.max_end.clone();
self.max_end = other.max_end;
}
#[cfg(debug_assertions)]
@@ -934,16 +934,16 @@ impl sum_tree::Summary for FoldSummary {
}
}
self.start = other.start.clone();
self.end = other.end.clone();
self.start = other.start;
self.end = other.end;
self.count += other.count;
}
}
impl<'a> sum_tree::Dimension<'a, FoldSummary> for FoldRange {
fn add_summary(&mut self, summary: &'a FoldSummary, _: &MultiBufferSnapshot) {
self.0.start = summary.start.clone();
self.0.end = summary.end.clone();
self.0.start = summary.start;
self.0.end = summary.end;
}
}
+2 -2
View File
@@ -283,7 +283,7 @@ impl<'a> Iterator for InlayChunks<'a> {
self.output_offset.0 += prefix.len();
let mut prefix = Chunk {
text: prefix,
..chunk.clone()
..*chunk
};
if !self.active_highlights.is_empty() {
let mut highlight_style = HighlightStyle::default();
@@ -322,7 +322,7 @@ impl<'a> Iterator for InlayChunks<'a> {
next_inlay_highlight_endpoint = range.end - offset_in_inlay.0;
highlight_style
.get_or_insert_with(|| Default::default())
.highlight(style.clone());
.highlight(*style);
}
} else {
next_inlay_highlight_endpoint = usize::MAX;
+22 -28
View File
@@ -1873,7 +1873,7 @@ impl Editor {
let new_cursor_position = self.selections.newest_anchor().head();
self.push_to_nav_history(
old_cursor_position.clone(),
*old_cursor_position,
Some(new_cursor_position.to_point(buffer)),
cx,
);
@@ -1892,8 +1892,7 @@ impl Editor {
if let Some(completion_menu) = completion_menu {
let cursor_position = new_cursor_position.to_offset(buffer);
let (word_range, kind) =
buffer.surrounding_word(completion_menu.initial_position.clone());
let (word_range, kind) = buffer.surrounding_word(completion_menu.initial_position);
if kind == Some(CharKind::Word)
&& word_range.to_inclusive().contains(&cursor_position)
{
@@ -2114,7 +2113,7 @@ impl Editor {
match click_count {
1 => {
start = buffer.anchor_before(position.to_point(&display_map));
end = start.clone();
end = start;
mode = SelectMode::Character;
auto_scroll = true;
}
@@ -2122,7 +2121,7 @@ impl Editor {
let range = movement::surrounding_word(&display_map, position);
start = buffer.anchor_before(range.start.to_point(&display_map));
end = buffer.anchor_before(range.end.to_point(&display_map));
mode = SelectMode::Word(start.clone()..end.clone());
mode = SelectMode::Word(start..end);
auto_scroll = true;
}
3 => {
@@ -2136,7 +2135,7 @@ impl Editor {
);
start = buffer.anchor_before(line_start);
end = buffer.anchor_before(next_line_start);
mode = SelectMode::Line(start.clone()..end.clone());
mode = SelectMode::Line(start..end);
auto_scroll = true;
}
_ => {
@@ -3208,7 +3207,7 @@ impl Editor {
let (buffer, buffer_position) = self
.buffer
.read(cx)
.text_anchor_for_position(position.clone(), cx)?;
.text_anchor_for_position(position, cx)?;
// OnTypeFormatting returns a list of edits, no need to pass them between Zed instances,
// hence we do LSP request & edit on host side only — add formats to host's history.
@@ -3252,17 +3251,14 @@ impl Editor {
};
let position = self.selections.newest_anchor().head();
let (buffer, buffer_position) = if let Some(output) = self
.buffer
.read(cx)
.text_anchor_for_position(position.clone(), cx)
{
output
} else {
return;
};
let (buffer, buffer_position) =
if let Some(output) = self.buffer.read(cx).text_anchor_for_position(position, cx) {
output
} else {
return;
};
let query = Self::completion_query(&self.buffer.read(cx).read(cx), position.clone());
let query = Self::completion_query(&self.buffer.read(cx).read(cx), position);
let completions = provider.completions(&buffer, buffer_position, cx);
let id = post_inc(&mut self.next_completion_id);
@@ -3700,7 +3696,7 @@ impl Editor {
let newest_selection = self.selections.newest_anchor().clone();
let cursor_position = newest_selection.head();
let (cursor_buffer, cursor_buffer_position) =
buffer.text_anchor_for_position(cursor_position.clone(), cx)?;
buffer.text_anchor_for_position(cursor_position, cx)?;
let (tail_buffer, _) = buffer.text_anchor_for_position(newest_selection.tail(), cx)?;
if cursor_buffer != tail_buffer {
return None;
@@ -3758,7 +3754,7 @@ impl Editor {
let range = Anchor {
buffer_id,
excerpt_id: excerpt_id.clone(),
excerpt_id: excerpt_id,
text_anchor: start,
}..Anchor {
buffer_id,
@@ -4741,7 +4737,7 @@ impl Editor {
row_range.end - 1,
snapshot.line_len(row_range.end - 1),
));
cursor_positions.push(anchor.clone()..anchor);
cursor_positions.push(anchor..anchor);
}
self.transact(cx, |this, cx| {
@@ -7447,10 +7443,8 @@ impl Editor {
pub fn open_url(&mut self, _: &OpenUrl, cx: &mut ViewContext<Self>) {
let position = self.selections.newest_anchor().head();
let Some((buffer, buffer_position)) = self
.buffer
.read(cx)
.text_anchor_for_position(position.clone(), cx)
let Some((buffer, buffer_position)) =
self.buffer.read(cx).text_anchor_for_position(position, cx)
else {
return;
};
@@ -7912,7 +7906,7 @@ impl Editor {
let block_id = this.insert_blocks(
[BlockProperties {
style: BlockStyle::Flex,
position: range.start.clone(),
position: range.start,
height: 1,
render: Arc::new({
let rename_editor = rename_editor.clone();
@@ -7976,11 +7970,11 @@ impl Editor {
let (start_buffer, start) = self
.buffer
.read(cx)
.text_anchor_for_position(rename.range.start.clone(), cx)?;
.text_anchor_for_position(rename.range.start, cx)?;
let (end_buffer, end) = self
.buffer
.read(cx)
.text_anchor_for_position(rename.range.end.clone(), cx)?;
.text_anchor_for_position(rename.range.end, cx)?;
if start_buffer != end_buffer {
return None;
}
@@ -8817,7 +8811,7 @@ impl Editor {
Ok(i) | Err(i) => i,
};
let right_position = right_position.clone();
let right_position = right_position;
ranges[start_ix..]
.iter()
.take_while(move |range| range.start.cmp(&right_position, buffer).is_le())
+8 -13
View File
@@ -381,7 +381,7 @@ pub fn show_link_definition(
let Some((buffer, buffer_position)) = editor
.buffer
.read(cx)
.text_anchor_for_position(trigger_anchor.clone(), cx)
.text_anchor_for_position(*trigger_anchor, cx)
else {
return;
};
@@ -389,7 +389,7 @@ pub fn show_link_definition(
let Some((excerpt_id, _, _)) = editor
.buffer()
.read(cx)
.excerpt_containing(trigger_anchor.clone(), cx)
.excerpt_containing(*trigger_anchor, cx)
else {
return;
};
@@ -424,9 +424,8 @@ pub fn show_link_definition(
TriggerPoint::Text(_) => {
if let Some((url_range, url)) = find_url(&buffer, buffer_position, cx.clone()) {
this.update(&mut cx, |_, _| {
let start =
snapshot.anchor_in_excerpt(excerpt_id.clone(), url_range.start);
let end = snapshot.anchor_in_excerpt(excerpt_id.clone(), url_range.end);
let start = snapshot.anchor_in_excerpt(excerpt_id, url_range.start);
let end = snapshot.anchor_in_excerpt(excerpt_id, url_range.end);
(
Some(RangeInEditor::Text(start..end)),
vec![HoverLink::Url(url)],
@@ -451,14 +450,10 @@ pub fn show_link_definition(
(
definition_result.iter().find_map(|link| {
link.origin.as_ref().map(|origin| {
let start = snapshot.anchor_in_excerpt(
excerpt_id.clone(),
origin.range.start,
);
let end = snapshot.anchor_in_excerpt(
excerpt_id.clone(),
origin.range.end,
);
let start = snapshot
.anchor_in_excerpt(excerpt_id, origin.range.start);
let end = snapshot
.anchor_in_excerpt(excerpt_id, origin.range.end);
RangeInEditor::Text(start..end)
})
}),
+3 -3
View File
@@ -297,10 +297,10 @@ fn show_hover(
let range = if let Some(range) = hover_result.range {
let start = snapshot
.buffer_snapshot
.anchor_in_excerpt(excerpt_id.clone(), range.start);
.anchor_in_excerpt(excerpt_id, range.start);
let end = snapshot
.buffer_snapshot
.anchor_in_excerpt(excerpt_id.clone(), range.end);
.anchor_in_excerpt(excerpt_id, range.end);
start..end
} else {
@@ -597,7 +597,7 @@ impl DiagnosticPopover {
.as_ref()
.unwrap_or(&self.local_diagnostic);
(entry.diagnostic.group_id, entry.range.start.clone())
(entry.diagnostic.group_id, entry.range.start)
}
}
+1 -1
View File
@@ -2197,7 +2197,7 @@ pub mod tests {
"another change #3",
] {
expected_changes.push(async_later_change);
let task_editor = editor.clone();
let task_editor = editor;
edits.push(cx.spawn(|mut cx| async move {
task_editor
.update(&mut cx, |editor, cx| {
+2 -2
View File
@@ -1147,8 +1147,8 @@ impl SearchableItem for Editor {
let end = excerpt
.buffer
.anchor_before(excerpt_range.start + range.end);
buffer.anchor_in_excerpt(excerpt.id.clone(), start)
..buffer.anchor_in_excerpt(excerpt.id.clone(), end)
buffer.anchor_in_excerpt(excerpt.id, start)
..buffer.anchor_in_excerpt(excerpt.id, end)
}),
);
}
+1 -1
View File
@@ -863,7 +863,7 @@ mod tests {
let mut cx = EditorTestContext::new(cx).await;
let editor = cx.editor.clone();
let window = cx.window.clone();
let window = cx.window;
_ = cx.update_window(window, |_, cx| {
let text_layout_details =
editor.update(cx, |editor, cx| editor.text_layout_details(cx));
+5 -5
View File
@@ -478,7 +478,7 @@ impl<'a> MutableSelectionsCollection<'a> {
if !oldest.start.cmp(&oldest.end, &self.buffer()).is_eq() {
let head = oldest.head();
oldest.start = head.clone();
oldest.start = head;
oldest.end = head;
self.collection.disjoint = Arc::from([oldest]);
self.selections_changed = true;
@@ -794,8 +794,8 @@ impl<'a> MutableSelectionsCollection<'a> {
let adjusted_disjoint: Vec<_> = anchors_with_status
.chunks(2)
.map(|selection_anchors| {
let (anchor_ix, start, kept_start) = selection_anchors[0].clone();
let (_, end, kept_end) = selection_anchors[1].clone();
let (anchor_ix, start, kept_start) = selection_anchors[0];
let (_, end, kept_end) = selection_anchors[1];
let selection = &self.disjoint[anchor_ix / 2];
let kept_head = if selection.reversed {
kept_start
@@ -826,8 +826,8 @@ impl<'a> MutableSelectionsCollection<'a> {
let buffer = self.buffer();
let anchors =
buffer.refresh_anchors([&pending.selection.start, &pending.selection.end]);
let (_, start, kept_start) = anchors[0].clone();
let (_, end, kept_end) = anchors[1].clone();
let (_, start, kept_start) = anchors[0];
let (_, end, kept_end) = anchors[1];
let kept_head = if pending.selection.reversed {
kept_start
} else {