summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Fitzgerald <fitzgen@gmail.com>2017-04-17 14:40:29 -0700
committerNick Fitzgerald <fitzgen@gmail.com>2017-04-17 16:01:58 -0700
commitbce13307645172be62e8895e82d9362f0c4e4fd6 (patch)
tree62f3e936c9a14c7a90270a2a0cbd5b8a2b909241
parent790826272861bd3eca2d149ac7b2b95fcbec6e09 (diff)
Resolve through type refs and aliases when marking type params used
In stylo bindings generation, we were hitting bugs where the analysis saw a template type parameter behind a type ref to a type alias, and this was then used as an argument to a template instantiation. Because of the indirection, the analysis got confused and ignored the template argument because it was "not" a named template type, and therefore we didn't care about its usage. This commit makes sure that we keep resolving through type references and aliases to find the inner named template type parameter to add to the current item's usage set. Fixes #638.
-rw-r--r--src/ir/named.rs4
-rw-r--r--tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs23
-rw-r--r--tests/headers/issue-638-stylo-cannot-find-T-in-this-scope.hpp12
3 files changed, 39 insertions, 0 deletions
diff --git a/src/ir/named.rs b/src/ir/named.rs
index 39fa2201..17f46eca 100644
--- a/src/ir/named.rs
+++ b/src/ir/named.rs
@@ -481,6 +481,10 @@ impl<'ctx, 'gen> MonotoneFramework for UsedTemplateParameters<'ctx, 'gen> {
if used_by_def.contains(param) {
debug!(" param is used by template definition");
+ let arg = arg.into_resolver()
+ .through_type_refs()
+ .through_type_aliases()
+ .resolve(self.ctx);
if let Some(named) = arg.as_named(self.ctx, &()) {
debug!(" arg is a type parameter, marking used");
used_by_this_id.insert(named);
diff --git a/tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs b/tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs
new file mode 100644
index 00000000..4ff0b5bc
--- /dev/null
+++ b/tests/expectations/tests/issue-638-stylo-cannot-find-T-in-this-scope.rs
@@ -0,0 +1,23 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(non_snake_case)]
+
+
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct RefPtr<T> {
+ pub use_of_t: T,
+}
+impl <T> Default for RefPtr<T> {
+ fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+}
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct UsesRefPtrWithAliasedTypeParam<U> {
+ pub member: RefPtr<UsesRefPtrWithAliasedTypeParam_V<U>>,
+}
+pub type UsesRefPtrWithAliasedTypeParam_V<U> = U;
+impl <U> Default for UsesRefPtrWithAliasedTypeParam<U> {
+ fn default() -> Self { unsafe { ::std::mem::zeroed() } }
+}
diff --git a/tests/headers/issue-638-stylo-cannot-find-T-in-this-scope.hpp b/tests/headers/issue-638-stylo-cannot-find-T-in-this-scope.hpp
new file mode 100644
index 00000000..13b656e1
--- /dev/null
+++ b/tests/headers/issue-638-stylo-cannot-find-T-in-this-scope.hpp
@@ -0,0 +1,12 @@
+// bindgen-flags: -- -std=c++14
+
+template <class T>
+class RefPtr {
+ T use_of_t;
+};
+
+template <typename U>
+class UsesRefPtrWithAliasedTypeParam {
+ using V = U;
+ RefPtr<V> member;
+};