Skip to content

Commit f498903

Browse files
author
bors-servo
authored
Auto merge of #210 - fitzgen:dangling-item-id-in-partial-specializations, r=emilio
Dangling item id in partial specializations See individual commit messages for details. r? @emilio
2 parents 7f88e8e + d14b602 commit f498903

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/ir/context.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -505,9 +505,15 @@ impl<'ctx> BindgenContext<'ctx> {
505505
found_invalid_template_ref = true;
506506
}
507507
if c.kind() == CXCursor_TypeRef {
508+
// The `with_id` id will potentially end up unused if we give up
509+
// on this type (for example, its a tricky partial template
510+
// specialization), so if we pass `with_id` as the parent, it is
511+
// potentially a dangling reference. Instead, use the canonical
512+
// template declaration as the parent. It is already parsed and
513+
// has a known-resolvable `ItemId`.
508514
let new_ty = Item::from_ty_or_ref(c.cur_type(),
509515
Some(c),
510-
Some(with_id),
516+
Some(wrapping),
511517
self);
512518
args.push(new_ty);
513519
}

src/ir/item.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ impl ItemId {
8888
/// Allocate the next `ItemId`.
8989
pub fn next() -> Self {
9090
static NEXT_ITEM_ID: AtomicUsize = ATOMIC_USIZE_INIT;
91-
ItemId(NEXT_ITEM_ID.fetch_add(1, Ordering::Relaxed))
91+
let next_id = NEXT_ITEM_ID.fetch_add(1, Ordering::Relaxed);
92+
ItemId(next_id)
9293
}
9394
}
9495

0 commit comments

Comments
 (0)