Skip to content

Commit 108c4ca

Browse files
author
bors-servo
authored
Auto merge of #224 - fitzgen:type-is-valid, r=emilio
Add `clang::Type::is_valid` and use it instead of checking self.kind() against CXType_Invalid Needed `is_valid()` when debugging, so figured we should land this and update places where we compare against the magical sentinel value. r? @emilio
2 parents 6c0d065 + d5ee20c commit 108c4ca

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/clang.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ impl Type {
639639
let ret = Type {
640640
x: unsafe { clang_getPointeeType(self.x) },
641641
};
642-
debug_assert!(ret.kind() != CXType_Invalid);
642+
debug_assert!(ret.is_valid());
643643
Some(ret)
644644
}
645645
_ => None,
@@ -652,7 +652,7 @@ impl Type {
652652
let current_type = Type {
653653
x: unsafe { clang_getElementType(self.x) },
654654
};
655-
if current_type.kind() != CXType_Invalid {
655+
if current_type.is_valid() {
656656
Some(current_type)
657657
} else {
658658
None
@@ -691,10 +691,10 @@ impl Type {
691691
let rt = Type {
692692
x: unsafe { clang_getResultType(self.x) },
693693
};
694-
if rt.kind() == CXType_Invalid {
695-
None
696-
} else {
694+
if rt.is_valid() {
697695
Some(rt)
696+
} else {
697+
None
698698
}
699699
}
700700

@@ -714,6 +714,11 @@ impl Type {
714714
}
715715
}
716716
}
717+
718+
/// Is this a valid type?
719+
pub fn is_valid(&self) -> bool {
720+
self.kind() != CXType_Invalid
721+
}
717722
}
718723

719724
/// An iterator for a type's template arguments.

0 commit comments

Comments
 (0)