You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/* automatically generated by rust-bindgen */#[repr(C)]#[derive(Copy,Clone,Debug,Default,Eq,Hash,Ord,PartialEq,PartialOrd)]pubstruct__BindgenBitfieldUnit<Storage,Align>whereStorage:AsRef<[u8]> + AsMut<[u8]>,{storage:Storage,align:[Align;0],}impl<Storage,Align>__BindgenBitfieldUnit<Storage,Align>whereStorage:AsRef<[u8]> + AsMut<[u8]>,{#[inline]pubfnnew(storage:Storage) -> Self{Self{ storage,align:[]}}#[inline]pubfnget_bit(&self,index:usize) -> bool{debug_assert!(index /8<self.storage.as_ref().len());let byte_index = index / 8;let byte = self.storage.as_ref()[byte_index];let bit_index = ifcfg!(target_endian ="big"){7 - (index % 8)}else{
index % 8};let mask = 1 << bit_index;
byte & mask == mask
}#[inline]pubfnset_bit(&mutself,index:usize,val:bool){debug_assert!(index /8<self.storage.as_ref().len());let byte_index = index / 8;let byte = &mutself.storage.as_mut()[byte_index];let bit_index = ifcfg!(target_endian ="big"){7 - (index % 8)}else{
index % 8};let mask = 1 << bit_index;if val {*byte |= mask;}else{*byte &= !mask;}}#[inline]pubfnget(&self,bit_offset:usize,bit_width:u8) -> u64{debug_assert!(bit_width <=64);debug_assert!(bit_offset /8<self.storage.as_ref().len());debug_assert!((bit_offset+(bit_widthasusize))/8<=self.storage.as_ref().len());letmut val = 0;for i in0..(bit_width asusize){ifself.get_bit(i + bit_offset){let index = ifcfg!(target_endian ="big"){
bit_width asusize - 1 - i
}else{
i
};
val |= 1 << index;}}
val
}#[inline]pubfnset(&mutself,bit_offset:usize,bit_width:u8,val:u64){debug_assert!(bit_width <=64);debug_assert!(bit_offset /8<self.storage.as_ref().len());debug_assert!((bit_offset+(bit_widthasusize))/8<=self.storage.as_ref().len());for i in0..(bit_width asusize){let mask = 1 << i;let val_bit_is_set = val & mask == mask;let index = ifcfg!(target_endian ="big"){
bit_width asusize - 1 - i
}else{
i
};self.set_bit(index + bit_offset, val_bit_is_set);}}}#[repr(C)]#[repr(align(4))]#[derive(Debug,Copy,Clone)]pubstructflags{pub_bitfield_1:__BindgenBitfieldUnit<[u8;1usize],u8>,pub__bindgen_padding_0:[u8;3usize],}
Expected Results
The min_const_fn feature was introduced in Rust 1.30. Because the --rust-target is >= 1.30, __BindgenBitfieldUnit::new should have been declared as a const fn:
The current behavior is undesirable because it means that it's impossible to instantiate a type containing a bitfield as a static binding using safe rust. i.e., the following is not possible:
static my_flags: flags = /* ??? */;
The same problem exists with __BindgenUnionField.
The text was updated successfully, but these errors were encountered:
I'm going to take a stab at fixing this. It looks like I can add a line to src/features.rs to detect the presence of rust >= 1.30, and then modify the utils::prepend_union_types function in src/codegen/mod.rs to conditionally output new as const.
Wallacoloo
added a commit
to Wallacoloo/rust-bindgen
that referenced
this issue
Jun 5, 2019
Input C/C++ Header
Bindgen Invocation
Actual Results
Expected Results
The
min_const_fn
feature was introduced in Rust 1.30. Because the--rust-target
is >= 1.30,__BindgenBitfieldUnit::new
should have been declared as aconst fn
:The current behavior is undesirable because it means that it's impossible to instantiate a type containing a bitfield as a
static
binding using safe rust. i.e., the following is not possible:The same problem exists with
__BindgenUnionField
.The text was updated successfully, but these errors were encountered: