diff --git a/native-windows-gui/examples/sync-draw/src/shared_memory.rs b/native-windows-gui/examples/sync-draw/src/shared_memory.rs index 50715c17..4f250ba5 100644 --- a/native-windows-gui/examples/sync-draw/src/shared_memory.rs +++ b/native-windows-gui/examples/sync-draw/src/shared_memory.rs @@ -128,8 +128,8 @@ impl SharedMemory { /// Fetch the next instance id in the shared memory. pub fn next_instance_id(&self) -> u32 { let header_ptr = SharedMemory::map_view(self.handle, 0, HEADER_SIZE) as *mut SharedHeader; - let next_id = unsafe { - let header = &mut *header_ptr; + let next_id = { + let header = unsafe { &mut *header_ptr }; header.next_instance_id += 1; header.next_instance_id }; @@ -234,14 +234,14 @@ impl SharedMemory { /// Safe wrapper over MapViewOfFile fn map_view(handle: HANDLE, offset: DWORD, size: SIZE_T) -> *mut u8 { - unsafe { - let handle = MapViewOfFile(handle, FILE_MAP_ALL_ACCESS, 0, offset, size) as *mut u8; + + let handle = unsafe { MapViewOfFile(handle, FILE_MAP_ALL_ACCESS, 0, offset, size) as *mut u8 }; if handle.is_null() { panic!("Could not map memory region"); } handle - } + } /// Safe wrapper over UnmapViewOfFile diff --git a/native-windows-gui/src/events.rs b/native-windows-gui/src/events.rs index 9b8f9123..fdbcdc87 100644 --- a/native-windows-gui/src/events.rs +++ b/native-windows-gui/src/events.rs @@ -478,9 +478,9 @@ impl ToolTipTextData { } self.clear(); + let data = unsafe { &mut *self.data }; + let local_text = to_utf16(text); unsafe { - let data = &mut *self.data; - let local_text = to_utf16(text); ptr::copy_nonoverlapping(local_text.as_ptr(), data.szText.as_mut_ptr(), text_len); } } @@ -539,11 +539,11 @@ impl PaintData { /// Wrapper over BeginPaint pub fn begin_paint(&self) -> PAINTSTRUCT { - unsafe { - let mut paint: PAINTSTRUCT = ::std::mem::zeroed(); - BeginPaint(self.hwnd, &mut paint); + + let mut paint: PAINTSTRUCT = unsafe { ::std::mem::zeroed() }; + unsafe { BeginPaint(self.hwnd, &mut paint) }; paint - } + } /// Wrapper over EndPaint @@ -568,11 +568,11 @@ impl DropFiles { pub fn point(&self) -> [i32; 2] { use winapi::um::shellapi::DragQueryPoint; - unsafe { + let mut pt = POINT { x: 0, y: 0 }; - DragQueryPoint(self.drop, &mut pt); + unsafe { DragQueryPoint(self.drop, &mut pt) }; [pt.x, pt.y] - } + } /// Return the number of files dropped @@ -593,19 +593,19 @@ impl DropFiles { let len = self.len(); let mut files = Vec::with_capacity(len); - unsafe { + for i in 0..len { // Need to add a +1 here for some reason - let buffer_size = (DragQueryFileW(self.drop, i as _, ptr::null_mut(), 0) + 1) as usize; + let buffer_size = unsafe { (DragQueryFileW(self.drop, i as _, ptr::null_mut(), 0) + 1) as usize }; let mut buffer: Vec = Vec::with_capacity(buffer_size); - buffer.set_len(buffer_size); + unsafe { buffer.set_len(buffer_size) }; - DragQueryFileW(self.drop, i as _, buffer.as_mut_ptr(), buffer_size as _); + unsafe { DragQueryFileW(self.drop, i as _, buffer.as_mut_ptr(), buffer_size as _) }; files.push(from_utf16(&buffer)); } - } + files } diff --git a/native-windows-gui/src/win32/window_helper.rs b/native-windows-gui/src/win32/window_helper.rs index 59ad057a..d20c4116 100644 --- a/native-windows-gui/src/win32/window_helper.rs +++ b/native-windows-gui/src/win32/window_helper.rs @@ -94,15 +94,15 @@ pub fn destroy_window(hwnd: HWND) { pub fn destroy_menu_item(parent: HMENU, item_id: u32) { use winapi::um::winuser::{DeleteMenu, GetMenuItemCount, GetMenuItemID, MF_BYPOSITION}; - unsafe { - let count = GetMenuItemCount(parent); + + let count = unsafe { GetMenuItemCount(parent) }; let mut index = 0; while index < count { - let id = GetMenuItemID(parent, index); + let id = unsafe { GetMenuItemID(parent, index) }; match id == item_id { true => { - DeleteMenu(parent, index as u32, MF_BYPOSITION); + unsafe { DeleteMenu(parent, index as u32, MF_BYPOSITION) }; index = count; }, false => { @@ -110,7 +110,7 @@ pub fn destroy_menu_item(parent: HMENU, item_id: u32) { } } } - } + } pub fn destroy_menu(menu: HMENU) {