Skip to content

Commit 4eb99c7

Browse files
nyurikpvdrz
authored andcommitted
Fix if_not_else lint
Using negations in the `if` makes them a bit harder to read... and there is a lint for that :) ``` cargo clippy --workspace --exclude bindgen-integration --exclude tests_expectations -- -W clippy::if_not_else ```
1 parent 09f32b3 commit 4eb99c7

File tree

7 files changed

+25
-25
lines changed

7 files changed

+25
-25
lines changed

bindgen/clang.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,10 @@ impl Cursor {
216216
})
217217
.or_else(|| {
218218
let canonical = self.canonical();
219-
if canonical != *self {
220-
canonical.num_template_args()
221-
} else {
219+
if canonical == *self {
222220
None
221+
} else {
222+
canonical.num_template_args()
223223
}
224224
})
225225
}
@@ -1443,10 +1443,10 @@ impl Type {
14431443
/// elements.
14441444
pub(crate) fn num_elements(&self) -> Option<usize> {
14451445
let num_elements_returned = unsafe { clang_getNumElements(self.x) };
1446-
if num_elements_returned != -1 {
1447-
Some(num_elements_returned as usize)
1448-
} else {
1446+
if num_elements_returned == -1 {
14491447
None
1448+
} else {
1449+
Some(num_elements_returned as usize)
14501450
}
14511451
}
14521452

bindgen/codegen/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2777,13 +2777,13 @@ impl CodeGenerator for CompInfo {
27772777
item,
27782778
&ty_for_impl,
27792779
) {
2780-
let partialeq_bounds = if !generic_param_names.is_empty() {
2780+
let partialeq_bounds = if generic_param_names.is_empty() {
2781+
quote! {}
2782+
} else {
27812783
let bounds = generic_param_names.iter().map(|t| {
27822784
quote! { #t: PartialEq }
27832785
});
27842786
quote! { where #( #bounds ),* }
2785-
} else {
2786-
quote! {}
27872787
};
27882788

27892789
let prefix = ctx.trait_prefix();
@@ -3444,10 +3444,10 @@ impl<'a> EnumBuilder<'a> {
34443444
emitted_any_variants,
34453445
..
34463446
} => {
3447-
let variants = if !emitted_any_variants {
3448-
quote!(__bindgen_cannot_repr_c_on_empty_enum = 0)
3449-
} else {
3447+
let variants = if emitted_any_variants {
34503448
tokens
3449+
} else {
3450+
quote!(__bindgen_cannot_repr_c_on_empty_enum = 0)
34513451
};
34523452

34533453
quote! {

bindgen/ir/analysis/derive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,6 @@ pub(crate) fn as_cannot_derive_set(
722722
) -> HashSet<ItemId> {
723723
can_derive
724724
.into_iter()
725-
.filter_map(|(k, v)| if v != CanDerive::Yes { Some(k) } else { None })
725+
.filter_map(|(k, v)| if v == CanDerive::Yes { None } else { Some(k) })
726726
.collect()
727727
}

bindgen/ir/analysis/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,10 @@ mod tests {
343343
}
344344

345345
let new_size = self.reachable[&node].len();
346-
if original_size != new_size {
347-
ConstrainResult::Changed
348-
} else {
346+
if original_size == new_size {
349347
ConstrainResult::Same
348+
} else {
349+
ConstrainResult::Changed
350350
}
351351
}
352352

bindgen/ir/analysis/template_params.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -570,10 +570,10 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> {
570570
self.used.insert(id, Some(used_by_this_id));
571571
extra_assert!(self.used.values().all(|v| v.is_some()));
572572

573-
if new_len != original_len {
574-
ConstrainResult::Changed
575-
} else {
573+
if new_len == original_len {
576574
ConstrainResult::Same
575+
} else {
576+
ConstrainResult::Changed
577577
}
578578
}
579579

bindgen/ir/annotations.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,10 @@ impl Annotations {
232232
"derive" => self.derives.push(attr.value),
233233
"attribute" => self.attributes.push(attr.value),
234234
"private" => {
235-
self.visibility_kind = if attr.value != "false" {
236-
Some(FieldVisibilityKind::Private)
237-
} else {
235+
self.visibility_kind = if attr.value == "false" {
238236
Some(FieldVisibilityKind::Public)
237+
} else {
238+
Some(FieldVisibilityKind::Private)
239239
};
240240
}
241241
"accessor" => {

bindgen/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,10 +1124,10 @@ fn parse(context: &mut BindgenContext) -> Result<(), BindgenError> {
11241124

11251125
if context.options().emit_ast {
11261126
fn dump_if_not_builtin(cur: &clang::Cursor) -> CXChildVisitResult {
1127-
if !cur.is_builtin() {
1128-
clang::ast_dump(cur, 0)
1129-
} else {
1127+
if cur.is_builtin() {
11301128
CXChildVisit_Continue
1129+
} else {
1130+
clang::ast_dump(cur, 0)
11311131
}
11321132
}
11331133
cursor.visit(|cur| dump_if_not_builtin(&cur));

0 commit comments

Comments
 (0)