Make DeviceId/WindowId::dummy() safe (#3784)

This commit is contained in:
daxpedda 2024-07-14 13:14:32 +02:00 committed by GitHub
parent bf97def398
commit 5b8f5cb54a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 28 additions and 33 deletions

View file

@ -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
}
}

View file

@ -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)
}
}

View file

@ -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
}
}

View file

@ -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() }
}
}

View file

@ -155,7 +155,7 @@ impl From<u64> 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());
}
}

View file

@ -66,7 +66,7 @@ impl From<WaylandError> for OsError {
pub struct DeviceId;
impl DeviceId {
pub const unsafe fn dummy() -> Self {
pub const fn dummy() -> Self {
DeviceId
}
}

View file

@ -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)
}
}

View file

@ -2,7 +2,7 @@
pub struct DeviceId(pub i32);
impl DeviceId {
pub const unsafe fn dummy() -> Self {
pub const fn dummy() -> Self {
Self(0)
}
}

View file

@ -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,

View file

@ -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 {

View file

@ -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)
}
}

View file

@ -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)
}
}