@@ -118,7 +118,7 @@ macro_rules! load_int_le {
118118/// Safety: this performs unchecked indexing of `buf` at `start..start+len`, so
119119/// that must be in-bounds.
120120#[ 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 {
122122 debug_assert ! ( len < 8 ) ;
123123 let mut i = 0 ; // current byte index (from LSB) in the output u64
124124 let mut out = 0 ;
@@ -138,7 +138,7 @@ unsafe fn u8to64_le(buf: &[u8], start: usize, len: usize) -> u64 {
138138 out |= ( unsafe { * buf. get_unchecked ( start + i) } as u64 ) << ( i * 8 ) ;
139139 i += 1 ;
140140 }
141- debug_assert_eq ! ( i, len) ;
141+ debug_assert ! ( i == len) ;
142142 out
143143}
144144
@@ -150,8 +150,9 @@ impl SipHasher {
150150 since = "1.13.0" ,
151151 note = "use `std::collections::hash_map::DefaultHasher` instead"
152152 ) ]
153+ #[ rustc_const_unstable( feature = "const_hash" , issue = "none" ) ]
153154 #[ must_use]
154- pub fn new ( ) -> SipHasher {
155+ pub const fn new ( ) -> SipHasher {
155156 SipHasher :: new_with_keys ( 0 , 0 )
156157 }
157158
@@ -162,8 +163,9 @@ impl SipHasher {
162163 since = "1.13.0" ,
163164 note = "use `std::collections::hash_map::DefaultHasher` instead"
164165 ) ]
166+ #[ rustc_const_unstable( feature = "const_hash" , issue = "none" ) ]
165167 #[ 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 {
167169 SipHasher ( SipHasher24 { hasher : Hasher :: new_with_keys ( key0, key1) } )
168170 }
169171}
@@ -176,7 +178,8 @@ impl SipHasher13 {
176178 since = "1.13.0" ,
177179 note = "use `std::collections::hash_map::DefaultHasher` instead"
178180 ) ]
179- pub fn new ( ) -> SipHasher13 {
181+ #[ rustc_const_unstable( feature = "const_hash" , issue = "none" ) ]
182+ pub const fn new ( ) -> SipHasher13 {
180183 SipHasher13 :: new_with_keys ( 0 , 0 )
181184 }
182185
@@ -187,14 +190,15 @@ impl SipHasher13 {
187190 since = "1.13.0" ,
188191 note = "use `std::collections::hash_map::DefaultHasher` instead"
189192 ) ]
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 {
191195 SipHasher13 { hasher : Hasher :: new_with_keys ( key0, key1) }
192196 }
193197}
194198
195199impl < S : Sip > Hasher < S > {
196200 #[ inline]
197- fn new_with_keys ( key0 : u64 , key1 : u64 ) -> Hasher < S > {
201+ const fn new_with_keys ( key0 : u64 , key1 : u64 ) -> Hasher < S > {
198202 let mut state = Hasher {
199203 k0 : key0,
200204 k1 : key1,
@@ -209,7 +213,7 @@ impl<S: Sip> Hasher<S> {
209213 }
210214
211215 #[ inline]
212- fn reset ( & mut self ) {
216+ const fn reset ( & mut self ) {
213217 self . length = 0 ;
214218 self . state . v0 = self . k0 ^ 0x736f6d6570736575 ;
215219 self . state . v1 = self . k1 ^ 0x646f72616e646f6d ;
@@ -220,7 +224,8 @@ impl<S: Sip> Hasher<S> {
220224}
221225
222226#[ 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 {
224229 #[ inline]
225230 fn write ( & mut self , msg : & [ u8 ] ) {
226231 self . 0 . hasher . write ( msg)
@@ -238,7 +243,11 @@ impl super::Hasher for SipHasher {
238243}
239244
240245#[ 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+ {
242251 #[ inline]
243252 fn write ( & mut self , msg : & [ u8 ] ) {
244253 self . hasher . write ( msg)
@@ -255,7 +264,7 @@ impl super::Hasher for SipHasher13 {
255264 }
256265}
257266
258- impl < S : Sip > super :: Hasher for Hasher < S > {
267+ impl < S : ~ const Sip > const super :: Hasher for Hasher < S > {
259268 // Note: no integer hashing methods (`write_u*`, `write_i*`) are defined
260269 // for this type. We could add them, copy the `short_write` implementation
261270 // in librustc_data_structures/sip128.rs, and add `write_u*`/`write_i*`
@@ -335,7 +344,7 @@ impl<S: Sip> super::Hasher for Hasher<S> {
335344 }
336345}
337346
338- impl < S : Sip > Clone for Hasher < S > {
347+ impl < S : Sip > const Clone for Hasher < S > {
339348 #[ inline]
340349 fn clone ( & self ) -> Hasher < S > {
341350 Hasher {
@@ -359,6 +368,7 @@ impl<S: Sip> Default for Hasher<S> {
359368}
360369
361370#[ doc( hidden) ]
371+ #[ const_trait]
362372trait Sip {
363373 fn c_rounds ( _: & mut State ) ;
364374 fn d_rounds ( _: & mut State ) ;
@@ -367,7 +377,7 @@ trait Sip {
367377#[ derive( Debug , Clone , Default ) ]
368378struct Sip13Rounds ;
369379
370- impl Sip for Sip13Rounds {
380+ impl const Sip for Sip13Rounds {
371381 #[ inline]
372382 fn c_rounds ( state : & mut State ) {
373383 compress ! ( state) ;
@@ -384,7 +394,7 @@ impl Sip for Sip13Rounds {
384394#[ derive( Debug , Clone , Default ) ]
385395struct Sip24Rounds ;
386396
387- impl Sip for Sip24Rounds {
397+ impl const Sip for Sip24Rounds {
388398 #[ inline]
389399 fn c_rounds ( state : & mut State ) {
390400 compress ! ( state) ;
0 commit comments