@@ -144,9 +144,6 @@ pub struct SourceMap {
144
144
// This is used to apply the file path remapping as specified via
145
145
// --remap-path-prefix to all SourceFiles allocated within this SourceMap.
146
146
path_mapping : FilePathMapping ,
147
- /// In case we are in a doctest, replace all file names with the PathBuf,
148
- /// and add the given offsets to the line info
149
- doctest_offset : Option < ( FileName , isize ) > ,
150
147
}
151
148
152
149
impl SourceMap {
@@ -155,27 +152,16 @@ impl SourceMap {
155
152
files : Default :: default ( ) ,
156
153
file_loader : Box :: new ( RealFileLoader ) ,
157
154
path_mapping,
158
- doctest_offset : None ,
159
155
}
160
156
}
161
157
162
- pub fn new_doctest ( path_mapping : FilePathMapping ,
163
- file : FileName , line : isize ) -> SourceMap {
164
- SourceMap {
165
- doctest_offset : Some ( ( file, line) ) ,
166
- ..SourceMap :: new ( path_mapping)
167
- }
168
-
169
- }
170
-
171
158
pub fn with_file_loader ( file_loader : Box < dyn FileLoader + Sync + Send > ,
172
159
path_mapping : FilePathMapping )
173
160
-> SourceMap {
174
161
SourceMap {
175
162
files : Default :: default ( ) ,
176
163
file_loader : file_loader,
177
164
path_mapping,
178
- doctest_offset : None ,
179
165
}
180
166
}
181
167
@@ -189,11 +175,7 @@ impl SourceMap {
189
175
190
176
pub fn load_file ( & self , path : & Path ) -> io:: Result < Lrc < SourceFile > > {
191
177
let src = self . file_loader . read_file ( path) ?;
192
- let filename = if let Some ( ( ref name, _) ) = self . doctest_offset {
193
- name. clone ( )
194
- } else {
195
- path. to_owned ( ) . into ( )
196
- } ;
178
+ let filename = path. to_owned ( ) . into ( ) ;
197
179
Ok ( self . new_source_file ( filename, src) )
198
180
}
199
181
@@ -328,15 +310,17 @@ impl SourceMap {
328
310
}
329
311
330
312
// If there is a doctest_offset, apply it to the line
331
- pub fn doctest_offset_line ( & self , mut orig : usize ) -> usize {
332
- if let Some ( ( _, line) ) = self . doctest_offset {
333
- if line >= 0 {
334
- orig = orig + line as usize ;
335
- } else {
336
- orig = orig - ( -line) as usize ;
337
- }
313
+ pub fn doctest_offset_line ( & self , file : & FileName , orig : usize ) -> usize {
314
+ return match file {
315
+ FileName :: DocTest ( _, offset) => {
316
+ return if * offset >= 0 {
317
+ orig + * offset as usize
318
+ } else {
319
+ orig - ( -( * offset) ) as usize
320
+ }
321
+ } ,
322
+ _ => orig
338
323
}
339
- orig
340
324
}
341
325
342
326
/// Lookup source information about a BytePos
@@ -1001,8 +985,8 @@ impl SourceMapper for SourceMap {
1001
985
}
1002
986
)
1003
987
}
1004
- fn doctest_offset_line ( & self , line : usize ) -> usize {
1005
- self . doctest_offset_line ( line)
988
+ fn doctest_offset_line ( & self , file : & FileName , line : usize ) -> usize {
989
+ self . doctest_offset_line ( file , line)
1006
990
}
1007
991
}
1008
992
0 commit comments