@@ -146,12 +146,12 @@ pub struct GetSet<'a, P, T, const START: usize, const STOP: usize> {
146
146
147
147
impl < ' a , P , T , const START : usize , const STOP : usize > GetSet < ' a , P , T , START , STOP > {
148
148
/// The bit offset at which this `GetSet` instance starts
149
- pub const fn start ( & self ) -> usize {
149
+ # [ must_use ] pub const fn start ( & self ) -> usize {
150
150
START
151
151
}
152
152
153
153
/// The bit offset at which this `GetSet` instance ends
154
- pub const fn stop ( & self ) -> usize {
154
+ # [ must_use ] pub const fn stop ( & self ) -> usize {
155
155
STOP
156
156
}
157
157
}
@@ -206,7 +206,7 @@ impl<
206
206
> GetSet < ' a , P , T , START , STOP >
207
207
{
208
208
/// Get the property this `GetSet` points at
209
- pub fn get ( & self ) -> T {
209
+ # [ must_use ] pub fn get ( & self ) -> T {
210
210
let section = self . get_raw ( ) ;
211
211
// Safety:
212
212
// This is guaranteed to be safe because the underlying storage must be bigger
@@ -216,14 +216,14 @@ impl<
216
216
217
217
/// Returns true if the memory this `GetSet` points at is a valid
218
218
/// representation of `T`
219
- pub fn is_valid ( & self ) -> bool {
219
+ # [ must_use ] pub fn is_valid ( & self ) -> bool {
220
220
let section = self . get_raw ( ) ;
221
221
T :: is_valid ( section)
222
222
}
223
223
224
224
/// Get the raw bits being pointed at, without type conversion nor any form
225
225
/// of validation
226
- pub fn get_raw ( & self ) -> P {
226
+ # [ must_use ] pub fn get_raw ( & self ) -> P {
227
227
let parent = * self . parent ;
228
228
let mask = self . mask ( ) ;
229
229
( parent >> START ) & mask
@@ -373,7 +373,7 @@ macro_rules! bit_struct_impl {
373
373
/// A bit struct which has a zero value we can get
374
374
pub trait BitStructZero : Zero {
375
375
/// Get a zero value for this bit struct
376
- fn bs_zero ( ) -> Self {
376
+ # [ must_use ] fn bs_zero ( ) -> Self {
377
377
Self :: zero ( )
378
378
}
379
379
}
@@ -540,6 +540,8 @@ macro_rules! bit_struct {
540
540
impl $crate:: BitStruct <{ $( <$actual as $crate:: ValidCheck <$kind>>:: ALWAYS_VALID &&) * true } > for $name {
541
541
type Kind = $kind;
542
542
543
+ /// # Safety
544
+ /// - This is implemented automatically by the bit-struct crate.
543
545
unsafe fn from_unchecked( inner: $kind) -> Self {
544
546
Self ( unsafe { $crate:: UnsafeStorage :: new_unsafe( inner) } )
545
547
}
@@ -548,12 +550,16 @@ macro_rules! bit_struct {
548
550
#[ allow( clippy:: used_underscore_binding) ]
549
551
impl $name {
550
552
553
+ /// # Safety
554
+ /// - This is implemented automatically by the bit-struct crate.
551
555
unsafe fn from_unchecked( inner: $kind) -> Self {
552
556
Self ( unsafe { $crate:: UnsafeStorage :: new_unsafe( inner) } )
553
557
}
554
558
555
559
#[ allow( clippy:: too_many_arguments) ]
556
560
pub fn new( $( $field: $actual) ,* ) -> Self {
561
+ // SAFETY:
562
+ // - This is implemented automatically by the bit-struct crate.
557
563
let mut res = unsafe { Self :: from_unchecked( <$kind as $crate:: BitStructZero >:: bs_zero( ) ) } ;
558
564
$(
559
565
res. $field( ) . set( $field) ;
@@ -607,7 +613,7 @@ macro_rules! count_idents {
607
613
/// assert_eq!(bits(5), 3);
608
614
/// assert_eq!(bits(32), 6);
609
615
/// ```
610
- pub const fn bits ( num : usize ) -> usize {
616
+ # [ must_use ] pub const fn bits ( num : usize ) -> usize {
611
617
/// Helper function for [`bits`]
612
618
const fn helper ( count : usize , on : usize ) -> usize {
613
619
// 0b11 = 3 log2_ceil(0b11) = 2 .. 2^2
@@ -637,6 +643,7 @@ macro_rules! enum_impl {
637
643
} ;
638
644
( VALID_CORE $name: ident: [ $( $kind: ty) ,* ] ) => {
639
645
$(
646
+ #[ allow( clippy:: undocumented_unsafe_blocks, clippy:: use_self) ]
640
647
unsafe impl $crate:: ValidCheck <$kind> for $name {
641
648
const ALWAYS_VALID : bool = <Self as $crate:: ValidCheck <u8 >>:: ALWAYS_VALID ;
642
649
fn is_valid( value: $kind) -> bool {
@@ -653,6 +660,7 @@ macro_rules! enum_impl {
653
660
} ;
654
661
( VALID_BIT_STRUCT $name: ident: [ $( $kind: ty) ,* ] ) => {
655
662
$(
663
+ #[ allow( clippy:: undocumented_unsafe_blocks, clippy:: use_self) ]
656
664
unsafe impl $crate:: ValidCheck <$kind> for $name {
657
665
const ALWAYS_VALID : bool = <Self as $crate:: ValidCheck <u8 >>:: ALWAYS_VALID ;
658
666
fn is_valid( value: $kind) -> bool {
@@ -709,14 +717,19 @@ macro_rules! enum_impl {
709
717
) ,*
710
718
}
711
719
720
+ /// # Safety
721
+ /// - This is implemented automatically by the bit-struct crate.
722
+ #[ allow( clippy:: use_self) ]
712
723
unsafe impl $crate:: BitCount for $name {
713
724
const COUNT : usize = $crate:: bits( $crate:: count_idents!( 0 , [ $( $field) ,* ] ) ) ;
714
725
}
715
726
727
+ #[ allow( clippy:: use_self) ]
716
728
impl $name {
717
729
const VARIANT_COUNT : usize = $crate:: enum_impl!( COUNT $fst_field $( , $field) * ) ;
718
730
}
719
731
732
+ #[ allow( clippy:: undocumented_unsafe_blocks, clippy:: use_self) ]
720
733
unsafe impl $crate:: ValidCheck <u8 > for $name {
721
734
const ALWAYS_VALID : bool = Self :: VARIANT_COUNT . count_ones( ) == 1 ;
722
735
fn is_valid( value: u8 ) -> bool {
@@ -730,6 +743,7 @@ macro_rules! enum_impl {
730
743
731
744
$crate:: enum_impl!( FROM_IMPLS $name) ;
732
745
746
+ #[ allow( clippy:: use_self) ]
733
747
impl Default for $name {
734
748
fn default ( ) -> Self {
735
749
Self :: $default
@@ -762,6 +776,7 @@ macro_rules! enum_impl {
762
776
) ,*
763
777
}
764
778
779
+ #[ allow( clippy:: use_self) ]
765
780
impl Default for $name {
766
781
fn default ( ) -> Self {
767
782
Self :: $fst_field
@@ -772,11 +787,12 @@ macro_rules! enum_impl {
772
787
const VARIANT_COUNT : usize = $crate:: enum_impl!( COUNT $fst_field $( , $field) * ) ;
773
788
}
774
789
790
+ #[ allow( clippy:: undocumented_unsafe_blocks) ]
775
791
unsafe impl $crate:: BitCount for $name {
776
792
const COUNT : usize = $crate:: bits( $crate:: count_idents!( 0 , [ $( $field) ,* ] ) ) ;
777
793
}
778
794
779
-
795
+ # [ allow ( clippy :: undocumented_unsafe_blocks ) ]
780
796
unsafe impl $crate:: ValidCheck <u8 > for $name {
781
797
const ALWAYS_VALID : bool = Self :: VARIANT_COUNT . count_ones( ) == 1 ;
782
798
0 commit comments