Auto-fix clippy::collapsible_if violations (#36428)

Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz
2025-08-19 13:27:24 +00:00
committed by GitHub
parent 9e8ec72bd5
commit 8f567383e4
281 changed files with 6625 additions and 7086 deletions
@@ -434,24 +434,24 @@ impl BladeRenderer {
}
fn wait_for_gpu(&mut self) {
if let Some(last_sp) = self.last_sync_point.take() {
if !self.gpu.wait_for(&last_sp, MAX_FRAME_TIME_MS) {
log::error!("GPU hung");
#[cfg(target_os = "linux")]
if self.gpu.device_information().driver_name == "radv" {
log::error!(
"there's a known bug with amdgpu/radv, try setting ZED_PATH_SAMPLE_COUNT=0 as a workaround"
);
log::error!(
"if that helps you're running into https://github.com/zed-industries/zed/issues/26143"
);
}
if let Some(last_sp) = self.last_sync_point.take()
&& !self.gpu.wait_for(&last_sp, MAX_FRAME_TIME_MS)
{
log::error!("GPU hung");
#[cfg(target_os = "linux")]
if self.gpu.device_information().driver_name == "radv" {
log::error!(
"your device information is: {:?}",
self.gpu.device_information()
"there's a known bug with amdgpu/radv, try setting ZED_PATH_SAMPLE_COUNT=0 as a workaround"
);
log::error!(
"if that helps you're running into https://github.com/zed-industries/zed/issues/26143"
);
while !self.gpu.wait_for(&last_sp, MAX_FRAME_TIME_MS) {}
}
log::error!(
"your device information is: {:?}",
self.gpu.device_information()
);
while !self.gpu.wait_for(&last_sp, MAX_FRAME_TIME_MS) {}
}
}
@@ -359,13 +359,13 @@ impl WaylandClientStatePtr {
}
changed
};
if changed {
if let Some(mut callback) = state.common.callbacks.keyboard_layout_change.take() {
drop(state);
callback();
state = client.borrow_mut();
state.common.callbacks.keyboard_layout_change = Some(callback);
}
if changed && let Some(mut callback) = state.common.callbacks.keyboard_layout_change.take()
{
drop(state);
callback();
state = client.borrow_mut();
state.common.callbacks.keyboard_layout_change = Some(callback);
}
}
@@ -373,15 +373,15 @@ impl WaylandClientStatePtr {
let mut client = self.get_client();
let mut state = client.borrow_mut();
let closed_window = state.windows.remove(surface_id).unwrap();
if let Some(window) = state.mouse_focused_window.take() {
if !window.ptr_eq(&closed_window) {
state.mouse_focused_window = Some(window);
}
if let Some(window) = state.mouse_focused_window.take()
&& !window.ptr_eq(&closed_window)
{
state.mouse_focused_window = Some(window);
}
if let Some(window) = state.keyboard_focused_window.take() {
if !window.ptr_eq(&closed_window) {
state.keyboard_focused_window = Some(window);
}
if let Some(window) = state.keyboard_focused_window.take()
&& !window.ptr_eq(&closed_window)
{
state.keyboard_focused_window = Some(window);
}
if state.windows.is_empty() {
state.common.signal.stop();
@@ -1784,17 +1784,17 @@ impl Dispatch<wl_pointer::WlPointer, ()> for WaylandClientStatePtr {
drop(state);
window.handle_input(input);
}
} else if let Some(discrete) = discrete {
if let Some(window) = state.mouse_focused_window.clone() {
let input = PlatformInput::ScrollWheel(ScrollWheelEvent {
position: state.mouse_location.unwrap(),
delta: ScrollDelta::Lines(discrete),
modifiers: state.modifiers,
touch_phase: TouchPhase::Moved,
});
drop(state);
window.handle_input(input);
}
} else if let Some(discrete) = discrete
&& let Some(window) = state.mouse_focused_window.clone()
{
let input = PlatformInput::ScrollWheel(ScrollWheelEvent {
position: state.mouse_location.unwrap(),
delta: ScrollDelta::Lines(discrete),
modifiers: state.modifiers,
touch_phase: TouchPhase::Moved,
});
drop(state);
window.handle_input(input);
}
}
}
@@ -45,10 +45,11 @@ impl Cursor {
}
fn set_theme_internal(&mut self, theme_name: Option<String>) {
if let Some(loaded_theme) = self.loaded_theme.as_ref() {
if loaded_theme.name == theme_name && loaded_theme.scaled_size == self.scaled_size {
return;
}
if let Some(loaded_theme) = self.loaded_theme.as_ref()
&& loaded_theme.name == theme_name
&& loaded_theme.scaled_size == self.scaled_size
{
return;
}
let result = if let Some(theme_name) = theme_name.as_ref() {
CursorTheme::load_from_name(
@@ -713,21 +713,20 @@ impl WaylandWindowStatePtr {
}
pub fn handle_input(&self, input: PlatformInput) {
if let Some(ref mut fun) = self.callbacks.borrow_mut().input {
if !fun(input.clone()).propagate {
return;
}
if let Some(ref mut fun) = self.callbacks.borrow_mut().input
&& !fun(input.clone()).propagate
{
return;
}
if let PlatformInput::KeyDown(event) = input {
if event.keystroke.modifiers.is_subset_of(&Modifiers::shift()) {
if let Some(key_char) = &event.keystroke.key_char {
let mut state = self.state.borrow_mut();
if let Some(mut input_handler) = state.input_handler.take() {
drop(state);
input_handler.replace_text_in_range(None, key_char);
self.state.borrow_mut().input_handler = Some(input_handler);
}
}
if let PlatformInput::KeyDown(event) = input
&& event.keystroke.modifiers.is_subset_of(&Modifiers::shift())
&& let Some(key_char) = &event.keystroke.key_char
{
let mut state = self.state.borrow_mut();
if let Some(mut input_handler) = state.input_handler.take() {
drop(state);
input_handler.replace_text_in_range(None, key_char);
self.state.borrow_mut().input_handler = Some(input_handler);
}
}
}
+15 -14
View File
@@ -565,10 +565,10 @@ impl X11Client {
events.push(last_keymap_change_event);
}
if let Some(last_press) = last_key_press.as_ref() {
if last_press.detail == key_press.detail {
continue;
}
if let Some(last_press) = last_key_press.as_ref()
&& last_press.detail == key_press.detail
{
continue;
}
if let Some(Event::KeyRelease(key_release)) =
@@ -2035,12 +2035,11 @@ fn xdnd_get_supported_atom(
),
)
.log_with_level(Level::Warn)
&& let Some(atoms) = reply.value32()
{
if let Some(atoms) = reply.value32() {
for atom in atoms {
if xdnd_is_atom_supported(atom, supported_atoms) {
return atom;
}
for atom in atoms {
if xdnd_is_atom_supported(atom, supported_atoms) {
return atom;
}
}
}
@@ -2411,11 +2410,13 @@ fn legacy_get_randr_scale_factor(connection: &XCBConnection, root: u32) -> Optio
let mut crtc_infos: HashMap<randr::Crtc, randr::GetCrtcInfoReply> = HashMap::default();
let mut valid_outputs: HashSet<randr::Output> = HashSet::new();
for (crtc, cookie) in crtc_cookies {
if let Ok(reply) = cookie.reply() {
if reply.width > 0 && reply.height > 0 && !reply.outputs.is_empty() {
crtc_infos.insert(crtc, reply.clone());
valid_outputs.extend(&reply.outputs);
}
if let Ok(reply) = cookie.reply()
&& reply.width > 0
&& reply.height > 0
&& !reply.outputs.is_empty()
{
crtc_infos.insert(crtc, reply.clone());
valid_outputs.extend(&reply.outputs);
}
}
+19 -19
View File
@@ -1120,25 +1120,25 @@ impl Drop for Clipboard {
log::error!("Failed to flush the clipboard window. Error: {}", e);
return;
}
if let Some(global_cb) = global_cb {
if let Err(e) = global_cb.server_handle.join() {
// Let's try extracting the error message
let message;
if let Some(msg) = e.downcast_ref::<&'static str>() {
message = Some((*msg).to_string());
} else if let Some(msg) = e.downcast_ref::<String>() {
message = Some(msg.clone());
} else {
message = None;
}
if let Some(message) = message {
log::error!(
"The clipboard server thread panicked. Panic message: '{}'",
message,
);
} else {
log::error!("The clipboard server thread panicked.");
}
if let Some(global_cb) = global_cb
&& let Err(e) = global_cb.server_handle.join()
{
// Let's try extracting the error message
let message;
if let Some(msg) = e.downcast_ref::<&'static str>() {
message = Some((*msg).to_string());
} else if let Some(msg) = e.downcast_ref::<String>() {
message = Some(msg.clone());
} else {
message = None;
}
if let Some(message) = message {
log::error!(
"The clipboard server thread panicked. Panic message: '{}'",
message,
);
} else {
log::error!("The clipboard server thread panicked.");
}
}
}
+24 -25
View File
@@ -515,19 +515,19 @@ impl X11WindowState {
xcb.configure_window(x_window, &xproto::ConfigureWindowAux::new().x(x).y(y)),
)?;
}
if let Some(titlebar) = params.titlebar {
if let Some(title) = titlebar.title {
check_reply(
|| "X11 ChangeProperty8 on window title failed.",
xcb.change_property8(
xproto::PropMode::REPLACE,
x_window,
xproto::AtomEnum::WM_NAME,
xproto::AtomEnum::STRING,
title.as_bytes(),
),
)?;
}
if let Some(titlebar) = params.titlebar
&& let Some(title) = titlebar.title
{
check_reply(
|| "X11 ChangeProperty8 on window title failed.",
xcb.change_property8(
xproto::PropMode::REPLACE,
x_window,
xproto::AtomEnum::WM_NAME,
xproto::AtomEnum::STRING,
title.as_bytes(),
),
)?;
}
if params.kind == WindowKind::PopUp {
check_reply(
@@ -956,10 +956,10 @@ impl X11WindowStatePtr {
}
pub fn handle_input(&self, input: PlatformInput) {
if let Some(ref mut fun) = self.callbacks.borrow_mut().input {
if !fun(input.clone()).propagate {
return;
}
if let Some(ref mut fun) = self.callbacks.borrow_mut().input
&& !fun(input.clone()).propagate
{
return;
}
if let PlatformInput::KeyDown(event) = input {
// only allow shift modifier when inserting text
@@ -1068,15 +1068,14 @@ impl X11WindowStatePtr {
}
let mut callbacks = self.callbacks.borrow_mut();
if let Some((content_size, scale_factor)) = resize_args {
if let Some(ref mut fun) = callbacks.resize {
fun(content_size, scale_factor)
}
if let Some((content_size, scale_factor)) = resize_args
&& let Some(ref mut fun) = callbacks.resize
{
fun(content_size, scale_factor)
}
if !is_resize {
if let Some(ref mut fun) = callbacks.moved {
fun();
}
if !is_resize && let Some(ref mut fun) = callbacks.moved {
fun();
}
Ok(())
+8 -8
View File
@@ -35,14 +35,14 @@ pub fn apply_features_and_fallbacks(
unsafe {
let mut keys = vec![kCTFontFeatureSettingsAttribute];
let mut values = vec![generate_feature_array(features)];
if let Some(fallbacks) = fallbacks {
if !fallbacks.fallback_list().is_empty() {
keys.push(kCTFontCascadeListAttribute);
values.push(generate_fallback_array(
fallbacks,
font.native_font().as_concrete_TypeRef(),
));
}
if let Some(fallbacks) = fallbacks
&& !fallbacks.fallback_list().is_empty()
{
keys.push(kCTFontCascadeListAttribute);
values.push(generate_fallback_array(
fallbacks,
font.native_font().as_concrete_TypeRef(),
));
}
let attrs = CFDictionaryCreate(
kCFAllocatorDefault,
+14 -13
View File
@@ -715,10 +715,10 @@ impl Platform for MacPlatform {
let urls = panel.URLs();
for i in 0..urls.count() {
let url = urls.objectAtIndex(i);
if url.isFileURL() == YES {
if let Ok(path) = ns_url_to_path(url) {
result.push(path)
}
if url.isFileURL() == YES
&& let Ok(path) = ns_url_to_path(url)
{
result.push(path)
}
}
Some(result)
@@ -786,15 +786,16 @@ impl Platform for MacPlatform {
// This is conditional on OS version because I'd like to get rid of it, so that
// you can manually create a file called `a.sql.s`. That said it seems better
// to break that use-case than breaking `a.sql`.
if chunks.len() == 3 && chunks[1].starts_with(chunks[2]) {
if Self::os_version() >= SemanticVersion::new(15, 0, 0) {
let new_filename = OsStr::from_bytes(
&filename.as_bytes()
[..chunks[0].len() + 1 + chunks[1].len()],
)
.to_owned();
result.set_file_name(&new_filename);
}
if chunks.len() == 3
&& chunks[1].starts_with(chunks[2])
&& Self::os_version() >= SemanticVersion::new(15, 0, 0)
{
let new_filename = OsStr::from_bytes(
&filename.as_bytes()
[..chunks[0].len() + 1 + chunks[1].len()],
)
.to_owned();
result.set_file_name(&new_filename);
}
return result;
})
+20 -21
View File
@@ -1478,18 +1478,18 @@ extern "C" fn handle_key_event(this: &Object, native_event: id, key_equivalent:
return YES;
}
if key_down_event.is_held {
if let Some(key_char) = key_down_event.keystroke.key_char.as_ref() {
let handled = with_input_handler(this, |input_handler| {
if !input_handler.apple_press_and_hold_enabled() {
input_handler.replace_text_in_range(None, key_char);
return YES;
}
NO
});
if handled == Some(YES) {
if key_down_event.is_held
&& let Some(key_char) = key_down_event.keystroke.key_char.as_ref()
{
let handled = with_input_handler(this, |input_handler| {
if !input_handler.apple_press_and_hold_enabled() {
input_handler.replace_text_in_range(None, key_char);
return YES;
}
NO
});
if handled == Some(YES) {
return YES;
}
}
@@ -1624,10 +1624,10 @@ extern "C" fn handle_view_event(this: &Object, _: Sel, native_event: id) {
modifiers: prev_modifiers,
capslock: prev_capslock,
})) = &lock.previous_modifiers_changed_event
&& prev_modifiers == modifiers
&& prev_capslock == capslock
{
if prev_modifiers == modifiers && prev_capslock == capslock {
return;
}
return;
}
lock.previous_modifiers_changed_event = Some(event.clone());
@@ -1995,10 +1995,10 @@ extern "C" fn attributed_substring_for_proposed_range(
let mut adjusted: Option<Range<usize>> = None;
let selected_text = input_handler.text_for_range(range.clone(), &mut adjusted)?;
if let Some(adjusted) = adjusted {
if adjusted != range {
unsafe { (actual_range as *mut NSRange).write(NSRange::from(adjusted)) };
}
if let Some(adjusted) = adjusted
&& adjusted != range
{
unsafe { (actual_range as *mut NSRange).write(NSRange::from(adjusted)) };
}
unsafe {
let string: id = msg_send![class!(NSAttributedString), alloc];
@@ -2073,11 +2073,10 @@ extern "C" fn dragging_entered(this: &Object, _: Sel, dragging_info: id) -> NSDr
let paths = external_paths_from_event(dragging_info);
if let Some(event) =
paths.map(|paths| PlatformInput::FileDrop(FileDropEvent::Entered { position, paths }))
&& send_new_event(&window_state, event)
{
if send_new_event(&window_state, event) {
window_state.lock().external_files_dragged = true;
return NSDragOperationCopy;
}
window_state.lock().external_files_dragged = true;
return NSDragOperationCopy;
}
NSDragOperationNone
}
+5 -5
View File
@@ -78,11 +78,11 @@ impl TestDispatcher {
let state = self.state.lock();
let next_due_time = state.delayed.first().map(|(time, _)| *time);
drop(state);
if let Some(due_time) = next_due_time {
if due_time <= new_now {
self.state.lock().time = due_time;
continue;
}
if let Some(due_time) = next_due_time
&& due_time <= new_now
{
self.state.lock().time = due_time;
continue;
}
break;
}
+4 -4
View File
@@ -201,10 +201,10 @@ impl TestPlatform {
executor
.spawn(async move {
if let Some(previous_window) = previous_window {
if let Some(window) = window.as_ref() {
if Rc::ptr_eq(&previous_window.0, &window.0) {
return;
}
if let Some(window) = window.as_ref()
&& Rc::ptr_eq(&previous_window.0, &window.0)
{
return;
}
previous_window.simulate_active_status_change(false);
}
+36 -39
View File
@@ -701,29 +701,28 @@ impl WindowsWindowInner {
// Fix auto hide taskbar not showing. This solution is based on the approach
// used by Chrome. However, it may result in one row of pixels being obscured
// in our client area. But as Chrome says, "there seems to be no better solution."
if is_maximized {
if let Some(ref taskbar_position) = self
if is_maximized
&& let Some(ref taskbar_position) = self
.state
.borrow()
.system_settings
.auto_hide_taskbar_position
{
// Fot the auto-hide taskbar, adjust in by 1 pixel on taskbar edge,
// so the window isn't treated as a "fullscreen app", which would cause
// the taskbar to disappear.
match taskbar_position {
AutoHideTaskbarPosition::Left => {
requested_client_rect[0].left += AUTO_HIDE_TASKBAR_THICKNESS_PX
}
AutoHideTaskbarPosition::Top => {
requested_client_rect[0].top += AUTO_HIDE_TASKBAR_THICKNESS_PX
}
AutoHideTaskbarPosition::Right => {
requested_client_rect[0].right -= AUTO_HIDE_TASKBAR_THICKNESS_PX
}
AutoHideTaskbarPosition::Bottom => {
requested_client_rect[0].bottom -= AUTO_HIDE_TASKBAR_THICKNESS_PX
}
{
// Fot the auto-hide taskbar, adjust in by 1 pixel on taskbar edge,
// so the window isn't treated as a "fullscreen app", which would cause
// the taskbar to disappear.
match taskbar_position {
AutoHideTaskbarPosition::Left => {
requested_client_rect[0].left += AUTO_HIDE_TASKBAR_THICKNESS_PX
}
AutoHideTaskbarPosition::Top => {
requested_client_rect[0].top += AUTO_HIDE_TASKBAR_THICKNESS_PX
}
AutoHideTaskbarPosition::Right => {
requested_client_rect[0].right -= AUTO_HIDE_TASKBAR_THICKNESS_PX
}
AutoHideTaskbarPosition::Bottom => {
requested_client_rect[0].bottom -= AUTO_HIDE_TASKBAR_THICKNESS_PX
}
}
}
@@ -1125,28 +1124,26 @@ impl WindowsWindowInner {
// lParam is a pointer to a string that indicates the area containing the system parameter
// that was changed.
let parameter = PCWSTR::from_raw(lparam.0 as _);
if unsafe { !parameter.is_null() && !parameter.is_empty() } {
if let Some(parameter_string) = unsafe { parameter.to_string() }.log_err() {
log::info!("System settings changed: {}", parameter_string);
match parameter_string.as_str() {
"ImmersiveColorSet" => {
let new_appearance = system_appearance()
.context(
"unable to get system appearance when handling ImmersiveColorSet",
)
.log_err()?;
let mut lock = self.state.borrow_mut();
if new_appearance != lock.appearance {
lock.appearance = new_appearance;
let mut callback = lock.callbacks.appearance_changed.take()?;
drop(lock);
callback();
self.state.borrow_mut().callbacks.appearance_changed = Some(callback);
configure_dwm_dark_mode(handle, new_appearance);
}
if unsafe { !parameter.is_null() && !parameter.is_empty() }
&& let Some(parameter_string) = unsafe { parameter.to_string() }.log_err()
{
log::info!("System settings changed: {}", parameter_string);
match parameter_string.as_str() {
"ImmersiveColorSet" => {
let new_appearance = system_appearance()
.context("unable to get system appearance when handling ImmersiveColorSet")
.log_err()?;
let mut lock = self.state.borrow_mut();
if new_appearance != lock.appearance {
lock.appearance = new_appearance;
let mut callback = lock.callbacks.appearance_changed.take()?;
drop(lock);
callback();
self.state.borrow_mut().callbacks.appearance_changed = Some(callback);
configure_dwm_dark_mode(handle, new_appearance);
}
_ => {}
}
_ => {}
}
}
Some(0)
+8 -8
View File
@@ -821,14 +821,14 @@ fn file_save_dialog(
window: Option<HWND>,
) -> Result<Option<PathBuf>> {
let dialog: IFileSaveDialog = unsafe { CoCreateInstance(&FileSaveDialog, None, CLSCTX_ALL)? };
if !directory.to_string_lossy().is_empty() {
if let Some(full_path) = directory.canonicalize().log_err() {
let full_path = SanitizedPath::from(full_path);
let full_path_string = full_path.to_string();
let path_item: IShellItem =
unsafe { SHCreateItemFromParsingName(&HSTRING::from(full_path_string), None)? };
unsafe { dialog.SetFolder(&path_item).log_err() };
}
if !directory.to_string_lossy().is_empty()
&& let Some(full_path) = directory.canonicalize().log_err()
{
let full_path = SanitizedPath::from(full_path);
let full_path_string = full_path.to_string();
let path_item: IShellItem =
unsafe { SHCreateItemFromParsingName(&HSTRING::from(full_path_string), None)? };
unsafe { dialog.SetFolder(&path_item).log_err() };
}
if let Some(suggested_name) = suggested_name {