Skip to content

Commit

Permalink
ir: We can't guarantee the type to be in the item map while propagati…
Browse files Browse the repository at this point in the history
…ng 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 rust-lang#1127
  • Loading branch information
emilio committed Oct 31, 2017
1 parent 3d623d3 commit 8e4d0e2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ir/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 11 additions & 0 deletions tests/expectations/tests/issue-1127-not-yet-type.rs
Original file line number Diff line number Diff line change
@@ -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,
}
13 changes: 13 additions & 0 deletions tests/headers/issue-1127-not-yet-type.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// bindgen-flags: -- -std=c++11

template <typename> struct A;
template <typename, typename, bool> struct _Map_base;
template <typename _Pair, typename _Traits>
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 <typename _Pair, typename _Traits>
auto _Map_base<_Pair, _Traits, true>::at(const key_type &) -> mapped_type & {}

0 comments on commit 8e4d0e2

Please sign in to comment.