diff options
-rw-r--r-- | src/ir/named.rs | 9 | ||||
-rw-r--r-- | src/lib.rs | 38 | ||||
-rw-r--r-- | tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs | 16 | ||||
-rw-r--r-- | tests/headers/issue-645-cannot-find-type-T-in-this-scope.hpp | 9 | ||||
-rwxr-xr-x | tests/test-one.sh | 11 |
5 files changed, 59 insertions, 24 deletions
diff --git a/src/ir/named.rs b/src/ir/named.rs index 84a63379..55f804ec 100644 --- a/src/ir/named.rs +++ b/src/ir/named.rs @@ -322,7 +322,14 @@ impl<'ctx, 'gen> UsedTemplateParameters<'ctx, 'gen> { let args = instantiation.template_arguments() .iter() - .filter_map(|a| a.as_named(self.ctx, &())); + .filter_map(|a| { + a.into_resolver() + .through_type_refs() + .through_type_aliases() + .resolve(self.ctx) + .as_named(self.ctx, &()) + }); + used_by_this_id.extend(args); } @@ -3,7 +3,7 @@ //! Provide a C/C++ header file, receive Rust FFI code to call into C/C++ //! functions and use types defined in the header. //! -//! See the [Builder](./struct.Builder.html) struct for usage. +//! See the [`Builder`](./struct.Builder.html) struct for usage. #![deny(missing_docs)] #![deny(warnings)] @@ -175,7 +175,7 @@ pub fn builder() -> Builder { } impl Builder { - ///Generates the command line flags use for creating `builder` + /// Generates the command line flags use for creating `Builder`. pub fn command_line_flags(&self) -> Vec<String> { let mut output_vector: Vec<String> = Vec::new(); @@ -455,21 +455,21 @@ impl Builder { /// /// This can be used to get bindgen to generate _exactly_ the types you want /// in your bindings, and then import other types manually via other means - /// (like `raw_line`). + /// (like [`raw_line`](#method.raw_line)). pub fn whitelist_recursively(mut self, doit: bool) -> Self { self.options.whitelist_recursively = doit; self } - /// Generate '#[macro_use] extern crate objc;' instead of 'use objc;' + /// Generate `#[macro_use] extern crate objc;` instead of `use objc;` /// in the prologue of the files generated from objective-c files pub fn objc_extern_crate(mut self, doit: bool) -> Self { self.options.objc_extern_crate = doit; self } - /// Whether to use the clang-provided name mangling. This is true and - /// probably needed for C++ features. + /// Whether to use the clang-provided name mangling. This is true by default + /// and probably needed for C++ features. /// /// However, some old libclang versions seem to return incorrect results in /// some cases for non-mangled functions, see [1], so we allow disabling it. @@ -593,7 +593,7 @@ impl Builder { self } - /// Avoid converting floats to f32/f64 by default. + /// Avoid converting floats to `f32`/`f64` by default. pub fn no_convert_floats(mut self) -> Self { self.options.convert_floats = false; self @@ -635,20 +635,19 @@ impl Builder { self } - /// Disable auto-namespacing of names if namespaces are disabled. + /// Disable name auto-namespacing. /// - /// By default, if namespaces are disabled, bindgen tries to mangle the - /// names to from `foo::bar::Baz` to look like `foo_bar_Baz`, instead of - /// just `Baz`. + /// By default, bindgen mangles names like `foo::bar::Baz` to look like + /// `foo_bar_Baz` instead of just `Baz`. /// - /// This option disables that behavior. + /// This method disables that behavior. /// - /// Note that this intentionally doesn't change the names using for - /// whitelisting and blacklisting, that should still be mangled with the + /// Note that this intentionally does not change the names used for + /// whitelisting and blacklisting, which should still be mangled with the /// namespaces. /// - /// Note, also, that using this option may cause duplicated names to be - /// generated. + /// Note, also, that this option may cause bindgen to generate duplicate + /// names. pub fn disable_name_namespacing(mut self) -> Builder { self.options.disable_name_namespacing = true; self @@ -727,14 +726,15 @@ impl Builder { self } - /// Allows configuring types in different situations, see the `ParseCallbacks` - /// documentation. + /// Allows configuring types in different situations, see the + /// [`ParseCallbacks`](./callbacks/trait.ParseCallbacks.html) documentation. pub fn parse_callbacks(mut self, cb: Box<callbacks::ParseCallbacks>) -> Self { self.options.parse_callbacks = Some(cb); self } - /// Choose what to generate using a CodegenConfig. + /// Choose what to generate using a + /// [`CodegenConfig`](./struct.CodegenConfig.html). pub fn with_codegen_config(mut self, config: CodegenConfig) -> Self { self.options.codegen_config = config; self diff --git a/tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs b/tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs new file mode 100644 index 00000000..531bce67 --- /dev/null +++ b/tests/expectations/tests/issue-645-cannot-find-type-T-in-this-scope.rs @@ -0,0 +1,16 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + +#[derive(Clone, Copy, Debug)] pub struct RefPtr<T>(T); + +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct HasRefPtr<T> { + pub refptr_member: RefPtr<HasRefPtr_TypedefOfT<T>>, +} +pub type HasRefPtr_TypedefOfT<T> = T; +impl <T> Default for HasRefPtr<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} diff --git a/tests/headers/issue-645-cannot-find-type-T-in-this-scope.hpp b/tests/headers/issue-645-cannot-find-type-T-in-this-scope.hpp new file mode 100644 index 00000000..f817f34d --- /dev/null +++ b/tests/headers/issue-645-cannot-find-type-T-in-this-scope.hpp @@ -0,0 +1,9 @@ +// bindgen-flags: --blacklist-type RefPtr --raw-line "#[derive(Clone, Copy, Debug)] pub struct RefPtr<T>(T);" --whitelist-type "HasRefPtr" -- -std=c++14 + +template <class> class RefPtr {}; + +template <typename T> +class HasRefPtr { + typedef T TypedefOfT; + RefPtr<TypedefOfT> refptr_member; +}; diff --git a/tests/test-one.sh b/tests/test-one.sh index d1950eb9..c7f9b2ae 100755 --- a/tests/test-one.sh +++ b/tests/test-one.sh @@ -21,13 +21,16 @@ TEST=$(find ./tests/headers -type f -iname "*$1*" | head -n 1) BINDINGS=$(mktemp -t bindings_XXXXXX.rs) TEST_BINDINGS_BINARY=$(mktemp -t bindings.XXXXX) -./target/debug/bindgen \ - "$TEST" \ +FLAGS="$(grep "// bindgen-flags: " "$TEST")" +FLAGS="${FLAGS/\/\/ bindgen\-flags:/}" + +eval ./target/debug/bindgen \ + "\"$TEST\"" \ --emit-ir \ --emit-ir-graphviz ir.dot \ --emit-clang-ast \ - -o "$BINDINGS" \ - -- -std=c++14 + -o "\"$BINDINGS\"" \ + $FLAGS dot -Tpng ir.dot -o ir.png |