Skip to content

Commit 027bf68

Browse files
committed
Constify bitfield constructor for Rust 1.57+
1 parent 68c741d commit 027bf68

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2498
-856
lines changed

bindgen-integration/src/lib.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,37 @@ fn test_bitfield_constructors() {
199199
});
200200
}
201201

202+
#[test]
203+
fn test_bitfield_const_constructors() {
204+
use std::mem;
205+
const FIRST: bindings::bitfields::First = bindings::bitfields::First {
206+
_bitfield_align_1: [],
207+
_bitfield_1: bindings::bitfields::First::new_bitfield_1(1, 2, 3),
208+
};
209+
let mut first = FIRST;
210+
assert!(unsafe { first.assert(1, 2, 3) });
211+
212+
const SECOND: bindings::bitfields::Second = bindings::bitfields::Second {
213+
_bitfield_align_1: [],
214+
_bitfield_1: bindings::bitfields::Second::new_bitfield_1(1337, true),
215+
};
216+
let mut second = SECOND;
217+
assert!(unsafe { second.assert(1337, true) });
218+
219+
const THIRD: bindings::bitfields::Third = bindings::bitfields::Third {
220+
_bitfield_align_1: [],
221+
_bitfield_1: bindings::bitfields::Third::new_bitfield_1(
222+
42,
223+
false,
224+
bindings::bitfields::ItemKind::ITEM_KIND_TRES,
225+
),
226+
};
227+
let mut third = THIRD;
228+
assert!(unsafe {
229+
third.assert(42, false, bindings::bitfields::ItemKind::ITEM_KIND_TRES)
230+
});
231+
}
232+
202233
impl Drop for bindings::AutoRestoreBool {
203234
fn drop(&mut self) {
204235
unsafe { bindings::AutoRestoreBool::destruct(self) }

0 commit comments

Comments
 (0)