@@ -174,7 +174,7 @@ impl<T: Source + Hash + PartialEq + Eq + 'static> Hash for CachedSource<T> {
174174 fn hash < H : std:: hash:: Hasher > ( & self , state : & mut H ) {
175175 ( self . cached_hash . get_or_init ( || {
176176 let mut hasher = FxHasher :: default ( ) ;
177- hasher . write ( self . source ( ) . as_bytes ( ) ) ;
177+ self . inner . hash ( & mut hasher ) ;
178178 hasher. finish ( )
179179 } ) )
180180 . hash ( state) ;
@@ -208,8 +208,8 @@ mod tests {
208208 use std:: borrow:: Borrow ;
209209
210210 use crate :: {
211- ConcatSource , OriginalSource , RawSource , SourceExt , SourceMapSource ,
212- WithoutOriginalOptions ,
211+ ConcatSource , OriginalSource , RawSource , ReplaceSource , SourceExt ,
212+ SourceMapSource , WithoutOriginalOptions ,
213213 } ;
214214
215215 use super :: * ;
@@ -364,4 +364,27 @@ mod tests {
364364 source. source ( ) ;
365365 assert_eq ! ( source. buffer( ) , buf. as_slice( ) ) ;
366366 }
367+
368+ #[ test]
369+ fn hash_should_different_when_map_are_different ( ) {
370+ let hash1 = {
371+ let mut source =
372+ ReplaceSource :: new ( OriginalSource :: new ( "Hello" , "hello.txt" ) . boxed ( ) ) ;
373+ source. insert ( 5 , " world" , None ) ;
374+ let cache = CachedSource :: new ( source) ;
375+ let mut hasher = FxHasher :: default ( ) ;
376+ cache. hash ( & mut hasher) ;
377+ hasher. finish ( )
378+ } ;
379+
380+ let hash2 = {
381+ let source = OriginalSource :: new ( "Hello world" , "hello.txt" ) . boxed ( ) ;
382+ let cache = CachedSource :: new ( source) ;
383+ let mut hasher = FxHasher :: default ( ) ;
384+ cache. hash ( & mut hasher) ;
385+ hasher. finish ( )
386+ } ;
387+
388+ assert ! ( hash1 != hash2) ;
389+ }
367390}
0 commit comments