55//! the `Span` to `CoverageRegion` conversion defined in
66//! https://github.com/rust-lang/rust/tree/master/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/spans.rs
77
8- use rustc_middle:: mir:: coverage:: FunctionCoverageInfo ;
98use rustc_span:: Span ;
109use rustc_span:: source_map:: SourceMap ;
1110use rustc_span:: { BytePos , SourceFile } ;
@@ -27,33 +26,22 @@ impl Debug for SourceRegion {
2726 }
2827}
2928
30- fn ensure_non_empty_span (
31- source_map : & SourceMap ,
32- fn_cov_info : & FunctionCoverageInfo ,
33- span : Span ,
34- ) -> Option < Span > {
29+ fn ensure_non_empty_span ( source_map : & SourceMap , span : Span ) -> Option < Span > {
3530 if !span. is_empty ( ) {
3631 return Some ( span) ;
3732 }
38- let lo = span. lo ( ) ;
39- let hi = span. hi ( ) ;
40- // The span is empty, so try to expand it to cover an adjacent '{' or '}',
41- // but only within the bounds of the body span.
42- let try_next = hi < fn_cov_info. body_span . hi ( ) ;
43- let try_prev = fn_cov_info. body_span . lo ( ) < lo;
44- if !( try_next || try_prev) {
45- return None ;
46- }
33+
34+ // The span is empty, so try to enlarge it to cover an adjacent '{' or '}'.
4735 source_map
4836 . span_to_source ( span, |src, start, end| try {
4937 // Adjusting span endpoints by `BytePos(1)` is normally a bug,
5038 // but in this case we have specifically checked that the character
5139 // we're skipping over is one of two specific ASCII characters, so
5240 // adjusting by exactly 1 byte is correct.
53- if try_next && src. as_bytes ( ) [ end] == b'{' {
54- Some ( span. with_hi ( hi + BytePos ( 1 ) ) )
55- } else if try_prev && src. as_bytes ( ) [ start - 1 ] == b'}' {
56- Some ( span. with_lo ( lo - BytePos ( 1 ) ) )
41+ if src. as_bytes ( ) . get ( end) . copied ( ) == Some ( b'{' ) {
42+ Some ( span. with_hi ( span . hi ( ) + BytePos ( 1 ) ) )
43+ } else if start > 0 && src. as_bytes ( ) [ start - 1 ] == b'}' {
44+ Some ( span. with_lo ( span . lo ( ) - BytePos ( 1 ) ) )
5745 } else {
5846 None
5947 }
@@ -104,11 +92,10 @@ fn check_source_region(source_region: SourceRegion) -> Option<SourceRegion> {
10492/// better than an ICE or `llvm-cov` failure that the user might have no way to avoid.
10593pub ( crate ) fn make_source_region (
10694 source_map : & SourceMap ,
107- fn_cov_info : & FunctionCoverageInfo ,
10895 file : & SourceFile ,
10996 span : Span ,
11097) -> Option < SourceRegion > {
111- let span = ensure_non_empty_span ( source_map, fn_cov_info , span) ?;
98+ let span = ensure_non_empty_span ( source_map, span) ?;
11299 let lo = span. lo ( ) ;
113100 let hi = span. hi ( ) ;
114101 // Column numbers need to be in bytes, so we can't use the more convenient
0 commit comments