Skip to content

Commit

Permalink
Appease clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Nov 15, 2022
1 parent a35fb75 commit 6a810be
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 23 deletions.
5 changes: 2 additions & 3 deletions crates/objc2-encode/src/encoding_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,13 @@ impl EncodingBox {
///
/// [`from_str`][Self::from_str] is simpler, use that instead if you can.
pub fn from_start_of_str(s: &mut &str) -> Result<Self, ParseError> {
let mut parser = Parser::new(*s);
let mut parser = Parser::new(s);
parser.strip_leading_qualifiers();

match parser.parse_encoding() {
Err(err) => return Err(ParseError::new(parser, err)),
Err(err) => Err(ParseError::new(parser, err)),
Ok(encoding) => {
let remaining = parser.remaining();
drop(parser);
*s = remaining;

Ok(encoding)
Expand Down
5 changes: 1 addition & 4 deletions crates/objc2/src/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,10 +744,7 @@ mod tests {
fn test_in_all_classes() {
fn is_present(cls: *const Class) -> bool {
// Check whether the class is present in Class::classes()
Class::classes()
.into_iter()
.find(|&item| ptr::eq(cls, *item))
.is_some()
Class::classes().iter().any(|item| ptr::eq(cls, *item))
}

let superclass = test_utils::custom_class();
Expand Down
4 changes: 2 additions & 2 deletions crates/objc2/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ mod tests {
assert!(<u32>::ENCODING.equivalent_to_str(&method.return_type()));
assert!(Sel::ENCODING.equivalent_to_str(&method.argument_type(1).unwrap()));

assert!(cls.instance_methods().into_iter().any(|m| *m == method));
assert!(cls.instance_methods().iter().any(|m| *m == method));
}
}

Expand All @@ -1039,7 +1039,7 @@ mod tests {
assert!(cls
.metaclass()
.instance_methods()
.into_iter()
.iter()
.any(|m| *m == method));
}
}
Expand Down
11 changes: 3 additions & 8 deletions crates/objc2/src/runtime/method_encoding_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,20 @@ impl<'a> MethodEncodingIter<'a> {
&mut self,
) -> Result<(EncodingBox, Option<isize>), EncodingParseError> {
// TODO: Verify stack layout
self.next()
.ok_or_else(|| EncodingParseError::MissingReturn)?
self.next().ok_or(EncodingParseError::MissingReturn)?
}

pub(crate) fn verify_receiver(&mut self) -> Result<(), EncodingParseError> {
// TODO: Verify stack layout
let (enc, _stack_layout) = self
.next()
.ok_or_else(|| EncodingParseError::MissingReceiver)??;
let (enc, _stack_layout) = self.next().ok_or(EncodingParseError::MissingReceiver)??;
if !Encoding::Object.equivalent_to_box(&enc) {
return Err(EncodingParseError::InvalidReceiver(enc));
}
Ok(())
}

pub(crate) fn verify_sel(&mut self) -> Result<(), EncodingParseError> {
let (enc, _stack_layout) = self
.next()
.ok_or_else(|| EncodingParseError::MissingSel)??;
let (enc, _stack_layout) = self.next().ok_or(EncodingParseError::MissingSel)??;
if !Encoding::Sel.equivalent_to_box(&enc) {
return Err(EncodingParseError::InvalidSel(enc));
}
Expand Down
8 changes: 2 additions & 6 deletions crates/tests/src/exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,11 @@ fn throw_catch_raise_catch() {
assert_retain_count(&exc, 2);

// TODO: Investigate this!
let extra_retain = if cfg!(all(
let extra_retain = usize::from(cfg!(all(
feature = "apple",
target_os = "macos",
target_arch = "x86"
)) {
1
} else {
0
};
)));

let exc = autoreleasepool(|_| {
let exc = NSException::into_exception(exc);
Expand Down

0 comments on commit 6a810be

Please sign in to comment.