Skip to content

Commit 0c0d102

Browse files
committed
Spanview needs the relevant body_span used for coverage
The coverage body_span doesn't always match the function body_span.
1 parent 36cb289 commit 0c0d102

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

compiler/rustc_mir/src/transform/coverage/debug.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ use rustc_index::vec::Idx;
120120
use rustc_middle::mir::coverage::*;
121121
use rustc_middle::mir::{self, BasicBlock, TerminatorKind};
122122
use rustc_middle::ty::TyCtxt;
123+
use rustc_span::Span;
123124

124125
use std::iter;
125126
use std::lazy::SyncOnceCell;
@@ -636,6 +637,7 @@ pub(super) fn dump_coverage_spanview(
636637
mir_body: &mir::Body<'tcx>,
637638
basic_coverage_blocks: &CoverageGraph,
638639
pass_name: &str,
640+
body_span: Span,
639641
coverage_spans: &Vec<CoverageSpan>,
640642
) {
641643
let mir_source = mir_body.source;
@@ -647,7 +649,7 @@ pub(super) fn dump_coverage_spanview(
647649
let crate_name = tcx.crate_name(def_id.krate);
648650
let item_name = tcx.def_path(def_id).to_filename_friendly_no_crate();
649651
let title = format!("{}.{} - Coverage Spans", crate_name, item_name);
650-
spanview::write_document(tcx, def_id, span_viewables, &title, &mut file)
652+
spanview::write_document(tcx, body_span, span_viewables, &title, &mut file)
651653
.expect("Unexpected IO error dumping coverage spans as HTML");
652654
}
653655

compiler/rustc_mir/src/transform/coverage/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
204204
self.mir_body,
205205
&self.basic_coverage_blocks,
206206
self.pass_name,
207+
body_span,
207208
&coverage_spans,
208209
);
209210
}

compiler/rustc_mir/src/util/spanview.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,32 +131,32 @@ where
131131
}
132132
}
133133
}
134-
write_document(tcx, def_id, span_viewables, title, w)?;
134+
write_document(tcx, fn_span(tcx, def_id), span_viewables, title, w)?;
135135
Ok(())
136136
}
137137

138138
/// Generate a spanview HTML+CSS document for the given local function `def_id`, and a pre-generated
139139
/// list `SpanViewable`s.
140140
pub fn write_document<'tcx, W>(
141141
tcx: TyCtxt<'tcx>,
142-
def_id: DefId,
142+
spanview_span: Span,
143143
mut span_viewables: Vec<SpanViewable>,
144144
title: &str,
145145
w: &mut W,
146146
) -> io::Result<()>
147147
where
148148
W: Write,
149149
{
150-
let fn_span = fn_span(tcx, def_id);
151-
let mut from_pos = fn_span.lo();
152-
let end_pos = fn_span.hi();
150+
let mut from_pos = spanview_span.lo();
151+
let end_pos = spanview_span.hi();
153152
let source_map = tcx.sess.source_map();
154153
let start = source_map.lookup_char_pos(from_pos);
155154
let indent_to_initial_start_col = " ".repeat(start.col.to_usize());
156155
debug!(
157-
"fn_span source is:\n{}{}",
156+
"spanview_span={:?}; source is:\n{}{}",
157+
spanview_span,
158158
indent_to_initial_start_col,
159-
source_map.span_to_snippet(fn_span).expect("function should have printable source")
159+
source_map.span_to_snippet(spanview_span).expect("function should have printable source")
160160
);
161161
writeln!(w, "{}", HEADER)?;
162162
writeln!(w, "<title>{}</title>", title)?;

0 commit comments

Comments
 (0)