Allow to generate associated constants in the body of C++ structs.

Opt-in since it uses a C++17 feature, but this allow exactly the same usage in
C++ and Rust, which I think is nice.

This also fixes constants of transparent structs in general, since the initial
version of this patch broke a test (associated constants in enums), so I added a
test for that too.
This commit is contained in:
Emilio Cobos Álvarez
2019-02-23 17:24:09 -08:00
parent 9761df66c2
commit 80da1f59aa
49 changed files with 430 additions and 233 deletions
+22
View File
@@ -0,0 +1,22 @@
bitflags! {
/// Constants shared by multiple CSS Box Alignment properties
///
/// These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
#[derive(MallocSizeOf, ToComputedValue)]
#[repr(C)]
pub struct AlignFlags: u8 {
/// 'auto'
const AUTO = 0;
/// 'normal'
const NORMAL = 1;
/// 'start'
const START = 1 << 1;
/// 'end'
const END = 1 << 2;
/// 'flex-start'
const FLEX_START = 1 << 3;
}
}
#[no_mangle]
pub extern "C" fn root(flags: AlignFlags) {}
+5
View File
@@ -0,0 +1,5 @@
[struct]
associated_constants_in_body = true
[export]
prefix = "Style" # Just ensuring they play well together :)
+3
View File
@@ -17,3 +17,6 @@ bitflags! {
const FLEX_START = 1 << 3;
}
}
#[no_mangle]
pub extern "C" fn root(flags: AlignFlags) {}
+4
View File
@@ -0,0 +1,4 @@
#[repr(transparent)]
struct Transparent { field: u8 }
const FOO: Transparent = Transparent { field: 0 };
+2
View File
@@ -1,3 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "derive-eq"
version = "0.1.0"
+2
View File
@@ -1,3 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "expand"
version = "0.1.0"
+2
View File
@@ -1,3 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "expand"
version = "0.1.0"
+2
View File
@@ -1,3 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "expand"
version = "0.1.0"
+2
View File
@@ -1,3 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "expand"
version = "0.1.0"
+2
View File
@@ -1,3 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "mod_attr"
version = "0.1.0"
+2
View File
@@ -1,3 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "mod_path"
version = "0.1.0"
+2
View File
@@ -1,3 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "dependency"
version = "0.1.0"
+2
View File
@@ -1,3 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "child"
version = "0.1.0"