@@ -28,7 +28,7 @@ use rustc_middle::mir::{
2828use rustc_middle:: ty:: TyCtxt ;
2929use rustc_span:: def_id:: DefId ;
3030use rustc_span:: source_map:: SourceMap ;
31- use rustc_span:: { CharPos , ExpnKind , Pos , SourceFile , Span , Symbol } ;
31+ use rustc_span:: { ExpnKind , SourceFile , Span , Symbol } ;
3232
3333/// A simple error message wrapper for `coverage::Error`s.
3434#[ derive( Debug ) ]
@@ -314,8 +314,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
314314 } ;
315315 graphviz_data. add_bcb_coverage_span_with_counter ( bcb, & covspan, & counter_kind) ;
316316
317- let code_region =
318- make_code_region ( source_map, file_name, & self . source_file , span, body_span) ;
317+ let code_region = make_code_region ( source_map, file_name, span, body_span) ;
319318
320319 inject_statement (
321320 self . mir_body ,
@@ -510,40 +509,36 @@ fn inject_intermediate_expression(mir_body: &mut mir::Body<'_>, expression: Cove
510509fn make_code_region (
511510 source_map : & SourceMap ,
512511 file_name : Symbol ,
513- source_file : & Lrc < SourceFile > ,
514512 span : Span ,
515513 body_span : Span ,
516514) -> CodeRegion {
517515 debug ! (
518- "Called make_code_region(file_name={}, source_file={:?}, span={}, body_span={})" ,
516+ "Called make_code_region(file_name={}, span={}, body_span={})" ,
519517 file_name,
520- source_file,
521518 source_map. span_to_diagnostic_string( span) ,
522519 source_map. span_to_diagnostic_string( body_span)
523520 ) ;
524521
525- let ( start_line, mut start_col) = source_file . lookup_file_pos ( span . lo ( ) ) ;
526- let ( end_line , end_col ) = if span . hi ( ) == span. lo ( ) {
527- let ( end_line , mut end_col ) = ( start_line , start_col ) ;
522+ let ( file , mut start_line, mut start_col, mut end_line , mut end_col ) =
523+ source_map . span_to_location_info ( span) ;
524+ if span . hi ( ) == span . lo ( ) {
528525 // Extend an empty span by one character so the region will be counted.
529- let CharPos ( char_pos) = start_col;
530526 if span. hi ( ) == body_span. hi ( ) {
531- start_col = CharPos ( char_pos . saturating_sub ( 1 ) ) ;
527+ start_col = start_col . saturating_sub ( 1 ) ;
532528 } else {
533- end_col = CharPos ( char_pos + 1 ) ;
529+ end_col = start_col + 1 ;
534530 }
535- ( end_line, end_col)
536- } else {
537- source_file. lookup_file_pos ( span. hi ( ) )
538531 } ;
539- let start_line = source_map. doctest_offset_line ( & source_file. name , start_line) ;
540- let end_line = source_map. doctest_offset_line ( & source_file. name , end_line) ;
532+ if let Some ( file) = file {
533+ start_line = source_map. doctest_offset_line ( & file. name , start_line) ;
534+ end_line = source_map. doctest_offset_line ( & file. name , end_line) ;
535+ }
541536 CodeRegion {
542537 file_name,
543538 start_line : start_line as u32 ,
544- start_col : start_col. to_u32 ( ) + 1 ,
539+ start_col : start_col as u32 ,
545540 end_line : end_line as u32 ,
546- end_col : end_col. to_u32 ( ) + 1 ,
541+ end_col : end_col as u32 ,
547542 }
548543}
549544
0 commit comments