Skip to content

Commit 3f5d045

Browse files
author
bors-servo
authored
Auto merge of rust-lang#182 - Incognitas:master, r=emilio
Fix rust-lang#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
2 parents 54d87d3 + 664786a commit 3f5d045

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/clang.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,14 @@ impl Cursor {
130130
/// Return the number of template arguments used by this cursor's referent,
131131
/// if the referent is either a template specialization or
132132
/// declaration. Returns -1 otherwise.
133-
pub fn num_template_args(&self) -> c_int {
134-
unsafe {
135-
clang_Cursor_getNumTemplateArguments(self.x)
133+
pub fn num_template_args(&self) -> Option<u32> {
134+
let n : c_int = unsafe { clang_Cursor_getNumTemplateArguments(self.x) };
135+
136+
if n >= 0 {
137+
Some(n as u32)
138+
} else {
139+
debug_assert_eq!(n, -1);
140+
None
136141
}
137142
}
138143

@@ -192,7 +197,7 @@ impl Cursor {
192197
/// Is the referent a fully specialized template specialization without any
193198
/// remaining free template arguments?
194199
pub fn is_fully_specialized_template(&self) -> bool {
195-
self.is_template() && self.num_template_args() > 0
200+
self.is_template() && self.num_template_args().unwrap() > 0
196201
}
197202

198203
/// Is the referent a template specialization that still has remaining free

0 commit comments

Comments
 (0)