diff --git a/examples/util/fill.rs b/examples/util/fill.rs index 36d3c8b087..a47ce95a04 100644 --- a/examples/util/fill.rs +++ b/examples/util/fill.rs @@ -7,8 +7,6 @@ //! The `softbuffer` crate is used, largely because of its ease of use. `glutin` or `wgpu` could //! also be used to fill the window buffer, but they are more complicated to use. -// TODO: Once softbuffer uses rwh_06, use that instead. - use winit::window::Window; #[cfg(all(feature = "rwh_05", not(any(target_os = "android", target_os = "ios"))))] diff --git a/src/platform_impl/ios/window.rs b/src/platform_impl/ios/window.rs index c3347e13c1..9482ec4e32 100644 --- a/src/platform_impl/ios/window.rs +++ b/src/platform_impl/ios/window.rs @@ -349,10 +349,9 @@ impl Inner { #[cfg(feature = "rwh_06")] pub fn raw_window_handle_rwh_06(&self) -> Result { - let mut window_handle = rwh_06::UiKitWindowHandle::new(unsafe { - // SAFETY: ns_view will never be null + let mut window_handle = rwh_06::UiKitWindowHandle::new({ let ui_view = Id::as_ptr(&self.view) as _; - std::ptr::NonNull::new_unchecked(ui_view) + std::ptr::NonNull::new(ui_view).expect("Id should never be null") }); window_handle.ui_view_controller = std::ptr::NonNull::new(Id::as_ptr(&self.view_controller) as _); diff --git a/src/platform_impl/linux/wayland/event_loop/mod.rs b/src/platform_impl/linux/wayland/event_loop/mod.rs index 15b53dfee8..85bc3983cc 100644 --- a/src/platform_impl/linux/wayland/event_loop/mod.rs +++ b/src/platform_impl/linux/wayland/event_loop/mod.rs @@ -677,10 +677,9 @@ impl EventLoopWindowTarget { ) -> Result { use sctk::reexports::client::Proxy; - Ok(rwh_06::WaylandDisplayHandle::new(unsafe { - // SAFETY: The display handle will never be null. + Ok(rwh_06::WaylandDisplayHandle::new({ let ptr = self.connection.display().id().as_ptr(); - std::ptr::NonNull::new_unchecked(ptr as *mut _) + std::ptr::NonNull::new(ptr as *mut _).expect("wl_display should never be null") }) .into()) } diff --git a/src/platform_impl/linux/wayland/window/mod.rs b/src/platform_impl/linux/wayland/window/mod.rs index 8288a23ba7..a612638645 100644 --- a/src/platform_impl/linux/wayland/window/mod.rs +++ b/src/platform_impl/linux/wayland/window/mod.rs @@ -668,10 +668,9 @@ impl Window { #[cfg(feature = "rwh_06")] #[inline] pub fn raw_window_handle_rwh_06(&self) -> Result { - Ok(rwh_06::WaylandWindowHandle::new(unsafe { - // SAFETY: Surface pointer will never be null. + Ok(rwh_06::WaylandWindowHandle::new({ let ptr = self.window.wl_surface().id().as_ptr(); - std::ptr::NonNull::new_unchecked(ptr as *mut _) + std::ptr::NonNull::new(ptr as *mut _).expect("wl_surface will never be null") }) .into()) } @@ -681,10 +680,9 @@ impl Window { pub fn raw_display_handle_rwh_06( &self, ) -> Result { - Ok(rwh_06::WaylandDisplayHandle::new(unsafe { - // SAFETY: Display pointer will never be null. + Ok(rwh_06::WaylandDisplayHandle::new({ let ptr = self.display.id().as_ptr(); - std::ptr::NonNull::new_unchecked(ptr as *mut _) + std::ptr::NonNull::new(ptr as *mut _).expect("wl_proxy should never be null") }) .into()) } diff --git a/src/platform_impl/linux/x11/mod.rs b/src/platform_impl/linux/x11/mod.rs index 2d6fc0d3b2..7b23bcd632 100644 --- a/src/platform_impl/linux/x11/mod.rs +++ b/src/platform_impl/linux/x11/mod.rs @@ -726,7 +726,7 @@ impl EventLoopWindowTarget { ) -> Result { let display_handle = rwh_06::XlibDisplayHandle::new( // SAFETY: display will never be null - Some(unsafe { std::ptr::NonNull::new_unchecked(self.xconn.display as *mut _) }), + Some(std::ptr::NonNull::new(self.xconn.display as *mut _).expect("X11 display should never be null")), self.xconn.default_screen_index() as c_int, ); Ok(display_handle.into()) diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index 8007deeb56..6f47f019ea 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -1839,8 +1839,7 @@ impl UnownedWindow { &self, ) -> Result { Ok(rwh_06::XlibDisplayHandle::new( - // SAFETY: The Xlib display pointer will never be null - Some(unsafe { std::ptr::NonNull::new_unchecked(self.xlib_display()) }), + Some(std::ptr::NonNull::new(self.xlib_display()).expect("display pointer should never be null")), self.screen_id, ) .into()) diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index 77935201bc..ea55a330fe 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -1369,10 +1369,9 @@ impl WinitWindow { #[cfg(feature = "rwh_06")] #[inline] pub fn raw_window_handle_rwh_06(&self) -> Result { - let window_handle = rwh_06::AppKitWindowHandle::new(unsafe { - // SAFETY: ns_view is never null. + let window_handle = rwh_06::AppKitWindowHandle::new({ let ptr = Id::as_ptr(&self.contentView()) as *mut _; - std::ptr::NonNull::new_unchecked(ptr) + std::ptr::NonNull::new(ptr).expect("Id should never be null") }); Ok(rwh_06::RawWindowHandle::AppKit(window_handle)) } diff --git a/src/platform_impl/orbital/window.rs b/src/platform_impl/orbital/window.rs index 466d6d8962..a3d30a18b4 100644 --- a/src/platform_impl/orbital/window.rs +++ b/src/platform_impl/orbital/window.rs @@ -415,10 +415,9 @@ impl Window { #[cfg(feature = "rwh_06")] #[inline] pub fn raw_window_handle_rwh_06(&self) -> Result { - let handle = rwh_06::OrbitalWindowHandle::new(unsafe { - // SAFETY: not zero. + let handle = rwh_06::OrbitalWindowHandle::new({ let window = self.window_socket.fd as *mut _; - std::ptr::NonNull::new_unchecked(window) + std::ptr::NonNull::new(window).expect("orbital fd shoul never be null") }); Ok(rwh_06::RawWindowHandle::Orbital(handle)) }