-
Notifications
You must be signed in to change notification settings - Fork 315
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
Add support for NonZero<T> #964
Conversation
"c_short" => (IntKind::Short, true), | ||
"c_int" => (IntKind::Int, true), | ||
"c_long" => (IntKind::Long, true), | ||
"c_longlong" => (IntKind::LongLong, true), |
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.
@@ -592,50 +516,14 @@ impl Type { | |||
} | |||
} | |||
|
|||
fn nonzero_to_primitive(&self) -> Option<Self> { |
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.
NOTE: This function is no longer needed, because the parser handles these types directly now.
// NOTE: This performs the type erasure directly, as if `NonZero<T>` had been specified, because | ||
// it's actually more code to register an erased typedef instead. | ||
fn maybe_nonzero_integer(path: &str) -> Option<PrimitiveType> { |
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.
NOTE: This replaces Type::nonzero_to_primitive
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.
Sweet.
fn simplified_type(&self, config: &Config) -> Option<Self> { | ||
let path = match *self { | ||
Type::Path(ref p) => p, | ||
_ => return None, | ||
}; | ||
|
||
if path.generics().is_empty() { | ||
return self.nonzero_to_primitive(); | ||
return Some(self.clone()); |
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.
You can just return None
, which is the shorthand for "no simplification needed", right?
Merged with that tweak. |
Currently, cbindgen only supports the various
NonZeroXX
type aliases, but notNonZero<T>
itself. Add that support, and also simplify the handling of types in general.