diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-10-27 11:28:17 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-27 11:28:17 -0500 |
commit | 72f435e5d0dd818f01173242839b2e89ed104b83 (patch) | |
tree | c6c5742f1ea0959c5352ae0dd1e4fa813392c219 | |
parent | e72e466deca59d1ab26036b96731bb4114d915ba (diff) | |
parent | 486f8ff7a57dad663e9ebefa6d2f9f46a5669138 (diff) |
Auto merge of #150 - malfunc:master, r=emilio,fitzgen
fix: clang::Cursor::num_args should return Option<u32> #132
Hi, tried to fix the issue mentioned. Not sure, if changing fn args makes sense (the err message probably doesn't...). cargo test --features llvm_stable was succesful.
- changed output of fn num_args to option<u32>
- changed fn args to handle option<u32> instead of usize
-rwxr-xr-x | src/clang.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/clang.rs b/src/clang.rs index fa4eb01b..e3e0f313 100755 --- a/src/clang.rs +++ b/src/clang.rs @@ -393,7 +393,7 @@ impl Cursor { /// parameters. pub fn args(&self) -> Vec<Cursor> { unsafe { - let num = self.num_args() as usize; + let num = self.num_args().expect("expected value, got none") as u32; let mut args = vec![]; for i in 0..num { args.push(Cursor { x: clang_Cursor_getArgument(self.x, i as c_uint) }); @@ -415,9 +415,14 @@ impl Cursor { /// /// Returns -1 if the cursor's referent is not a function/method call or /// declaration. - pub fn num_args(&self) -> i32 { + pub fn num_args(&self) -> Result<u32, ()> { unsafe { - clang_Cursor_getNumArguments(self.x) + let w = clang_Cursor_getNumArguments(self.x); + if w == -1 { + Err(()) + } else { + Ok(w as u32) + } } } |