-
Notifications
You must be signed in to change notification settings - Fork 743
Make clang::Cursor::specialized return an Option #191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,7 +187,7 @@ impl Cursor { | |
|
||
/// Is the referent a template specialization? | ||
pub fn is_template(&self) -> bool { | ||
self.specialized().is_valid() | ||
self.specialized().map_or(false, |c| c.is_valid()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice :) |
||
} | ||
|
||
/// Is the referent a fully specialized template specialization without any | ||
|
@@ -287,11 +287,15 @@ impl Cursor { | |
|
||
/// Given that this cursor points to a template specialization, get a cursor | ||
/// pointing to the template definition that is being specialized. | ||
pub fn specialized(&self) -> Cursor { | ||
pub fn specialized(&self) -> Option<Cursor> { | ||
if !self.is_valid() { | ||
return None; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than checking if Does that make sense? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, I misread the issue description. I thought the concern was that the existing |
||
} | ||
|
||
unsafe { | ||
Cursor { | ||
Some(Cursor { | ||
x: clang_getSpecializedCursorTemplate(self.x), | ||
} | ||
}) | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be
self.specialized().is_some()
now, given we check if the cursor is valid inspecialized
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking
is_some()
will only work after my requested changes to theis_valid()
checking. This is a good insight, though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, I misread the implementation, but yeah :)