Skip to content

Commit 18df9aa

Browse files
Some clippy fixes. (#624)
1 parent 062041a commit 18df9aa

File tree

20 files changed

+83
-84
lines changed

20 files changed

+83
-84
lines changed

cocoa-foundation/src/foundation.rs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ mod macos {
4848
impl NSPoint {
4949
#[inline]
5050
pub fn new(x: CGFloat, y: CGFloat) -> NSPoint {
51-
NSPoint { x: x, y: y }
51+
NSPoint { x, y }
5252
}
5353
}
5454

@@ -73,10 +73,7 @@ mod macos {
7373
impl NSSize {
7474
#[inline]
7575
pub fn new(width: CGFloat, height: CGFloat) -> NSSize {
76-
NSSize {
77-
width: width,
78-
height: height,
79-
}
76+
NSSize { width, height }
8077
}
8178
}
8279

@@ -101,10 +98,7 @@ mod macos {
10198
impl NSRect {
10299
#[inline]
103100
pub fn new(origin: NSPoint, size: NSSize) -> NSRect {
104-
NSRect {
105-
origin: origin,
106-
size: size,
107-
}
101+
NSRect { origin, size }
108102
}
109103

110104
#[inline]
@@ -169,10 +163,7 @@ pub struct NSRange {
169163
impl NSRange {
170164
#[inline]
171165
pub fn new(location: NSUInteger, length: NSUInteger) -> NSRange {
172-
NSRange {
173-
location: location,
174-
length: length,
175-
}
166+
NSRange { location, length }
176167
}
177168
}
178169

@@ -216,9 +207,9 @@ impl NSOperatingSystemVersion {
216207
patchVersion: NSUInteger,
217208
) -> NSOperatingSystemVersion {
218209
NSOperatingSystemVersion {
219-
majorVersion: majorVersion,
220-
minorVersion: minorVersion,
221-
patchVersion: patchVersion,
210+
majorVersion,
211+
minorVersion,
212+
patchVersion,
222213
}
223214
}
224215
}
@@ -663,10 +654,10 @@ impl NSString for id {
663654
}
664655

665656
unsafe fn init_str(self, string: &str) -> id {
666-
return msg_send![self,
667-
initWithBytes:string.as_ptr()
668-
length:string.len()
669-
encoding:UTF8_ENCODING as id];
657+
msg_send![self,
658+
initWithBytes:string.as_ptr()
659+
length:string.len()
660+
encoding:UTF8_ENCODING as id]
670661
}
671662

672663
unsafe fn len(self) -> usize {
@@ -734,7 +725,7 @@ impl Iterator for NSFastIterator {
734725
}
735726

736727
if self.idx < self.len {
737-
let object = unsafe { *self.state.items_ptr.offset(self.idx as isize) };
728+
let object = unsafe { *self.state.items_ptr.add(self.idx) };
738729
self.mut_val = Some(new_mut);
739730
self.idx += 1;
740731
Some(object)

cocoa-foundation/tests/foundation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ mod foundation {
116116

117117
#[test]
118118
fn test_get() {
119-
const KEY: &'static str = "The key";
120-
const VALUE: &'static str = "Some value";
119+
const KEY: &str = "The key";
120+
const VALUE: &str = "Some value";
121121
unsafe {
122122
let key = NSString::alloc(nil).init_str(KEY);
123123
let value = NSString::alloc(nil).init_str(VALUE);

cocoa/examples/color.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,5 @@ unsafe fn create_app() -> id {
133133
let current_app = NSRunningApplication::currentApplication(nil);
134134
current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps);
135135

136-
return app;
136+
app
137137
}

cocoa/examples/tab_view.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,5 @@ unsafe fn create_app(title: id, content: id) -> id {
8383
let current_app = NSRunningApplication::currentApplication(nil);
8484
current_app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps);
8585

86-
return app;
86+
app
8787
}

cocoa/src/appkit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ impl NSApplication for id {
583583

584584
unsafe fn presentationOptions_(self) -> NSApplicationPresentationOptions {
585585
let options = msg_send![self, presentationOptions];
586-
return NSApplicationPresentationOptions::from_bits(options).unwrap();
586+
NSApplicationPresentationOptions::from_bits(options).unwrap()
587587
}
588588

589589
unsafe fn setMainMenu_(self, menu: id) {

core-foundation-sys/src/base.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ pub type CFComparatorFunction = extern "C" fn(
4949
context: *mut c_void,
5050
) -> CFComparisonResult;
5151

52-
impl Into<Ordering> for CFComparisonResult {
53-
fn into(self) -> Ordering {
54-
match self {
52+
impl From<CFComparisonResult> for Ordering {
53+
fn from(val: CFComparisonResult) -> Self {
54+
match val {
5555
CFComparisonResult::LessThan => Ordering::Less,
5656
CFComparisonResult::EqualTo => Ordering::Equal,
5757
CFComparisonResult::GreaterThan => Ordering::Greater,
@@ -69,10 +69,7 @@ pub struct CFRange {
6969
// for back-compat
7070
impl CFRange {
7171
pub fn init(location: CFIndex, length: CFIndex) -> CFRange {
72-
CFRange {
73-
location: location,
74-
length: length,
75-
}
72+
CFRange { location, length }
7673
}
7774
}
7875

core-foundation/src/array.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl<T> CFArray<T> {
115115
/// Core Foundation objects (not always true), they need to be wrapped with
116116
/// `TCFType::wrap_under_get_rule()`.
117117
#[inline]
118-
pub fn iter<'a>(&'a self) -> CFArrayIterator<'a, T> {
118+
pub fn iter(&self) -> CFArrayIterator<'_, T> {
119119
CFArrayIterator {
120120
array: self,
121121
index: 0,
@@ -128,16 +128,22 @@ impl<T> CFArray<T> {
128128
unsafe { CFArrayGetCount(self.0) }
129129
}
130130

131+
/// Returns `true` if the array contains no elements.
131132
#[inline]
132-
pub unsafe fn get_unchecked<'a>(&'a self, index: CFIndex) -> ItemRef<'a, T>
133+
pub fn is_empty(&self) -> bool {
134+
self.len() == 0
135+
}
136+
137+
#[inline]
138+
pub unsafe fn get_unchecked(&self, index: CFIndex) -> ItemRef<'_, T>
133139
where
134140
T: FromVoid,
135141
{
136142
T::from_void(CFArrayGetValueAtIndex(self.0, index))
137143
}
138144

139145
#[inline]
140-
pub fn get<'a>(&'a self, index: CFIndex) -> Option<ItemRef<'a, T>>
146+
pub fn get(&self, index: CFIndex) -> Option<ItemRef<'_, T>>
141147
where
142148
T: FromVoid,
143149
{

core-foundation/src/data.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl CFData {
8080
/// Returns a pointer to the underlying bytes in this data. Note that this byte buffer is
8181
/// read-only.
8282
#[inline]
83-
pub fn bytes<'a>(&'a self) -> &'a [u8] {
83+
pub fn bytes(&self) -> &[u8] {
8484
unsafe { slice::from_raw_parts(CFDataGetBytePtr(self.0), self.len() as usize) }
8585
}
8686

@@ -89,6 +89,12 @@ impl CFData {
8989
pub fn len(&self) -> CFIndex {
9090
unsafe { CFDataGetLength(self.0) }
9191
}
92+
93+
/// Returns `true` if this byte buffer is empty.
94+
#[inline]
95+
pub fn is_empty(&self) -> bool {
96+
self.len() == 0
97+
}
9298
}
9399

94100
impl Deref for CFData {

core-foundation/src/date.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ mod test {
7979

8080
let same_sign = a.is_sign_positive() == b.is_sign_positive();
8181
let equal = ((a - b).abs() / f64::min(a.abs() + b.abs(), f64::MAX)) < f64::EPSILON;
82-
(same_sign && equal)
82+
same_sign && equal
8383
}
8484

8585
#[test]

core-foundation/src/dictionary.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<K, V> CFDictionary<K, V> {
4747
{
4848
let (keys, values): (Vec<CFTypeRef>, Vec<CFTypeRef>) = pairs
4949
.iter()
50-
.map(|&(ref key, ref value)| (key.as_CFTypeRef(), value.as_CFTypeRef()))
50+
.map(|(key, value)| (key.as_CFTypeRef(), value.as_CFTypeRef()))
5151
.unzip();
5252

5353
unsafe {
@@ -103,7 +103,7 @@ impl<K, V> CFDictionary<K, V> {
103103
}
104104

105105
#[inline]
106-
pub fn find<'a, T: ToVoid<K>>(&'a self, key: T) -> Option<ItemRef<'a, V>>
106+
pub fn find<T: ToVoid<K>>(&self, key: T) -> Option<ItemRef<'_, V>>
107107
where
108108
V: FromVoid,
109109
K: ToVoid<K>,
@@ -123,7 +123,7 @@ impl<K, V> CFDictionary<K, V> {
123123
/// Panics if the key is not present in the dictionary. Use `find` to get an `Option` instead
124124
/// of panicking.
125125
#[inline]
126-
pub fn get<'a, T: ToVoid<K>>(&'a self, key: T) -> ItemRef<'a, V>
126+
pub fn get<T: ToVoid<K>>(&self, key: T) -> ItemRef<'_, V>
127127
where
128128
V: FromVoid,
129129
K: ToVoid<K>,
@@ -195,7 +195,7 @@ impl<K, V> CFMutableDictionary<K, V> {
195195
V: ToVoid<V>,
196196
{
197197
let mut result = Self::with_capacity(pairs.len() as _);
198-
for &(ref key, ref value) in pairs {
198+
for (key, value) in pairs {
199199
result.add(key, value);
200200
}
201201
result
@@ -265,7 +265,7 @@ impl<K, V> CFMutableDictionary<K, V> {
265265
K: ToVoid<K>,
266266
{
267267
let ptr = key.to_void();
268-
self.find(&key)
268+
self.find(key)
269269
.unwrap_or_else(|| panic!("No entry found for key {:p}", ptr))
270270
}
271271

0 commit comments

Comments
 (0)