@@ -233,8 +233,6 @@ impl<'a, 'b, 'tcx> DecodeContext<'a, 'b, 'tcx> {
233
233
/// codemap as a side-effect of creating the crate_metadata's
234
234
/// `codemap_import_info`.
235
235
pub fn tr_span ( & self , span : Span ) -> Span {
236
- let imported_filemaps = & self . cdata . codemap_import_info [ ..] ;
237
-
238
236
let span = if span. lo > span. hi {
239
237
// Currently macro expansion sometimes produces invalid Span values
240
238
// where lo > hi. In order not to crash the compiler when trying to
@@ -248,16 +246,18 @@ impl<'a, 'b, 'tcx> DecodeContext<'a, 'b, 'tcx> {
248
246
span
249
247
} ;
250
248
251
- let filemap_index = {
249
+ let imported_filemaps = self . cdata . imported_filemaps ( self . tcx . sess . codemap ( ) ) ;
250
+ let filemap = {
252
251
// Optimize for the case that most spans within a translated item
253
252
// originate from the same filemap.
254
253
let last_filemap_index = self . last_filemap_index . get ( ) ;
254
+ let last_filemap = & imported_filemaps[ last_filemap_index] ;
255
255
256
- if span. lo >= imported_filemaps [ last_filemap_index ] . original_start_pos &&
257
- span. lo <= imported_filemaps [ last_filemap_index ] . original_end_pos &&
258
- span. hi >= imported_filemaps [ last_filemap_index ] . original_start_pos &&
259
- span. hi <= imported_filemaps [ last_filemap_index ] . original_end_pos {
260
- last_filemap_index
256
+ if span. lo >= last_filemap . original_start_pos &&
257
+ span. lo <= last_filemap . original_end_pos &&
258
+ span. hi >= last_filemap . original_start_pos &&
259
+ span. hi <= last_filemap . original_end_pos {
260
+ last_filemap
261
261
} else {
262
262
let mut a = 0 ;
263
263
let mut b = imported_filemaps. len ( ) ;
@@ -272,14 +272,14 @@ impl<'a, 'b, 'tcx> DecodeContext<'a, 'b, 'tcx> {
272
272
}
273
273
274
274
self . last_filemap_index . set ( a) ;
275
- a
275
+ & imported_filemaps [ a ]
276
276
}
277
277
} ;
278
278
279
- let lo = ( span. lo - imported_filemaps [ filemap_index ] . original_start_pos ) +
280
- imported_filemaps [ filemap_index ] . translated_filemap . start_pos ;
281
- let hi = ( span. hi - imported_filemaps [ filemap_index ] . original_start_pos ) +
282
- imported_filemaps [ filemap_index ] . translated_filemap . start_pos ;
279
+ let lo = ( span. lo - filemap . original_start_pos ) +
280
+ filemap . translated_filemap . start_pos ;
281
+ let hi = ( span. hi - filemap . original_start_pos ) +
282
+ filemap . translated_filemap . start_pos ;
283
283
284
284
codemap:: mk_sp ( lo, hi)
285
285
}
0 commit comments