diff --git a/src/bindgen/ir/item.rs b/src/bindgen/ir/item.rs index 0dc447fd47da87eccca6c6d630e82b96d76f1d19..769970c7a6e24bfb63e4d70b7203ab9f372a08b5 100644 --- a/src/bindgen/ir/item.rs +++ b/src/bindgen/ir/item.rs @@ -22,7 +22,9 @@ pub trait Item { fn rename_for_config(&mut self, _config: &Config) { } fn add_dependencies(&self, _library: &Library, _out: &mut Dependencies) { } - fn instantiate_monomorph(&self, _generics: &Vec<Type>, _library: &Library, _out: &mut Monomorphs) { } + fn instantiate_monomorph(&self, _generics: &Vec<Type>, _library: &Library, _out: &mut Monomorphs) { + unreachable!("Cannot instantiate {} as a generic.", self.name()) + } } #[derive(Debug, Clone)] diff --git a/src/bindgen/ir/opaque.rs b/src/bindgen/ir/opaque.rs index 1bd75a58501cf40c2bdf4ecafe94131a41ce38eb..383403e88e2f2f6f7eb3ed045de59ea0fa451eaa 100644 --- a/src/bindgen/ir/opaque.rs +++ b/src/bindgen/ir/opaque.rs @@ -36,20 +36,6 @@ impl OpaqueItem { documentation: Documentation::load(attrs), } } - - pub fn instantiate_monomorph(&self, generic_values: &Vec<Type>, out: &mut Monomorphs) { - assert!(self.generic_params.len() > 0); - - let monomorph = OpaqueItem { - name: mangle::mangle_path(&self.name, generic_values), - generic_params: GenericParams::default(), - cfg: self.cfg.clone(), - annotations: self.annotations.clone(), - documentation: self.documentation.clone(), - }; - - out.insert_opaque(self, monomorph, generic_values.clone()); - } } impl Item for OpaqueItem { @@ -75,6 +61,21 @@ impl Item for OpaqueItem { fn add_dependencies(&self, _: &Library, _: &mut Dependencies) { } + + fn instantiate_monomorph(&self, generic_values: &Vec<Type>, _library: &Library, out: &mut Monomorphs) { + assert!(self.generic_params.len() > 0 && + self.generic_params.len() == generic_values.len()); + + let monomorph = OpaqueItem { + name: mangle::mangle_path(&self.name, generic_values), + generic_params: GenericParams::default(), + cfg: self.cfg.clone(), + annotations: self.annotations.clone(), + documentation: self.documentation.clone(), + }; + + out.insert_opaque(self, monomorph, generic_values.clone()); + } } impl Source for OpaqueItem { diff --git a/src/bindgen/ir/ty.rs b/src/bindgen/ir/ty.rs index c42b7f93f39f85c6d8b9706b28c9e5897704514f..963eaf465e05cd46e154ec083255a5b2663d2004 100644 --- a/src/bindgen/ir/ty.rs +++ b/src/bindgen/ir/ty.rs @@ -10,7 +10,7 @@ use syn; use bindgen::cdecl; use bindgen::config::Config; use bindgen::dependencies::Dependencies; -use bindgen::ir::{Documentation, GenericParams, GenericPath, ItemContainer, Item, Path}; +use bindgen::ir::{Documentation, GenericParams, GenericPath, Path}; use bindgen::library::Library; use bindgen::monomorph::Monomorphs; use bindgen::utilities::IterHelpers; @@ -419,29 +419,7 @@ impl Type { if let Some(items) = library.get_items(&path.name) { for item in items { - match item { - ItemContainer::Constant(..) => { - warn!("Cannot instantiate a generic constant.") - }, - ItemContainer::Static(..) => { - warn!("Cannot instantiate a generic static.") - }, - ItemContainer::OpaqueItem(ref x) => { - x.instantiate_monomorph(&path.generics, out); - }, - ItemContainer::Union(ref x) => { - x.instantiate_monomorph(&path.generics, library, out); - }, - ItemContainer::Struct(ref x) => { - x.instantiate_monomorph(&path.generics, library, out); - }, - ItemContainer::Enum(..) => { - warn!("Cannot instantiate a generic enum.") - }, - ItemContainer::Typedef(ref x) => { - x.instantiate_monomorph(&path.generics, library, out); - }, - } + item.deref().instantiate_monomorph(&path.generics, library, out); } } }