From af247eac0f62fc4a1dfb025470f809d3413536d9 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sat, 30 Sep 2023 21:43:41 +0200 Subject: [PATCH] X11: Add `#[deny(unsafe_op_in_unsafe_fn)]` (#3121) * X11: Add #[deny(unsafe_op_in_unsafe_fn)] * Enable #![deny(unsafe_op_in_unsafe_fn)] everywhere --- src/event.rs | 3 +- src/lib.rs | 1 + src/platform_impl/ios/uikit/mod.rs | 1 - src/platform_impl/linux/common/xkb_state.rs | 105 ++++++++------- src/platform_impl/linux/mod.rs | 37 +++--- .../linux/x11/event_processor.rs | 14 +- src/platform_impl/linux/x11/ime/callbacks.rs | 124 ++++++++++-------- src/platform_impl/linux/x11/ime/context.rs | 89 +++++++------ src/platform_impl/linux/x11/ime/inner.rs | 10 +- .../linux/x11/ime/input_method.rs | 38 +++--- src/platform_impl/macos/mod.rs | 2 - src/platform_impl/windows/mod.rs | 1 - src/window.rs | 3 +- 13 files changed, 237 insertions(+), 191 deletions(-) diff --git a/src/event.rs b/src/event.rs index 1ebe05cf..f41e69eb 100644 --- a/src/event.rs +++ b/src/event.rs @@ -572,7 +572,8 @@ impl DeviceId { /// /// **Passing this into a winit function will result in undefined behavior.** pub const unsafe fn dummy() -> Self { - DeviceId(platform_impl::DeviceId::dummy()) + #[allow(unused_unsafe)] + DeviceId(unsafe { platform_impl::DeviceId::dummy() }) } } diff --git a/src/lib.rs b/src/lib.rs index bb5debf3..86e10e1e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -132,6 +132,7 @@ #![deny(rust_2018_idioms)] #![deny(rustdoc::broken_intra_doc_links)] #![deny(clippy::all)] +#![deny(unsafe_op_in_unsafe_fn)] #![cfg_attr(feature = "cargo-clippy", deny(warnings))] // Doc feature labels can be tested locally by running RUSTDOCFLAGS="--cfg=docsrs" cargo +nightly doc #![cfg_attr(docsrs, feature(doc_auto_cfg))] diff --git a/src/platform_impl/ios/uikit/mod.rs b/src/platform_impl/ios/uikit/mod.rs index 42b7e1ed..e2707c0f 100644 --- a/src/platform_impl/ios/uikit/mod.rs +++ b/src/platform_impl/ios/uikit/mod.rs @@ -1,4 +1,3 @@ -#![deny(unsafe_op_in_unsafe_fn)] #![allow(non_snake_case)] #![allow(non_upper_case_globals)] diff --git a/src/platform_impl/linux/common/xkb_state.rs b/src/platform_impl/linux/common/xkb_state.rs index b6ba73df..d8bfc9e0 100644 --- a/src/platform_impl/linux/common/xkb_state.rs +++ b/src/platform_impl/linux/common/xkb_state.rs @@ -250,37 +250,43 @@ impl KbdState { .unwrap_or_else(|| "C".into()); let locale = CString::new(locale.into_vec()).unwrap(); - let compose_table = (XKBCH.xkb_compose_table_new_from_locale)( - self.xkb_context, - locale.as_ptr(), - ffi::xkb_compose_compile_flags::XKB_COMPOSE_COMPILE_NO_FLAGS, - ); + let compose_table = unsafe { + (XKBCH.xkb_compose_table_new_from_locale)( + self.xkb_context, + locale.as_ptr(), + ffi::xkb_compose_compile_flags::XKB_COMPOSE_COMPILE_NO_FLAGS, + ) + }; if compose_table.is_null() { // init of compose table failed, continue without compose return; } - let compose_state = (XKBCH.xkb_compose_state_new)( - compose_table, - ffi::xkb_compose_state_flags::XKB_COMPOSE_STATE_NO_FLAGS, - ); + let compose_state = unsafe { + (XKBCH.xkb_compose_state_new)( + compose_table, + ffi::xkb_compose_state_flags::XKB_COMPOSE_STATE_NO_FLAGS, + ) + }; if compose_state.is_null() { // init of compose state failed, continue without compose - (XKBCH.xkb_compose_table_unref)(compose_table); + unsafe { (XKBCH.xkb_compose_table_unref)(compose_table) }; return; } - let compose_state_2 = (XKBCH.xkb_compose_state_new)( - compose_table, - ffi::xkb_compose_state_flags::XKB_COMPOSE_STATE_NO_FLAGS, - ); + let compose_state_2 = unsafe { + (XKBCH.xkb_compose_state_new)( + compose_table, + ffi::xkb_compose_state_flags::XKB_COMPOSE_STATE_NO_FLAGS, + ) + }; if compose_state_2.is_null() { // init of compose state failed, continue without compose - (XKBCH.xkb_compose_table_unref)(compose_table); - (XKBCH.xkb_compose_state_unref)(compose_state); + unsafe { (XKBCH.xkb_compose_table_unref)(compose_table) }; + unsafe { (XKBCH.xkb_compose_state_unref)(compose_state) }; return; } @@ -296,62 +302,71 @@ impl KbdState { } unsafe fn de_init(&mut self) { - (XKBH.xkb_state_unref)(self.xkb_state); + unsafe { (XKBH.xkb_state_unref)(self.xkb_state) }; self.xkb_state = ptr::null_mut(); - (XKBH.xkb_keymap_unref)(self.xkb_keymap); + unsafe { (XKBH.xkb_keymap_unref)(self.xkb_keymap) }; self.xkb_keymap = ptr::null_mut(); } #[cfg(feature = "x11")] pub unsafe fn init_with_x11_keymap(&mut self) { if !self.xkb_keymap.is_null() { - self.de_init(); + unsafe { self.de_init() }; } // TODO: Support keyboards other than the "virtual core keyboard device". - self.core_keyboard_id = (XKBXH.xkb_x11_get_core_keyboard_device_id)(self.xcb_connection); - let keymap = (XKBXH.xkb_x11_keymap_new_from_device)( - self.xkb_context, - self.xcb_connection, - self.core_keyboard_id, - xkbcommon_dl::xkb_keymap_compile_flags::XKB_KEYMAP_COMPILE_NO_FLAGS, - ); + self.core_keyboard_id = + unsafe { (XKBXH.xkb_x11_get_core_keyboard_device_id)(self.xcb_connection) }; + let keymap = unsafe { + (XKBXH.xkb_x11_keymap_new_from_device)( + self.xkb_context, + self.xcb_connection, + self.core_keyboard_id, + xkbcommon_dl::xkb_keymap_compile_flags::XKB_KEYMAP_COMPILE_NO_FLAGS, + ) + }; if keymap.is_null() { panic!("Failed to get keymap from X11 server."); } - let state = (XKBXH.xkb_x11_state_new_from_device)( - keymap, - self.xcb_connection, - self.core_keyboard_id, - ); - self.post_init(state, keymap); + let state = unsafe { + (XKBXH.xkb_x11_state_new_from_device)( + keymap, + self.xcb_connection, + self.core_keyboard_id, + ) + }; + unsafe { self.post_init(state, keymap) }; } #[cfg(feature = "wayland")] pub unsafe fn init_with_fd(&mut self, fd: OwnedFd, size: usize) { if !self.xkb_keymap.is_null() { - self.de_init(); + unsafe { self.de_init() }; } - let map = MmapOptions::new() - .len(size) - .map_copy_read_only(&fd) - .unwrap(); + let map = unsafe { + MmapOptions::new() + .len(size) + .map_copy_read_only(&fd) + .unwrap() + }; - let keymap = (XKBH.xkb_keymap_new_from_string)( - self.xkb_context, - map.as_ptr() as *const _, - ffi::xkb_keymap_format::XKB_KEYMAP_FORMAT_TEXT_V1, - ffi::xkb_keymap_compile_flags::XKB_KEYMAP_COMPILE_NO_FLAGS, - ); + let keymap = unsafe { + (XKBH.xkb_keymap_new_from_string)( + self.xkb_context, + map.as_ptr() as *const _, + ffi::xkb_keymap_format::XKB_KEYMAP_FORMAT_TEXT_V1, + ffi::xkb_keymap_compile_flags::XKB_KEYMAP_COMPILE_NO_FLAGS, + ) + }; if keymap.is_null() { panic!("Received invalid keymap from compositor."); } - let state = (XKBH.xkb_state_new)(keymap); - self.post_init(state, keymap); + let state = unsafe { (XKBH.xkb_state_new)(keymap) }; + unsafe { self.post_init(state, keymap) }; } pub fn key_repeats(&mut self, keycode: ffi::xkb_keycode_t) -> bool { diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index 4a52f88c..0ecd6a0d 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -178,9 +178,9 @@ pub enum DeviceId { impl DeviceId { pub const unsafe fn dummy() -> Self { #[cfg(wayland_platform)] - return DeviceId::Wayland(wayland::DeviceId::dummy()); + return DeviceId::Wayland(unsafe { wayland::DeviceId::dummy() }); #[cfg(all(not(wayland_platform), x11_platform))] - return DeviceId::X(x11::DeviceId::dummy()); + return DeviceId::X(unsafe { x11::DeviceId::dummy() }); } } @@ -649,26 +649,31 @@ unsafe extern "C" fn x_error_callback( if let Ok(ref xconn) = *xconn_lock { // Call all the hooks. let mut error_handled = false; - for hook in XLIB_ERROR_HOOKS.lock().unwrap().iter() { + for hook in unsafe { XLIB_ERROR_HOOKS.lock() }.unwrap().iter() { error_handled |= hook(display as *mut _, event as *mut _); } // `assume_init` is safe here because the array consists of `MaybeUninit` values, // which do not require initialization. - let mut buf: [MaybeUninit; 1024] = MaybeUninit::uninit().assume_init(); - (xconn.xlib.XGetErrorText)( - display, - (*event).error_code as c_int, - buf.as_mut_ptr() as *mut c_char, - buf.len() as c_int, - ); - let description = CStr::from_ptr(buf.as_ptr() as *const c_char).to_string_lossy(); + let mut buf: [MaybeUninit; 1024] = unsafe { MaybeUninit::uninit().assume_init() }; + unsafe { + (xconn.xlib.XGetErrorText)( + display, + (*event).error_code as c_int, + buf.as_mut_ptr() as *mut c_char, + buf.len() as c_int, + ) + }; + let description = + unsafe { CStr::from_ptr(buf.as_ptr() as *const c_char) }.to_string_lossy(); - let error = XError { - description: description.into_owned(), - error_code: (*event).error_code, - request_code: (*event).request_code, - minor_code: (*event).minor_code, + let error = unsafe { + XError { + description: description.into_owned(), + error_code: (*event).error_code, + request_code: (*event).request_code, + minor_code: (*event).minor_code, + } }; // Don't log error. diff --git a/src/platform_impl/linux/x11/event_processor.rs b/src/platform_impl/linux/x11/event_processor.rs index 81a816a4..f23c1700 100644 --- a/src/platform_impl/linux/x11/event_processor.rs +++ b/src/platform_impl/linux/x11/event_processor.rs @@ -122,12 +122,14 @@ impl EventProcessor { 1 } - let result = (wt.xconn.xlib.XCheckIfEvent)( - wt.xconn.display, - event_ptr, - Some(predicate), - std::ptr::null_mut(), - ); + let result = unsafe { + (wt.xconn.xlib.XCheckIfEvent)( + wt.xconn.display, + event_ptr, + Some(predicate), + std::ptr::null_mut(), + ) + }; result != 0 } diff --git a/src/platform_impl/linux/x11/ime/callbacks.rs b/src/platform_impl/linux/x11/ime/callbacks.rs index fd96afbe..b5a01071 100644 --- a/src/platform_impl/linux/x11/ime/callbacks.rs +++ b/src/platform_impl/linux/x11/ime/callbacks.rs @@ -16,7 +16,7 @@ pub(crate) unsafe fn xim_set_callback( ) -> Result<(), XError> { // It's advisable to wrap variadic FFI functions in our own functions, as we want to minimize // access that isn't type-checked. - (xconn.xlib.XSetIMValues)(xim, field, callback, ptr::null_mut::<()>()); + unsafe { (xconn.xlib.XSetIMValues)(xim, field, callback, ptr::null_mut::<()>()) }; xconn.check_errors() } @@ -30,14 +30,16 @@ pub(crate) unsafe fn set_instantiate_callback( xconn: &Arc, client_data: ffi::XPointer, ) -> Result<(), XError> { - (xconn.xlib.XRegisterIMInstantiateCallback)( - xconn.display, - ptr::null_mut(), - ptr::null_mut(), - ptr::null_mut(), - Some(xim_instantiate_callback), - client_data, - ); + unsafe { + (xconn.xlib.XRegisterIMInstantiateCallback)( + xconn.display, + ptr::null_mut(), + ptr::null_mut(), + ptr::null_mut(), + Some(xim_instantiate_callback), + client_data, + ) + }; xconn.check_errors() } @@ -45,14 +47,16 @@ pub(crate) unsafe fn unset_instantiate_callback( xconn: &Arc, client_data: ffi::XPointer, ) -> Result<(), XError> { - (xconn.xlib.XUnregisterIMInstantiateCallback)( - xconn.display, - ptr::null_mut(), - ptr::null_mut(), - ptr::null_mut(), - Some(xim_instantiate_callback), - client_data, - ); + unsafe { + (xconn.xlib.XUnregisterIMInstantiateCallback)( + xconn.display, + ptr::null_mut(), + ptr::null_mut(), + ptr::null_mut(), + Some(xim_instantiate_callback), + client_data, + ) + }; xconn.check_errors() } @@ -61,12 +65,14 @@ pub(crate) unsafe fn set_destroy_callback( im: ffi::XIM, inner: &ImeInner, ) -> Result<(), XError> { - xim_set_callback( - xconn, - im, - ffi::XNDestroyCallback_0.as_ptr() as *const _, - &inner.destroy_callback as *const _ as *mut _, - ) + unsafe { + xim_set_callback( + xconn, + im, + ffi::XNDestroyCallback_0.as_ptr() as *const _, + &inner.destroy_callback as *const _ as *mut _, + ) + } } #[derive(Debug)] @@ -82,14 +88,16 @@ enum ReplaceImError { // includes replacing all existing input contexts and free'ing resources as necessary. This only // modifies existing state if all operations succeed. unsafe fn replace_im(inner: *mut ImeInner) -> Result<(), ReplaceImError> { - let xconn = &(*inner).xconn; + let xconn = unsafe { &(*inner).xconn }; let (new_im, is_fallback) = { - let new_im = (*inner).potential_input_methods.open_im(xconn, None); + let new_im = unsafe { (*inner).potential_input_methods.open_im(xconn, None) }; let is_fallback = new_im.is_fallback(); ( new_im.ok().ok_or_else(|| { - ReplaceImError::MethodOpenFailed(Box::new((*inner).potential_input_methods.clone())) + ReplaceImError::MethodOpenFailed(Box::new(unsafe { + (*inner).potential_input_methods.clone() + })) })?, is_fallback, ) @@ -98,16 +106,16 @@ unsafe fn replace_im(inner: *mut ImeInner) -> Result<(), ReplaceImError> { // It's important to always set a destroy callback, since there's otherwise potential for us // to try to use or free a resource that's already been destroyed on the server. { - let result = set_destroy_callback(xconn, new_im.im, &*inner); + let result = unsafe { set_destroy_callback(xconn, new_im.im, &*inner) }; if result.is_err() { - let _ = close_im(xconn, new_im.im); + let _ = unsafe { close_im(xconn, new_im.im) }; } result } .map_err(ReplaceImError::SetDestroyCallbackFailed)?; let mut new_contexts = HashMap::new(); - for (window, old_context) in (*inner).contexts.iter() { + for (window, old_context) in unsafe { (*inner).contexts.iter() } { let spot = old_context.as_ref().map(|old_context| old_context.ic_spot); // Check if the IME was allowed on that context. @@ -125,16 +133,18 @@ unsafe fn replace_im(inner: *mut ImeInner) -> Result<(), ReplaceImError> { }; let new_context = { - let result = ImeContext::new( - xconn, - new_im.im, - style, - *window, - spot, - (*inner).event_sender.clone(), - ); + let result = unsafe { + ImeContext::new( + xconn, + new_im.im, + style, + *window, + spot, + (*inner).event_sender.clone(), + ) + }; if result.is_err() { - let _ = close_im(xconn, new_im.im); + let _ = unsafe { close_im(xconn, new_im.im) }; } result.map_err(ReplaceImError::ContextCreationFailed)? }; @@ -142,12 +152,14 @@ unsafe fn replace_im(inner: *mut ImeInner) -> Result<(), ReplaceImError> { } // If we've made it this far, everything succeeded. - let _ = (*inner).destroy_all_contexts_if_necessary(); - let _ = (*inner).close_im_if_necessary(); - (*inner).im = Some(new_im); - (*inner).contexts = new_contexts; - (*inner).is_destroyed = false; - (*inner).is_fallback = is_fallback; + unsafe { + let _ = (*inner).destroy_all_contexts_if_necessary(); + let _ = (*inner).close_im_if_necessary(); + (*inner).im = Some(new_im); + (*inner).contexts = new_contexts; + (*inner).is_destroyed = false; + (*inner).is_fallback = is_fallback; + } Ok(()) } @@ -159,18 +171,18 @@ pub unsafe extern "C" fn xim_instantiate_callback( ) { let inner: *mut ImeInner = client_data as _; if !inner.is_null() { - let xconn = &(*inner).xconn; - match replace_im(inner) { - Ok(()) => { + let xconn = unsafe { &(*inner).xconn }; + match unsafe { replace_im(inner) } { + Ok(()) => unsafe { let _ = unset_instantiate_callback(xconn, client_data); (*inner).is_fallback = false; - } - Err(err) => { + }, + Err(err) => unsafe { if (*inner).is_destroyed { // We have no usable input methods! panic!("Failed to reopen input method: {err:?}"); } - } + }, } } } @@ -186,13 +198,13 @@ pub unsafe extern "C" fn xim_destroy_callback( ) { let inner: *mut ImeInner = client_data as _; if !inner.is_null() { - (*inner).is_destroyed = true; - let xconn = &(*inner).xconn; - if !(*inner).is_fallback { - let _ = set_instantiate_callback(xconn, client_data); + unsafe { (*inner).is_destroyed = true }; + let xconn = unsafe { &(*inner).xconn }; + if unsafe { !(*inner).is_fallback } { + let _ = unsafe { set_instantiate_callback(xconn, client_data) }; // Attempt to open fallback input method. - match replace_im(inner) { - Ok(()) => (*inner).is_fallback = true, + match unsafe { replace_im(inner) } { + Ok(()) => unsafe { (*inner).is_fallback = true }, Err(err) => { // We have no usable input methods! panic!("Failed to open fallback input method: {err:?}"); diff --git a/src/platform_impl/linux/x11/ime/context.rs b/src/platform_impl/linux/x11/ime/context.rs index 96c0ffb8..dab2c6bd 100644 --- a/src/platform_impl/linux/x11/ime/context.rs +++ b/src/platform_impl/linux/x11/ime/context.rs @@ -217,15 +217,19 @@ impl ImeContext { })); let ic = match style as _ { - Style::Preedit(style) => ImeContext::create_preedit_ic( - xconn, - im, - style, - window, - client_data as ffi::XPointer, - ), - Style::Nothing(style) => ImeContext::create_nothing_ic(xconn, im, style, window), - Style::None(style) => ImeContext::create_none_ic(xconn, im, style, window), + Style::Preedit(style) => unsafe { + ImeContext::create_preedit_ic( + xconn, + im, + style, + window, + client_data as ffi::XPointer, + ) + }, + Style::Nothing(style) => unsafe { + ImeContext::create_nothing_ic(xconn, im, style, window) + }, + Style::None(style) => unsafe { ImeContext::create_none_ic(xconn, im, style, window) }, } .ok_or(ImeContextCreationError::Null)?; @@ -237,7 +241,7 @@ impl ImeContext { ic, ic_spot: ffi::XPoint { x: 0, y: 0 }, style, - _client_data: Box::from_raw(client_data), + _client_data: unsafe { Box::from_raw(client_data) }, }; // Set the spot location, if it's present. @@ -254,14 +258,16 @@ impl ImeContext { style: XIMStyle, window: ffi::Window, ) -> Option { - let ic = (xconn.xlib.XCreateIC)( - im, - ffi::XNInputStyle_0.as_ptr() as *const _, - style, - ffi::XNClientWindow_0.as_ptr() as *const _, - window, - ptr::null_mut::<()>(), - ); + let ic = unsafe { + (xconn.xlib.XCreateIC)( + im, + ffi::XNInputStyle_0.as_ptr() as *const _, + style, + ffi::XNClientWindow_0.as_ptr() as *const _, + window, + ptr::null_mut::<()>(), + ) + }; (!ic.is_null()).then_some(ic) } @@ -274,8 +280,7 @@ impl ImeContext { client_data: ffi::XPointer, ) -> Option { let preedit_callbacks = PreeditCallbacks::new(client_data); - let preedit_attr = util::memory::XSmartPointer::new( - xconn, + let preedit_attr = util::memory::XSmartPointer::new(xconn, unsafe { (xconn.xlib.XVaCreateNestedList)( 0, ffi::XNPreeditStartCallback_0.as_ptr() as *const _, @@ -287,20 +292,22 @@ impl ImeContext { ffi::XNPreeditDrawCallback_0.as_ptr() as *const _, &(preedit_callbacks.draw_callback) as *const _, ptr::null_mut::<()>(), - ), - ) + ) + }) .expect("XVaCreateNestedList returned NULL"); - let ic = (xconn.xlib.XCreateIC)( - im, - ffi::XNInputStyle_0.as_ptr() as *const _, - style, - ffi::XNClientWindow_0.as_ptr() as *const _, - window, - ffi::XNPreeditAttributes_0.as_ptr() as *const _, - preedit_attr.ptr, - ptr::null_mut::<()>(), - ); + let ic = unsafe { + (xconn.xlib.XCreateIC)( + im, + ffi::XNInputStyle_0.as_ptr() as *const _, + style, + ffi::XNClientWindow_0.as_ptr() as *const _, + window, + ffi::XNPreeditAttributes_0.as_ptr() as *const _, + preedit_attr.ptr, + ptr::null_mut::<()>(), + ) + }; (!ic.is_null()).then_some(ic) } @@ -311,14 +318,16 @@ impl ImeContext { style: XIMStyle, window: ffi::Window, ) -> Option { - let ic = (xconn.xlib.XCreateIC)( - im, - ffi::XNInputStyle_0.as_ptr() as *const _, - style, - ffi::XNClientWindow_0.as_ptr() as *const _, - window, - ptr::null_mut::<()>(), - ); + let ic = unsafe { + (xconn.xlib.XCreateIC)( + im, + ffi::XNInputStyle_0.as_ptr() as *const _, + style, + ffi::XNClientWindow_0.as_ptr() as *const _, + window, + ptr::null_mut::<()>(), + ) + }; (!ic.is_null()).then_some(ic) } diff --git a/src/platform_impl/linux/x11/ime/inner.rs b/src/platform_impl/linux/x11/ime/inner.rs index e6eca9d0..ddff12fb 100644 --- a/src/platform_impl/linux/x11/ime/inner.rs +++ b/src/platform_impl/linux/x11/ime/inner.rs @@ -9,12 +9,12 @@ use super::{ use crate::platform_impl::platform::x11::ime::ImeEventSender; pub(crate) unsafe fn close_im(xconn: &Arc, im: ffi::XIM) -> Result<(), XError> { - (xconn.xlib.XCloseIM)(im); + unsafe { (xconn.xlib.XCloseIM)(im) }; xconn.check_errors() } pub(crate) unsafe fn destroy_ic(xconn: &Arc, ic: ffi::XIC) -> Result<(), XError> { - (xconn.xlib.XDestroyIC)(ic); + unsafe { (xconn.xlib.XDestroyIC)(ic) }; xconn.check_errors() } @@ -52,7 +52,7 @@ impl ImeInner { pub unsafe fn close_im_if_necessary(&self) -> Result { if !self.is_destroyed && self.im.is_some() { - close_im(&self.xconn, self.im.as_ref().unwrap().im).map(|_| true) + unsafe { close_im(&self.xconn, self.im.as_ref().unwrap().im) }.map(|_| true) } else { Ok(false) } @@ -60,7 +60,7 @@ impl ImeInner { pub unsafe fn destroy_ic_if_necessary(&self, ic: ffi::XIC) -> Result { if !self.is_destroyed { - destroy_ic(&self.xconn, ic).map(|_| true) + unsafe { destroy_ic(&self.xconn, ic) }.map(|_| true) } else { Ok(false) } @@ -68,7 +68,7 @@ impl ImeInner { pub unsafe fn destroy_all_contexts_if_necessary(&self) -> Result { for context in self.contexts.values().flatten() { - self.destroy_ic_if_necessary(context.ic)?; + unsafe { self.destroy_ic_if_necessary(context.ic)? }; } Ok(!self.is_destroyed) } diff --git a/src/platform_impl/linux/x11/ime/input_method.rs b/src/platform_impl/linux/x11/ime/input_method.rs index 454fd5e9..30a4a3eb 100644 --- a/src/platform_impl/linux/x11/ime/input_method.rs +++ b/src/platform_impl/linux/x11/ime/input_method.rs @@ -21,14 +21,16 @@ unsafe fn open_im(xconn: &Arc, locale_modifiers: &CStr) -> Option) -> Result, GetXi let atoms = xconn.atoms(); let servers_atom = atoms[XIM_SERVERS]; - let root = (xconn.xlib.XDefaultRootWindow)(xconn.display); + let root = unsafe { (xconn.xlib.XDefaultRootWindow)(xconn.display) }; let mut atoms: Vec = xconn .get_property::( @@ -192,21 +194,23 @@ unsafe fn get_xim_servers(xconn: &Arc) -> Result, GetXi .collect::>(); let mut names: Vec<*const c_char> = Vec::with_capacity(atoms.len()); - (xconn.xlib.XGetAtomNames)( - xconn.display, - atoms.as_mut_ptr(), - atoms.len() as _, - names.as_mut_ptr() as _, - ); - names.set_len(atoms.len()); + unsafe { + (xconn.xlib.XGetAtomNames)( + xconn.display, + atoms.as_mut_ptr(), + atoms.len() as _, + names.as_mut_ptr() as _, + ) + }; + unsafe { names.set_len(atoms.len()) }; let mut formatted_names = Vec::with_capacity(names.len()); for name in names { - let string = CStr::from_ptr(name) + let string = unsafe { CStr::from_ptr(name) } .to_owned() .into_string() .map_err(GetXimServersError::InvalidUtf8)?; - (xconn.xlib.XFree)(name as _); + unsafe { (xconn.xlib.XFree)(name as _) }; formatted_names.push(string.replace("@server=", "@im=")); } xconn.check_errors().map_err(GetXimServersError::XError)?; diff --git a/src/platform_impl/macos/mod.rs b/src/platform_impl/macos/mod.rs index 749647a6..7169ca9d 100644 --- a/src/platform_impl/macos/mod.rs +++ b/src/platform_impl/macos/mod.rs @@ -1,5 +1,3 @@ -#![deny(unsafe_op_in_unsafe_fn)] - #[macro_use] mod util; diff --git a/src/platform_impl/windows/mod.rs b/src/platform_impl/windows/mod.rs index 87f155e5..bc6caeb6 100644 --- a/src/platform_impl/windows/mod.rs +++ b/src/platform_impl/windows/mod.rs @@ -1,5 +1,4 @@ #![cfg(windows_platform)] -#![deny(unsafe_op_in_unsafe_fn)] use smol_str::SmolStr; use windows_sys::Win32::{ diff --git a/src/window.rs b/src/window.rs index 81cbaf40..f6fecf78 100644 --- a/src/window.rs +++ b/src/window.rs @@ -101,7 +101,8 @@ impl WindowId { /// /// **Passing this into a winit function will result in undefined behavior.** pub const unsafe fn dummy() -> Self { - WindowId(platform_impl::WindowId::dummy()) + #[allow(unused_unsafe)] + WindowId(unsafe { platform_impl::WindowId::dummy() }) } }