File tree Expand file tree Collapse file tree 2 files changed +22
-7
lines changed Expand file tree Collapse file tree 2 files changed +22
-7
lines changed Original file line number Diff line number Diff line change @@ -567,13 +567,8 @@ impl CodeMapper for CodeMap {
567
567
} ;
568
568
569
569
if * file_map. external_src . borrow ( ) == ExternalSource :: AbsentOk {
570
- let mut external_src = file_map. external_src . borrow_mut ( ) ;
571
- if let Ok ( src) = self . file_loader . read_file ( Path :: new ( & filename) ) {
572
- * external_src = ExternalSource :: Present ( src) ;
573
- return true ;
574
- } else {
575
- * external_src = ExternalSource :: AbsentErr ;
576
- }
570
+ let src = self . file_loader . read_file ( Path :: new ( & filename) ) . ok ( ) ;
571
+ return file_map. add_external_src ( src) ;
577
572
}
578
573
579
574
false
Original file line number Diff line number Diff line change @@ -604,6 +604,26 @@ impl FileMap {
604
604
lines. push ( pos) ;
605
605
}
606
606
607
+ /// add externally loaded source.
608
+ /// if the hash of the input doesn't match or no input is supplied via None,
609
+ /// it is interpreted as an error and the corresponding enum variant is set.
610
+ pub fn add_external_src ( & self , src : Option < String > ) -> bool {
611
+ let mut external_src = self . external_src . borrow_mut ( ) ;
612
+ if let Some ( src) = src {
613
+ let mut hasher: StableHasher < u128 > = StableHasher :: new ( ) ;
614
+ hasher. write ( src. as_bytes ( ) ) ;
615
+
616
+ if hasher. finish ( ) == self . src_hash {
617
+ * external_src = ExternalSource :: Present ( src) ;
618
+ return true ;
619
+ }
620
+ } else {
621
+ * external_src = ExternalSource :: AbsentErr ;
622
+ }
623
+
624
+ false
625
+ }
626
+
607
627
/// get a line from the list of pre-computed line-beginnings.
608
628
/// line-number here is 0-based.
609
629
pub fn get_line ( & self , line_number : usize ) -> Option < Cow < str > > {
You can’t perform that action at this time.
0 commit comments