Skip to content

Commit

Permalink
Auto merge of #210 - fitzgen:dangling-item-id-in-partial-specializati…
Browse files Browse the repository at this point in the history
…ons, r=emilio

Dangling item id in partial specializations

See individual commit messages for details.

r? @emilio
  • Loading branch information
bors-servo authored Nov 4, 2016
2 parents 7f88e8e + d14b602 commit f498903
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/ir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,15 @@ impl<'ctx> BindgenContext<'ctx> {
found_invalid_template_ref = true;
}
if c.kind() == CXCursor_TypeRef {
// The `with_id` id will potentially end up unused if we give up
// on this type (for example, its a tricky partial template
// specialization), so if we pass `with_id` as the parent, it is
// potentially a dangling reference. Instead, use the canonical
// template declaration as the parent. It is already parsed and
// has a known-resolvable `ItemId`.
let new_ty = Item::from_ty_or_ref(c.cur_type(),
Some(c),
Some(with_id),
Some(wrapping),
self);
args.push(new_ty);
}
Expand Down
3 changes: 2 additions & 1 deletion src/ir/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ impl ItemId {
/// Allocate the next `ItemId`.
pub fn next() -> Self {
static NEXT_ITEM_ID: AtomicUsize = ATOMIC_USIZE_INIT;
ItemId(NEXT_ITEM_ID.fetch_add(1, Ordering::Relaxed))
let next_id = NEXT_ITEM_ID.fetch_add(1, Ordering::Relaxed);
ItemId(next_id)
}
}

Expand Down

0 comments on commit f498903

Please sign in to comment.