Skip to content

clang::Cursor::typedef_type should return Option<Type> #129

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

Closed
fitzgen opened this issue Oct 25, 2016 · 7 comments
Closed

clang::Cursor::typedef_type should return Option<Type> #129

fitzgen opened this issue Oct 25, 2016 · 7 comments

Comments

@fitzgen
Copy link
Member

fitzgen commented Oct 25, 2016

The FFI call that typedef_type makes will return an invalid type if the cursor's referent is not a typedef. We should check whether the referent is a typedef and return None if it is not, and make the FFI call and return Some if it is a typedef. This would be one less foot gun.

I can mentor anyone who'd like to pick up this bug.

@highfive
Copy link

Please make a comment here if you intend to work on this issue. Thank you!

@codingHahn
Copy link

How difficult is this? I am just getting my foots wet with rust. I am almost halfway through the Rust book form the website.

@fitzgen
Copy link
Member Author

fitzgen commented Nov 7, 2016

@codingHahn, I think you should be able to handle this, it is pretty straight forward.

You don't actually need to do the check before the FFI call, you can instead check the validity of the resulting cursor. Something like this:

let inner = Type {
    x: unsafe { clang_getTypedefDeclUnderlyingType(self.x) }
};
if inner.is_valid() { Some(inner) } else { None }

Then, you'll need to fix up the places where we call this method. For each call site: if the call site is explicitly checking the resulting cursor for validity, change that to an is_some()/is_none()/if let Some(...) = ... { ... } check; if the call site is not checking the validity of the result, change it to a .expect("expected inner typedef type") call to unwrap the Option and panic if we get an invalid cursor.

Does that make sense? Would you like to take this issue?

@codingHahn
Copy link

Ok. I should implement the check inside the function and return Some() or None? And every calling that checks the validity of this function should be wrapped into is_some() etc.? And every other function calling should have .expect(sth)? Then a am working on it in the next couple days.

@fitzgen
Copy link
Member Author

fitzgen commented Nov 7, 2016

Yep that sounds right! Let me know if you run into any roadblocks.

@codingHahn
Copy link

I'll let you know :)

@impowski
Copy link
Contributor

@codingHahn Have you done any progress on that or I can take it?

bors-servo pushed a commit that referenced this issue Dec 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants