Fix a bunch of other low-hanging style lints (#36498)

- **Fix a bunch of low hanging style lints like unnecessary-return**
- **Fix single worktree violation**
- **And the rest**

Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2025-08-19 21:26:17 +02:00 committed by GitHub
parent df9c2aefb1
commit 05fc0c432c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
239 changed files with 854 additions and 1015 deletions

View file

@ -786,7 +786,7 @@ impl<T: 'static> PartialOrd for WeakEntity<T> {
#[cfg(any(test, feature = "leak-detection"))]
static LEAK_BACKTRACE: std::sync::LazyLock<bool> =
std::sync::LazyLock::new(|| std::env::var("LEAK_BACKTRACE").map_or(false, |b| !b.is_empty()));
std::sync::LazyLock::new(|| std::env::var("LEAK_BACKTRACE").is_ok_and(|b| !b.is_empty()));
#[cfg(any(test, feature = "leak-detection"))]
#[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq)]

View file

@ -2274,7 +2274,7 @@ impl Interactivity {
window.on_mouse_event(move |_: &MouseDownEvent, phase, window, _cx| {
if phase == DispatchPhase::Bubble && !window.default_prevented() {
let group_hovered = active_group_hitbox
.map_or(false, |group_hitbox_id| group_hitbox_id.is_hovered(window));
.is_some_and(|group_hitbox_id| group_hitbox_id.is_hovered(window));
let element_hovered = hitbox.is_hovered(window);
if group_hovered || element_hovered {
*active_state.borrow_mut() = ElementClickedState {
@ -2614,7 +2614,7 @@ pub(crate) fn register_tooltip_mouse_handlers(
window.on_mouse_event({
let active_tooltip = active_tooltip.clone();
move |_: &MouseDownEvent, _phase, window: &mut Window, _cx| {
if !tooltip_id.map_or(false, |tooltip_id| tooltip_id.is_hovered(window)) {
if !tooltip_id.is_some_and(|tooltip_id| tooltip_id.is_hovered(window)) {
clear_active_tooltip_if_not_hoverable(&active_tooltip, window);
}
}
@ -2623,7 +2623,7 @@ pub(crate) fn register_tooltip_mouse_handlers(
window.on_mouse_event({
let active_tooltip = active_tooltip.clone();
move |_: &ScrollWheelEvent, _phase, window: &mut Window, _cx| {
if !tooltip_id.map_or(false, |tooltip_id| tooltip_id.is_hovered(window)) {
if !tooltip_id.is_some_and(|tooltip_id| tooltip_id.is_hovered(window)) {
clear_active_tooltip_if_not_hoverable(&active_tooltip, window);
}
}

View file

@ -64,7 +64,7 @@ mod any_image_cache {
cx: &mut App,
) -> Option<Result<Arc<RenderImage>, ImageCacheError>> {
let image_cache = image_cache.clone().downcast::<I>().unwrap();
return image_cache.update(cx, |image_cache, cx| image_cache.load(resource, window, cx));
image_cache.update(cx, |image_cache, cx| image_cache.load(resource, window, cx))
}
}

View file

@ -938,9 +938,10 @@ impl Element for List {
let hitbox = window.insert_hitbox(bounds, HitboxBehavior::Normal);
// If the width of the list has changed, invalidate all cached item heights
if state.last_layout_bounds.map_or(true, |last_bounds| {
last_bounds.size.width != bounds.size.width
}) {
if state
.last_layout_bounds
.is_none_or(|last_bounds| last_bounds.size.width != bounds.size.width)
{
let new_items = SumTree::from_iter(
state.items.iter().map(|item| ListItem::Unmeasured {
focus_handle: item.focus_handle(),

View file

@ -458,7 +458,7 @@ impl DispatchTree {
.keymap
.borrow()
.bindings_for_input(input, &context_stack);
return (bindings, partial, context_stack);
(bindings, partial, context_stack)
}
/// dispatch_key processes the keystroke
@ -639,10 +639,7 @@ mod tests {
}
fn partial_eq(&self, action: &dyn Action) -> bool {
action
.as_any()
.downcast_ref::<Self>()
.map_or(false, |a| self == a)
action.as_any().downcast_ref::<Self>() == Some(self)
}
fn boxed_clone(&self) -> std::boxed::Box<dyn Action> {

View file

@ -287,7 +287,7 @@ impl KeyBindingContextPredicate {
return false;
}
}
return true;
true
}
// Workspace > Pane > Editor
//
@ -305,7 +305,7 @@ impl KeyBindingContextPredicate {
return true;
}
}
return false;
false
}
Self::And(left, right) => {
left.eval_inner(contexts, all_contexts) && right.eval_inner(contexts, all_contexts)

View file

@ -592,7 +592,7 @@ impl PlatformTextSystem for NoopTextSystem {
}
fn font_id(&self, _descriptor: &Font) -> Result<FontId> {
return Ok(FontId(1));
Ok(FontId(1))
}
fn font_metrics(&self, _font_id: FontId) -> FontMetrics {

View file

@ -49,7 +49,7 @@ fn parse_pci_id(id: &str) -> anyhow::Result<u32> {
"Expected a 4 digit PCI ID in hexadecimal format"
);
return u32::from_str_radix(id, 16).context("parsing PCI ID as hex");
u32::from_str_radix(id, 16).context("parsing PCI ID as hex")
}
#[cfg(test)]

View file

@ -441,7 +441,7 @@ impl<P: LinuxClient + 'static> Platform for P {
fn app_path(&self) -> Result<PathBuf> {
// get the path of the executable of the current process
let app_path = env::current_exe()?;
return Ok(app_path);
Ok(app_path)
}
fn set_menus(&self, menus: Vec<Menu>, _keymap: &Keymap) {

View file

@ -710,9 +710,7 @@ impl LinuxClient for WaylandClient {
fn set_cursor_style(&self, style: CursorStyle) {
let mut state = self.0.borrow_mut();
let need_update = state
.cursor_style
.map_or(true, |current_style| current_style != style);
let need_update = state.cursor_style != Some(style);
if need_update {
let serial = state.serial_tracker.get(SerialKind::MouseEnter);
@ -1577,7 +1575,7 @@ impl Dispatch<wl_pointer::WlPointer, ()> for WaylandClientStatePtr {
if state
.keyboard_focused_window
.as_ref()
.map_or(false, |keyboard_window| window.ptr_eq(keyboard_window))
.is_some_and(|keyboard_window| window.ptr_eq(keyboard_window))
{
state.enter_token = None;
}

View file

@ -669,8 +669,8 @@ impl WaylandWindowStatePtr {
pub fn set_size_and_scale(&self, size: Option<Size<Pixels>>, scale: Option<f32>) {
let (size, scale) = {
let mut state = self.state.borrow_mut();
if size.map_or(true, |size| size == state.bounds.size)
&& scale.map_or(true, |scale| scale == state.scale)
if size.is_none_or(|size| size == state.bounds.size)
&& scale.is_none_or(|scale| scale == state.scale)
{
return;
}

View file

@ -1586,11 +1586,11 @@ impl LinuxClient for X11Client {
fn read_from_primary(&self) -> Option<crate::ClipboardItem> {
let state = self.0.borrow_mut();
return state
state
.clipboard
.get_any(clipboard::ClipboardKind::Primary)
.context("X11: Failed to read from clipboard (primary)")
.log_with_level(log::Level::Debug);
.log_with_level(log::Level::Debug)
}
fn read_from_clipboard(&self) -> Option<crate::ClipboardItem> {
@ -1603,11 +1603,11 @@ impl LinuxClient for X11Client {
{
return state.clipboard_item.clone();
}
return state
state
.clipboard
.get_any(clipboard::ClipboardKind::Clipboard)
.context("X11: Failed to read from clipboard (clipboard)")
.log_with_level(log::Level::Debug);
.log_with_level(log::Level::Debug)
}
fn run(&self) {
@ -2010,12 +2010,12 @@ fn check_gtk_frame_extents_supported(
}
fn xdnd_is_atom_supported(atom: u32, atoms: &XcbAtoms) -> bool {
return atom == atoms.TEXT
atom == atoms.TEXT
|| atom == atoms.STRING
|| atom == atoms.UTF8_STRING
|| atom == atoms.TEXT_PLAIN
|| atom == atoms.TEXT_PLAIN_UTF8
|| atom == atoms.TextUriList;
|| atom == atoms.TextUriList
}
fn xdnd_get_supported_atom(
@ -2043,7 +2043,7 @@ fn xdnd_get_supported_atom(
}
}
}
return 0;
0
}
fn xdnd_send_finished(
@ -2144,7 +2144,7 @@ fn current_pointer_device_states(
if pointer_device_states.is_empty() {
log::error!("Found no xinput mouse pointers.");
}
return Some(pointer_device_states);
Some(pointer_device_states)
}
/// Returns true if the device is a pointer device. Does not include pointer device groups.

View file

@ -1078,11 +1078,11 @@ impl Clipboard {
} else {
String::from_utf8(result.bytes).map_err(|_| Error::ConversionFailure)?
};
return Ok(ClipboardItem::new_string(text));
Ok(ClipboardItem::new_string(text))
}
pub fn is_owner(&self, selection: ClipboardKind) -> bool {
return self.inner.is_owner(selection).unwrap_or(false);
self.inner.is_owner(selection).unwrap_or(false)
}
}

View file

@ -104,7 +104,7 @@ fn bit_is_set_in_vec(bit_vec: &Vec<u32>, bit_index: u16) -> bool {
let array_index = bit_index as usize / 32;
bit_vec
.get(array_index)
.map_or(false, |bits| bit_is_set(*bits, bit_index % 32))
.is_some_and(|bits| bit_is_set(*bits, bit_index % 32))
}
fn bit_is_set(bits: u32, bit_index: u16) -> bool {

View file

@ -311,9 +311,8 @@ unsafe fn parse_keystroke(native_event: id) -> Keystroke {
let mut shift = modifiers.contains(NSEventModifierFlags::NSShiftKeyMask);
let command = modifiers.contains(NSEventModifierFlags::NSCommandKeyMask);
let function = modifiers.contains(NSEventModifierFlags::NSFunctionKeyMask)
&& first_char.map_or(true, |ch| {
!(NSUpArrowFunctionKey..=NSModeSwitchFunctionKey).contains(&ch)
});
&& first_char
.is_none_or(|ch| !(NSUpArrowFunctionKey..=NSModeSwitchFunctionKey).contains(&ch));
#[allow(non_upper_case_globals)]
let key = match first_char {

View file

@ -797,7 +797,7 @@ impl Platform for MacPlatform {
.to_owned();
result.set_file_name(&new_filename);
}
return result;
result
})
}
}

View file

@ -319,7 +319,7 @@ impl MacTextSystemState {
fn is_emoji(&self, font_id: FontId) -> bool {
self.postscript_names_by_font_id
.get(&font_id)
.map_or(false, |postscript_name| {
.is_some_and(|postscript_name| {
postscript_name == "AppleColorEmoji" || postscript_name == ".AppleColorEmojiUI"
})
}

View file

@ -653,7 +653,7 @@ impl MacWindow {
.and_then(|titlebar| titlebar.traffic_light_position),
transparent_titlebar: titlebar
.as_ref()
.map_or(true, |titlebar| titlebar.appears_transparent),
.is_none_or(|titlebar| titlebar.appears_transparent),
previous_modifiers_changed_event: None,
keystroke_for_do_command: None,
do_command_handled: None,
@ -688,7 +688,7 @@ impl MacWindow {
});
}
if titlebar.map_or(true, |titlebar| titlebar.appears_transparent) {
if titlebar.is_none_or(|titlebar| titlebar.appears_transparent) {
native_window.setTitlebarAppearsTransparent_(YES);
native_window.setTitleVisibility_(NSWindowTitleVisibility::NSWindowTitleHidden);
}

View file

@ -270,9 +270,7 @@ impl PlatformDispatcher for TestDispatcher {
fn dispatch(&self, runnable: Runnable, label: Option<TaskLabel>) {
{
let mut state = self.state.lock();
if label.map_or(false, |label| {
state.deprioritized_task_labels.contains(&label)
}) {
if label.is_some_and(|label| state.deprioritized_task_labels.contains(&label)) {
state.deprioritized_background.push(runnable);
} else {
state.background.push(runnable);

View file

@ -573,7 +573,7 @@ impl Style {
if self
.border_color
.map_or(false, |color| !color.is_transparent())
.is_some_and(|color| !color.is_transparent())
{
min.x += self.border_widths.left.to_pixels(rem_size);
max.x -= self.border_widths.right.to_pixels(rem_size);
@ -633,7 +633,7 @@ impl Style {
window.paint_shadows(bounds, corner_radii, &self.box_shadow);
let background_color = self.background.as_ref().and_then(Fill::color);
if background_color.map_or(false, |color| !color.is_transparent()) {
if background_color.is_some_and(|color| !color.is_transparent()) {
let mut border_color = match background_color {
Some(color) => match color.tag {
BackgroundTag::Solid => color.solid,
@ -729,7 +729,7 @@ impl Style {
fn is_border_visible(&self) -> bool {
self.border_color
.map_or(false, |color| !color.is_transparent())
.is_some_and(|color| !color.is_transparent())
&& self.border_widths.any(|length| !length.is_zero())
}
}

View file

@ -435,7 +435,7 @@ impl WindowTextSystem {
});
}
if decoration_runs.last().map_or(false, |last_run| {
if decoration_runs.last().is_some_and(|last_run| {
last_run.color == run.color
&& last_run.underline == run.underline
&& last_run.strikethrough == run.strikethrough

View file

@ -243,14 +243,14 @@ impl FocusId {
pub fn contains_focused(&self, window: &Window, cx: &App) -> bool {
window
.focused(cx)
.map_or(false, |focused| self.contains(focused.id, window))
.is_some_and(|focused| self.contains(focused.id, window))
}
/// Obtains whether the element associated with this handle is contained within the
/// focused element or is itself focused.
pub fn within_focused(&self, window: &Window, cx: &App) -> bool {
let focused = window.focused(cx);
focused.map_or(false, |focused| focused.id.contains(*self, window))
focused.is_some_and(|focused| focused.id.contains(*self, window))
}
/// Obtains whether this handle contains the given handle in the most recently rendered frame.
@ -504,7 +504,7 @@ impl HitboxId {
return true;
}
}
return false;
false
}
/// Checks if the hitbox with this ID contains the mouse and should handle scroll events.
@ -634,7 +634,7 @@ impl TooltipId {
window
.tooltip_bounds
.as_ref()
.map_or(false, |tooltip_bounds| {
.is_some_and(|tooltip_bounds| {
tooltip_bounds.id == *self
&& tooltip_bounds.bounds.contains(&window.mouse_position())
})
@ -4466,7 +4466,7 @@ impl Window {
}
}
}
return None;
None
}
}