1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 13:20:05 -04:00

Enable the clippy::std_instead_of_core lint (#8394)

Prefer `core::` over `std::` where either work

* Part of https://github.com/emilk/egui/issues/5735
This commit is contained in:
Emil Ernerfeldt
2026-08-06 04:19:13 -07:00
committed by GitHub
parent 2a5f3d99b5
commit 6aea7eff94
176 changed files with 633 additions and 615 deletions

View File

@@ -123,7 +123,7 @@ fn set_app_icon_windows(icon_data: &IconData) -> AppIconStatus {
)
.is_err()
{
return std::ptr::null_mut();
return core::ptr::null_mut();
}
// SAFETY: Creating an HICON which should be readonly on our data.

View File

@@ -83,7 +83,7 @@ pub fn viewport_builder(
}
}
match std::mem::take(&mut native_options.window_builder) {
match core::mem::take(&mut native_options.window_builder) {
Some(hook) => hook(viewport_builder),
None => viewport_builder,
}
@@ -310,7 +310,7 @@ impl EpiIntegration {
}
self.pending_full_output.append(full_output);
std::mem::take(&mut self.pending_full_output)
core::mem::take(&mut self.pending_full_output)
}
/// Let the app tick its logic without showing any ui,
@@ -354,7 +354,7 @@ impl EpiIntegration {
app: &mut dyn epi::App,
new_input: egui::RawInput,
) -> egui::RawInput {
let mut raw_input = std::mem::take(&mut self.pending_raw_input);
let mut raw_input = core::mem::take(&mut self.pending_raw_input);
raw_input.append(new_input); // The new input wins where they overlap
raw_input.time = Some(self.beginning.elapsed().as_secs_f64());
@@ -379,7 +379,7 @@ impl EpiIntegration {
pub fn post_rendering(&mut self, window: &winit::window::Window) {
profiling::function_scope!();
if std::mem::take(&mut self.is_first_frame) {
if core::mem::take(&mut self.is_first_frame) {
// We keep hidden until we've painted something. See https://github.com/emilk/egui/pull/2279
window.set_visible(true);
}

View File

@@ -1,4 +1,4 @@
use std::cell::Cell;
use core::cell::Cell;
use winit::event_loop::ActiveEventLoop;
thread_local! {
@@ -14,7 +14,7 @@ impl EventLoopGuard {
cell.get().is_none(),
"Attempted to set a new event loop while one is already set"
);
cell.set(Some(std::ptr::from_ref::<ActiveEventLoop>(event_loop)));
cell.set(Some(core::ptr::from_ref::<ActiveEventLoop>(event_loop)));
});
Self
}

View File

@@ -44,10 +44,10 @@ pub fn storage_dir(app_id: &str) -> Option<PathBuf> {
#[cfg(all(windows, not(target_vendor = "uwp")))]
#[expect(unsafe_code)]
fn roaming_appdata() -> Option<PathBuf> {
use core::ptr;
use core::slice;
use std::ffi::OsString;
use std::os::windows::ffi::OsStringExt as _;
use std::ptr;
use std::slice;
use windows_sys::Win32::Foundation::S_OK;
use windows_sys::Win32::System::Com::CoTaskMemFree;
@@ -66,7 +66,7 @@ fn roaming_appdata() -> Option<PathBuf> {
SHGetKnownFolderPath(
&FOLDERID_RoamingAppData,
KF_FLAG_DONT_VERIFY as u32,
std::ptr::null_mut(),
core::ptr::null_mut(),
&mut path_raw,
)
};

View File

@@ -8,7 +8,8 @@
#![expect(clippy::undocumented_unsafe_blocks)]
#![expect(clippy::unwrap_used)]
use std::{cell::RefCell, num::NonZeroU32, rc::Rc, sync::Arc, time::Instant};
use core::{cell::RefCell, num::NonZeroU32};
use std::{rc::Rc, sync::Arc, time::Instant};
use egui_winit::ActionRequested;
use glutin::{
@@ -152,7 +153,7 @@ impl Viewport {
egui_winit::process_viewport_commands(
egui_ctx,
&mut self.info,
std::mem::take(&mut self.deferred_commands),
core::mem::take(&mut self.deferred_commands),
window,
&mut self.actions_requested,
);
@@ -338,7 +339,7 @@ impl<'app> GlowWinitApp<'app> {
log::warn!("set_cursor_hittest(false) failed: {err}");
}
let app_creator = std::mem::take(&mut self.app_creator)
let app_creator = core::mem::take(&mut self.app_creator)
.expect("Single-use AppCreator has unexpectedly already been taken");
crate::maybe_attach_inspection_plugin(&integration.egui_ctx, Some(self.app_name.clone()));
@@ -1408,7 +1409,7 @@ impl GlutinWindowContext {
}
}
fn get_proc_address(&self, addr: &std::ffi::CStr) -> *const std::ffi::c_void {
fn get_proc_address(&self, addr: &core::ffi::CStr) -> *const core::ffi::c_void {
self.gl_config.display().get_proc_address(addr)
}

View File

@@ -1,4 +1,5 @@
use std::time::{Duration, Instant};
use core::time::Duration;
use std::time::Instant;
use winit::{
application::ApplicationHandler,
@@ -41,7 +42,7 @@ fn create_event_loop(native_options: &mut epi::NativeOptions) -> Result<EventLoo
))
})?);
if let Some(hook) = std::mem::take(&mut native_options.event_loop_builder) {
if let Some(hook) = core::mem::take(&mut native_options.event_loop_builder) {
hook(&mut builder);
}
@@ -58,7 +59,7 @@ fn with_event_loop<R>(
mut native_options: epi::NativeOptions,
f: impl FnOnce(&mut EventLoop<UserEvent>, epi::NativeOptions) -> R,
) -> Result<R> {
thread_local!(static EVENT_LOOP: std::cell::RefCell<Option<EventLoop<UserEvent>>> = const { std::cell::RefCell::new(None) });
thread_local!(static EVENT_LOOP: core::cell::RefCell<Option<EventLoop<UserEvent>>> = const { core::cell::RefCell::new(None) });
EVENT_LOOP.with(|event_loop| {
// Since we want to reference NativeOptions when creating the EventLoop we can't
@@ -550,7 +551,7 @@ impl<'a> EframeWinitApplication<'a> {
pub fn pump_eframe_app(
&mut self,
event_loop: &mut EventLoop<UserEvent>,
timeout: Option<std::time::Duration>,
timeout: Option<core::time::Duration>,
) -> EframePumpStatus {
use winit::platform::pump_events::{EventLoopExtPumpEvents as _, PumpStatus};

View File

@@ -5,7 +5,8 @@
//! There is a bunch of improvements we could do,
//! like removing a bunch of `unwraps`.
use std::{cell::RefCell, num::NonZeroU32, rc::Rc, sync::Arc, time::Instant};
use core::{cell::RefCell, num::NonZeroU32};
use std::{rc::Rc, sync::Arc, time::Instant};
use egui_winit::ActionRequested;
use parking_lot::Mutex;
@@ -309,7 +310,7 @@ impl<'app> WgpuWinitApp<'app> {
egui_winit.init_accesskit(event_loop, &window, event_loop_proxy);
}
let app_creator = std::mem::take(&mut self.app_creator)
let app_creator = core::mem::take(&mut self.app_creator)
.expect("Single-use AppCreator has unexpectedly already been taken");
crate::maybe_attach_inspection_plugin(&egui_ctx, Some(self.app_name.clone()));
@@ -1040,7 +1041,7 @@ impl Viewport {
egui_winit::process_viewport_commands(
egui_ctx,
&mut self.info,
std::mem::take(&mut self.deferred_commands),
core::mem::take(&mut self.deferred_commands),
window,
&mut self.actions_requested,
);

View File

@@ -25,7 +25,7 @@ pub fn is_invisible_or_minimized(window: &Window) -> bool {
pub fn sleep_if_invisible_or_minimized(window: Option<&Window>) {
if window.is_some_and(is_invisible_or_minimized) {
profiling::scope!("minimized_sleep");
std::thread::sleep(std::time::Duration::from_millis(10));
std::thread::sleep(core::time::Duration::from_millis(10));
}
}