diff --git a/src/changelog/unreleased.md b/src/changelog/unreleased.md index 6111d23787..85bb63da6f 100644 --- a/src/changelog/unreleased.md +++ b/src/changelog/unreleased.md @@ -68,6 +68,7 @@ changelog entry. - Change signature of `EventLoop::run_app`, `EventLoopExtPumpEvents::pump_app_events` and `EventLoopExtRunOnDemand::run_app_on_demand` to accept a `impl ApplicationHandler` directly, instead of requiring a `&mut` reference to it. +- `DeviceId::dummy()` and `WindowId::dummy()` are no longer marked `unsafe`. ### Removed diff --git a/src/event.rs b/src/event.rs index 25a1f51601..e0a6d4376d 100644 --- a/src/event.rs +++ b/src/event.rs @@ -440,16 +440,13 @@ pub struct DeviceId(pub(crate) platform_impl::DeviceId); impl DeviceId { /// Returns a dummy id, useful for unit testing. /// - /// # Safety + /// # Notes /// /// The only guarantee made about the return value of this function is that /// it will always be equal to itself and to future values returned by this function. /// No other guarantees are made. This may be equal to a real `DeviceId`. - /// - /// **Passing this into a winit function will result in undefined behavior.** - pub const unsafe fn dummy() -> Self { - #[allow(unused_unsafe)] - DeviceId(unsafe { platform_impl::DeviceId::dummy() }) + pub const fn dummy() -> Self { + DeviceId(platform_impl::DeviceId::dummy()) } } @@ -1013,7 +1010,7 @@ mod tests { ($closure:expr) => {{ #[allow(unused_mut)] let mut x = $closure; - let did = unsafe { event::DeviceId::dummy() }; + let did = event::DeviceId::dummy(); #[allow(deprecated)] { @@ -1023,7 +1020,7 @@ mod tests { use crate::window::WindowId; // Mainline events. - let wid = unsafe { WindowId::dummy() }; + let wid = WindowId::dummy(); x(NewEvents(event::StartCause::Init)); x(AboutToWait); x(LoopExiting); @@ -1138,7 +1135,7 @@ mod tests { }); let _ = event::StartCause::Init.clone(); - let did = unsafe { crate::event::DeviceId::dummy() }.clone(); + let did = crate::event::DeviceId::dummy().clone(); HashSet::new().insert(did); let mut set = [did, did, did]; set.sort_unstable(); diff --git a/src/platform_impl/apple/appkit/mod.rs b/src/platform_impl/apple/appkit/mod.rs index 9ed0e05396..2867814932 100644 --- a/src/platform_impl/apple/appkit/mod.rs +++ b/src/platform_impl/apple/appkit/mod.rs @@ -35,7 +35,7 @@ pub(crate) use crate::platform_impl::Fullscreen; pub struct DeviceId; impl DeviceId { - pub const unsafe fn dummy() -> Self { + pub const fn dummy() -> Self { DeviceId } } diff --git a/src/platform_impl/apple/appkit/window.rs b/src/platform_impl/apple/appkit/window.rs index eb1f75deea..04da8b29ee 100644 --- a/src/platform_impl/apple/appkit/window.rs +++ b/src/platform_impl/apple/appkit/window.rs @@ -74,7 +74,7 @@ impl Window { pub struct WindowId(pub usize); impl WindowId { - pub const unsafe fn dummy() -> Self { + pub const fn dummy() -> Self { Self(0) } } diff --git a/src/platform_impl/apple/uikit/mod.rs b/src/platform_impl/apple/uikit/mod.rs index 8eb839e787..2c3221e041 100644 --- a/src/platform_impl/apple/uikit/mod.rs +++ b/src/platform_impl/apple/uikit/mod.rs @@ -31,7 +31,7 @@ pub(crate) use crate::platform_impl::Fullscreen; pub struct DeviceId; impl DeviceId { - pub const unsafe fn dummy() -> Self { + pub const fn dummy() -> Self { DeviceId } } diff --git a/src/platform_impl/apple/uikit/window.rs b/src/platform_impl/apple/uikit/window.rs index 1f95c9b43e..3184489d7c 100644 --- a/src/platform_impl/apple/uikit/window.rs +++ b/src/platform_impl/apple/uikit/window.rs @@ -699,7 +699,7 @@ pub struct WindowId { } impl WindowId { - pub const unsafe fn dummy() -> Self { + pub const fn dummy() -> Self { WindowId { window: std::ptr::null_mut() } } } diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index 9601a4c399..b7e612c4b5 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -155,7 +155,7 @@ impl From for WindowId { } impl WindowId { - pub const unsafe fn dummy() -> Self { + pub const fn dummy() -> Self { Self(0) } } @@ -169,11 +169,11 @@ pub enum DeviceId { } impl DeviceId { - pub const unsafe fn dummy() -> Self { + pub const fn dummy() -> Self { #[cfg(wayland_platform)] - return DeviceId::Wayland(unsafe { wayland::DeviceId::dummy() }); + return DeviceId::Wayland(wayland::DeviceId::dummy()); #[cfg(all(not(wayland_platform), x11_platform))] - return DeviceId::X(unsafe { x11::DeviceId::dummy() }); + return DeviceId::X(x11::DeviceId::dummy()); } } diff --git a/src/platform_impl/linux/wayland/mod.rs b/src/platform_impl/linux/wayland/mod.rs index 07aad45db2..67e6e90d1e 100644 --- a/src/platform_impl/linux/wayland/mod.rs +++ b/src/platform_impl/linux/wayland/mod.rs @@ -66,7 +66,7 @@ impl From for OsError { pub struct DeviceId; impl DeviceId { - pub const unsafe fn dummy() -> Self { + pub const fn dummy() -> Self { DeviceId } } diff --git a/src/platform_impl/linux/x11/mod.rs b/src/platform_impl/linux/x11/mod.rs index 205a3735c8..e39228f243 100644 --- a/src/platform_impl/linux/x11/mod.rs +++ b/src/platform_impl/linux/x11/mod.rs @@ -768,7 +768,7 @@ pub struct DeviceId(xinput::DeviceId); impl DeviceId { #[allow(unused)] - pub const unsafe fn dummy() -> Self { + pub const fn dummy() -> Self { DeviceId(0) } } diff --git a/src/platform_impl/web/device.rs b/src/platform_impl/web/device.rs index 383bf3a1b8..91d08586c8 100644 --- a/src/platform_impl/web/device.rs +++ b/src/platform_impl/web/device.rs @@ -2,7 +2,7 @@ pub struct DeviceId(pub i32); impl DeviceId { - pub const unsafe fn dummy() -> Self { + pub const fn dummy() -> Self { Self(0) } } diff --git a/src/platform_impl/web/event_loop/runner.rs b/src/platform_impl/web/event_loop/runner.rs index c7275dcc3e..317ff077fa 100644 --- a/src/platform_impl/web/event_loop/runner.rs +++ b/src/platform_impl/web/event_loop/runner.rs @@ -369,7 +369,7 @@ impl Shared { } runner.send_event(Event::DeviceEvent { - device_id: RootDeviceId(unsafe { DeviceId::dummy() }), + device_id: RootDeviceId(DeviceId::dummy()), event: DeviceEvent::Key(RawKeyEvent { physical_key: backend::event::key_code(&event), state: ElementState::Pressed, @@ -387,7 +387,7 @@ impl Shared { } runner.send_event(Event::DeviceEvent { - device_id: RootDeviceId(unsafe { DeviceId::dummy() }), + device_id: RootDeviceId(DeviceId::dummy()), event: DeviceEvent::Key(RawKeyEvent { physical_key: backend::event::key_code(&event), state: ElementState::Released, diff --git a/src/platform_impl/web/event_loop/window_target.rs b/src/platform_impl/web/event_loop/window_target.rs index 9df6748cf5..6a44a614cb 100644 --- a/src/platform_impl/web/event_loop/window_target.rs +++ b/src/platform_impl/web/event_loop/window_target.rs @@ -150,7 +150,7 @@ impl ActiveEventLoop { } }); - let device_id = RootDeviceId(unsafe { DeviceId::dummy() }); + let device_id = RootDeviceId(DeviceId::dummy()); runner.send_events( iter::once(Event::WindowEvent { @@ -186,7 +186,7 @@ impl ActiveEventLoop { } }); - let device_id = RootDeviceId(unsafe { DeviceId::dummy() }); + let device_id = RootDeviceId(DeviceId::dummy()); runner.send_events( iter::once(Event::WindowEvent { diff --git a/src/platform_impl/web/window.rs b/src/platform_impl/web/window.rs index b071bc5ba4..29d854047f 100644 --- a/src/platform_impl/web/window.rs +++ b/src/platform_impl/web/window.rs @@ -431,7 +431,7 @@ impl Drop for Inner { pub struct WindowId(pub(crate) u32); impl WindowId { - pub const unsafe fn dummy() -> Self { + pub const fn dummy() -> Self { Self(0) } } diff --git a/src/platform_impl/windows/mod.rs b/src/platform_impl/windows/mod.rs index a479ff268e..4b3255c4dd 100644 --- a/src/platform_impl/windows/mod.rs +++ b/src/platform_impl/windows/mod.rs @@ -64,7 +64,7 @@ unsafe impl Sync for PlatformSpecificWindowAttributes {} pub struct DeviceId(u32); impl DeviceId { - pub const unsafe fn dummy() -> Self { + pub const fn dummy() -> Self { DeviceId(0) } } @@ -100,7 +100,7 @@ unsafe impl Send for WindowId {} unsafe impl Sync for WindowId {} impl WindowId { - pub const unsafe fn dummy() -> Self { + pub const fn dummy() -> Self { WindowId(0) } } diff --git a/src/window.rs b/src/window.rs index b0d4b98d07..d95e868065 100644 --- a/src/window.rs +++ b/src/window.rs @@ -70,16 +70,13 @@ pub struct WindowId(pub(crate) platform_impl::WindowId); impl WindowId { /// Returns a dummy id, useful for unit testing. /// - /// # Safety + /// # Notes /// /// The only guarantee made about the return value of this function is that /// it will always be equal to itself and to future values returned by this function. /// No other guarantees are made. This may be equal to a real [`WindowId`]. - /// - /// **Passing this into a winit function will result in undefined behavior.** - pub const unsafe fn dummy() -> Self { - #[allow(unused_unsafe)] - WindowId(unsafe { platform_impl::WindowId::dummy() }) + pub const fn dummy() -> Self { + WindowId(platform_impl::WindowId::dummy()) } }