@@ -28,7 +28,7 @@ use rustc_middle::mir::{
28
28
use rustc_middle:: ty:: TyCtxt ;
29
29
use rustc_span:: def_id:: DefId ;
30
30
use rustc_span:: source_map:: SourceMap ;
31
- use rustc_span:: { CharPos , ExpnKind , Pos , SourceFile , Span , Symbol } ;
31
+ use rustc_span:: { ExpnKind , SourceFile , Span , Symbol } ;
32
32
33
33
/// A simple error message wrapper for `coverage::Error`s.
34
34
#[ derive( Debug ) ]
@@ -314,8 +314,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
314
314
} ;
315
315
graphviz_data. add_bcb_coverage_span_with_counter ( bcb, & covspan, & counter_kind) ;
316
316
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) ;
319
318
320
319
inject_statement (
321
320
self . mir_body ,
@@ -510,40 +509,36 @@ fn inject_intermediate_expression(mir_body: &mut mir::Body<'_>, expression: Cove
510
509
fn make_code_region (
511
510
source_map : & SourceMap ,
512
511
file_name : Symbol ,
513
- source_file : & Lrc < SourceFile > ,
514
512
span : Span ,
515
513
body_span : Span ,
516
514
) -> CodeRegion {
517
515
debug ! (
518
- "Called make_code_region(file_name={}, source_file={:?}, span={}, body_span={})" ,
516
+ "Called make_code_region(file_name={}, span={}, body_span={})" ,
519
517
file_name,
520
- source_file,
521
518
source_map. span_to_diagnostic_string( span) ,
522
519
source_map. span_to_diagnostic_string( body_span)
523
520
) ;
524
521
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 ( ) {
528
525
// Extend an empty span by one character so the region will be counted.
529
- let CharPos ( char_pos) = start_col;
530
526
if span. hi ( ) == body_span. hi ( ) {
531
- start_col = CharPos ( char_pos . saturating_sub ( 1 ) ) ;
527
+ start_col = start_col . saturating_sub ( 1 ) ;
532
528
} else {
533
- end_col = CharPos ( char_pos + 1 ) ;
529
+ end_col = start_col + 1 ;
534
530
}
535
- ( end_line, end_col)
536
- } else {
537
- source_file. lookup_file_pos ( span. hi ( ) )
538
531
} ;
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
+ }
541
536
CodeRegion {
542
537
file_name,
543
538
start_line : start_line as u32 ,
544
- start_col : start_col. to_u32 ( ) + 1 ,
539
+ start_col : start_col as u32 ,
545
540
end_line : end_line as u32 ,
546
- end_col : end_col. to_u32 ( ) + 1 ,
541
+ end_col : end_col as u32 ,
547
542
}
548
543
}
549
544
0 commit comments