summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Fitzgerald <fitzgen@gmail.com>2017-06-20 14:45:52 -0700
committerNick Fitzgerald <fitzgen@gmail.com>2017-06-20 15:35:27 -0700
commitc736faaa3728d6e7475f85cbf0fe1d3ff05586a1 (patch)
tree91d498f10a29099799a8e077cc37870e69eb6aa1 /src
parent33272cdc36063746645c557c5b43aeefd943e360 (diff)
Assert that every item is a child of an ancestor module
This commit adds assertions that run when the "testing_only_extra_assertions" feature is enabled, which make sure that every single item we parse is a child of some ancestor module.
Diffstat (limited to 'src')
-rw-r--r--src/ir/context.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/ir/context.rs b/src/ir/context.rs
index f61f92e2..a53eba14 100644
--- a/src/ir/context.rs
+++ b/src/ir/context.rs
@@ -749,6 +749,11 @@ impl<'ctx> BindgenContext<'ctx> {
self.process_replacements();
}
+ // Make sure to do this after processing replacements, since that messes
+ // with the parentage and module children, and we want to assert that it
+ // messes with them correctly.
+ self.assert_every_item_in_a_module();
+
self.find_used_template_parameters();
let ret = cb(self);
@@ -779,6 +784,42 @@ impl<'ctx> BindgenContext<'ctx> {
traversal::all_edges)
}
+ /// When the `testing_only_extra_assertions` feature is enabled, walk over
+ /// every item and ensure that it is in the children set of one of its
+ /// module ancestors.
+ 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);
+
+ for (&id, _item) in self.items() {
+ if id == self.root_module {
+ continue;
+ }
+
+ assert!(
+ {
+ let id = id.into_resolver()
+ .through_type_refs()
+ .through_type_aliases()
+ .resolve(self)
+ .id();
+ id.ancestors(self)
+ .chain(Some(self.root_module))
+ .any(|ancestor| {
+ debug!("Checking if {:?} is a child of {:?}", id, ancestor);
+ self.resolve_item(ancestor)
+ .as_module()
+ .map_or(false, |m| m.children().contains(&id))
+ })
+ },
+ "{:?} should be in some ancestor module's children set",
+ id
+ );
+ }
+ }
+ }
+
fn find_used_template_parameters(&mut self) {
if self.options.whitelist_recursively {
let used_params = analyze::<UsedTemplateParameters>(self);