File tree Expand file tree Collapse file tree 4 files changed +28
-4
lines changed Expand file tree Collapse file tree 4 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -131,7 +131,7 @@ impl EmitterWriter {
131
131
}
132
132
}
133
133
134
- fn preprocess_annotations ( & self , msp : & MultiSpan ) -> Vec < FileWithAnnotatedLines > {
134
+ fn preprocess_annotations ( & mut self , msp : & MultiSpan ) -> Vec < FileWithAnnotatedLines > {
135
135
fn add_annotation_to_file ( file_vec : & mut Vec < FileWithAnnotatedLines > ,
136
136
file : Rc < FileMap > ,
137
137
line_index : usize ,
@@ -175,6 +175,9 @@ impl EmitterWriter {
175
175
if span_label. span == DUMMY_SP {
176
176
continue ;
177
177
}
178
+
179
+ cm. load_source_for_filemap ( cm. span_to_filename ( span_label. span ) ) ;
180
+
178
181
let lo = cm. lookup_char_pos ( span_label. span . lo ) ;
179
182
let mut hi = cm. lookup_char_pos ( span_label. span . hi ) ;
180
183
Original file line number Diff line number Diff line change @@ -103,7 +103,7 @@ pub trait CodeMapper {
103
103
fn span_to_filename ( & self , sp : Span ) -> FileName ;
104
104
fn merge_spans ( & self , sp_lhs : Span , sp_rhs : Span ) -> Option < Span > ;
105
105
fn call_span_if_macro ( & self , sp : Span ) -> Span ;
106
- fn load_source_for_filemap ( & mut self , file : FileName ) -> bool ;
106
+ fn load_source_for_filemap ( & self , file : FileName ) -> bool ;
107
107
}
108
108
109
109
impl CodeSuggestion {
Original file line number Diff line number Diff line change @@ -559,7 +559,7 @@ impl CodeMapper for CodeMap {
559
559
}
560
560
sp
561
561
}
562
- fn load_source_for_filemap ( & mut self , filename : FileName ) -> bool {
562
+ fn load_source_for_filemap ( & self , filename : FileName ) -> bool {
563
563
let file_map = if let Some ( fm) = self . get_filemap ( & filename) {
564
564
fm
565
565
} else {
Original file line number Diff line number Diff line change @@ -374,14 +374,35 @@ pub struct MultiByteChar {
374
374
pub bytes : usize ,
375
375
}
376
376
377
+ /// The state of the lazy external source loading mechanism of a FileMap.
377
378
#[ derive( PartialEq , Eq , Clone ) ]
378
379
pub enum ExternalSource {
380
+ /// The external source has been loaded already.
379
381
Present ( String ) ,
382
+ /// No attempt has been made to load the external source.
380
383
AbsentOk ,
384
+ /// A failed attempt has been made to load the external source.
381
385
AbsentErr ,
386
+ /// No external source has to be loaded, since the FileMap represents a local crate.
382
387
Unneeded ,
383
388
}
384
389
390
+ impl ExternalSource {
391
+ pub fn is_absent ( & self ) -> bool {
392
+ match * self {
393
+ ExternalSource :: Present ( _) => false ,
394
+ _ => true ,
395
+ }
396
+ }
397
+
398
+ pub fn get_source ( & self ) -> Option < & str > {
399
+ match * self {
400
+ ExternalSource :: Present ( ref src) => Some ( src) ,
401
+ _ => None ,
402
+ }
403
+ }
404
+ }
405
+
385
406
/// A single source in the CodeMap.
386
407
#[ derive( Clone ) ]
387
408
pub struct FileMap {
@@ -620,7 +641,7 @@ impl FileMap {
620
641
}
621
642
622
643
pub fn is_imported ( & self ) -> bool {
623
- self . src . is_none ( )
644
+ self . src . is_none ( ) // TODO: change to something more sensible
624
645
}
625
646
626
647
pub fn byte_length ( & self ) -> u32 {
You can’t perform that action at this time.
0 commit comments