From 8e4d0e252627301f7afae87872ff316470ad0075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 31 Oct 2017 17:41:00 +0100 Subject: [PATCH 1/2] ir: We can't guarantee the type to be in the item map while propagating AlreadyResolved. The item may come from a recursive check down the stack, and as we say there: > Unchecked because we haven't finished this type yet. Fixes #1127 --- src/ir/item.rs | 2 +- tests/expectations/tests/issue-1127-not-yet-type.rs | 11 +++++++++++ tests/headers/issue-1127-not-yet-type.hpp | 13 +++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tests/expectations/tests/issue-1127-not-yet-type.rs create mode 100644 tests/headers/issue-1127-not-yet-type.hpp diff --git a/src/ir/item.rs b/src/ir/item.rs index d863d9077b..a92036398b 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -1512,7 +1512,7 @@ impl ClangItemParser for Item { let result = Type::from_clang_ty(id, ty, location, parent_id, ctx); let relevant_parent_id = parent_id.unwrap_or(current_module); let ret = match result { - Ok(ParseResult::AlreadyResolved(ty)) => Ok(ty.expect_type_id(ctx)), + Ok(ParseResult::AlreadyResolved(ty)) => Ok(ty.as_type_id_unchecked()), Ok(ParseResult::New(item, declaration)) => { ctx.add_item( Item::new( diff --git a/tests/expectations/tests/issue-1127-not-yet-type.rs b/tests/expectations/tests/issue-1127-not-yet-type.rs new file mode 100644 index 0000000000..755eef28b1 --- /dev/null +++ b/tests/expectations/tests/issue-1127-not-yet-type.rs @@ -0,0 +1,11 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] + + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct A { + pub _address: u8, +} diff --git a/tests/headers/issue-1127-not-yet-type.hpp b/tests/headers/issue-1127-not-yet-type.hpp new file mode 100644 index 0000000000..8202e75326 --- /dev/null +++ b/tests/headers/issue-1127-not-yet-type.hpp @@ -0,0 +1,13 @@ +// bindgen-flags: -- -std=c++11 + +template struct A; +template struct _Map_base; +template +struct _Map_base<_Pair, _Traits, true> { + using __hashtable_base = A<_Traits>; + using key_type = typename __hashtable_base::key_type; + using mapped_type = typename _Pair::type; + mapped_type &at(const key_type &); +}; +template +auto _Map_base<_Pair, _Traits, true>::at(const key_type &) -> mapped_type & {} From 9601c1beb400f5a5e5f332f0e6d9b5e882d34796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 31 Oct 2017 17:47:48 +0100 Subject: [PATCH 2/2] Bugfix version bump. --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e2e2284afa..81551c769d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,7 +23,7 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.31.2" +version = "0.31.3" dependencies = [ "cexpr 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index b6ed1b8a6b..eee82f0c02 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ name = "bindgen" readme = "README.md" repository = "https://github.com/rust-lang-nursery/rust-bindgen" documentation = "https://docs.rs/bindgen" -version = "0.31.2" +version = "0.31.3" build = "build.rs" include = [