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

@ -974,8 +974,6 @@ impl Buffer {
TextBuffer::new_normalized(0, buffer_id, Default::default(), text).snapshot();
let mut syntax = SyntaxMap::new(&text).snapshot();
if let Some(language) = language.clone() {
let text = text.clone();
let language = language.clone();
let language_registry = language_registry.clone();
syntax.reparse(&text, language_registry, language);
}
@ -1020,9 +1018,6 @@ impl Buffer {
let text = TextBuffer::new_normalized(0, buffer_id, Default::default(), text).snapshot();
let mut syntax = SyntaxMap::new(&text).snapshot();
if let Some(language) = language.clone() {
let text = text.clone();
let language = language.clone();
let language_registry = language_registry.clone();
syntax.reparse(&text, language_registry, language);
}
BufferSnapshot {
@ -2206,7 +2201,7 @@ impl Buffer {
self.remote_selections.insert(
AGENT_REPLICA_ID,
SelectionSet {
selections: selections.clone(),
selections,
lamport_timestamp,
line_mode,
cursor_shape,
@ -3006,9 +3001,9 @@ impl BufferSnapshot {
}
let mut error_ranges = Vec::<Range<Point>>::new();
let mut matches = self.syntax.matches(range.clone(), &self.text, |grammar| {
grammar.error_query.as_ref()
});
let mut matches = self
.syntax
.matches(range, &self.text, |grammar| grammar.error_query.as_ref());
while let Some(mat) = matches.peek() {
let node = mat.captures[0].node;
let start = Point::from_ts_point(node.start_position());
@ -4075,7 +4070,7 @@ impl BufferSnapshot {
// Get the ranges of the innermost pair of brackets.
let mut result: Option<(Range<usize>, Range<usize>)> = None;
for pair in self.enclosing_bracket_ranges(range.clone()) {
for pair in self.enclosing_bracket_ranges(range) {
if let Some(range_filter) = range_filter
&& !range_filter(pair.open_range.clone(), pair.close_range.clone())
{
@ -4248,7 +4243,7 @@ impl BufferSnapshot {
.map(|(range, name)| {
(
name.to_string(),
self.text_for_range(range.clone()).collect::<String>(),
self.text_for_range(range).collect::<String>(),
)
})
.collect();

View file

@ -1744,7 +1744,7 @@ fn test_autoindent_block_mode(cx: &mut App) {
buffer.edit(
[(Point::new(2, 8)..Point::new(2, 8), inserted_text)],
Some(AutoindentMode::Block {
original_indent_columns: original_indent_columns.clone(),
original_indent_columns,
}),
cx,
);
@ -1790,9 +1790,9 @@ fn test_autoindent_block_mode_with_newline(cx: &mut App) {
"#
.unindent();
buffer.edit(
[(Point::new(2, 0)..Point::new(2, 0), inserted_text.clone())],
[(Point::new(2, 0)..Point::new(2, 0), inserted_text)],
Some(AutoindentMode::Block {
original_indent_columns: original_indent_columns.clone(),
original_indent_columns,
}),
cx,
);
@ -1843,7 +1843,7 @@ fn test_autoindent_block_mode_without_original_indent_columns(cx: &mut App) {
buffer.edit(
[(Point::new(2, 0)..Point::new(2, 0), inserted_text)],
Some(AutoindentMode::Block {
original_indent_columns: original_indent_columns.clone(),
original_indent_columns,
}),
cx,
);
@ -2030,7 +2030,7 @@ fn test_autoindent_with_injected_languages(cx: &mut App) {
let language_registry = Arc::new(LanguageRegistry::test(cx.background_executor().clone()));
language_registry.add(html_language.clone());
language_registry.add(javascript_language.clone());
language_registry.add(javascript_language);
cx.new(|cx| {
let (text, ranges) = marked_text_ranges(

View file

@ -206,7 +206,7 @@ impl CachedLspAdapter {
}
pub fn name(&self) -> LanguageServerName {
self.adapter.name().clone()
self.adapter.name()
}
pub async fn get_language_server_command(

View file

@ -432,7 +432,7 @@ impl LanguageRegistry {
let mut state = self.state.write();
state
.lsp_adapters
.entry(language_name.clone())
.entry(language_name)
.or_default()
.push(adapter.clone());
state.all_lsp_adapters.insert(adapter.name(), adapter);
@ -454,7 +454,7 @@ impl LanguageRegistry {
let cached_adapter = CachedLspAdapter::new(Arc::new(adapter));
state
.lsp_adapters
.entry(language_name.clone())
.entry(language_name)
.or_default()
.push(cached_adapter.clone());
state
@ -1167,8 +1167,7 @@ impl LanguageRegistryState {
soft_wrap: language.config.soft_wrap,
auto_indent_on_paste: language.config.auto_indent_on_paste,
..Default::default()
}
.clone(),
},
);
self.languages.push(language);
self.version += 1;

View file

@ -199,7 +199,7 @@ impl LanguageSettings {
if language_server.0.as_ref() == Self::REST_OF_LANGUAGE_SERVERS {
rest.clone()
} else {
vec![language_server.clone()]
vec![language_server]
}
})
.collect::<Vec<_>>()
@ -1793,7 +1793,7 @@ mod tests {
assert!(!settings.enabled_for_file(&dot_env_file, &cx));
// Test tilde expansion
let home = shellexpand::tilde("~").into_owned().to_string();
let home = shellexpand::tilde("~").into_owned();
let home_file = make_test_file(&[&home, "test.rs"]);
let settings = build_settings(&["~/test.rs"]);
assert!(!settings.enabled_for_file(&home_file, &cx));

View file

@ -832,7 +832,7 @@ impl SyntaxSnapshot {
query: fn(&Grammar) -> Option<&Query>,
) -> SyntaxMapCaptures<'a> {
SyntaxMapCaptures::new(
range.clone(),
range,
text,
[SyntaxLayer {
language,

View file

@ -58,8 +58,7 @@ fn test_splice_included_ranges() {
assert_eq!(change, 0..1);
// does not create overlapping ranges
let (new_ranges, change) =
splice_included_ranges(ranges.clone(), &[0..18], &[ts_range(20..32)]);
let (new_ranges, change) = splice_included_ranges(ranges, &[0..18], &[ts_range(20..32)]);
assert_eq!(
new_ranges,
&[ts_range(20..32), ts_range(50..60), ts_range(80..90)]
@ -104,7 +103,7 @@ fn test_syntax_map_layers_for_range(cx: &mut App) {
);
let mut syntax_map = SyntaxMap::new(&buffer);
syntax_map.set_language_registry(registry.clone());
syntax_map.set_language_registry(registry);
syntax_map.reparse(language.clone(), &buffer);
assert_layers_for_range(
@ -165,7 +164,7 @@ fn test_syntax_map_layers_for_range(cx: &mut App) {
// Put the vec! macro back, adding back the syntactic layer.
buffer.undo();
syntax_map.interpolate(&buffer);
syntax_map.reparse(language.clone(), &buffer);
syntax_map.reparse(language, &buffer);
assert_layers_for_range(
&syntax_map,
@ -252,8 +251,8 @@ fn test_dynamic_language_injection(cx: &mut App) {
assert!(syntax_map.contains_unknown_injections());
registry.add(Arc::new(html_lang()));
syntax_map.reparse(markdown.clone(), &buffer);
syntax_map.reparse(markdown_inline.clone(), &buffer);
syntax_map.reparse(markdown, &buffer);
syntax_map.reparse(markdown_inline, &buffer);
assert_layers_for_range(
&syntax_map,
&buffer,
@ -862,7 +861,7 @@ fn test_syntax_map_languages_loading_with_erb(cx: &mut App) {
log::info!("editing");
buffer.edit_via_marked_text(&text);
syntax_map.interpolate(&buffer);
syntax_map.reparse(language.clone(), &buffer);
syntax_map.reparse(language, &buffer);
assert_capture_ranges(
&syntax_map,
@ -986,7 +985,7 @@ fn test_random_edits(
syntax_map.reparse(language.clone(), &buffer);
let mut reference_syntax_map = SyntaxMap::new(&buffer);
reference_syntax_map.set_language_registry(registry.clone());
reference_syntax_map.set_language_registry(registry);
log::info!("initial text:\n{}", buffer.text());

View file

@ -88,11 +88,11 @@ pub fn text_diff_with_options(
let new_offset = new_byte_range.start;
hunk_input.clear();
hunk_input.update_before(tokenize(
&old_text[old_byte_range.clone()],
&old_text[old_byte_range],
options.language_scope.clone(),
));
hunk_input.update_after(tokenize(
&new_text[new_byte_range.clone()],
&new_text[new_byte_range],
options.language_scope.clone(),
));
diff_internal(&hunk_input, |old_byte_range, new_byte_range, _, _| {
@ -103,7 +103,7 @@ pub fn text_diff_with_options(
let replacement_text = if new_byte_range.is_empty() {
empty.clone()
} else {
new_text[new_byte_range.clone()].into()
new_text[new_byte_range].into()
};
edits.push((old_byte_range, replacement_text));
});
@ -111,9 +111,9 @@ pub fn text_diff_with_options(
let replacement_text = if new_byte_range.is_empty() {
empty.clone()
} else {
new_text[new_byte_range.clone()].into()
new_text[new_byte_range].into()
};
edits.push((old_byte_range.clone(), replacement_text));
edits.push((old_byte_range, replacement_text));
}
},
);