Skip to content

Commit

Permalink
Fix if_not_else lint
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
nyurik authored and pvdrz committed Dec 1, 2024
1 parent 09f32b3 commit 4eb99c7
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
12 changes: 6 additions & 6 deletions bindgen/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ impl Cursor {
})
.or_else(|| {
let canonical = self.canonical();
if canonical != *self {
canonical.num_template_args()
} else {
if canonical == *self {
None
} else {
canonical.num_template_args()
}
})
}
Expand Down Expand Up @@ -1443,10 +1443,10 @@ impl Type {
/// elements.
pub(crate) fn num_elements(&self) -> Option<usize> {
let num_elements_returned = unsafe { clang_getNumElements(self.x) };
if num_elements_returned != -1 {
Some(num_elements_returned as usize)
} else {
if num_elements_returned == -1 {
None
} else {
Some(num_elements_returned as usize)
}
}

Expand Down
12 changes: 6 additions & 6 deletions bindgen/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2777,13 +2777,13 @@ impl CodeGenerator for CompInfo {
item,
&ty_for_impl,
) {
let partialeq_bounds = if !generic_param_names.is_empty() {
let partialeq_bounds = if generic_param_names.is_empty() {
quote! {}
} else {
let bounds = generic_param_names.iter().map(|t| {
quote! { #t: PartialEq }
});
quote! { where #( #bounds ),* }
} else {
quote! {}
};

let prefix = ctx.trait_prefix();
Expand Down Expand Up @@ -3444,10 +3444,10 @@ impl<'a> EnumBuilder<'a> {
emitted_any_variants,
..
} => {
let variants = if !emitted_any_variants {
quote!(__bindgen_cannot_repr_c_on_empty_enum = 0)
} else {
let variants = if emitted_any_variants {
tokens
} else {
quote!(__bindgen_cannot_repr_c_on_empty_enum = 0)
};

quote! {
Expand Down
2 changes: 1 addition & 1 deletion bindgen/ir/analysis/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,6 @@ pub(crate) fn as_cannot_derive_set(
) -> HashSet<ItemId> {
can_derive
.into_iter()
.filter_map(|(k, v)| if v != CanDerive::Yes { Some(k) } else { None })
.filter_map(|(k, v)| if v == CanDerive::Yes { None } else { Some(k) })
.collect()
}
6 changes: 3 additions & 3 deletions bindgen/ir/analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,10 @@ mod tests {
}

let new_size = self.reachable[&node].len();
if original_size != new_size {
ConstrainResult::Changed
} else {
if original_size == new_size {
ConstrainResult::Same
} else {
ConstrainResult::Changed
}
}

Expand Down
6 changes: 3 additions & 3 deletions bindgen/ir/analysis/template_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,10 @@ impl<'ctx> MonotoneFramework for UsedTemplateParameters<'ctx> {
self.used.insert(id, Some(used_by_this_id));
extra_assert!(self.used.values().all(|v| v.is_some()));

if new_len != original_len {
ConstrainResult::Changed
} else {
if new_len == original_len {
ConstrainResult::Same
} else {
ConstrainResult::Changed
}
}

Expand Down
6 changes: 3 additions & 3 deletions bindgen/ir/annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,10 @@ impl Annotations {
"derive" => self.derives.push(attr.value),
"attribute" => self.attributes.push(attr.value),
"private" => {
self.visibility_kind = if attr.value != "false" {
Some(FieldVisibilityKind::Private)
} else {
self.visibility_kind = if attr.value == "false" {
Some(FieldVisibilityKind::Public)
} else {
Some(FieldVisibilityKind::Private)
};
}
"accessor" => {
Expand Down
6 changes: 3 additions & 3 deletions bindgen/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1124,10 +1124,10 @@ fn parse(context: &mut BindgenContext) -> Result<(), BindgenError> {

if context.options().emit_ast {
fn dump_if_not_builtin(cur: &clang::Cursor) -> CXChildVisitResult {
if !cur.is_builtin() {
clang::ast_dump(cur, 0)
} else {
if cur.is_builtin() {
CXChildVisit_Continue
} else {
clang::ast_dump(cur, 0)
}
}
cursor.visit(|cur| dump_if_not_builtin(&cur));
Expand Down

0 comments on commit 4eb99c7

Please sign in to comment.