Some clippy fixes. (#624)

This commit is contained in:
Bruce Mitchener
2023-08-03 21:20:26 +07:00
committed by GitHub
parent 062041a921
commit 18df9aafe7
20 changed files with 83 additions and 84 deletions
+12 -21
View File
@@ -48,7 +48,7 @@ mod macos {
impl NSPoint {
#[inline]
pub fn new(x: CGFloat, y: CGFloat) -> NSPoint {
NSPoint { x: x, y: y }
NSPoint { x, y }
}
}
@@ -73,10 +73,7 @@ mod macos {
impl NSSize {
#[inline]
pub fn new(width: CGFloat, height: CGFloat) -> NSSize {
NSSize {
width: width,
height: height,
}
NSSize { width, height }
}
}
@@ -101,10 +98,7 @@ mod macos {
impl NSRect {
#[inline]
pub fn new(origin: NSPoint, size: NSSize) -> NSRect {
NSRect {
origin: origin,
size: size,
}
NSRect { origin, size }
}
#[inline]
@@ -169,10 +163,7 @@ pub struct NSRange {
impl NSRange {
#[inline]
pub fn new(location: NSUInteger, length: NSUInteger) -> NSRange {
NSRange {
location: location,
length: length,
}
NSRange { location, length }
}
}
@@ -216,9 +207,9 @@ impl NSOperatingSystemVersion {
patchVersion: NSUInteger,
) -> NSOperatingSystemVersion {
NSOperatingSystemVersion {
majorVersion: majorVersion,
minorVersion: minorVersion,
patchVersion: patchVersion,
majorVersion,
minorVersion,
patchVersion,
}
}
}
@@ -663,10 +654,10 @@ impl NSString for id {
}
unsafe fn init_str(self, string: &str) -> id {
return msg_send![self,
initWithBytes:string.as_ptr()
length:string.len()
encoding:UTF8_ENCODING as id];
msg_send![self,
initWithBytes:string.as_ptr()
length:string.len()
encoding:UTF8_ENCODING as id]
}
unsafe fn len(self) -> usize {
@@ -734,7 +725,7 @@ impl Iterator for NSFastIterator {
}
if self.idx < self.len {
let object = unsafe { *self.state.items_ptr.offset(self.idx as isize) };
let object = unsafe { *self.state.items_ptr.add(self.idx) };
self.mut_val = Some(new_mut);
self.idx += 1;
Some(object)
+2 -2
View File
@@ -116,8 +116,8 @@ mod foundation {
#[test]
fn test_get() {
const KEY: &'static str = "The key";
const VALUE: &'static str = "Some value";
const KEY: &str = "The key";
const VALUE: &str = "Some value";
unsafe {
let key = NSString::alloc(nil).init_str(KEY);
let value = NSString::alloc(nil).init_str(VALUE);
+1 -1
View File
@@ -133,5 +133,5 @@ unsafe fn create_app() -> id {
let current_app = NSRunningApplication::currentApplication(nil);
current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps);
return app;
app
}
+1 -1
View File
@@ -83,5 +83,5 @@ unsafe fn create_app(title: id, content: id) -> id {
let current_app = NSRunningApplication::currentApplication(nil);
current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps);
return app;
app
}
+1 -1
View File
@@ -583,7 +583,7 @@ impl NSApplication for id {
unsafe fn presentationOptions_(self) -> NSApplicationPresentationOptions {
let options = msg_send![self, presentationOptions];
return NSApplicationPresentationOptions::from_bits(options).unwrap();
NSApplicationPresentationOptions::from_bits(options).unwrap()
}
unsafe fn setMainMenu_(self, menu: id) {
+4 -7
View File
@@ -49,9 +49,9 @@ pub type CFComparatorFunction = extern "C" fn(
context: *mut c_void,
) -> CFComparisonResult;
impl Into<Ordering> for CFComparisonResult {
fn into(self) -> Ordering {
match self {
impl From<CFComparisonResult> for Ordering {
fn from(val: CFComparisonResult) -> Self {
match val {
CFComparisonResult::LessThan => Ordering::Less,
CFComparisonResult::EqualTo => Ordering::Equal,
CFComparisonResult::GreaterThan => Ordering::Greater,
@@ -69,10 +69,7 @@ pub struct CFRange {
// for back-compat
impl CFRange {
pub fn init(location: CFIndex, length: CFIndex) -> CFRange {
CFRange {
location: location,
length: length,
}
CFRange { location, length }
}
}
+9 -3
View File
@@ -115,7 +115,7 @@ impl<T> CFArray<T> {
/// Core Foundation objects (not always true), they need to be wrapped with
/// `TCFType::wrap_under_get_rule()`.
#[inline]
pub fn iter<'a>(&'a self) -> CFArrayIterator<'a, T> {
pub fn iter(&self) -> CFArrayIterator<'_, T> {
CFArrayIterator {
array: self,
index: 0,
@@ -128,8 +128,14 @@ impl<T> CFArray<T> {
unsafe { CFArrayGetCount(self.0) }
}
/// Returns `true` if the array contains no elements.
#[inline]
pub unsafe fn get_unchecked<'a>(&'a self, index: CFIndex) -> ItemRef<'a, T>
pub fn is_empty(&self) -> bool {
self.len() == 0
}
#[inline]
pub unsafe fn get_unchecked(&self, index: CFIndex) -> ItemRef<'_, T>
where
T: FromVoid,
{
@@ -137,7 +143,7 @@ impl<T> CFArray<T> {
}
#[inline]
pub fn get<'a>(&'a self, index: CFIndex) -> Option<ItemRef<'a, T>>
pub fn get(&self, index: CFIndex) -> Option<ItemRef<'_, T>>
where
T: FromVoid,
{
+7 -1
View File
@@ -80,7 +80,7 @@ impl CFData {
/// Returns a pointer to the underlying bytes in this data. Note that this byte buffer is
/// read-only.
#[inline]
pub fn bytes<'a>(&'a self) -> &'a [u8] {
pub fn bytes(&self) -> &[u8] {
unsafe { slice::from_raw_parts(CFDataGetBytePtr(self.0), self.len() as usize) }
}
@@ -89,6 +89,12 @@ impl CFData {
pub fn len(&self) -> CFIndex {
unsafe { CFDataGetLength(self.0) }
}
/// Returns `true` if this byte buffer is empty.
#[inline]
pub fn is_empty(&self) -> bool {
self.len() == 0
}
}
impl Deref for CFData {
+1 -1
View File
@@ -79,7 +79,7 @@ mod test {
let same_sign = a.is_sign_positive() == b.is_sign_positive();
let equal = ((a - b).abs() / f64::min(a.abs() + b.abs(), f64::MAX)) < f64::EPSILON;
(same_sign && equal)
same_sign && equal
}
#[test]
+5 -5
View File
@@ -47,7 +47,7 @@ impl<K, V> CFDictionary<K, V> {
{
let (keys, values): (Vec<CFTypeRef>, Vec<CFTypeRef>) = pairs
.iter()
.map(|&(ref key, ref value)| (key.as_CFTypeRef(), value.as_CFTypeRef()))
.map(|(key, value)| (key.as_CFTypeRef(), value.as_CFTypeRef()))
.unzip();
unsafe {
@@ -103,7 +103,7 @@ impl<K, V> CFDictionary<K, V> {
}
#[inline]
pub fn find<'a, T: ToVoid<K>>(&'a self, key: T) -> Option<ItemRef<'a, V>>
pub fn find<T: ToVoid<K>>(&self, key: T) -> Option<ItemRef<'_, V>>
where
V: FromVoid,
K: ToVoid<K>,
@@ -123,7 +123,7 @@ impl<K, V> CFDictionary<K, V> {
/// Panics if the key is not present in the dictionary. Use `find` to get an `Option` instead
/// of panicking.
#[inline]
pub fn get<'a, T: ToVoid<K>>(&'a self, key: T) -> ItemRef<'a, V>
pub fn get<T: ToVoid<K>>(&self, key: T) -> ItemRef<'_, V>
where
V: FromVoid,
K: ToVoid<K>,
@@ -195,7 +195,7 @@ impl<K, V> CFMutableDictionary<K, V> {
V: ToVoid<V>,
{
let mut result = Self::with_capacity(pairs.len() as _);
for &(ref key, ref value) in pairs {
for (key, value) in pairs {
result.add(key, value);
}
result
@@ -265,7 +265,7 @@ impl<K, V> CFMutableDictionary<K, V> {
K: ToVoid<K>,
{
let ptr = key.to_void();
self.find(&key)
self.find(key)
.unwrap_or_else(|| panic!("No entry found for key {:p}", ptr))
}
+6 -1
View File
@@ -49,8 +49,13 @@ impl CFSet {
}
impl<T> CFSet<T> {
/// Get the number of elements in the CFSet
/// Get the number of elements in the `CFSet`.
pub fn len(&self) -> usize {
unsafe { CFSetGetCount(self.0) as usize }
}
/// Returns `true` if the set contains no elements.
pub fn is_empty(&self) -> bool {
self.len() == 0
}
}
+1 -1
View File
@@ -34,7 +34,7 @@ impl fmt::Debug for CFURL {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
unsafe {
let string: CFString = TCFType::wrap_under_get_rule(CFURLGetString(self.0));
write!(f, "{}", string.to_string())
write!(f, "{}", string)
}
}
}
+3 -3
View File
@@ -44,9 +44,9 @@ impl Default for CFUUID {
}
#[cfg(feature = "with-uuid")]
impl Into<Uuid> for CFUUID {
fn into(self) -> Uuid {
let b = unsafe { CFUUIDGetUUIDBytes(self.0) };
impl From<CFUUID> for Uuid {
fn from(val: CFUUID) -> Self {
let b = unsafe { CFUUIDGetUUIDBytes(val.0) };
let bytes = [
b.byte0, b.byte1, b.byte2, b.byte3, b.byte4, b.byte5, b.byte6, b.byte7, b.byte8,
b.byte9, b.byte10, b.byte11, b.byte12, b.byte13, b.byte14, b.byte15,
+2 -5
View File
@@ -42,10 +42,7 @@ pub struct CGSize {
impl CGSize {
#[inline]
pub fn new(width: CGFloat, height: CGFloat) -> CGSize {
CGSize {
width: width,
height: height,
}
CGSize { width, height }
}
#[inline]
@@ -64,7 +61,7 @@ pub struct CGPoint {
impl CGPoint {
#[inline]
pub fn new(x: CGFloat, y: CGFloat) -> CGPoint {
CGPoint { x: x, y: y }
CGPoint { x, y }
}
#[inline]
+1 -1
View File
@@ -165,7 +165,7 @@ impl CGContext {
unsafe {
slice::from_raw_parts_mut(
CGBitmapContextGetData(self.as_ptr()) as *mut u8,
(self.height() * self.bytes_per_row()) as usize,
self.height() * self.bytes_per_row(),
)
}
}
+4 -5
View File
@@ -127,7 +127,7 @@ foreign_type! {
impl CGDisplay {
#[inline]
pub fn new(id: CGDirectDisplayID) -> CGDisplay {
CGDisplay { id: id }
CGDisplay { id }
}
/// Returns the the main display.
@@ -462,8 +462,7 @@ impl CGDisplay {
pub fn active_displays() -> Result<Vec<CGDirectDisplayID>, CGError> {
let count = CGDisplay::active_display_count()?;
let mut buf: Vec<CGDirectDisplayID> = vec![0; count as usize];
let result =
unsafe { CGGetActiveDisplayList(count as u32, buf.as_mut_ptr(), ptr::null_mut()) };
let result = unsafe { CGGetActiveDisplayList(count, buf.as_mut_ptr(), ptr::null_mut()) };
if result == 0 {
Ok(buf)
} else {
@@ -477,7 +476,7 @@ impl CGDisplay {
let mut count: u32 = 0;
let result = unsafe { CGGetActiveDisplayList(0, ptr::null_mut(), &mut count) };
if result == 0 {
Ok(count as u32)
Ok(count)
} else {
Err(result)
}
@@ -603,7 +602,7 @@ impl CGDisplayMode {
/// Returns the I/O Kit flags of the specified display mode.
#[inline]
pub fn io_flags(&self) -> u32 {
unsafe { CGDisplayModeGetIOFlags(self.as_ptr()) as u32 }
unsafe { CGDisplayModeGetIOFlags(self.as_ptr()) }
}
/// Returns the pixel encoding of the specified display mode.
+1 -1
View File
@@ -83,7 +83,7 @@ pub struct CGPathElementRef<'a> {
impl<'a> CGPathElementRef<'a> {
fn new<'b>(element: *const CGPathElement) -> CGPathElementRef<'b> {
CGPathElementRef {
element: element,
element,
phantom: PhantomData,
}
}
+5 -5
View File
@@ -31,7 +31,7 @@ impl CGSRegion {
unsafe {
let mut region = ptr::null_mut();
assert!(ffi::CGSNewRegionWithRect(rect, &mut region) == 0);
CGSRegion { region: region }
CGSRegion { region }
}
}
@@ -43,7 +43,7 @@ impl CGSRegion {
ffi::CGSNewRegionWithRectList(rects.as_ptr(), rects.len() as c_uint, &mut region)
== 0
);
CGSRegion { region: region }
CGSRegion { region }
}
}
}
@@ -59,9 +59,9 @@ impl CGSSurface {
#[inline]
pub fn from_ids(context_id: c_uint, window_number: c_int, surface_id: c_uint) -> CGSSurface {
CGSSurface {
context_id: context_id,
window_number: window_number,
surface_id: surface_id,
context_id,
window_number,
surface_id,
}
}
+16 -18
View File
@@ -99,10 +99,10 @@ pub enum CTFontNameSpecifier {
PostScriptCID,
}
impl Into<CFStringRef> for CTFontNameSpecifier {
fn into(self) -> CFStringRef {
impl From<CTFontNameSpecifier> for CFStringRef {
fn from(val: CTFontNameSpecifier) -> Self {
unsafe {
match self {
match val {
CTFontNameSpecifier::Copyright => kCTFontCopyrightNameKey,
CTFontNameSpecifier::Family => kCTFontFamilyNameKey,
CTFontNameSpecifier::SubFamily => kCTFontSubFamilyNameKey,
@@ -803,7 +803,7 @@ fn macos_version() -> (i32, i32, i32) {
.to_string();
match version
.split(".")
.split('.')
.map(|x| x.parse().unwrap())
.collect::<Vec<_>>()[..]
{
@@ -1007,21 +1007,19 @@ fn equal_descriptor_different_font() {
from_font_desc.attributes().to_untyped(),
resized_font_desc.attributes().to_untyped()
);
} else if macos_version() >= (10, 13, 0) {
// this is unsurprising
assert_ne!(from_font_desc, resized_font_desc);
assert_ne!(
from_font_desc.attributes().to_untyped(),
resized_font_desc.attributes().to_untyped()
);
} else {
if macos_version() >= (10, 13, 0) {
// this is unsurprising
assert_ne!(from_font_desc, resized_font_desc);
assert_ne!(
from_font_desc.attributes().to_untyped(),
resized_font_desc.attributes().to_untyped()
);
} else {
assert_ne!(from_font_desc, resized_font_desc);
assert_eq!(
from_font_desc.attributes().to_untyped(),
resized_font_desc.attributes().to_untyped()
);
}
assert_ne!(from_font_desc, resized_font_desc);
assert_eq!(
from_font_desc.attributes().to_untyped(),
resized_font_desc.attributes().to_untyped()
);
}
}
+1 -1
View File
@@ -79,7 +79,7 @@ impl TCFType for IOSurface {
#[inline]
unsafe fn wrap_under_create_rule(obj: IOSurfaceRef) -> IOSurface {
assert!(!obj.is_null(), "Attempted to create a NULL object.");
IOSurface { obj: obj }
IOSurface { obj }
}
#[inline]