Skip to content

Commit f568d09

Browse files
phekiemilio
authored andcommitted
Indicate undefined behaviour in enum docs and point to alternative
1 parent 92e8fa0 commit f568d09

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/codegen/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2285,7 +2285,9 @@ impl MethodCodegen for Method {
22852285
/// A helper type that represents different enum variations.
22862286
#[derive(Copy, Clone, PartialEq, Debug)]
22872287
pub enum EnumVariation {
2288-
/// The code for this enum will use a Rust enum
2288+
/// The code for this enum will use a Rust enum. Note that creating this in unsafe code
2289+
/// (including FFI) with an invalid value will invoke undefined behaviour, whether or not
2290+
/// its marked as non_exhaustive.
22892291
Rust {
22902292
/// Indicates whether the generated struct should be `#[non_exhaustive]`
22912293
non_exhaustive: bool,

src/lib.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -939,9 +939,9 @@ impl Builder {
939939
/// This makes bindgen generate enums instead of constants. Regular
940940
/// expressions are supported.
941941
///
942-
/// **Use this with caution,** you probably want to use the non_exhaustive
943-
/// flavor of rust enums instead of this one. Take a look at
944-
/// https://github.com/rust-lang/rust/issues/36927 for more information.
942+
/// **Use this with caution**, creating this in unsafe code
943+
/// (including FFI) with an invalid value will invoke undefined behaviour.
944+
/// You may want to use the newtype enum style instead.
945945
pub fn rustified_enum<T: AsRef<str>>(mut self, arg: T) -> Builder {
946946
self.options.rustified_enums.insert(arg);
947947
self
@@ -952,6 +952,10 @@ impl Builder {
952952
///
953953
/// This makes bindgen generate enums instead of constants. Regular
954954
/// expressions are supported.
955+
///
956+
/// **Use this with caution**, creating this in unsafe code
957+
/// (including FFI) with an invalid value will invoke undefined behaviour.
958+
/// You may want to use the newtype enum style instead.
955959
pub fn rustified_non_exhaustive_enum<T: AsRef<str>>(
956960
mut self,
957961
arg: T,

0 commit comments

Comments
 (0)