forked from rust-lang/rust-bindgen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request rust-lang#1483 from LegNeato/repr_transparent
Bitfield enums use #[repr(transparent)] on Rust 1.28+
- Loading branch information
Showing
7 changed files
with
133 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* automatically generated by rust-bindgen */ | ||
|
||
#![allow( | ||
dead_code, | ||
non_snake_case, | ||
non_camel_case_types, | ||
non_upper_case_globals | ||
)] | ||
|
||
impl Foo { | ||
pub const Bar: Foo = Foo(2); | ||
} | ||
impl Foo { | ||
pub const Baz: Foo = Foo(4); | ||
} | ||
impl Foo { | ||
pub const Duplicated: Foo = Foo(4); | ||
} | ||
impl Foo { | ||
pub const Negative: Foo = Foo(-3); | ||
} | ||
impl ::std::ops::BitOr<Foo> for Foo { | ||
type Output = Self; | ||
#[inline] | ||
fn bitor(self, other: Self) -> Self { | ||
Foo(self.0 | other.0) | ||
} | ||
} | ||
impl ::std::ops::BitOrAssign for Foo { | ||
#[inline] | ||
fn bitor_assign(&mut self, rhs: Foo) { | ||
self.0 |= rhs.0; | ||
} | ||
} | ||
impl ::std::ops::BitAnd<Foo> for Foo { | ||
type Output = Self; | ||
#[inline] | ||
fn bitand(self, other: Self) -> Self { | ||
Foo(self.0 & other.0) | ||
} | ||
} | ||
impl ::std::ops::BitAndAssign for Foo { | ||
#[inline] | ||
fn bitand_assign(&mut self, rhs: Foo) { | ||
self.0 &= rhs.0; | ||
} | ||
} | ||
#[repr(C)] | ||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] | ||
pub struct Foo(pub i32); |
50 changes: 50 additions & 0 deletions
50
tests/expectations/tests/bitfield-enum-repr-transparent.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* automatically generated by rust-bindgen */ | ||
|
||
#![allow( | ||
dead_code, | ||
non_snake_case, | ||
non_camel_case_types, | ||
non_upper_case_globals | ||
)] | ||
|
||
impl Foo { | ||
pub const Bar: Foo = Foo(2); | ||
} | ||
impl Foo { | ||
pub const Baz: Foo = Foo(4); | ||
} | ||
impl Foo { | ||
pub const Duplicated: Foo = Foo(4); | ||
} | ||
impl Foo { | ||
pub const Negative: Foo = Foo(-3); | ||
} | ||
impl ::std::ops::BitOr<Foo> for Foo { | ||
type Output = Self; | ||
#[inline] | ||
fn bitor(self, other: Self) -> Self { | ||
Foo(self.0 | other.0) | ||
} | ||
} | ||
impl ::std::ops::BitOrAssign for Foo { | ||
#[inline] | ||
fn bitor_assign(&mut self, rhs: Foo) { | ||
self.0 |= rhs.0; | ||
} | ||
} | ||
impl ::std::ops::BitAnd<Foo> for Foo { | ||
type Output = Self; | ||
#[inline] | ||
fn bitand(self, other: Self) -> Self { | ||
Foo(self.0 & other.0) | ||
} | ||
} | ||
impl ::std::ops::BitAndAssign for Foo { | ||
#[inline] | ||
fn bitand_assign(&mut self, rhs: Foo) { | ||
self.0 &= rhs.0; | ||
} | ||
} | ||
#[repr(transparent)] | ||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] | ||
pub struct Foo(pub i32); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// bindgen-flags: --bitfield-enum "Foo" --rust-target 1.27 -- -std=c++11 | ||
|
||
enum Foo { | ||
Bar = 1 << 1, | ||
Baz = 1 << 2, | ||
Duplicated = 1 << 2, | ||
Negative = -3, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// bindgen-flags: --bitfield-enum "Foo" --rust-target 1.28 -- -std=c++11 | ||
|
||
enum Foo { | ||
Bar = 1 << 1, | ||
Baz = 1 << 2, | ||
Duplicated = 1 << 2, | ||
Negative = -3, | ||
}; |