From 373e18bc88e4aa9c55c660da72f38ceb14fed986 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Sat, 2 Mar 2024 23:10:56 -0500 Subject: [PATCH] Enable `clippy::unnecessary_unwrap` (#8756) This PR enables the [`clippy::unnecessary_unwrap`](https://rust-lang.github.io/rust-clippy/master/index.html#/unnecessary_unwrap) rule and fixes the outstanding violations. Release Notes: - N/A --- crates/ai/src/embedding.rs | 8 +++----- crates/ui/src/components/popover_menu.rs | 6 ++++-- crates/ui/src/components/right_click_menu.rs | 15 ++++++++------- tooling/xtask/src/main.rs | 1 - 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/crates/ai/src/embedding.rs b/crates/ai/src/embedding.rs index 1be99d7b06..49611e002a 100644 --- a/crates/ai/src/embedding.rs +++ b/crates/ai/src/embedding.rs @@ -19,11 +19,9 @@ pub struct Embedding(pub Vec); impl FromSql for Embedding { fn column_result(value: ValueRef) -> FromSqlResult { let bytes = value.as_blob()?; - let embedding: Result, Box> = bincode::deserialize(bytes); - if embedding.is_err() { - return Err(rusqlite::types::FromSqlError::Other(embedding.unwrap_err())); - } - Ok(Embedding(embedding.unwrap())) + let embedding = + bincode::deserialize(bytes).map_err(|err| rusqlite::types::FromSqlError::Other(err))?; + Ok(Embedding(embedding)) } } diff --git a/crates/ui/src/components/popover_menu.rs b/crates/ui/src/components/popover_menu.rs index 0bbbee2900..de4de73f42 100644 --- a/crates/ui/src/components/popover_menu.rs +++ b/crates/ui/src/components/popover_menu.rs @@ -51,8 +51,10 @@ impl PopoverMenu { cx.subscribe(&new_menu, move |modal, _: &DismissEvent, cx| { if modal.focus_handle(cx).contains_focused(cx) { - if previous_focus_handle.is_some() { - cx.focus(previous_focus_handle.as_ref().unwrap()) + if let Some(previous_focus_handle) = + previous_focus_handle.as_ref() + { + cx.focus(previous_focus_handle); } } *menu2.borrow_mut() = None; diff --git a/crates/ui/src/components/right_click_menu.rs b/crates/ui/src/components/right_click_menu.rs index 8ad72c7b9e..4f7f062ec4 100644 --- a/crates/ui/src/components/right_click_menu.rs +++ b/crates/ui/src/components/right_click_menu.rs @@ -154,8 +154,8 @@ impl Element for RightClickMenu { cx.subscribe(&new_menu, move |modal, _: &DismissEvent, cx| { if modal.focus_handle(cx).contains_focused(cx) { - if previous_focus_handle.is_some() { - cx.focus(previous_focus_handle.as_ref().unwrap()) + if let Some(previous_focus_handle) = previous_focus_handle.as_ref() { + cx.focus(previous_focus_handle); } } *menu2.borrow_mut() = None; @@ -165,11 +165,12 @@ impl Element for RightClickMenu { cx.focus_view(&new_menu); *menu.borrow_mut() = Some(new_menu); - *position.borrow_mut() = if attach.is_some() && child_layout_id.is_some() { - attach.unwrap().corner(child_bounds) - } else { - cx.mouse_position() - }; + *position.borrow_mut() = + if let Some(attach) = attach.filter(|_| child_layout_id.is_some()) { + attach.corner(child_bounds) + } else { + cx.mouse_position() + }; cx.refresh(); } }); diff --git a/tooling/xtask/src/main.rs b/tooling/xtask/src/main.rs index 241cb96bc6..515436e58c 100644 --- a/tooling/xtask/src/main.rs +++ b/tooling/xtask/src/main.rs @@ -112,7 +112,6 @@ fn run_clippy(args: ClippyArgs) -> Result<()> { "clippy::suspicious_to_owned", "clippy::type_complexity", "clippy::unnecessary_to_owned", - "clippy::unnecessary_unwrap", "clippy::useless_conversion", "clippy::useless_format", "clippy::vec_init_then_push",