From 032800fe731082ff115a5346b5178d12cfd1bf02 Mon Sep 17 00:00:00 2001 From: Aleksi Juvani Date: Wed, 7 Aug 2019 21:29:04 +0300 Subject: [PATCH] Add explicit return types for `msg_send!` calls --- examples/argument-buffer/main.rs | 2 +- examples/bind/main.rs | 2 +- examples/compute/compute-argument-buffer.rs | 2 +- examples/compute/embedded-lib.rs | 4 ++- examples/compute/main.rs | 2 +- examples/reflection/main.rs | 2 +- examples/window/main.rs | 2 +- src/capturemanager.rs | 12 ++++----- src/commandbuffer.rs | 2 +- src/commandqueue.rs | 2 +- src/device.rs | 6 ++--- src/encoder.rs | 4 +-- src/heap.rs | 4 +-- src/lib.rs | 28 +++++++++------------ src/library.rs | 2 +- src/pipeline/compute.rs | 4 +-- src/pipeline/render.rs | 4 +-- src/renderpass.rs | 4 +-- src/resource.rs | 2 +- 19 files changed, 42 insertions(+), 48 deletions(-) diff --git a/examples/argument-buffer/main.rs b/examples/argument-buffer/main.rs index 8f94f0c8..c16ee92f 100644 --- a/examples/argument-buffer/main.rs +++ b/examples/argument-buffer/main.rs @@ -38,6 +38,6 @@ fn main() { println!("{:?}", sampler); unsafe { - msg_send![pool, release]; + let () = msg_send![pool, release]; } } diff --git a/examples/bind/main.rs b/examples/bind/main.rs index 93229481..197c0b9b 100644 --- a/examples/bind/main.rs +++ b/examples/bind/main.rs @@ -37,6 +37,6 @@ fn main() { println!("Everything is bound"); unsafe { - msg_send![pool, release]; + let () = msg_send![pool, release]; } } diff --git a/examples/compute/compute-argument-buffer.rs b/examples/compute/compute-argument-buffer.rs index c7ab2014..085031e4 100644 --- a/examples/compute/compute-argument-buffer.rs +++ b/examples/compute/compute-argument-buffer.rs @@ -96,6 +96,6 @@ fn main() { unsafe { assert_eq!(465, *ptr); - msg_send![pool, release]; + let () = msg_send![pool, release]; } } diff --git a/examples/compute/embedded-lib.rs b/examples/compute/embedded-lib.rs index 67a8e7dd..dae1ae9f 100644 --- a/examples/compute/embedded-lib.rs +++ b/examples/compute/embedded-lib.rs @@ -25,5 +25,7 @@ fn main() { println!("Function type: {:?}", kernel.function_type()); println!("OK"); - unsafe { msg_send![pool, release] } + unsafe { + let () = msg_send![pool, release]; + } } diff --git a/examples/compute/main.rs b/examples/compute/main.rs index e491aed2..a42adb32 100644 --- a/examples/compute/main.rs +++ b/examples/compute/main.rs @@ -83,6 +83,6 @@ fn main() { unsafe { assert_eq!(465, *ptr); - msg_send![pool, release]; + let () = msg_send![pool, release]; } } diff --git a/examples/reflection/main.rs b/examples/reflection/main.rs index f340beaa..8b556636 100644 --- a/examples/reflection/main.rs +++ b/examples/reflection/main.rs @@ -78,6 +78,6 @@ fn main() { }; unsafe { - msg_send![pool, release]; + let () = msg_send![pool, release]; } } diff --git a/examples/window/main.rs b/examples/window/main.rs index cb20ece6..3751c89d 100644 --- a/examples/window/main.rs +++ b/examples/window/main.rs @@ -177,7 +177,7 @@ fn main() { r += 0.01f32; //let _: () = msg_send![command_queue.0, _submitAvailableCommandBuffers]; unsafe { - msg_send![pool, release]; + let () = msg_send![pool, release]; pool = NSAutoreleasePool::new(cocoa::base::nil); } } diff --git a/src/capturemanager.rs b/src/capturemanager.rs index 0215a35c..04e2862e 100644 --- a/src/capturemanager.rs +++ b/src/capturemanager.rs @@ -18,13 +18,13 @@ foreign_obj_type! { impl CaptureScopeRef { pub fn begin_scope(&self) { unsafe { - msg_send![self, beginScope]; + msg_send![self, beginScope] } } pub fn end_scope(&self) { unsafe { - msg_send![self, endScope]; + msg_send![self, endScope] } } @@ -75,25 +75,25 @@ impl CaptureManagerRef { pub fn start_capture_with_device(&self, device: &DeviceRef) { unsafe { - msg_send![self, startCaptureWithDevice: device]; + msg_send![self, startCaptureWithDevice: device] } } pub fn start_capture_with_command_queue(&self, command_queue: &CommandQueueRef) { unsafe { - msg_send![self, startCaptureWithCommandQueue: command_queue]; + msg_send![self, startCaptureWithCommandQueue: command_queue] } } pub fn start_capture_with_scope(&self, scope: &CaptureScopeRef) { unsafe { - msg_send![self, startCaptureWithScope: scope]; + msg_send![self, startCaptureWithScope: scope] } } pub fn stop_capture(&self) { unsafe { - msg_send![self, stopCapture]; + msg_send![self, stopCapture] } } diff --git a/src/commandbuffer.rs b/src/commandbuffer.rs index b4d71e53..ca278f35 100644 --- a/src/commandbuffer.rs +++ b/src/commandbuffer.rs @@ -63,7 +63,7 @@ impl CommandBufferRef { pub fn set_label(&self, label: &str) { unsafe { let nslabel = crate::nsstring_from_str(label); - msg_send![self, setLabel: nslabel]; + let () = msg_send![self, setLabel: nslabel]; } } diff --git a/src/commandqueue.rs b/src/commandqueue.rs index 948f02cd..470d8dbe 100644 --- a/src/commandqueue.rs +++ b/src/commandqueue.rs @@ -26,7 +26,7 @@ impl CommandQueueRef { pub fn set_label(&self, label: &str) { unsafe { let nslabel = crate::nsstring_from_str(label); - msg_send![self, setLabel: nslabel]; + let () = msg_send![self, setLabel: nslabel]; } } diff --git a/src/device.rs b/src/device.rs index 75c246f1..aab28e1a 100644 --- a/src/device.rs +++ b/src/device.rs @@ -1407,7 +1407,7 @@ impl Device { let ret = (0..count) .map(|i| msg_send![array, objectAtIndex: i]) .collect(); - msg_send![array, release]; + let () = msg_send![array, release]; ret } } @@ -1530,13 +1530,13 @@ impl DeviceRef { let library: *mut MTLLibrary = msg_send![self, newLibraryWithSource:source options:options error:&mut err]; - msg_send![source, release]; + let () = msg_send![source, release]; if !err.is_null() { let desc: *mut Object = msg_send![err, localizedDescription]; let compile_error: *const std::os::raw::c_char = msg_send![desc, UTF8String]; let message = CStr::from_ptr(compile_error).to_string_lossy().into_owned(); if library.is_null() { - msg_send![err, release]; + let () = msg_send![err, release]; return Err(message); } else { warn!("Shader warnings: {}", message); diff --git a/src/encoder.rs b/src/encoder.rs index 83594d0d..0a23ef87 100644 --- a/src/encoder.rs +++ b/src/encoder.rs @@ -132,13 +132,13 @@ impl CommandEncoderRef { pub fn set_label(&self, label: &str) { unsafe { let nslabel = crate::nsstring_from_str(label); - msg_send![self, setLabel: nslabel]; + let () = msg_send![self, setLabel: nslabel]; } } pub fn end_encoding(&self) { unsafe { - msg_send![self, endEncoding]; + msg_send![self, endEncoding] } } } diff --git a/src/heap.rs b/src/heap.rs index ff0c9973..a18d7907 100644 --- a/src/heap.rs +++ b/src/heap.rs @@ -105,8 +105,6 @@ impl HeapDescriptorRef { } pub fn set_size(&self, size: NSUInteger) { - unsafe { - msg_send![self, setSize: size]; - } + unsafe { msg_send![self, setSize: size] } } } diff --git a/src/lib.rs b/src/lib.rs index 523b67a0..73e46934 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,20 +21,22 @@ use std::borrow::{Borrow, ToOwned}; use std::marker::PhantomData; use std::mem; use std::ops::Deref; +use std::os::raw::c_void; use core_graphics::base::CGFloat; use core_graphics::geometry::CGSize; use foreign_types::ForeignType; use objc::runtime::{Object, NO, YES}; +use cocoa::foundation::NSUInteger; fn nsstring_as_str(nsstr: &objc::runtime::Object) -> &str { let bytes = unsafe { let bytes: *const std::os::raw::c_char = msg_send![nsstr, UTF8String]; bytes as *const u8 }; - let len = unsafe { msg_send![nsstr, length] }; + let len: NSUInteger = unsafe { msg_send![nsstr, length] }; unsafe { - let bytes = std::slice::from_raw_parts(bytes, len); + let bytes = std::slice::from_raw_parts(bytes, len as usize); std::str::from_utf8(bytes).unwrap() } } @@ -43,13 +45,13 @@ fn nsstring_from_str(string: &str) -> *mut objc::runtime::Object { const UTF8_ENCODING: usize = 4; let cls = class!(NSString); - let bytes = string.as_ptr() as *const std::os::raw::c_void; + let bytes = string.as_ptr() as *const c_void; unsafe { let obj: *mut objc::runtime::Object = msg_send![cls, alloc]; let obj: *mut objc::runtime::Object = msg_send![obj, initWithBytes:bytes length:string.len() encoding:UTF8_ENCODING]; - msg_send![obj, autorelease]; + let _: *mut c_void = msg_send![obj, autorelease]; obj } } @@ -119,7 +121,7 @@ macro_rules! try_objc { let desc: *mut Object = msg_send![$err_name, localizedDescription]; let compile_error: *const std::os::raw::c_char = msg_send![desc, UTF8String]; let message = CStr::from_ptr(compile_error).to_string_lossy().into_owned(); - msg_send![$err_name, release]; + let () = msg_send![$err_name, release]; return Err(message); } value @@ -147,7 +149,7 @@ where { fn drop(&mut self) { unsafe { - msg_send![self.0, release]; + let () = msg_send![self.0, release]; } } } @@ -318,9 +320,7 @@ impl CoreAnimationLayerRef { } pub fn set_presents_with_transaction(&self, transaction: bool) { - unsafe { - msg_send![self, setPresentsWithTransaction: transaction]; - } + unsafe { msg_send![self, setPresentsWithTransaction: transaction] } } pub fn set_edge_antialiasing_mask(&self, mask: u64) { @@ -332,9 +332,7 @@ impl CoreAnimationLayerRef { } pub fn remove_all_animations(&self) { - unsafe { - msg_send![self, removeAllAnimations]; - } + unsafe { msg_send![self, removeAllAnimations] } } pub fn next_drawable(&self) -> Option<&CoreAnimationDrawableRef> { @@ -342,9 +340,7 @@ impl CoreAnimationLayerRef { } pub fn set_contents_scale(&self, scale: CGFloat) { - unsafe { - msg_send![self, setContentsScale: scale]; - } + unsafe { msg_send![self, setContentsScale: scale] } } } @@ -390,7 +386,7 @@ pub use vertexdescriptor::*; #[inline] unsafe fn obj_drop(p: *mut T) { - msg_send![(p as *mut Object), release]; + msg_send![(p as *mut Object), release] } #[inline] diff --git a/src/library.rs b/src/library.rs index ea7e8e21..eb98ac13 100644 --- a/src/library.rs +++ b/src/library.rs @@ -207,7 +207,7 @@ impl LibraryRef { pub fn set_label(&self, label: &str) { unsafe { let nslabel = crate::nsstring_from_str(label); - msg_send![self, setLabel: nslabel]; + let () = msg_send![self, setLabel: nslabel]; } } diff --git a/src/pipeline/compute.rs b/src/pipeline/compute.rs index 41adc1e1..c6ec9a08 100644 --- a/src/pipeline/compute.rs +++ b/src/pipeline/compute.rs @@ -135,7 +135,7 @@ impl ComputePipelineDescriptorRef { pub fn set_label(&self, label: &str) { unsafe { let nslabel = crate::nsstring_from_str(label); - msg_send![self, setLabel: nslabel] + let () = msg_send![self, setLabel: nslabel]; } } @@ -205,7 +205,7 @@ impl ComputePipelineStateRef { pub fn set_label(&self, label: &str) { unsafe { let nslabel = crate::nsstring_from_str(label); - msg_send![self, setLabel: nslabel]; + let () = msg_send![self, setLabel: nslabel]; } } diff --git a/src/pipeline/render.rs b/src/pipeline/render.rs index 1e8d1574..2b103018 100644 --- a/src/pipeline/render.rs +++ b/src/pipeline/render.rs @@ -224,7 +224,7 @@ impl RenderPipelineDescriptorRef { pub fn set_label(&self, label: &str) { unsafe { let nslabel = crate::nsstring_from_str(label); - msg_send![self, setLabel: nslabel]; + let () = msg_send![self, setLabel: nslabel]; } } @@ -378,7 +378,7 @@ impl RenderPipelineStateRef { pub fn set_label(&self, label: &str) { unsafe { let nslabel = crate::nsstring_from_str(label); - msg_send![self, setLabel: nslabel]; + let () = msg_send![self, setLabel: nslabel]; } } } diff --git a/src/renderpass.rs b/src/renderpass.rs index 09f450f1..dc963877 100644 --- a/src/renderpass.rs +++ b/src/renderpass.rs @@ -70,9 +70,7 @@ impl RenderPassAttachmentDescriptorRef { } pub fn set_texture(&self, texture: Option<&TextureRef>) { - unsafe { - msg_send![self, setTexture: texture]; - } + unsafe { msg_send![self, setTexture: texture] } } pub fn level(&self) -> NSUInteger { diff --git a/src/resource.rs b/src/resource.rs index ed995ff5..f8af9abe 100644 --- a/src/resource.rs +++ b/src/resource.rs @@ -87,7 +87,7 @@ impl ResourceRef { pub fn set_label(&self, label: &str) { unsafe { let nslabel = crate::nsstring_from_str(label); - msg_send![self, setLabel: nslabel]; + let () = msg_send![self, setLabel: nslabel]; } }