summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ir/context.rs19
-rw-r--r--src/ir/function.rs6
-rw-r--r--src/ir/item.rs5
-rw-r--r--src/ir/ty.rs2
4 files changed, 20 insertions, 12 deletions
diff --git a/src/ir/context.rs b/src/ir/context.rs
index aa268926..cdc1dceb 100644
--- a/src/ir/context.rs
+++ b/src/ir/context.rs
@@ -67,7 +67,7 @@ impl ItemId {
/// otherwise return `None`.
pub fn as_type_id(&self, ctx: &BindgenContext) -> Option<TypeId> {
if ctx.resolve_item(*self).kind().is_type() {
- Some(self.as_type_id_unchecked())
+ Some(TypeId(*self))
} else {
None
}
@@ -1348,7 +1348,7 @@ impl BindgenContext {
fn get_declaration_info_for_template_instantiation(
&self,
instantiation: &Cursor,
- ) -> Option<(Cursor, TypeId, usize)> {
+ ) -> Option<(Cursor, ItemId, usize)> {
instantiation
.cur_type()
.canonical_declaration(Some(instantiation))
@@ -1359,7 +1359,7 @@ impl BindgenContext {
|num_params| {
(
*canon_decl.cursor(),
- template_decl_id,
+ template_decl_id.into(),
num_params,
)
},
@@ -1540,7 +1540,9 @@ impl BindgenContext {
let sub_name = Some(template_decl_cursor.spelling());
let sub_inst = TemplateInstantiation::new(
- template_decl_id,
+ // This isn't guaranteed to be a type that we've
+ // already finished parsing yet.
+ template_decl_id.as_type_id_unchecked(),
sub_args,
);
let sub_kind =
@@ -2398,13 +2400,14 @@ impl ItemResolver {
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct PartialType {
decl: Cursor,
- id: TypeId,
+ // Just an ItemId, and not a TypeId, because we haven't finished this type
+ // yet, so there's still time for things to go wrong.
+ id: ItemId,
}
impl PartialType {
/// Construct a new `PartialType`.
- pub fn new<Id: Into<ItemId>>(decl: Cursor, id: Id) -> PartialType {
- let id = id.into().as_type_id_unchecked();
+ pub fn new(decl: Cursor, id: ItemId) -> PartialType {
// assert!(decl == decl.canonical());
PartialType {
decl: decl,
@@ -2419,7 +2422,7 @@ impl PartialType {
/// The item ID allocated for this type. This is *NOT* a key for an entry in
/// the context's item set yet!
- pub fn id(&self) -> TypeId {
+ pub fn id(&self) -> ItemId {
self.id
}
}
diff --git a/src/ir/function.rs b/src/ir/function.rs
index 990fbaff..ccdfc4f3 100644
--- a/src/ir/function.rs
+++ b/src/ir/function.rs
@@ -384,8 +384,12 @@ impl FunctionSig {
if !is_static && !is_virtual {
let class = Item::parse(cursor.semantic_parent(), None, ctx)
.expect("Expected to parse the class");
+ // The `class` most likely is not finished parsing yet, so use
+ // the unchecked variant.
+ let class = class.as_type_id_unchecked();
+
let ptr =
- Item::builtin_type(TypeKind::Pointer(class.as_type_id_unchecked()), is_const, ctx);
+ Item::builtin_type(TypeKind::Pointer(class), is_const, ctx);
args.insert(0, (Some("this".into()), ptr));
} else if is_virtual {
let void = Item::builtin_type(TypeKind::Void, false, ctx);
diff --git a/src/ir/item.rs b/src/ir/item.rs
index 825b9bc4..1e18cb73 100644
--- a/src/ir/item.rs
+++ b/src/ir/item.rs
@@ -1472,7 +1472,8 @@ impl ClangItemParser for Item {
)
{
debug!("Avoiding recursion parsing type: {:?}", ty);
- return Ok(partial.id());
+ // Unchecked because we haven't finished this type yet.
+ return Ok(partial.id().as_type_id_unchecked());
}
}
@@ -1485,7 +1486,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.as_type_id_unchecked()),
+ Ok(ParseResult::AlreadyResolved(ty)) => Ok(ty.expect_type_id(ctx)),
Ok(ParseResult::New(item, declaration)) => {
ctx.add_item(
Item::new(
diff --git a/src/ir/ty.rs b/src/ir/ty.rs
index a5f3a694..601dce6c 100644
--- a/src/ir/ty.rs
+++ b/src/ir/ty.rs
@@ -397,7 +397,7 @@ impl AsTemplateParam for TypeKind {
item: &Item,
) -> Option<TypeId> {
match *self {
- TypeKind::TypeParam => Some(item.id().as_type_id_unchecked()),
+ TypeKind::TypeParam => Some(item.id().expect_type_id(ctx)),
TypeKind::ResolvedTypeRef(id) => id.as_template_param(ctx, &()),
_ => None,
}