summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-11-01 10:51:11 -0500
committerGitHub <noreply@github.com>2016-11-01 10:51:11 -0500
commit3f5d045ca08d1e7f25213e51e854ecf86d88218f (patch)
tree521595738d5ae4d4ffa8e631e568e4d70870b6ae
parent54d87d37f3eb2f1a19fc53b8c92558417a27d47e (diff)
parent664786a4ed877973c250141790a6a1f6a94ba9f3 (diff)
Auto merge of #182 - Incognitas:master, r=emilio
Fix #121: Cursor::num_template_args(...) returns Option<u32> instead of c_int Now, functions calling Cursor::num_template_args() call expect() on the return value to make sure it is a valid value
-rwxr-xr-xsrc/clang.rs13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/clang.rs b/src/clang.rs
index 07680367..ba6fc7f6 100755
--- a/src/clang.rs
+++ b/src/clang.rs
@@ -130,9 +130,14 @@ impl Cursor {
/// Return the number of template arguments used by this cursor's referent,
/// if the referent is either a template specialization or
/// declaration. Returns -1 otherwise.
- pub fn num_template_args(&self) -> c_int {
- unsafe {
- clang_Cursor_getNumTemplateArguments(self.x)
+ pub fn num_template_args(&self) -> Option<u32> {
+ let n : c_int = unsafe { clang_Cursor_getNumTemplateArguments(self.x) };
+
+ if n >= 0 {
+ Some(n as u32)
+ } else {
+ debug_assert_eq!(n, -1);
+ None
}
}
@@ -192,7 +197,7 @@ impl Cursor {
/// Is the referent a fully specialized template specialization without any
/// remaining free template arguments?
pub fn is_fully_specialized_template(&self) -> bool {
- self.is_template() && self.num_template_args() > 0
+ self.is_template() && self.num_template_args().unwrap() > 0
}
/// Is the referent a template specialization that still has remaining free