2727#![ feature( specialization) ]
2828
2929use std:: borrow:: Cow ;
30- use std:: cell:: { Cell , RefCell } ;
30+ use std:: cell:: Cell ;
3131use std:: cmp:: { self , Ordering } ;
3232use std:: fmt;
3333use std:: hash:: { Hasher , Hash } ;
@@ -699,17 +699,17 @@ pub struct FileMap {
699699 pub src_hash : u128 ,
700700 /// The external source code (used for external crates, which will have a `None`
701701 /// value as `self.src`.
702- pub external_src : RefCell < ExternalSource > ,
702+ pub external_src : Lock < ExternalSource > ,
703703 /// The start position of this source in the CodeMap
704704 pub start_pos : BytePos ,
705705 /// The end position of this source in the CodeMap
706706 pub end_pos : BytePos ,
707707 /// Locations of lines beginnings in the source code
708- pub lines : RefCell < Vec < BytePos > > ,
708+ pub lines : Lock < Vec < BytePos > > ,
709709 /// Locations of multi-byte characters in the source code
710- pub multibyte_chars : RefCell < Vec < MultiByteChar > > ,
710+ pub multibyte_chars : Lock < Vec < MultiByteChar > > ,
711711 /// Width of characters that are not narrow in the source code
712- pub non_narrow_chars : RefCell < Vec < NonNarrowChar > > ,
712+ pub non_narrow_chars : Lock < Vec < NonNarrowChar > > ,
713713 /// A hash of the filename, used for speeding up the incr. comp. hashing.
714714 pub name_hash : u128 ,
715715}
@@ -839,10 +839,10 @@ impl Decodable for FileMap {
839839 end_pos,
840840 src : None ,
841841 src_hash,
842- external_src : RefCell :: new ( ExternalSource :: AbsentOk ) ,
843- lines : RefCell :: new ( lines) ,
844- multibyte_chars : RefCell :: new ( multibyte_chars) ,
845- non_narrow_chars : RefCell :: new ( non_narrow_chars) ,
842+ external_src : Lock :: new ( ExternalSource :: AbsentOk ) ,
843+ lines : Lock :: new ( lines) ,
844+ multibyte_chars : Lock :: new ( multibyte_chars) ,
845+ non_narrow_chars : Lock :: new ( non_narrow_chars) ,
846846 name_hash,
847847 } )
848848 } )
@@ -882,12 +882,12 @@ impl FileMap {
882882 crate_of_origin : 0 ,
883883 src : Some ( Lrc :: new ( src) ) ,
884884 src_hash,
885- external_src : RefCell :: new ( ExternalSource :: Unneeded ) ,
885+ external_src : Lock :: new ( ExternalSource :: Unneeded ) ,
886886 start_pos,
887887 end_pos : Pos :: from_usize ( end_pos) ,
888- lines : RefCell :: new ( Vec :: new ( ) ) ,
889- multibyte_chars : RefCell :: new ( Vec :: new ( ) ) ,
890- non_narrow_chars : RefCell :: new ( Vec :: new ( ) ) ,
888+ lines : Lock :: new ( Vec :: new ( ) ) ,
889+ multibyte_chars : Lock :: new ( Vec :: new ( ) ) ,
890+ non_narrow_chars : Lock :: new ( Vec :: new ( ) ) ,
891891 name_hash,
892892 }
893893 }
@@ -919,19 +919,24 @@ impl FileMap {
919919 if * self . external_src . borrow ( ) == ExternalSource :: AbsentOk {
920920 let src = get_src ( ) ;
921921 let mut external_src = self . external_src . borrow_mut ( ) ;
922- if let Some ( src) = src {
923- let mut hasher: StableHasher < u128 > = StableHasher :: new ( ) ;
924- hasher. write ( src. as_bytes ( ) ) ;
925-
926- if hasher. finish ( ) == self . src_hash {
927- * external_src = ExternalSource :: Present ( src) ;
928- return true ;
922+ // Check that no-one else have provided the source while we were getting it
923+ if * external_src == ExternalSource :: AbsentOk {
924+ if let Some ( src) = src {
925+ let mut hasher: StableHasher < u128 > = StableHasher :: new ( ) ;
926+ hasher. write ( src. as_bytes ( ) ) ;
927+
928+ if hasher. finish ( ) == self . src_hash {
929+ * external_src = ExternalSource :: Present ( src) ;
930+ return true ;
931+ }
932+ } else {
933+ * external_src = ExternalSource :: AbsentErr ;
929934 }
935+
936+ false
930937 } else {
931- * external_src = ExternalSource :: AbsentErr ;
938+ self . src . is_some ( ) || external_src . get_source ( ) . is_some ( )
932939 }
933-
934- false
935940 } else {
936941 self . src . is_some ( ) || self . external_src . borrow ( ) . get_source ( ) . is_some ( )
937942 }
@@ -951,14 +956,16 @@ impl FileMap {
951956 }
952957 }
953958
954- let lines = self . lines . borrow ( ) ;
955- let line = if let Some ( line) = lines. get ( line_number) {
956- line
957- } else {
958- return None ;
959+ let begin = {
960+ let lines = self . lines . borrow ( ) ;
961+ let line = if let Some ( line) = lines. get ( line_number) {
962+ line
963+ } else {
964+ return None ;
965+ } ;
966+ let begin: BytePos = * line - self . start_pos ;
967+ begin. to_usize ( )
959968 } ;
960- let begin: BytePos = * line - self . start_pos ;
961- let begin = begin. to_usize ( ) ;
962969
963970 if let Some ( ref src) = self . src {
964971 Some ( Cow :: from ( get_until_newline ( src, begin) ) )
0 commit comments