@@ -2535,7 +2535,7 @@ fn assert_covariance() {
25352535mod test_map {
25362536 use super :: DefaultHashBuilder ;
25372537 use super :: Entry :: { Occupied , Vacant } ;
2538- use super :: HashMap ;
2538+ use super :: { HashMap , RawEntryMut } ;
25392539 use rand:: { rngs:: SmallRng , Rng , SeedableRng } ;
25402540 use std:: cell:: RefCell ;
25412541 use std:: usize;
@@ -3531,4 +3531,48 @@ mod test_map {
35313531 }
35323532 }
35333533
3534+ #[ test]
3535+ fn test_key_without_hash_impl ( ) {
3536+ #[ derive( Debug ) ]
3537+ struct IntWrapper ( u64 ) ;
3538+
3539+ let mut m: HashMap < IntWrapper , ( ) > = HashMap :: new ( ) ;
3540+ {
3541+ assert ! ( m. raw_entry( ) . from_hash( 0 , |k| k. 0 == 0 ) . is_none( ) ) ;
3542+ }
3543+ {
3544+ let vacant_entry = match m. raw_entry_mut ( ) . from_hash ( 0 , |k| k. 0 == 0 ) {
3545+ RawEntryMut :: Occupied ( ..) => panic ! ( "Found entry for key 0" ) ,
3546+ RawEntryMut :: Vacant ( e) => e,
3547+ } ;
3548+ vacant_entry. insert_with_hasher ( 0 , IntWrapper ( 0 ) , ( ) , |k| k. 0 ) ;
3549+ }
3550+ {
3551+ assert ! ( m. raw_entry( ) . from_hash( 0 , |k| k. 0 == 0 ) . is_some( ) ) ;
3552+ assert ! ( m. raw_entry( ) . from_hash( 1 , |k| k. 0 == 1 ) . is_none( ) ) ;
3553+ assert ! ( m. raw_entry( ) . from_hash( 2 , |k| k. 0 == 2 ) . is_none( ) ) ;
3554+ }
3555+ {
3556+ let vacant_entry = match m. raw_entry_mut ( ) . from_hash ( 1 , |k| k. 0 == 1 ) {
3557+ RawEntryMut :: Occupied ( ..) => panic ! ( "Found entry for key 1" ) ,
3558+ RawEntryMut :: Vacant ( e) => e,
3559+ } ;
3560+ vacant_entry. insert_with_hasher ( 1 , IntWrapper ( 1 ) , ( ) , |k| k. 0 ) ;
3561+ }
3562+ {
3563+ assert ! ( m. raw_entry( ) . from_hash( 0 , |k| k. 0 == 0 ) . is_some( ) ) ;
3564+ assert ! ( m. raw_entry( ) . from_hash( 1 , |k| k. 0 == 1 ) . is_some( ) ) ;
3565+ assert ! ( m. raw_entry( ) . from_hash( 2 , |k| k. 0 == 2 ) . is_none( ) ) ;
3566+ }
3567+ {
3568+ let occupied_entry = match m. raw_entry_mut ( ) . from_hash ( 0 , |k| k. 0 == 0 ) {
3569+ RawEntryMut :: Occupied ( e) => e,
3570+ RawEntryMut :: Vacant ( ..) => panic ! ( "Couldn't find entry for key 0" ) ,
3571+ } ;
3572+ occupied_entry. remove ( ) ;
3573+ }
3574+ assert ! ( m. raw_entry( ) . from_hash( 0 , |k| k. 0 == 0 ) . is_none( ) ) ;
3575+ assert ! ( m. raw_entry( ) . from_hash( 1 , |k| k. 0 == 1 ) . is_some( ) ) ;
3576+ assert ! ( m. raw_entry( ) . from_hash( 2 , |k| k. 0 == 2 ) . is_none( ) ) ;
3577+ }
35343578}
0 commit comments