Skip to content

Commit

Permalink
Indicate undefined behaviour in enum docs and point to alternative
Browse files Browse the repository at this point in the history
  • Loading branch information
pheki authored and emilio committed Mar 25, 2020
1 parent 92e8fa0 commit f568d09
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2285,7 +2285,9 @@ impl MethodCodegen for Method {
/// A helper type that represents different enum variations.
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum EnumVariation {
/// The code for this enum will use a Rust enum
/// The code for this enum will use a Rust enum. Note that creating this in unsafe code
/// (including FFI) with an invalid value will invoke undefined behaviour, whether or not
/// its marked as non_exhaustive.
Rust {
/// Indicates whether the generated struct should be `#[non_exhaustive]`
non_exhaustive: bool,
Expand Down
10 changes: 7 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -939,9 +939,9 @@ impl Builder {
/// This makes bindgen generate enums instead of constants. Regular
/// expressions are supported.
///
/// **Use this with caution,** you probably want to use the non_exhaustive
/// flavor of rust enums instead of this one. Take a look at
/// https://github.com/rust-lang/rust/issues/36927 for more information.
/// **Use this with caution**, creating this in unsafe code
/// (including FFI) with an invalid value will invoke undefined behaviour.
/// You may want to use the newtype enum style instead.
pub fn rustified_enum<T: AsRef<str>>(mut self, arg: T) -> Builder {
self.options.rustified_enums.insert(arg);
self
Expand All @@ -952,6 +952,10 @@ impl Builder {
///
/// This makes bindgen generate enums instead of constants. Regular
/// expressions are supported.
///
/// **Use this with caution**, creating this in unsafe code
/// (including FFI) with an invalid value will invoke undefined behaviour.
/// You may want to use the newtype enum style instead.
pub fn rustified_non_exhaustive_enum<T: AsRef<str>>(
mut self,
arg: T,
Expand Down

0 comments on commit f568d09

Please sign in to comment.