Skip to content

Commit cebb2d1

Browse files
committed
Introduce a resolve_fallible function.
Will be used in subsequent commits, to avoid trying to resolve items which we've loaned and therefore can't be resolved.
1 parent b04cde1 commit cebb2d1

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

src/ir/context.rs

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2692,27 +2692,40 @@ impl ItemResolver {
26922692

26932693
/// Finish configuring and perform the actual item resolution.
26942694
pub fn resolve(self, ctx: &BindgenContext) -> &Item {
2695+
match self.resolve_fallible(ctx) {
2696+
Some(item) => item,
2697+
None => panic!("Not an item: {:?}", self.id),
2698+
}
2699+
}
2700+
2701+
/// Finish configuring and perform the actual item resolution.
2702+
pub fn resolve_fallible(self, ctx: &BindgenContext) -> Option<&Item> {
26952703
assert!(ctx.collected_typerefs());
26962704

26972705
let mut id = self.id;
26982706
loop {
2699-
let item = ctx.resolve_item(id);
2700-
let ty_kind = item.as_type().map(|t| t.kind());
2701-
match ty_kind {
2702-
Some(&TypeKind::ResolvedTypeRef(next_id))
2703-
if self.through_type_refs =>
2704-
{
2705-
id = next_id.into();
2706-
}
2707-
// We intentionally ignore template aliases here, as they are
2708-
// more complicated, and don't represent a simple renaming of
2709-
// some type.
2710-
Some(&TypeKind::Alias(next_id))
2711-
if self.through_type_aliases =>
2712-
{
2713-
id = next_id.into();
2707+
let item = ctx.resolve_item_fallible(id);
2708+
match item {
2709+
None => return None,
2710+
Some(item) => {
2711+
let ty_kind = item.as_type().map(|t| t.kind());
2712+
match ty_kind {
2713+
Some(&TypeKind::ResolvedTypeRef(next_id))
2714+
if self.through_type_refs =>
2715+
{
2716+
id = next_id.into();
2717+
}
2718+
// We intentionally ignore template aliases here, as they are
2719+
// more complicated, and don't represent a simple renaming of
2720+
// some type.
2721+
Some(&TypeKind::Alias(next_id))
2722+
if self.through_type_aliases =>
2723+
{
2724+
id = next_id.into();
2725+
}
2726+
_ => return Some(item),
2727+
}
27142728
}
2715-
_ => return item,
27162729
}
27172730
}
27182731
}

0 commit comments

Comments
 (0)