Fix `clippy::manual_map` lint violations (#36584)

tidely created

#36577

Release Notes:

- N/A

Change summary

Cargo.toml                                                       |  1 
crates/acp_thread/src/acp_thread.rs                              |  8 
crates/agent_ui/src/acp/thread_view.rs                           |  7 
crates/agent_ui/src/active_thread.rs                             | 10 
crates/agent_ui/src/inline_assistant.rs                          | 10 
crates/assistant_tools/src/edit_agent/streaming_fuzzy_matcher.rs |  8 
crates/editor/src/editor_tests.rs                                |  8 
crates/editor/src/hover_popover.rs                               | 24 -
crates/file_finder/src/file_finder.rs                            |  7 
crates/git_ui/src/commit_modal.rs                                | 12 
crates/gpui/src/platform/windows/window.rs                       |  5 
crates/multi_buffer/src/multi_buffer.rs                          | 10 
crates/project/src/lsp_command.rs                                | 15 
crates/project/src/lsp_store.rs                                  | 15 
crates/project_panel/src/project_panel.rs                        | 20 -
crates/vim/src/command.rs                                        |  6 
crates/workspace/src/pane.rs                                     |  4 
crates/workspace/src/workspace.rs                                | 10 
18 files changed, 62 insertions(+), 118 deletions(-)

Detailed changes

Cargo.toml 🔗

@@ -871,6 +871,7 @@ manual_dangling_ptr = "warn"
 manual_is_ascii_check = "warn"
 manual_is_finite = "warn"
 manual_is_infinite = "warn"
+manual_map = "warn"
 manual_next_back = "warn"
 manual_non_exhaustive = "warn"
 manual_ok_or = "warn"

crates/acp_thread/src/acp_thread.rs 🔗

@@ -301,11 +301,9 @@ impl ToolCall {
     ) -> Option<AgentLocation> {
         let buffer = project
             .update(cx, |project, cx| {
-                if let Some(path) = project.project_path_for_absolute_path(&location.path, cx) {
-                    Some(project.open_buffer(path, cx))
-                } else {
-                    None
-                }
+                project
+                    .project_path_for_absolute_path(&location.path, cx)
+                    .map(|path| project.open_buffer(path, cx))
             })
             .ok()??;
         let buffer = buffer.await.log_err()?;

crates/agent_ui/src/acp/thread_view.rs 🔗

@@ -4012,12 +4012,9 @@ impl Render for AcpThreadView {
             .children(
                 if let Some(usage_callout) = self.render_usage_callout(line_height, cx) {
                     Some(usage_callout.into_any_element())
-                } else if let Some(token_limit_callout) =
-                    self.render_token_limit_callout(line_height, cx)
-                {
-                    Some(token_limit_callout.into_any_element())
                 } else {
-                    None
+                    self.render_token_limit_callout(line_height, cx)
+                        .map(|token_limit_callout| token_limit_callout.into_any_element())
                 },
             )
             .child(self.render_message_editor(window, cx))

crates/agent_ui/src/active_thread.rs 🔗

@@ -779,13 +779,11 @@ impl ActiveThread {
 
         let list_state = ListState::new(0, ListAlignment::Bottom, px(2048.));
 
-        let workspace_subscription = if let Some(workspace) = workspace.upgrade() {
-            Some(cx.observe_release(&workspace, |this, _, cx| {
+        let workspace_subscription = workspace.upgrade().map(|workspace| {
+            cx.observe_release(&workspace, |this, _, cx| {
                 this.dismiss_notifications(cx);
-            }))
-        } else {
-            None
-        };
+            })
+        });
 
         let mut this = Self {
             language_registry,

crates/agent_ui/src/inline_assistant.rs 🔗

@@ -1532,13 +1532,11 @@ impl InlineAssistant {
             .and_then(|item| item.act_as::<Editor>(cx))
         {
             Some(InlineAssistTarget::Editor(workspace_editor))
-        } else if let Some(terminal_view) = workspace
-            .active_item(cx)
-            .and_then(|item| item.act_as::<TerminalView>(cx))
-        {
-            Some(InlineAssistTarget::Terminal(terminal_view))
         } else {
-            None
+            workspace
+                .active_item(cx)
+                .and_then(|item| item.act_as::<TerminalView>(cx))
+                .map(InlineAssistTarget::Terminal)
         }
     }
 }

crates/assistant_tools/src/edit_agent/streaming_fuzzy_matcher.rs 🔗

@@ -794,10 +794,8 @@ mod tests {
     fn finish(mut finder: StreamingFuzzyMatcher) -> Option<String> {
         let snapshot = finder.snapshot.clone();
         let matches = finder.finish();
-        if let Some(range) = matches.first() {
-            Some(snapshot.text_for_range(range.clone()).collect::<String>())
-        } else {
-            None
-        }
+        matches
+            .first()
+            .map(|range| snapshot.text_for_range(range.clone()).collect::<String>())
     }
 }

crates/editor/src/editor_tests.rs 🔗

@@ -21065,13 +21065,7 @@ fn add_log_breakpoint_at_cursor(
     let (anchor, bp) = editor
         .breakpoints_at_cursors(window, cx)
         .first()
-        .and_then(|(anchor, bp)| {
-            if let Some(bp) = bp {
-                Some((*anchor, bp.clone()))
-            } else {
-                None
-            }
-        })
+        .and_then(|(anchor, bp)| bp.as_ref().map(|bp| (*anchor, bp.clone())))
         .unwrap_or_else(|| {
             let cursor_position: Point = editor.selections.newest(cx).head();
 

crates/editor/src/hover_popover.rs 🔗

@@ -174,11 +174,9 @@ pub fn hover_at_inlay(
 
                 let subscription = this
                     .update(cx, |_, cx| {
-                        if let Some(parsed_content) = &parsed_content {
-                            Some(cx.observe(parsed_content, |_, _, cx| cx.notify()))
-                        } else {
-                            None
-                        }
+                        parsed_content.as_ref().map(|parsed_content| {
+                            cx.observe(parsed_content, |_, _, cx| cx.notify())
+                        })
                     })
                     .ok()
                     .flatten();
@@ -450,11 +448,9 @@ fn show_hover(
                 let scroll_handle = ScrollHandle::new();
                 let subscription = this
                     .update(cx, |_, cx| {
-                        if let Some(parsed_content) = &parsed_content {
-                            Some(cx.observe(parsed_content, |_, _, cx| cx.notify()))
-                        } else {
-                            None
-                        }
+                        parsed_content.as_ref().map(|parsed_content| {
+                            cx.observe(parsed_content, |_, _, cx| cx.notify())
+                        })
                     })
                     .ok()
                     .flatten();
@@ -502,11 +498,9 @@ fn show_hover(
                 hover_highlights.push(range.clone());
                 let subscription = this
                     .update(cx, |_, cx| {
-                        if let Some(parsed_content) = &parsed_content {
-                            Some(cx.observe(parsed_content, |_, _, cx| cx.notify()))
-                        } else {
-                            None
-                        }
+                        parsed_content.as_ref().map(|parsed_content| {
+                            cx.observe(parsed_content, |_, _, cx| cx.notify())
+                        })
                     })
                     .ok()
                     .flatten();

crates/file_finder/src/file_finder.rs 🔗

@@ -267,10 +267,9 @@ impl FileFinder {
     ) {
         self.picker.update(cx, |picker, cx| {
             picker.delegate.include_ignored = match picker.delegate.include_ignored {
-                Some(true) => match FileFinderSettings::get_global(cx).include_ignored {
-                    Some(_) => Some(false),
-                    None => None,
-                },
+                Some(true) => FileFinderSettings::get_global(cx)
+                    .include_ignored
+                    .map(|_| false),
                 Some(false) => Some(true),
                 None => Some(true),
             };

crates/git_ui/src/commit_modal.rs 🔗

@@ -391,15 +391,9 @@ impl CommitModal {
             });
         let focus_handle = self.focus_handle(cx);
 
-        let close_kb_hint =
-            if let Some(close_kb) = ui::KeyBinding::for_action(&menu::Cancel, window, cx) {
-                Some(
-                    KeybindingHint::new(close_kb, cx.theme().colors().editor_background)
-                        .suffix("Cancel"),
-                )
-            } else {
-                None
-            };
+        let close_kb_hint = ui::KeyBinding::for_action(&menu::Cancel, window, cx).map(|close_kb| {
+            KeybindingHint::new(close_kb, cx.theme().colors().editor_background).suffix("Cancel")
+        });
 
         h_flex()
             .group("commit_editor_footer")

crates/gpui/src/platform/windows/window.rs 🔗

@@ -592,10 +592,7 @@ impl PlatformWindow for WindowsWindow {
     ) -> Option<Receiver<usize>> {
         let (done_tx, done_rx) = oneshot::channel();
         let msg = msg.to_string();
-        let detail_string = match detail {
-            Some(info) => Some(info.to_string()),
-            None => None,
-        };
+        let detail_string = detail.map(|detail| detail.to_string());
         let handle = self.0.hwnd;
         let answers = answers.to_vec();
         self.0

crates/multi_buffer/src/multi_buffer.rs 🔗

@@ -4069,13 +4069,9 @@ impl MultiBufferSnapshot {
                         buffer_end = buffer_end.min(end_buffer_offset);
                     }
 
-                    if let Some(iterator) =
-                        get_buffer_metadata(&excerpt.buffer, buffer_start..buffer_end)
-                    {
-                        Some(&mut current_excerpt_metadata.insert((excerpt.id, iterator)).1)
-                    } else {
-                        None
-                    }
+                    get_buffer_metadata(&excerpt.buffer, buffer_start..buffer_end).map(|iterator| {
+                        &mut current_excerpt_metadata.insert((excerpt.id, iterator)).1
+                    })
                 };
 
                 // Visit each metadata item.

crates/project/src/lsp_command.rs 🔗

@@ -2595,11 +2595,9 @@ impl LspCommand for GetCodeActions {
         server_id: LanguageServerId,
         cx: AsyncApp,
     ) -> Result<Vec<CodeAction>> {
-        let requested_kinds_set = if let Some(kinds) = self.kinds {
-            Some(kinds.into_iter().collect::<HashSet<_>>())
-        } else {
-            None
-        };
+        let requested_kinds_set = self
+            .kinds
+            .map(|kinds| kinds.into_iter().collect::<HashSet<_>>());
 
         let language_server = cx.update(|cx| {
             lsp_store
@@ -3821,12 +3819,11 @@ impl GetDocumentDiagnostics {
                 _ => None,
             },
             code,
-            code_description: match diagnostic.code_description {
-                Some(code_description) => Some(CodeDescription {
+            code_description: diagnostic
+                .code_description
+                .map(|code_description| CodeDescription {
                     href: Some(lsp::Url::parse(&code_description).unwrap()),
                 }),
-                None => None,
-            },
             related_information: Some(related_information),
             tags: Some(tags),
             source: diagnostic.source.clone(),

crates/project/src/lsp_store.rs 🔗

@@ -12270,11 +12270,10 @@ async fn populate_labels_for_completions(
     let lsp_completions = new_completions
         .iter()
         .filter_map(|new_completion| {
-            if let Some(lsp_completion) = new_completion.source.lsp_completion(true) {
-                Some(lsp_completion.into_owned())
-            } else {
-                None
-            }
+            new_completion
+                .source
+                .lsp_completion(true)
+                .map(|lsp_completion| lsp_completion.into_owned())
         })
         .collect::<Vec<_>>();
 
@@ -12294,11 +12293,7 @@ async fn populate_labels_for_completions(
     for completion in new_completions {
         match completion.source.lsp_completion(true) {
             Some(lsp_completion) => {
-                let documentation = if let Some(docs) = lsp_completion.documentation.clone() {
-                    Some(docs.into())
-                } else {
-                    None
-                };
+                let documentation = lsp_completion.documentation.clone().map(|docs| docs.into());
 
                 let mut label = labels.next().flatten().unwrap_or_else(|| {
                     CodeLabel::fallback_for_completion(&lsp_completion, language.as_deref())

crates/project_panel/src/project_panel.rs 🔗

@@ -3895,14 +3895,12 @@ impl ProjectPanel {
         // Always highlight directory or parent directory if it's file
         if target_entry.is_dir() {
             Some(target_entry.id)
-        } else if let Some(parent_entry) = target_entry
-            .path
-            .parent()
-            .and_then(|parent_path| target_worktree.entry_for_path(parent_path))
-        {
-            Some(parent_entry.id)
         } else {
-            None
+            target_entry
+                .path
+                .parent()
+                .and_then(|parent_path| target_worktree.entry_for_path(parent_path))
+                .map(|parent_entry| parent_entry.id)
         }
     }
 
@@ -3939,12 +3937,10 @@ impl ProjectPanel {
         // Always highlight directory or parent directory if it's file
         if target_entry.is_dir() {
             Some(target_entry.id)
-        } else if let Some(parent_entry) =
-            target_parent_path.and_then(|parent_path| target_worktree.entry_for_path(parent_path))
-        {
-            Some(parent_entry.id)
         } else {
-            None
+            target_parent_path
+                .and_then(|parent_path| target_worktree.entry_for_path(parent_path))
+                .map(|parent_entry| parent_entry.id)
         }
     }
 

crates/vim/src/command.rs 🔗

@@ -1408,11 +1408,7 @@ pub fn command_interceptor(mut input: &str, cx: &App) -> Vec<CommandInterceptRes
             start: Position::Line { row: 0, offset: 0 },
             end: Some(Position::LastLine { offset: 0 }),
         });
-        if let Some(action) = OnMatchingLines::parse(query, invert, range, cx) {
-            Some(action.boxed_clone())
-        } else {
-            None
-        }
+        OnMatchingLines::parse(query, invert, range, cx).map(|action| action.boxed_clone())
     } else if query.contains('!') {
         ShellExec::parse(query, range.clone())
     } else {

crates/workspace/src/pane.rs 🔗

@@ -2583,10 +2583,8 @@ impl Pane {
                     .children(
                         std::iter::once(if let Some(decorated_icon) = decorated_icon {
                             Some(div().child(decorated_icon.into_any_element()))
-                        } else if let Some(icon) = icon {
-                            Some(div().child(icon.into_any_element()))
                         } else {
-                            None
+                            icon.map(|icon| div().child(icon.into_any_element()))
                         })
                         .flatten(),
                     )

crates/workspace/src/workspace.rs 🔗

@@ -4732,14 +4732,12 @@ impl Workspace {
                         })
                     });
 
-                    if let Some(view) = view {
-                        Some(entry.insert(FollowerView {
+                    view.map(|view| {
+                        entry.insert(FollowerView {
                             view,
                             location: None,
-                        }))
-                    } else {
-                        None
-                    }
+                        })
+                    })
                 }
             };