Enable clippy::option_map_unit_fn (#8751)

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

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-03-02 22:08:37 -05:00 committed by GitHub
parent d19957b705
commit ea68f86476
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 75 additions and 55 deletions

View File

@ -631,14 +631,12 @@ impl ChatPanel {
"Copy message text", "Copy message text",
None, None,
cx.handler_for(&this, move |this, cx| { cx.handler_for(&this, move |this, cx| {
this.active_chat().map(|active_chat| { if let Some(message) = this.active_chat().and_then(|active_chat| {
if let Some(message) = active_chat.read(cx).find_loaded_message(message_id)
active_chat.read(cx).find_loaded_message(message_id) }) {
{ let text = message.body.clone();
let text = message.body.clone(); cx.write_to_clipboard(ClipboardItem::new(text))
cx.write_to_clipboard(ClipboardItem::new(text)) }
}
});
}), }),
) )
.when(can_delete_message, move |menu| { .when(can_delete_message, move |menu| {

View File

@ -119,7 +119,9 @@ impl Render for CopilotButton {
impl CopilotButton { impl CopilotButton {
pub fn new(fs: Arc<dyn Fs>, cx: &mut ViewContext<Self>) -> Self { pub fn new(fs: Arc<dyn Fs>, cx: &mut ViewContext<Self>) -> Self {
Copilot::global(cx).map(|copilot| cx.observe(&copilot, |_, _, cx| cx.notify()).detach()); if let Some(copilot) = Copilot::global(cx) {
cx.observe(&copilot, |_, _, cx| cx.notify()).detach()
}
cx.observe_global::<SettingsStore>(move |_, cx| cx.notify()) cx.observe_global::<SettingsStore>(move |_, cx| cx.notify())
.detach(); .detach();

View File

@ -957,14 +957,14 @@ impl CompletionsMenu {
.selected(item_ix == selected_item) .selected(item_ix == selected_item)
.on_click(cx.listener(move |editor, _event, cx| { .on_click(cx.listener(move |editor, _event, cx| {
cx.stop_propagation(); cx.stop_propagation();
editor if let Some(task) = editor.confirm_completion(
.confirm_completion( &ConfirmCompletion {
&ConfirmCompletion { item_ix: Some(item_ix),
item_ix: Some(item_ix), },
}, cx,
cx, ) {
) task.detach_and_log_err(cx)
.map(|task| task.detach_and_log_err(cx)); }
})) }))
.child(h_flex().overflow_hidden().child(completion_label)) .child(h_flex().overflow_hidden().child(completion_label))
.end_slot::<Div>(documentation_label), .end_slot::<Div>(documentation_label),
@ -1175,14 +1175,14 @@ impl CodeActionsMenu {
MouseButton::Left, MouseButton::Left,
cx.listener(move |editor, _, cx| { cx.listener(move |editor, _, cx| {
cx.stop_propagation(); cx.stop_propagation();
editor if let Some(task) = editor.confirm_code_action(
.confirm_code_action( &ConfirmCodeAction {
&ConfirmCodeAction { item_ix: Some(item_ix),
item_ix: Some(item_ix), },
}, cx,
cx, ) {
) task.detach_and_log_err(cx)
.map(|task| task.detach_and_log_err(cx)); }
}), }),
) )
// TASK: It would be good to make lsp_action.title a SharedString to avoid allocating here. // TASK: It would be good to make lsp_action.title a SharedString to avoid allocating here.

View File

@ -72,7 +72,9 @@ pub fn run_test(
if is_randomized { if is_randomized {
eprintln!("failing seed: {}", seed); eprintln!("failing seed: {}", seed);
} }
on_fail_fn.map(|f| f()); if let Some(f) = on_fail_fn {
f()
}
panic::resume_unwind(error); panic::resume_unwind(error);
} }
} }

View File

@ -657,9 +657,9 @@ impl SemanticIndex {
if register.await.log_err().is_none() { if register.await.log_err().is_none() {
// Stop tracking this worktree if the registration failed. // Stop tracking this worktree if the registration failed.
this.update(&mut cx, |this, _| { this.update(&mut cx, |this, _| {
this.projects.get_mut(&project).map(|project_state| { if let Some(project_state) = this.projects.get_mut(&project) {
project_state.worktrees.remove(&worktree_id); project_state.worktrees.remove(&worktree_id);
}); }
}) })
.ok(); .ok();
} }

View File

@ -1433,16 +1433,20 @@ impl Pane {
"Close Clean", "Close Clean",
Some(Box::new(CloseCleanItems)), Some(Box::new(CloseCleanItems)),
cx.handler_for(&pane, move |pane, cx| { cx.handler_for(&pane, move |pane, cx| {
pane.close_clean_items(&CloseCleanItems, cx) if let Some(task) = pane.close_clean_items(&CloseCleanItems, cx) {
.map(|task| task.detach_and_log_err(cx)); task.detach_and_log_err(cx)
}
}), }),
) )
.entry( .entry(
"Close All", "Close All",
Some(Box::new(CloseAllItems { save_intent: None })), Some(Box::new(CloseAllItems { save_intent: None })),
cx.handler_for(&pane, |pane, cx| { cx.handler_for(&pane, |pane, cx| {
pane.close_all_items(&CloseAllItems { save_intent: None }, cx) if let Some(task) =
.map(|task| task.detach_and_log_err(cx)); pane.close_all_items(&CloseAllItems { save_intent: None }, cx)
{
task.detach_and_log_err(cx)
}
}), }),
); );
@ -1783,42 +1787,49 @@ impl Render for Pane {
})) }))
.on_action( .on_action(
cx.listener(|pane: &mut Self, action: &CloseActiveItem, cx| { cx.listener(|pane: &mut Self, action: &CloseActiveItem, cx| {
pane.close_active_item(action, cx) if let Some(task) = pane.close_active_item(action, cx) {
.map(|task| task.detach_and_log_err(cx)); task.detach_and_log_err(cx)
}
}), }),
) )
.on_action( .on_action(
cx.listener(|pane: &mut Self, action: &CloseInactiveItems, cx| { cx.listener(|pane: &mut Self, action: &CloseInactiveItems, cx| {
pane.close_inactive_items(action, cx) if let Some(task) = pane.close_inactive_items(action, cx) {
.map(|task| task.detach_and_log_err(cx)); task.detach_and_log_err(cx)
}
}), }),
) )
.on_action( .on_action(
cx.listener(|pane: &mut Self, action: &CloseCleanItems, cx| { cx.listener(|pane: &mut Self, action: &CloseCleanItems, cx| {
pane.close_clean_items(action, cx) if let Some(task) = pane.close_clean_items(action, cx) {
.map(|task| task.detach_and_log_err(cx)); task.detach_and_log_err(cx)
}
}), }),
) )
.on_action( .on_action(
cx.listener(|pane: &mut Self, action: &CloseItemsToTheLeft, cx| { cx.listener(|pane: &mut Self, action: &CloseItemsToTheLeft, cx| {
pane.close_items_to_the_left(action, cx) if let Some(task) = pane.close_items_to_the_left(action, cx) {
.map(|task| task.detach_and_log_err(cx)); task.detach_and_log_err(cx)
}
}), }),
) )
.on_action( .on_action(
cx.listener(|pane: &mut Self, action: &CloseItemsToTheRight, cx| { cx.listener(|pane: &mut Self, action: &CloseItemsToTheRight, cx| {
pane.close_items_to_the_right(action, cx) if let Some(task) = pane.close_items_to_the_right(action, cx) {
.map(|task| task.detach_and_log_err(cx)); task.detach_and_log_err(cx)
}
}), }),
) )
.on_action(cx.listener(|pane: &mut Self, action: &CloseAllItems, cx| { .on_action(cx.listener(|pane: &mut Self, action: &CloseAllItems, cx| {
pane.close_all_items(action, cx) if let Some(task) = pane.close_all_items(action, cx) {
.map(|task| task.detach_and_log_err(cx)); task.detach_and_log_err(cx)
}
})) }))
.on_action( .on_action(
cx.listener(|pane: &mut Self, action: &CloseActiveItem, cx| { cx.listener(|pane: &mut Self, action: &CloseActiveItem, cx| {
pane.close_active_item(action, cx) if let Some(task) = pane.close_active_item(action, cx) {
.map(|task| task.detach_and_log_err(cx)); task.detach_and_log_err(cx)
}
}), }),
) )
.on_action( .on_action(

View File

@ -1627,8 +1627,11 @@ impl Workspace {
action: &CloseInactiveTabsAndPanes, action: &CloseInactiveTabsAndPanes,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) { ) {
self.close_all_internal(true, action.save_intent.unwrap_or(SaveIntent::Close), cx) if let Some(task) =
.map(|task| task.detach_and_log_err(cx)); self.close_all_internal(true, action.save_intent.unwrap_or(SaveIntent::Close), cx)
{
task.detach_and_log_err(cx)
}
} }
pub fn close_all_items_and_panes( pub fn close_all_items_and_panes(
@ -1636,8 +1639,11 @@ impl Workspace {
action: &CloseAllItemsAndPanes, action: &CloseAllItemsAndPanes,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) { ) {
self.close_all_internal(false, action.save_intent.unwrap_or(SaveIntent::Close), cx) if let Some(task) =
.map(|task| task.detach_and_log_err(cx)); self.close_all_internal(false, action.save_intent.unwrap_or(SaveIntent::Close), cx)
{
task.detach_and_log_err(cx)
}
} }
fn close_all_internal( fn close_all_internal(
@ -2599,8 +2605,9 @@ impl Workspace {
if Some(leader_id) == self.unfollow(&pane, cx) { if Some(leader_id) == self.unfollow(&pane, cx) {
return; return;
} }
self.start_following(leader_id, cx) if let Some(task) = self.start_following(leader_id, cx) {
.map(|task| task.detach_and_log_err(cx)); task.detach_and_log_err(cx)
}
} }
pub fn follow(&mut self, leader_id: PeerId, cx: &mut ViewContext<Self>) { pub fn follow(&mut self, leader_id: PeerId, cx: &mut ViewContext<Self>) {
@ -2642,8 +2649,9 @@ impl Workspace {
} }
// Otherwise, follow. // Otherwise, follow.
self.start_following(leader_id, cx) if let Some(task) = self.start_following(leader_id, cx) {
.map(|task| task.detach_and_log_err(cx)); task.detach_and_log_err(cx)
}
} }
pub fn unfollow(&mut self, pane: &View<Pane>, cx: &mut ViewContext<Self>) -> Option<PeerId> { pub fn unfollow(&mut self, pane: &View<Pane>, cx: &mut ViewContext<Self>) -> Option<PeerId> {

View File

@ -108,7 +108,6 @@ fn run_clippy(args: ClippyArgs) -> Result<()> {
"clippy::non_canonical_clone_impl", "clippy::non_canonical_clone_impl",
"clippy::non_canonical_partial_ord_impl", "clippy::non_canonical_partial_ord_impl",
"clippy::nonminimal_bool", "clippy::nonminimal_bool",
"clippy::option_map_unit_fn",
"clippy::redundant_closure_call", "clippy::redundant_closure_call",
"clippy::redundant_guards", "clippy::redundant_guards",
"clippy::reversed_empty_ranges", "clippy::reversed_empty_ranges",