From 7774cb32263aafb36a226a502d7d7b2af431a84a Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Thu, 9 Jan 2025 00:27:41 -0500 Subject: [PATCH] use `assert_eq|_ne` instead of `assert!` --- bindgen/codegen/mod.rs | 2 +- bindgen/ir/context.rs | 16 ++++++++-------- bindgen/ir/objc.rs | 5 +---- bindgen/lib.rs | 5 +++-- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index cf819950db..7ba6a55a7d 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -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, diff --git a/bindgen/ir/context.rs b/bindgen/ir/context.rs index 098dd25e59..5781b51824 100644 --- a/bindgen/ir/context.rs +++ b/bindgen/ir/context.rs @@ -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] { @@ -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() @@ -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( @@ -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 { @@ -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() } @@ -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 @@ -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"); diff --git a/bindgen/ir/objc.rs b/bindgen/ir/objc.rs index d413d6bb95..6cdadb131d 100644 --- a/bindgen/ir/objc.rs +++ b/bindgen/ir/objc.rs @@ -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![]; diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 9e22e37ce6..813d76fc13 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -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(())