Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Fix `clippy::manual_map` lint violations (#36584)
tidelybc79076ad376
diff --git a/Cargo.toml b/Cargo.tomlindex d69e87fd6bb..9cd206cebf7 100644--- a/Cargo.toml+++ b/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"diff --git a/crates/acp_thread/src/acp_thread.rs b/crates/acp_thread/src/acp_thread.rsindex 4f20dbd5874..b8908fa0da5 100644--- a/crates/acp_thread/src/acp_thread.rs+++ b/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()?;diff --git a/crates/agent_ui/src/acp/thread_view.rs b/crates/agent_ui/src/acp/thread_view.rsindex b5277758509..f89198c84b2 100644--- a/crates/agent_ui/src/acp/thread_view.rs+++ b/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))diff --git a/crates/agent_ui/src/active_thread.rs b/crates/agent_ui/src/active_thread.rsindex bb5b47f0d69..e214986b82b 100644--- a/crates/agent_ui/src/active_thread.rs+++ b/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,diff --git a/crates/agent_ui/src/inline_assistant.rs b/crates/agent_ui/src/inline_assistant.rsindex 21115533400..13f1234b4de 100644--- a/crates/agent_ui/src/inline_assistant.rs+++ b/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)}}}diff --git a/crates/assistant_tools/src/edit_agent/streaming_fuzzy_matcher.rs b/crates/assistant_tools/src/edit_agent/streaming_fuzzy_matcher.rsindex 2dba8a2b6d4..33b37679f0a 100644--- a/crates/assistant_tools/src/edit_agent/streaming_fuzzy_matcher.rs+++ b/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>())}}diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rsindex 955ade04cd1..44c05dbc143 100644--- a/crates/editor/src/editor_tests.rs+++ b/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();diff --git a/crates/editor/src/hover_popover.rs b/crates/editor/src/hover_popover.rsindex 497f193cb4e..28a09e947f5 100644--- a/crates/editor/src/hover_popover.rs+++ b/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();diff --git a/crates/file_finder/src/file_finder.rs b/crates/file_finder/src/file_finder.rsindex 40acf012c91..8aaaa047292 100644--- a/crates/file_finder/src/file_finder.rs+++ b/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),};diff --git a/crates/git_ui/src/commit_modal.rs b/crates/git_ui/src/commit_modal.rsindex e1e6cee93c3..cae4d28a83b 100644--- a/crates/git_ui/src/commit_modal.rs+++ b/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")diff --git a/crates/gpui/src/platform/windows/window.rs b/crates/gpui/src/platform/windows/window.rsindex 32a6da23915..99e50733714 100644--- a/crates/gpui/src/platform/windows/window.rs+++ b/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.0diff --git a/crates/multi_buffer/src/multi_buffer.rs b/crates/multi_buffer/src/multi_buffer.rsindex 6b6d17a2461..60e9c14c344 100644--- a/crates/multi_buffer/src/multi_buffer.rs+++ b/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.diff --git a/crates/project/src/lsp_command.rs b/crates/project/src/lsp_command.rsindex a91e3fb402f..c90d85358a2 100644--- a/crates/project/src/lsp_command.rs+++ b/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(),diff --git a/crates/project/src/lsp_store.rs b/crates/project/src/lsp_store.rsindex e989b974e12..1b461178972 100644--- a/crates/project/src/lsp_store.rs+++ b/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())diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rsindex a5bfa883d5a..52ec7a98800 100644--- a/crates/project_panel/src/project_panel.rs+++ b/crates/project_panel/src/project_panel.rs@@ -3895,14 +3895,12 @@ impl ProjectPanel {// Always highlight directory or parent directory if it's fileif 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 fileif 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)}}diff --git a/crates/vim/src/command.rs b/crates/vim/src/command.rsindex 680c87f9e56..79d18a85e97 100644--- a/crates/vim/src/command.rs+++ b/crates/vim/src/command.rs@@ -1408,11 +1408,7 @@ pub fn command_interceptor(mut input: &str, cx: &App) -> Vec<CommandInterceptResstart: 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 {diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rsindex e49eb0a3455..dea18ddbe20 100644--- a/crates/workspace/src/pane.rs+++ b/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(),)diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rsindex b52687f3357..499e4f46190 100644--- a/crates/workspace/src/workspace.rs+++ b/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- }+ })+ })}};