diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-11-14 03:18:21 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-14 03:18:21 -0600 |
commit | 26c3afe401095b3d24a354ac9aa537240935d824 (patch) | |
tree | 41ead83d950369c143c8711d8b56b1a30e0a0869 | |
parent | bdfab643e70df469dd0d163cc91bf48955250735 (diff) | |
parent | 76b5372efa95047bc0200067a3f7493b39060a5f (diff) |
Auto merge of #232 - 11Takanori:124-clang-cursor-referenced-option-cursor, r=emilio
clang::Cursor::referenced should return Option<clang::Cursor>
Fixes https://github.com/servo/rust-bindgen/issues/124
Since I am new to Rust, I hope I didn't do things too badly
-rwxr-xr-x | src/clang.rs | 8 | ||||
-rw-r--r-- | src/ir/ty.rs | 4 |
2 files changed, 7 insertions, 5 deletions
diff --git a/src/clang.rs b/src/clang.rs index 47b7b31e..385fd09a 100755 --- a/src/clang.rs +++ b/src/clang.rs @@ -264,11 +264,13 @@ impl Cursor { /// Given that this cursor's referent is reference type, get the cursor /// pointing to the referenced type. - pub fn referenced(&self) -> Cursor { + pub fn referenced(&self) -> Option<Cursor> { unsafe { - Cursor { + let ret = Cursor { x: clang_getCursorReferenced(self.x), - } + }; + + if ret.is_valid() { Some(ret) } else { None } } } diff --git a/src/ir/ty.rs b/src/ir/ty.rs index d5ac6116..59044bdd 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -667,7 +667,7 @@ impl Type { TypeKind::TemplateAlias(inner.unwrap(), args) } CXCursor_TemplateRef => { - let referenced = location.referenced(); + let referenced = location.referenced().expect("expected value, got none"); let referenced_ty = referenced.cur_type(); let referenced_declaration = Some(referenced_ty.declaration()); @@ -679,7 +679,7 @@ impl Type { ctx); } CXCursor_TypeRef => { - let referenced = location.referenced(); + let referenced = location.referenced().expect("expected value, got none"); let referenced_ty = referenced.cur_type(); let referenced_declaration = Some(referenced_ty.declaration()); |