Fix clippy::manual_map lint violations (#36584)

#36577

Release Notes:

- N/A
This commit is contained in:
tidely 2025-08-20 16:17:28 +03:00 committed by GitHub
parent de12633591
commit bc79076ad3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 62 additions and 118 deletions

View file

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

View file

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

View file

@ -4012,12 +4012,9 @@ impl Render for AcpThreadView {
.children( .children(
if let Some(usage_callout) = self.render_usage_callout(line_height, cx) { if let Some(usage_callout) = self.render_usage_callout(line_height, cx) {
Some(usage_callout.into_any_element()) 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 { } 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)) .child(self.render_message_editor(window, cx))

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -3895,14 +3895,12 @@ impl ProjectPanel {
// Always highlight directory or parent directory if it's file // Always highlight directory or parent directory if it's file
if target_entry.is_dir() { if target_entry.is_dir() {
Some(target_entry.id) 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 { } 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 // Always highlight directory or parent directory if it's file
if target_entry.is_dir() { if target_entry.is_dir() {
Some(target_entry.id) 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 { } else {
None target_parent_path
.and_then(|parent_path| target_worktree.entry_for_path(parent_path))
.map(|parent_entry| parent_entry.id)
} }
} }

View file

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

View file

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

View file

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