Skip to content

Commit 3c4a840

Browse files
author
bors-servo
authored
Auto merge of #223 - fitzgen:useful-helpers, r=emilio
Useful little helpers for Item and Type Just a couple things I have found helpful when debugging, and should probably exist either way. r? @emilio
2 parents c314a2f + cc82b83 commit 3c4a840

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/ir/item.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,12 @@ impl Item {
331331
self.kind().expect_type()
332332
}
333333

334+
/// Get a reference to this item's underlying `Type`, or `None` if this is
335+
/// some other kind of item.
336+
pub fn as_type(&self) -> Option<&Type> {
337+
self.kind().as_type()
338+
}
339+
334340
/// Get a reference to this item's underlying `Function`. Panic if this is
335341
/// some other kind of item.
336342
pub fn expect_function(&self) -> &Function {
@@ -531,6 +537,11 @@ impl Item {
531537
ctx.opaque_by_name(&self.real_canonical_name(ctx, false, true))
532538
}
533539

540+
/// Is this a reference to another type?
541+
pub fn is_type_ref(&self) -> bool {
542+
self.as_type().map_or(false, |ty| ty.is_type_ref())
543+
}
544+
534545
/// Get the canonical name without taking into account the replaces
535546
/// annotation.
536547
///

src/ir/ty.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,15 @@ impl Type {
136136
self.is_const
137137
}
138138

139+
/// Is this a reference to another type?
140+
pub fn is_type_ref(&self) -> bool {
141+
match self.kind {
142+
TypeKind::ResolvedTypeRef(_) |
143+
TypeKind::UnresolvedTypeRef(_, _, _) => true,
144+
_ => false,
145+
}
146+
}
147+
139148
/// What is the layout of this type?
140149
pub fn layout(&self, ctx: &BindgenContext) -> Option<Layout> {
141150
use std::mem;

0 commit comments

Comments
 (0)