@@ -118,7 +118,7 @@ macro_rules! load_int_le {
118
118
/// Safety: this performs unchecked indexing of `buf` at `start..start+len`, so
119
119
/// that must be in-bounds.
120
120
#[ inline]
121
- unsafe fn u8to64_le ( buf : & [ u8 ] , start : usize , len : usize ) -> u64 {
121
+ const unsafe fn u8to64_le ( buf : & [ u8 ] , start : usize , len : usize ) -> u64 {
122
122
debug_assert ! ( len < 8 ) ;
123
123
let mut i = 0 ; // current byte index (from LSB) in the output u64
124
124
let mut out = 0 ;
@@ -138,7 +138,7 @@ unsafe fn u8to64_le(buf: &[u8], start: usize, len: usize) -> u64 {
138
138
out |= ( unsafe { * buf. get_unchecked ( start + i) } as u64 ) << ( i * 8 ) ;
139
139
i += 1 ;
140
140
}
141
- debug_assert_eq ! ( i, len) ;
141
+ debug_assert ! ( i == len) ;
142
142
out
143
143
}
144
144
@@ -150,8 +150,9 @@ impl SipHasher {
150
150
since = "1.13.0" ,
151
151
note = "use `std::collections::hash_map::DefaultHasher` instead"
152
152
) ]
153
+ #[ rustc_const_unstable( feature = "const_hash" , issue = "none" ) ]
153
154
#[ must_use]
154
- pub fn new ( ) -> SipHasher {
155
+ pub const fn new ( ) -> SipHasher {
155
156
SipHasher :: new_with_keys ( 0 , 0 )
156
157
}
157
158
@@ -162,8 +163,9 @@ impl SipHasher {
162
163
since = "1.13.0" ,
163
164
note = "use `std::collections::hash_map::DefaultHasher` instead"
164
165
) ]
166
+ #[ rustc_const_unstable( feature = "const_hash" , issue = "none" ) ]
165
167
#[ must_use]
166
- pub fn new_with_keys ( key0 : u64 , key1 : u64 ) -> SipHasher {
168
+ pub const fn new_with_keys ( key0 : u64 , key1 : u64 ) -> SipHasher {
167
169
SipHasher ( SipHasher24 { hasher : Hasher :: new_with_keys ( key0, key1) } )
168
170
}
169
171
}
@@ -176,7 +178,8 @@ impl SipHasher13 {
176
178
since = "1.13.0" ,
177
179
note = "use `std::collections::hash_map::DefaultHasher` instead"
178
180
) ]
179
- pub fn new ( ) -> SipHasher13 {
181
+ #[ rustc_const_unstable( feature = "const_hash" , issue = "none" ) ]
182
+ pub const fn new ( ) -> SipHasher13 {
180
183
SipHasher13 :: new_with_keys ( 0 , 0 )
181
184
}
182
185
@@ -187,14 +190,15 @@ impl SipHasher13 {
187
190
since = "1.13.0" ,
188
191
note = "use `std::collections::hash_map::DefaultHasher` instead"
189
192
) ]
190
- pub fn new_with_keys ( key0 : u64 , key1 : u64 ) -> SipHasher13 {
193
+ #[ rustc_const_unstable( feature = "const_hash" , issue = "none" ) ]
194
+ pub const fn new_with_keys ( key0 : u64 , key1 : u64 ) -> SipHasher13 {
191
195
SipHasher13 { hasher : Hasher :: new_with_keys ( key0, key1) }
192
196
}
193
197
}
194
198
195
199
impl < S : Sip > Hasher < S > {
196
200
#[ inline]
197
- fn new_with_keys ( key0 : u64 , key1 : u64 ) -> Hasher < S > {
201
+ const fn new_with_keys ( key0 : u64 , key1 : u64 ) -> Hasher < S > {
198
202
let mut state = Hasher {
199
203
k0 : key0,
200
204
k1 : key1,
@@ -209,7 +213,7 @@ impl<S: Sip> Hasher<S> {
209
213
}
210
214
211
215
#[ inline]
212
- fn reset ( & mut self ) {
216
+ const fn reset ( & mut self ) {
213
217
self . length = 0 ;
214
218
self . state . v0 = self . k0 ^ 0x736f6d6570736575 ;
215
219
self . state . v1 = self . k1 ^ 0x646f72616e646f6d ;
@@ -220,7 +224,8 @@ impl<S: Sip> Hasher<S> {
220
224
}
221
225
222
226
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
223
- impl super :: Hasher for SipHasher {
227
+ #[ rustc_const_unstable( feature = "const_hash" , issue = "none" ) ]
228
+ impl const super :: Hasher for SipHasher {
224
229
#[ inline]
225
230
fn write ( & mut self , msg : & [ u8 ] ) {
226
231
self . 0 . hasher . write ( msg)
@@ -238,7 +243,11 @@ impl super::Hasher for SipHasher {
238
243
}
239
244
240
245
#[ unstable( feature = "hashmap_internals" , issue = "none" ) ]
241
- impl super :: Hasher for SipHasher13 {
246
+ #[ rustc_const_unstable( feature = "const_hash" , issue = "none" ) ]
247
+ impl const super :: Hasher for SipHasher13
248
+ where
249
+ Hasher < Sip13Rounds > : ~const super :: Hasher ,
250
+ {
242
251
#[ inline]
243
252
fn write ( & mut self , msg : & [ u8 ] ) {
244
253
self . hasher . write ( msg)
@@ -255,7 +264,7 @@ impl super::Hasher for SipHasher13 {
255
264
}
256
265
}
257
266
258
- impl < S : Sip > super :: Hasher for Hasher < S > {
267
+ impl < S : ~ const Sip > const super :: Hasher for Hasher < S > {
259
268
// Note: no integer hashing methods (`write_u*`, `write_i*`) are defined
260
269
// for this type. We could add them, copy the `short_write` implementation
261
270
// in librustc_data_structures/sip128.rs, and add `write_u*`/`write_i*`
@@ -335,7 +344,7 @@ impl<S: Sip> super::Hasher for Hasher<S> {
335
344
}
336
345
}
337
346
338
- impl < S : Sip > Clone for Hasher < S > {
347
+ impl < S : Sip > const Clone for Hasher < S > {
339
348
#[ inline]
340
349
fn clone ( & self ) -> Hasher < S > {
341
350
Hasher {
@@ -359,6 +368,7 @@ impl<S: Sip> Default for Hasher<S> {
359
368
}
360
369
361
370
#[ doc( hidden) ]
371
+ #[ const_trait]
362
372
trait Sip {
363
373
fn c_rounds ( _: & mut State ) ;
364
374
fn d_rounds ( _: & mut State ) ;
@@ -367,7 +377,7 @@ trait Sip {
367
377
#[ derive( Debug , Clone , Default ) ]
368
378
struct Sip13Rounds ;
369
379
370
- impl Sip for Sip13Rounds {
380
+ impl const Sip for Sip13Rounds {
371
381
#[ inline]
372
382
fn c_rounds ( state : & mut State ) {
373
383
compress ! ( state) ;
@@ -384,7 +394,7 @@ impl Sip for Sip13Rounds {
384
394
#[ derive( Debug , Clone , Default ) ]
385
395
struct Sip24Rounds ;
386
396
387
- impl Sip for Sip24Rounds {
397
+ impl const Sip for Sip24Rounds {
388
398
#[ inline]
389
399
fn c_rounds ( state : & mut State ) {
390
400
compress ! ( state) ;
0 commit comments