Skip to content

Commit

Permalink
use assert_eq|_ne instead of assert!
Browse files Browse the repository at this point in the history
  • Loading branch information
nyurik authored and emilio committed Jan 9, 2025
1 parent 59a43e1 commit ec4033f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion bindgen/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2703,7 +2703,7 @@ impl CodeGenerator for CompInfo {
let mut method_names = Default::default();
if ctx.options().codegen_config.methods() {
for method in self.methods() {
assert!(method.kind() != MethodKind::Constructor);
assert_ne!(method.kind(), MethodKind::Constructor);
method.codegen_method(
ctx,
&mut methods,
Expand Down
16 changes: 8 additions & 8 deletions bindgen/ir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
/// codegen'd, even if its parent is not allowlisted. See issue #769 for
/// details.
fn add_item_to_module(&mut self, item: &Item) {
assert!(item.id() != self.root_module);
assert_ne!(item.id(), self.root_module);
assert!(self.resolve_item_fallible(item.id()).is_none());

if let Some(ref mut parent) = self.items[item.parent_id().0] {
Expand All @@ -804,7 +804,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
self.current_module
);

self.items[(self.current_module.0).0]
self.items[self.current_module.0 .0]
.as_mut()
.expect("Should always have an item for self.current_module")
.as_module_mut()
Expand Down Expand Up @@ -1232,7 +1232,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
&self,
) -> traversal::AssertNoDanglingItemsTraversal {
assert!(self.in_codegen_phase());
assert!(self.current_module == self.root_module);
assert_eq!(self.current_module, self.root_module);

let roots = self.items().map(|(id, _)| id);
traversal::AssertNoDanglingItemsTraversal::new(
Expand All @@ -1248,7 +1248,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
fn assert_every_item_in_a_module(&self) {
if cfg!(feature = "__testing_only_extra_assertions") {
assert!(self.in_codegen_phase());
assert!(self.current_module == self.root_module);
assert_eq!(self.current_module, self.root_module);

for (id, _item) in self.items() {
if id == self.root_module {
Expand Down Expand Up @@ -2346,7 +2346,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
/// allowlisted.
pub(crate) fn allowlisted_items(&self) -> &ItemSet {
assert!(self.in_codegen_phase());
assert!(self.current_module == self.root_module);
assert_eq!(self.current_module, self.root_module);

self.allowlisted.as_ref().unwrap()
}
Expand All @@ -2359,7 +2359,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
derive_trait: DeriveTrait,
) -> CanDerive {
assert!(self.in_codegen_phase());
assert!(self.current_module == self.root_module);
assert_eq!(self.current_module, self.root_module);

*self
.blocklisted_types_implement_traits
Expand Down Expand Up @@ -2407,14 +2407,14 @@ If you encounter an error missing from this list, please file an issue or a PR!"
/// Get a reference to the set of items we should generate.
pub(crate) fn codegen_items(&self) -> &ItemSet {
assert!(self.in_codegen_phase());
assert!(self.current_module == self.root_module);
assert_eq!(self.current_module, self.root_module);
self.codegen_items.as_ref().unwrap()
}

/// Compute the allowlisted items set and populate `self.allowlisted`.
fn compute_allowlisted_and_codegen_items(&mut self) {
assert!(self.in_codegen_phase());
assert!(self.current_module == self.root_module);
assert_eq!(self.current_module, self.root_module);
assert!(self.allowlisted.is_none());
let _t = self.timer("compute_allowlisted_and_codegen_items");

Expand Down
5 changes: 1 addition & 4 deletions bindgen/ir/objc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,7 @@ impl ObjCMethod {
}

// Check right amount of arguments
assert!(
args.len() == split_name.len() - 1,
"Incorrect method name or arguments for objc method, {args:?} vs {split_name:?}"
);
assert_eq!(args.len(), split_name.len() - 1, "Incorrect method name or arguments for objc method, {args:?} vs {split_name:?}");

// Get arguments without type signatures to pass to `msg_send!`
let mut args_without_types = vec![];
Expand Down
5 changes: 3 additions & 2 deletions bindgen/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1146,8 +1146,9 @@ fn parse(context: &mut BindgenContext) -> Result<(), BindgenError> {
cursor.visit_sorted(ctx, |ctx, child| parse_one(ctx, child, None));
});

assert!(
context.current_module() == context.root_module(),
assert_eq!(
context.current_module(),
context.root_module(),
"How did this happen?"
);
Ok(())
Expand Down

0 comments on commit ec4033f

Please sign in to comment.