55 html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg"
66) ]
77#![ warn(
8+ clippy:: cast_lossless,
89 clippy:: cast_possible_truncation,
10+ clippy:: cast_precision_loss,
11+ clippy:: checked_conversions,
12+ clippy:: implicit_saturating_sub,
913 clippy:: integer_division_remainder_used,
1014 clippy:: mod_module_files,
11- missing_docs,
15+ clippy:: panic,
16+ clippy:: panic_in_result_fn,
17+ clippy:: std_instead_of_alloc,
18+ clippy:: std_instead_of_core,
19+ clippy:: unwrap_used,
1220 missing_debug_implementations,
13- missing_copy_implementations ,
21+ missing_docs ,
1422 rust_2018_idioms,
1523 trivial_casts,
1624 trivial_numeric_casts,
25+ unused_lifetimes,
1726 unused_qualifications
1827) ]
1928
@@ -73,30 +82,30 @@ pub trait CmovEq {
7382impl Cmov for u8 {
7483 #[ inline]
7584 fn cmovnz ( & mut self , value : & Self , condition : Condition ) {
76- let mut tmp = * self as u16 ;
77- tmp. cmovnz ( & ( * value as u16 ) , condition) ;
78- debug_assert ! ( tmp <= u8 :: MAX as u16 ) ;
85+ let mut tmp = u16 :: from ( * self ) ;
86+ tmp. cmovnz ( & u16 :: from ( * value) , condition) ;
87+ debug_assert ! ( u8 :: try_from ( tmp ) . is_ok ( ) ) ;
7988 * self = ( tmp & 0xFF ) as u8 ;
8089 }
8190
8291 #[ inline]
8392 fn cmovz ( & mut self , value : & Self , condition : Condition ) {
84- let mut tmp = * self as u16 ;
85- tmp. cmovz ( & ( * value as u16 ) , condition) ;
86- debug_assert ! ( tmp <= u8 :: MAX as u16 ) ;
93+ let mut tmp = u16 :: from ( * self ) ;
94+ tmp. cmovz ( & u16 :: from ( * value) , condition) ;
95+ debug_assert ! ( u8 :: try_from ( tmp ) . is_ok ( ) ) ;
8796 * self = ( tmp & 0xFF ) as u8 ;
8897 }
8998}
9099
91100impl CmovEq for u8 {
92101 #[ inline]
93102 fn cmoveq ( & self , rhs : & Self , input : Condition , output : & mut Condition ) {
94- ( * self as u16 ) . cmoveq ( & ( * rhs as u16 ) , input, output) ;
103+ u16 :: from ( * self ) . cmoveq ( & u16 :: from ( * rhs) , input, output) ;
95104 }
96105
97106 #[ inline]
98107 fn cmovne ( & self , rhs : & Self , input : Condition , output : & mut Condition ) {
99- ( * self as u16 ) . cmovne ( & ( * rhs as u16 ) , input, output) ;
108+ u16 :: from ( * self ) . cmovne ( & u16 :: from ( * rhs) , input, output) ;
100109 }
101110}
102111
@@ -105,24 +114,24 @@ impl CmovEq for u8 {
105114impl Cmov for u128 {
106115 #[ inline]
107116 fn cmovnz ( & mut self , value : & Self , condition : Condition ) {
108- let mut lo = ( * self & u64:: MAX as u128 ) as u64 ;
117+ let mut lo = ( * self & u128 :: from ( u64:: MAX ) ) as u64 ;
109118 let mut hi = ( * self >> 64 ) as u64 ;
110119
111- lo. cmovnz ( & ( ( * value & u64:: MAX as u128 ) as u64 ) , condition) ;
120+ lo. cmovnz ( & ( ( * value & u128 :: from ( u64:: MAX ) ) as u64 ) , condition) ;
112121 hi. cmovnz ( & ( ( * value >> 64 ) as u64 ) , condition) ;
113122
114- * self = ( lo as u128 ) | ( ( hi as u128 ) << 64 ) ;
123+ * self = u128 :: from ( lo) | ( u128 :: from ( hi) << 64 ) ;
115124 }
116125
117126 #[ inline]
118127 fn cmovz ( & mut self , value : & Self , condition : Condition ) {
119- let mut lo = ( * self & u64:: MAX as u128 ) as u64 ;
128+ let mut lo = ( * self & u128 :: from ( u64:: MAX ) ) as u64 ;
120129 let mut hi = ( * self >> 64 ) as u64 ;
121130
122- lo. cmovz ( & ( ( * value & u64:: MAX as u128 ) as u64 ) , condition) ;
131+ lo. cmovz ( & ( ( * value & u128 :: from ( u64:: MAX ) ) as u64 ) , condition) ;
123132 hi. cmovz ( & ( ( * value >> 64 ) as u64 ) , condition) ;
124133
125- * self = ( lo as u128 ) | ( ( hi as u128 ) << 64 ) ;
134+ * self = u128 :: from ( lo) | ( u128 :: from ( hi) << 64 ) ;
126135 }
127136}
128137
@@ -131,22 +140,22 @@ impl Cmov for u128 {
131140impl CmovEq for u128 {
132141 #[ inline]
133142 fn cmovne ( & self , rhs : & Self , input : Condition , output : & mut Condition ) {
134- let lo = ( * self & u64:: MAX as u128 ) as u64 ;
143+ let lo = ( * self & u128 :: from ( u64:: MAX ) ) as u64 ;
135144 let hi = ( * self >> 64 ) as u64 ;
136145
137146 let mut tmp = 1u8 ;
138- lo. cmovne ( & ( ( * rhs & u64:: MAX as u128 ) as u64 ) , 0 , & mut tmp) ;
147+ lo. cmovne ( & ( ( * rhs & u128 :: from ( u64:: MAX ) ) as u64 ) , 0 , & mut tmp) ;
139148 hi. cmovne ( & ( ( * rhs >> 64 ) as u64 ) , 0 , & mut tmp) ;
140149 tmp. cmoveq ( & 0 , input, output) ;
141150 }
142151
143152 #[ inline]
144153 fn cmoveq ( & self , rhs : & Self , input : Condition , output : & mut Condition ) {
145- let lo = ( * self & u64:: MAX as u128 ) as u64 ;
154+ let lo = ( * self & u128 :: from ( u64:: MAX ) ) as u64 ;
146155 let hi = ( * self >> 64 ) as u64 ;
147156
148157 let mut tmp = 1u8 ;
149- lo. cmovne ( & ( ( * rhs & u64:: MAX as u128 ) as u64 ) , 0 , & mut tmp) ;
158+ lo. cmovne ( & ( ( * rhs & u128 :: from ( u64:: MAX ) ) as u64 ) , 0 , & mut tmp) ;
150159 hi. cmovne ( & ( ( * rhs >> 64 ) as u64 ) , 0 , & mut tmp) ;
151160 tmp. cmoveq ( & 1 , input, output) ;
152161 }
0 commit comments