@@ -200,39 +200,12 @@ impl Not for Choice {
200
200
}
201
201
}
202
202
203
- /// This function is a best-effort attempt to prevent the compiler from knowing
204
- /// anything about the value of the returned `u8`, other than its type.
205
- ///
206
- /// Because we want to support stable Rust, we don't have access to inline
207
- /// assembly or test::black_box, so we use the fact that volatile values will
208
- /// never be elided to register values.
209
- ///
210
- /// Note: Rust's notion of "volatile" is subject to change over time. While this
211
- /// code may break in a non-destructive way in the future, “constant-time” code
212
- /// is a continually moving target, and this is better than doing nothing.
213
- #[ inline( never) ]
214
- fn black_box ( input : u8 ) -> u8 {
215
- debug_assert ! ( ( input == 0u8 ) | ( input == 1u8 ) ) ;
216
-
217
- unsafe {
218
- // Optimization barrier
219
- //
220
- // Unsafe is ok, because:
221
- // - &input is not NULL;
222
- // - size of input is not zero;
223
- // - u8 is neither Sync, nor Send;
224
- // - u8 is Copy, so input is always live;
225
- // - u8 type is always properly aligned.
226
- core:: ptr:: read_volatile ( & input as * const u8 )
227
- }
228
- }
229
-
230
203
impl From < u8 > for Choice {
231
204
#[ inline]
232
205
fn from ( input : u8 ) -> Choice {
233
206
// Our goal is to prevent the compiler from inferring that the value held inside the
234
207
// resulting `Choice` struct is really an `i1` instead of an `i8`.
235
- Choice ( black_box ( input) )
208
+ Choice ( core :: hint :: black_box ( input) )
236
209
}
237
210
}
238
211
0 commit comments