Spanview needs the relevant body_span used for coverage
The coverage body_span doesn't always match the function body_span.
This commit is contained in:
parent
9daf546b77
commit
e354cca696
3 changed files with 11 additions and 8 deletions
|
@ -120,6 +120,7 @@ use rustc_index::vec::Idx;
|
||||||
use rustc_middle::mir::coverage::*;
|
use rustc_middle::mir::coverage::*;
|
||||||
use rustc_middle::mir::{self, BasicBlock, TerminatorKind};
|
use rustc_middle::mir::{self, BasicBlock, TerminatorKind};
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
|
use rustc_span::Span;
|
||||||
|
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::lazy::SyncOnceCell;
|
use std::lazy::SyncOnceCell;
|
||||||
|
@ -636,6 +637,7 @@ pub(super) fn dump_coverage_spanview(
|
||||||
mir_body: &mir::Body<'tcx>,
|
mir_body: &mir::Body<'tcx>,
|
||||||
basic_coverage_blocks: &CoverageGraph,
|
basic_coverage_blocks: &CoverageGraph,
|
||||||
pass_name: &str,
|
pass_name: &str,
|
||||||
|
body_span: Span,
|
||||||
coverage_spans: &Vec<CoverageSpan>,
|
coverage_spans: &Vec<CoverageSpan>,
|
||||||
) {
|
) {
|
||||||
let mir_source = mir_body.source;
|
let mir_source = mir_body.source;
|
||||||
|
@ -647,7 +649,7 @@ pub(super) fn dump_coverage_spanview(
|
||||||
let crate_name = tcx.crate_name(def_id.krate);
|
let crate_name = tcx.crate_name(def_id.krate);
|
||||||
let item_name = tcx.def_path(def_id).to_filename_friendly_no_crate();
|
let item_name = tcx.def_path(def_id).to_filename_friendly_no_crate();
|
||||||
let title = format!("{}.{} - Coverage Spans", crate_name, item_name);
|
let title = format!("{}.{} - Coverage Spans", crate_name, item_name);
|
||||||
spanview::write_document(tcx, def_id, span_viewables, &title, &mut file)
|
spanview::write_document(tcx, body_span, span_viewables, &title, &mut file)
|
||||||
.expect("Unexpected IO error dumping coverage spans as HTML");
|
.expect("Unexpected IO error dumping coverage spans as HTML");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -204,6 +204,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
|
||||||
self.mir_body,
|
self.mir_body,
|
||||||
&self.basic_coverage_blocks,
|
&self.basic_coverage_blocks,
|
||||||
self.pass_name,
|
self.pass_name,
|
||||||
|
body_span,
|
||||||
&coverage_spans,
|
&coverage_spans,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,7 +131,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
write_document(tcx, def_id, span_viewables, title, w)?;
|
write_document(tcx, fn_span(tcx, def_id), span_viewables, title, w)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ where
|
||||||
/// list `SpanViewable`s.
|
/// list `SpanViewable`s.
|
||||||
pub fn write_document<'tcx, W>(
|
pub fn write_document<'tcx, W>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
def_id: DefId,
|
spanview_span: Span,
|
||||||
mut span_viewables: Vec<SpanViewable>,
|
mut span_viewables: Vec<SpanViewable>,
|
||||||
title: &str,
|
title: &str,
|
||||||
w: &mut W,
|
w: &mut W,
|
||||||
|
@ -147,16 +147,16 @@ pub fn write_document<'tcx, W>(
|
||||||
where
|
where
|
||||||
W: Write,
|
W: Write,
|
||||||
{
|
{
|
||||||
let fn_span = fn_span(tcx, def_id);
|
let mut from_pos = spanview_span.lo();
|
||||||
let mut from_pos = fn_span.lo();
|
let end_pos = spanview_span.hi();
|
||||||
let end_pos = fn_span.hi();
|
|
||||||
let source_map = tcx.sess.source_map();
|
let source_map = tcx.sess.source_map();
|
||||||
let start = source_map.lookup_char_pos(from_pos);
|
let start = source_map.lookup_char_pos(from_pos);
|
||||||
let indent_to_initial_start_col = " ".repeat(start.col.to_usize());
|
let indent_to_initial_start_col = " ".repeat(start.col.to_usize());
|
||||||
debug!(
|
debug!(
|
||||||
"fn_span source is:\n{}{}",
|
"spanview_span={:?}; source is:\n{}{}",
|
||||||
|
spanview_span,
|
||||||
indent_to_initial_start_col,
|
indent_to_initial_start_col,
|
||||||
source_map.span_to_snippet(fn_span).expect("function should have printable source")
|
source_map.span_to_snippet(spanview_span).expect("function should have printable source")
|
||||||
);
|
);
|
||||||
writeln!(w, "{}", HEADER)?;
|
writeln!(w, "{}", HEADER)?;
|
||||||
writeln!(w, "<title>{}</title>", title)?;
|
writeln!(w, "<title>{}</title>", title)?;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue