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 12:20:13 +02:00
committed by GitHub
parent cf7c64d77f
commit 7bdc99abc1
306 changed files with 805 additions and 1102 deletions
+1 -1
View File
@@ -465,7 +465,7 @@ impl VisualContext for AsyncWindowContext {
V: Focusable,
{
self.window.update(self, |_, window, cx| {
view.read(cx).focus_handle(cx).clone().focus(window);
view.read(cx).focus_handle(cx).focus(window);
})
}
}
+2 -1
View File
@@ -231,14 +231,15 @@ impl AnyEntity {
Self {
entity_id: id,
entity_type,
entity_map: entity_map.clone(),
#[cfg(any(test, feature = "leak-detection"))]
handle_id: entity_map
.clone()
.upgrade()
.unwrap()
.write()
.leak_detector
.handle_created(id),
entity_map,
}
}
+4 -4
View File
@@ -134,7 +134,7 @@ impl TestAppContext {
app: App::new_app(platform.clone(), asset_source, http_client),
background_executor,
foreground_executor,
dispatcher: dispatcher.clone(),
dispatcher,
test_platform: platform,
text_system,
fn_name,
@@ -339,7 +339,7 @@ impl TestAppContext {
/// Returns all windows open in the test.
pub fn windows(&self) -> Vec<AnyWindowHandle> {
self.app.borrow().windows().clone()
self.app.borrow().windows()
}
/// Run the given task on the main thread.
@@ -619,7 +619,7 @@ impl<V> Entity<V> {
}
}),
cx.subscribe(self, {
let mut tx = tx.clone();
let mut tx = tx;
move |_, _: &Evt, _| {
tx.blocking_send(()).ok();
}
@@ -1026,7 +1026,7 @@ impl VisualContext for VisualTestContext {
fn focus<V: crate::Focusable>(&mut self, view: &Entity<V>) -> Self::Result<()> {
self.window
.update(&mut self.cx, |_, window, cx| {
view.read(cx).focus_handle(cx).clone().focus(window)
view.read(cx).focus_handle(cx).focus(window)
})
.unwrap()
}
+1 -1
View File
@@ -475,7 +475,7 @@ impl Element for Img {
.paint_image(
new_bounds,
corner_radii,
data.clone(),
data,
layout_state.frame_index,
self.style.grayscale,
)
+7 -7
View File
@@ -1046,7 +1046,7 @@ where
size: self.size.clone()
+ size(
amount.left.clone() + amount.right.clone(),
amount.top.clone() + amount.bottom.clone(),
amount.top.clone() + amount.bottom,
),
}
}
@@ -1159,10 +1159,10 @@ where
/// Computes the space available within outer bounds.
pub fn space_within(&self, outer: &Self) -> Edges<T> {
Edges {
top: self.top().clone() - outer.top().clone(),
right: outer.right().clone() - self.right().clone(),
bottom: outer.bottom().clone() - self.bottom().clone(),
left: self.left().clone() - outer.left().clone(),
top: self.top() - outer.top(),
right: outer.right() - self.right(),
bottom: outer.bottom() - self.bottom(),
left: self.left() - outer.left(),
}
}
}
@@ -1712,7 +1712,7 @@ where
top: self.top.clone() * rhs.top,
right: self.right.clone() * rhs.right,
bottom: self.bottom.clone() * rhs.bottom,
left: self.left.clone() * rhs.left,
left: self.left * rhs.left,
}
}
}
@@ -2411,7 +2411,7 @@ where
top_left: self.top_left.clone() * rhs.top_left,
top_right: self.top_right.clone() * rhs.top_right,
bottom_right: self.bottom_right.clone() * rhs.bottom_right,
bottom_left: self.bottom_left.clone() * rhs.bottom_left,
bottom_left: self.bottom_left * rhs.bottom_left,
}
}
}
+16 -16
View File
@@ -264,7 +264,7 @@ mod tests {
];
let mut keymap = Keymap::default();
keymap.add_bindings(bindings.clone());
keymap.add_bindings(bindings);
let (result, pending) = keymap.bindings_for_input(
&[Keystroke::parse("ctrl-a").unwrap()],
@@ -290,7 +290,7 @@ mod tests {
];
let mut keymap = Keymap::default();
keymap.add_bindings(bindings.clone());
keymap.add_bindings(bindings);
// binding is only enabled in a specific context
assert!(
@@ -344,7 +344,7 @@ mod tests {
];
let mut keymap = Keymap::default();
keymap.add_bindings(bindings.clone());
keymap.add_bindings(bindings);
let space = || Keystroke::parse("space").unwrap();
let w = || Keystroke::parse("w").unwrap();
@@ -396,7 +396,7 @@ mod tests {
KeyBinding::new("space w x", ActionAlpha {}, Some("editor")),
];
let mut keymap = Keymap::default();
keymap.add_bindings(bindings.clone());
keymap.add_bindings(bindings);
let space_editor = keymap.bindings_for_input(&[space()], &editor_workspace_context());
assert!(space_editor.0.is_empty());
@@ -410,7 +410,7 @@ mod tests {
KeyBinding::new("space w w", NoAction {}, Some("editor")),
];
let mut keymap = Keymap::default();
keymap.add_bindings(bindings.clone());
keymap.add_bindings(bindings);
let space_editor = keymap.bindings_for_input(&[space()], &editor_workspace_context());
assert!(space_editor.0.is_empty());
@@ -424,7 +424,7 @@ mod tests {
KeyBinding::new("space w w", NoAction {}, Some("editor")),
];
let mut keymap = Keymap::default();
keymap.add_bindings(bindings.clone());
keymap.add_bindings(bindings);
let space_editor = keymap.bindings_for_input(&[space()], &editor_workspace_context());
assert!(space_editor.0.is_empty());
@@ -439,7 +439,7 @@ mod tests {
];
let mut keymap = Keymap::default();
keymap.add_bindings(bindings.clone());
keymap.add_bindings(bindings);
// Ensure `space` results in pending input on the workspace, but not editor
let (result, pending) = keymap.bindings_for_input(
@@ -455,7 +455,7 @@ mod tests {
];
let mut keymap = Keymap::default();
keymap.add_bindings(bindings.clone());
keymap.add_bindings(bindings);
// Ensure `space` results in pending input on the workspace, but not editor
let (result, pending) = keymap.bindings_for_input(
@@ -474,7 +474,7 @@ mod tests {
];
let mut keymap = Keymap::default();
keymap.add_bindings(bindings.clone());
keymap.add_bindings(bindings);
// Ensure `space` results in pending input on the workspace, but not editor
let (result, pending) = keymap.bindings_for_input(
@@ -494,7 +494,7 @@ mod tests {
];
let mut keymap = Keymap::default();
keymap.add_bindings(bindings.clone());
keymap.add_bindings(bindings);
// Ensure `space` results in pending input on the workspace, but not editor
let (result, pending) = keymap.bindings_for_input(
@@ -516,7 +516,7 @@ mod tests {
];
let mut keymap = Keymap::default();
keymap.add_bindings(bindings.clone());
keymap.add_bindings(bindings);
// Ensure `space` results in pending input on the workspace, but not editor
let (result, pending) = keymap.bindings_for_input(
@@ -537,7 +537,7 @@ mod tests {
KeyBinding::new("ctrl-x 0", ActionAlpha, Some("Workspace")),
];
let mut keymap = Keymap::default();
keymap.add_bindings(bindings.clone());
keymap.add_bindings(bindings);
let matched = keymap.bindings_for_input(
&[Keystroke::parse("ctrl-x")].map(Result::unwrap),
@@ -560,7 +560,7 @@ mod tests {
KeyBinding::new("ctrl-x 0", NoAction, Some("Workspace")),
];
let mut keymap = Keymap::default();
keymap.add_bindings(bindings.clone());
keymap.add_bindings(bindings);
let matched = keymap.bindings_for_input(
&[Keystroke::parse("ctrl-x")].map(Result::unwrap),
@@ -579,7 +579,7 @@ mod tests {
KeyBinding::new("ctrl-x 0", NoAction, Some("vim_mode == normal")),
];
let mut keymap = Keymap::default();
keymap.add_bindings(bindings.clone());
keymap.add_bindings(bindings);
let matched = keymap.bindings_for_input(
&[Keystroke::parse("ctrl-x")].map(Result::unwrap),
@@ -602,7 +602,7 @@ mod tests {
KeyBinding::new("ctrl-x", ActionBeta, Some("vim_mode == normal")),
];
let mut keymap = Keymap::default();
keymap.add_bindings(bindings.clone());
keymap.add_bindings(bindings);
let matched = keymap.bindings_for_input(
&[Keystroke::parse("ctrl-x")].map(Result::unwrap),
@@ -629,7 +629,7 @@ mod tests {
];
let mut keymap = Keymap::default();
keymap.add_bindings(bindings.clone());
keymap.add_bindings(bindings);
assert_bindings(&keymap, &ActionAlpha {}, &["ctrl-a"]);
assert_bindings(&keymap, &ActionBeta {}, &[]);
+3 -7
View File
@@ -668,11 +668,7 @@ mod tests {
let contexts = vec![other_context.clone(), child_context.clone()];
assert!(!predicate.eval(&contexts));
let contexts = vec![
parent_context.clone(),
other_context.clone(),
child_context.clone(),
];
let contexts = vec![parent_context.clone(), other_context, child_context.clone()];
assert!(predicate.eval(&contexts));
assert!(!predicate.eval(&[]));
@@ -681,7 +677,7 @@ mod tests {
let zany_predicate = KeyBindingContextPredicate::parse("child > child").unwrap();
assert!(!zany_predicate.eval(slice::from_ref(&child_context)));
assert!(zany_predicate.eval(&[child_context.clone(), child_context.clone()]));
assert!(zany_predicate.eval(&[child_context.clone(), child_context]));
}
#[test]
@@ -718,7 +714,7 @@ mod tests {
let not_descendant = KeyBindingContextPredicate::parse("parent > !child").unwrap();
assert!(!not_descendant.eval(slice::from_ref(&parent_context)));
assert!(!not_descendant.eval(slice::from_ref(&child_context)));
assert!(!not_descendant.eval(&[parent_context.clone(), child_context.clone()]));
assert!(!not_descendant.eval(&[parent_context, child_context]));
let double_not = KeyBindingContextPredicate::parse("!!editor").unwrap();
assert!(double_not.eval(slice::from_ref(&editor_context)));
+2 -2
View File
@@ -108,13 +108,13 @@ impl LinuxCommon {
let callbacks = PlatformHandlers::default();
let dispatcher = Arc::new(LinuxDispatcher::new(main_sender.clone()));
let dispatcher = Arc::new(LinuxDispatcher::new(main_sender));
let background_executor = BackgroundExecutor::new(dispatcher.clone());
let common = LinuxCommon {
background_executor,
foreground_executor: ForegroundExecutor::new(dispatcher.clone()),
foreground_executor: ForegroundExecutor::new(dispatcher),
text_system,
appearance: WindowAppearance::Light,
auto_hide_scrollbars: false,
@@ -1280,7 +1280,6 @@ impl Dispatch<wl_keyboard::WlKeyboard, ()> for WaylandClientStatePtr {
let Some(focused_window) = focused_window else {
return;
};
let focused_window = focused_window.clone();
let keymap_state = state.keymap_state.as_ref().unwrap();
let keycode = Keycode::from(key + MIN_KEYCODE);
@@ -67,7 +67,7 @@ impl Cursor {
{
self.loaded_theme = Some(LoadedTheme {
theme,
name: theme_name.map(|name| name.to_string()),
name: theme_name,
scaled_size: self.scaled_size,
});
}
+1 -1
View File
@@ -1329,7 +1329,7 @@ impl X11Client {
state.composing = false;
drop(state);
if let Some(mut keystroke) = keystroke {
keystroke.key_char = Some(text.clone());
keystroke.key_char = Some(text);
window.handle_input(PlatformInput::KeyDown(crate::KeyDownEvent {
keystroke,
is_held: false,
@@ -332,7 +332,7 @@ impl MetalRenderer {
self.path_intermediate_texture = Some(self.device.new_texture(&texture_descriptor));
if self.path_sample_count > 1 {
let mut msaa_descriptor = texture_descriptor.clone();
let mut msaa_descriptor = texture_descriptor;
msaa_descriptor.set_texture_type(metal::MTLTextureType::D2Multisample);
msaa_descriptor.set_storage_mode(metal::MTLStorageMode::Private);
msaa_descriptor.set_sample_count(self.path_sample_count as _);
+2 -2
View File
@@ -187,14 +187,14 @@ impl TestPlatform {
.push_back(TestPrompt {
msg: msg.to_string(),
detail: detail.map(|s| s.to_string()),
answers: answers.clone(),
answers,
tx,
});
rx
}
pub(crate) fn set_active_window(&self, window: Option<TestWindow>) {
let executor = self.foreground_executor().clone();
let executor = self.foreground_executor();
let previous_window = self.active_window.borrow_mut().take();
self.active_window.borrow_mut().clone_from(&window);
+1 -1
View File
@@ -956,7 +956,7 @@ impl WindowsWindowInner {
click_count,
first_mouse: false,
});
let result = func(input.clone());
let result = func(input);
let handled = !result.propagate || result.default_prevented;
self.state.borrow_mut().callbacks.input = Some(func);
+1 -1
View File
@@ -108,7 +108,7 @@ impl From<SharedString> for Arc<str> {
fn from(val: SharedString) -> Self {
match val.0 {
ArcCow::Borrowed(borrowed) => Arc::from(borrowed),
ArcCow::Owned(owned) => owned.clone(),
ArcCow::Owned(owned) => owned,
}
}
}
+5 -5
View File
@@ -2453,7 +2453,7 @@ impl Window {
/// time.
pub fn get_asset<A: Asset>(&mut self, source: &A::Source, cx: &mut App) -> Option<A::Output> {
let (task, _) = cx.fetch_asset::<A>(source);
task.clone().now_or_never()
task.now_or_never()
}
/// Obtain the current element offset. This method should only be called during the
/// prepaint phase of element drawing.
@@ -3044,7 +3044,7 @@ impl Window {
let tile = self
.sprite_atlas
.get_or_insert_with(&params.clone().into(), &mut || {
.get_or_insert_with(&params.into(), &mut || {
Ok(Some((
data.size(frame_index),
Cow::Borrowed(
@@ -3731,7 +3731,7 @@ impl Window {
self.dispatch_keystroke_observers(
event,
Some(binding.action),
match_result.context_stack.clone(),
match_result.context_stack,
cx,
);
self.pending_input_changed(cx);
@@ -4442,7 +4442,7 @@ impl Window {
if let Some((_, inspector_id)) =
self.hovered_inspector_hitbox(inspector, &self.rendered_frame)
{
inspector.set_active_element_id(inspector_id.clone(), self);
inspector.set_active_element_id(inspector_id, self);
}
}
});
@@ -4583,7 +4583,7 @@ impl<V: 'static + Render> WindowHandle<V> {
where
C: AppContext,
{
cx.read_window(self, |root_view, _cx| root_view.clone())
cx.read_window(self, |root_view, _cx| root_view)
}
/// Check if this window is 'active'.