Skip to content

Commit 40da211

Browse files
author
Aurélien Normand
committed
Fix rust-lang#121: Cursor::num_template_args(...) returns Option<u32> instead of c_int
1 parent 54d87d3 commit 40da211

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/clang.rs

+10-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,8 @@ 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()
201+
.expect("Not a class template specialization") > 0
196202
}
197203

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

0 commit comments

Comments
 (0)