Skip to content

clang::Type::template_args return Option<TypeTemplateArgIterator> #175

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

Merged
merged 1 commit into from
Nov 1, 2016

Conversation

jeanphilippeD
Copy link
Contributor

Fix #136 by providing a bound checked iterator replacing the interface.

@highfive
Copy link

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!

Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me with that, thanks!


impl ExactSizeIterator for TypeTemplateArgIterator {
fn len(&self) -> usize {
if self.index < self.length {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.index can never be greater than self.length right? In that case, this if is not needed, since we'll always return the correct value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or an assert!(self.index <= self.length)

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! I have just a few stylistic nitpicks :)

/// template arguments. Otherwise, return None.
pub fn num_template_args(&self) -> Option<u32> {
pub fn template_args(&self) -> Option<TypeTemplateArgIterator>
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: { on same line as the signature.

@@ -747,6 +741,36 @@ impl Type {
}
}

/// An iterator for a type's template arguments
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: add a period at the end of the sentence.

let args = arg_types
.filter(|t| t.kind() != CXType_Invalid)
.map(|t| Item::from_ty_or_ref(t, None, None, ctx))
.collect::<Vec<_>>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So much nicer :)

let n = unsafe { clang_Type_getNumTemplateArguments(self.x) };
if n >= 0 {
Some(n as u32)
Some(TypeTemplateArgIterator { x: self.x, length: n as u32, index: 0 })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: put each field on its own line, like this:

Some(TypeTemplateArgIterator {
    x: self.x,
    length: n as u32,
    index: 0,
})

@emilio
Copy link
Contributor

emilio commented Nov 1, 2016

@bors-servo r=fitzgen,emilio

@bors-servo
Copy link

📌 Commit c8c2bdb has been approved by fitzgen,emilio

@bors-servo
Copy link

⌛ Testing commit c8c2bdb with merge 54d87d3...

bors-servo pushed a commit that referenced this pull request Nov 1, 2016
clang::Type::template_args return Option<TypeTemplateArgIterator>

Fix #136 by providing a bound checked iterator replacing the interface.
@emilio
Copy link
Contributor

emilio commented Nov 1, 2016

Thanks again, this is awesome :)

@bors-servo
Copy link

☀️ Test successful - status-travis

@bors-servo bors-servo merged commit c8c2bdb into rust-lang:master Nov 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants