Auto merge of #1232 - emilio:enum-colon-bool, r=pepyakin

codegen: Try to reasonably handle enum : bool.

Just use the repr name we generate, since we generate constants for that.

It's not worth trying to guess the actual type to use IMO.

Bindings lose a bit of portability I guess, but that's really a lost bet
already, so instead of special-casing bool and map constants, let's use a
consistent representation everywhere.

Fixes #1145
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 5641b84..43a2ec0 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -2486,13 +2486,10 @@
             });
         }
 
-        let repr =
-            self.repr()
-                .and_then(|repr| repr.try_to_rust_ty_or_opaque(ctx, &()).ok())
-                .unwrap_or_else(|| {
-                    let repr_name = ctx.rust_ident_raw(repr_name);
-                    quote! { #repr_name }
-                });
+        let repr = {
+            let repr_name = ctx.rust_ident_raw(repr_name);
+            quote! { #repr_name }
+        };
 
         let mut builder = EnumBuilder::new(
             &name,
diff --git a/tests/expectations/tests/bitfield-enum-basic.rs b/tests/expectations/tests/bitfield-enum-basic.rs
index 84362d1..091dc70 100644
--- a/tests/expectations/tests/bitfield-enum-basic.rs
+++ b/tests/expectations/tests/bitfield-enum-basic.rs
@@ -1,9 +1,7 @@
 /* automatically generated by rust-bindgen */
 
-
 #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
 
-
 pub const Foo_Bar: Foo = Foo(2);
 pub const Foo_Baz: Foo = Foo(4);
 pub const Foo_Duplicated: Foo = Foo(4);
@@ -36,7 +34,7 @@
 }
 #[repr(C)]
 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub struct Foo(pub ::std::os::raw::c_int);
+pub struct Foo(pub i32);
 pub const Buz_Bar: Buz = Buz(2);
 pub const Buz_Baz: Buz = Buz(4);
 pub const Buz_Duplicated: Buz = Buz(4);
@@ -69,7 +67,7 @@
 }
 #[repr(C)]
 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub struct Buz(pub ::std::os::raw::c_schar);
+pub struct Buz(pub i8);
 pub const NS_FOO: _bindgen_ty_1 = _bindgen_ty_1(1);
 pub const NS_BAR: _bindgen_ty_1 = _bindgen_ty_1(2);
 impl ::std::ops::BitOr<_bindgen_ty_1> for _bindgen_ty_1 {
@@ -100,7 +98,7 @@
 }
 #[repr(C)]
 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub struct _bindgen_ty_1(pub ::std::os::raw::c_uint);
+pub struct _bindgen_ty_1(pub u32);
 #[repr(C)]
 #[derive(Debug, Default, Copy, Clone)]
 pub struct Dummy {
@@ -136,7 +134,7 @@
 }
 #[repr(C)]
 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-pub struct Dummy__bindgen_ty_1(pub ::std::os::raw::c_uint);
+pub struct Dummy__bindgen_ty_1(pub u32);
 #[test]
 fn bindgen_test_layout_Dummy() {
     assert_eq!(
diff --git a/tests/expectations/tests/constify-all-enums.rs b/tests/expectations/tests/constify-all-enums.rs
index 1d518b5..b2e1e97 100644
--- a/tests/expectations/tests/constify-all-enums.rs
+++ b/tests/expectations/tests/constify-all-enums.rs
@@ -1,13 +1,11 @@
 /* automatically generated by rust-bindgen */
 
-
 #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
 
-
 pub const foo_THIS: foo = 0;
 pub const foo_SHOULD_BE: foo = 1;
 pub const foo_A_CONSTANT: foo = 2;
-pub type foo = ::std::os::raw::c_uint;
+pub type foo = u32;
 #[repr(C)]
 #[derive(Debug, Copy, Clone)]
 pub struct bar {
diff --git a/tests/expectations/tests/constify-module-enums-basic.rs b/tests/expectations/tests/constify-module-enums-basic.rs
index f8f45f1..342e5ba 100644
--- a/tests/expectations/tests/constify-module-enums-basic.rs
+++ b/tests/expectations/tests/constify-module-enums-basic.rs
@@ -1,11 +1,9 @@
 /* automatically generated by rust-bindgen */
 
-
 #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
 
-
 pub mod foo {
-    pub type Type = ::std::os::raw::c_uint;
+    pub type Type = u32;
     pub const THIS: Type = 0;
     pub const SHOULD_BE: Type = 1;
     pub const A_CONSTANT: Type = 2;
diff --git a/tests/expectations/tests/constify-module-enums-namespace.rs b/tests/expectations/tests/constify-module-enums-namespace.rs
index a69044e..7f1c134 100644
--- a/tests/expectations/tests/constify-module-enums-namespace.rs
+++ b/tests/expectations/tests/constify-module-enums-namespace.rs
@@ -1,9 +1,7 @@
 /* automatically generated by rust-bindgen */
 
-
 #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
 
-
 #[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
 pub mod root {
     #[allow(unused_imports)]
@@ -15,7 +13,7 @@
             #[allow(unused_imports)]
             use self::super::super::super::root;
             pub mod foo {
-                pub type Type = ::std::os::raw::c_uint;
+                pub type Type = u32;
                 pub const THIS: Type = 0;
                 pub const SHOULD_BE: Type = 1;
                 pub const A_CONSTANT: Type = 2;
diff --git a/tests/expectations/tests/constify-module-enums-shadow-name.rs b/tests/expectations/tests/constify-module-enums-shadow-name.rs
index b7da1cc..9642871 100644
--- a/tests/expectations/tests/constify-module-enums-shadow-name.rs
+++ b/tests/expectations/tests/constify-module-enums-shadow-name.rs
@@ -1,11 +1,9 @@
 /* automatically generated by rust-bindgen */
 
-
 #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
 
-
 pub mod foo {
-    pub type Type = ::std::os::raw::c_uint;
+    pub type Type = u32;
     pub const Type: Type = 0;
     pub const Type_: Type = 1;
     pub const Type1: Type = 2;
diff --git a/tests/expectations/tests/constify-module-enums-simple-alias.rs b/tests/expectations/tests/constify-module-enums-simple-alias.rs
index 89b3ead..70c881b 100644
--- a/tests/expectations/tests/constify-module-enums-simple-alias.rs
+++ b/tests/expectations/tests/constify-module-enums-simple-alias.rs
@@ -1,11 +1,9 @@
 /* automatically generated by rust-bindgen */
 
-
 #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
 
-
 pub mod Foo {
-    pub type Type = ::std::os::raw::c_int;
+    pub type Type = i32;
     pub const Variant1: Type = 0;
     pub const Variant2: Type = 1;
     pub const Variant3: Type = 2;
diff --git a/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs b/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs
index b85edba..ee15b57 100644
--- a/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs
+++ b/tests/expectations/tests/constify-module-enums-simple-nonamespace.rs
@@ -1,11 +1,9 @@
 /* automatically generated by rust-bindgen */
 
-
 #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
 
-
 pub mod one_Foo {
-    pub type Type = ::std::os::raw::c_int;
+    pub type Type = i32;
     pub const Variant1: Type = 0;
     pub const Variant2: Type = 1;
 }
diff --git a/tests/expectations/tests/constify-module-enums-types.rs b/tests/expectations/tests/constify-module-enums-types.rs
index 8849cc3..155839b 100644
--- a/tests/expectations/tests/constify-module-enums-types.rs
+++ b/tests/expectations/tests/constify-module-enums-types.rs
@@ -1,11 +1,9 @@
 /* automatically generated by rust-bindgen */
 
-
 #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
 
-
 pub mod foo {
-    pub type Type = ::std::os::raw::c_uint;
+    pub type Type = u32;
     pub const THIS: Type = 0;
     pub const SHOULD_BE: Type = 1;
     pub const A_CONSTANT: Type = 2;
@@ -13,20 +11,20 @@
     pub const AND_ALSO_THIS: Type = 42;
 }
 pub mod anon_enum {
-    pub type Type = ::std::os::raw::c_uint;
+    pub type Type = u32;
     pub const Variant1: Type = 0;
     pub const Variant2: Type = 1;
     pub const Variant3: Type = 2;
 }
 pub mod ns1_foo {
-    pub type Type = ::std::os::raw::c_uint;
+    pub type Type = u32;
     pub const THIS: Type = 0;
     pub const SHOULD_BE: Type = 1;
     pub const A_CONSTANT: Type = 2;
     pub const ALSO_THIS: Type = 42;
 }
 pub mod ns2_Foo {
-    pub type Type = ::std::os::raw::c_int;
+    pub type Type = i32;
     pub const Variant1: Type = 0;
     pub const Variant2: Type = 1;
 }
@@ -202,7 +200,7 @@
     }
 }
 pub mod one_Foo {
-    pub type Type = ::std::os::raw::c_int;
+    pub type Type = i32;
     pub const Variant1: Type = 0;
     pub const Variant2: Type = 1;
 }
diff --git a/tests/expectations/tests/empty-enum.rs b/tests/expectations/tests/empty-enum.rs
index 99ffc27..473a508 100644
--- a/tests/expectations/tests/empty-enum.rs
+++ b/tests/expectations/tests/empty-enum.rs
@@ -2,30 +2,30 @@
 
 #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
 
-pub type EmptyConstified = ::std::os::raw::c_uint;
+pub type EmptyConstified = u32;
 #[repr(u32)]
 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
 pub enum EmptyRustified {
     __bindgen_cannot_repr_c_on_empty_enum = 0,
 }
 pub mod EmptyModule {
-    pub type Type = ::std::os::raw::c_uint;
+    pub type Type = u32;
 }
 #[repr(i8)]
 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
 pub enum EmptyClassRustified {
     __bindgen_cannot_repr_c_on_empty_enum = 0,
 }
-pub type EmptyClassConstified = ::std::os::raw::c_char;
+pub type EmptyClassConstified = i8;
 pub mod EmptyClassModule {
-    pub type Type = ::std::os::raw::c_char;
+    pub type Type = i8;
 }
 #[repr(i8)]
 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
 pub enum ForwardClassRustified {
     __bindgen_cannot_repr_c_on_empty_enum = 0,
 }
-pub type ForwardClassConstified = ::std::os::raw::c_char;
+pub type ForwardClassConstified = i8;
 pub mod ForwardClassModule {
-    pub type Type = ::std::os::raw::c_char;
+    pub type Type = i8;
 }
diff --git a/tests/expectations/tests/enum_explicit_type.rs b/tests/expectations/tests/enum_explicit_type.rs
index 17f135b..a5ec4a5 100644
--- a/tests/expectations/tests/enum_explicit_type.rs
+++ b/tests/expectations/tests/enum_explicit_type.rs
@@ -35,3 +35,8 @@
 pub enum MuchULongLong {
     MuchHigh = 4294967296,
 }
+#[repr(u8)]
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+pub enum BoolEnumsAreFun {
+    Value = 1,
+}
diff --git a/tests/expectations/tests/enum_explicit_type_constants.rs b/tests/expectations/tests/enum_explicit_type_constants.rs
new file mode 100644
index 0000000..cd1a922
--- /dev/null
+++ b/tests/expectations/tests/enum_explicit_type_constants.rs
@@ -0,0 +1,21 @@
+/* automatically generated by rust-bindgen */
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+pub const Foo_Bar: Foo = 0;
+pub const Foo_Qux: Foo = 1;
+pub type Foo = u8;
+pub const Neg_MinusOne: Neg = -1;
+pub const Neg_One: Neg = 1;
+pub type Neg = i8;
+pub const Bigger_Much: Bigger = 255;
+pub const Bigger_Larger: Bigger = 256;
+pub type Bigger = u16;
+pub const MuchLong_MuchLow: MuchLong = -4294967296;
+pub type MuchLong = i64;
+pub const MuchLongLong_I64_MIN: MuchLongLong = -9223372036854775808;
+pub type MuchLongLong = i64;
+pub const MuchULongLong_MuchHigh: MuchULongLong = 4294967296;
+pub type MuchULongLong = u64;
+pub const BoolEnumsAreFun_Value: BoolEnumsAreFun = 1;
+pub type BoolEnumsAreFun = u8;
diff --git a/tests/expectations/tests/prepend_enum_name.rs b/tests/expectations/tests/prepend_enum_name.rs
index c409e54..96c7b61 100644
--- a/tests/expectations/tests/prepend_enum_name.rs
+++ b/tests/expectations/tests/prepend_enum_name.rs
@@ -1,9 +1,7 @@
 /* automatically generated by rust-bindgen */
 
-
 #![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
 
-
 pub const FOO_BAR: foo = 0;
 pub const FOO_BAZ: foo = 1;
-pub type foo = ::std::os::raw::c_uint;
+pub type foo = u32;
diff --git a/tests/headers/enum_explicit_type.hpp b/tests/headers/enum_explicit_type.hpp
index e611de7..3cb9313 100644
--- a/tests/headers/enum_explicit_type.hpp
+++ b/tests/headers/enum_explicit_type.hpp
@@ -26,3 +26,7 @@
 enum MuchULongLong: unsigned long long {
     MuchHigh = 4294967296,
 };
+
+enum BoolEnumsAreFun: bool {
+    Value = true,
+};
diff --git a/tests/headers/enum_explicit_type_constants.hpp b/tests/headers/enum_explicit_type_constants.hpp
new file mode 100644
index 0000000..7deab36
--- /dev/null
+++ b/tests/headers/enum_explicit_type_constants.hpp
@@ -0,0 +1,5 @@
+// bindgen-flags: -- -std=c++11
+//
+// This test is much like enum_explicit_type, but without --rustified-enum.
+
+#include "enum_explicit_type.hpp"