|
1 | 1 | use rustc_data_structures::captures::Captures;
|
2 | 2 | use rustc_middle::mir::{
|
3 |
| - self, FakeReadCause, Statement, StatementKind, Terminator, TerminatorKind, |
| 3 | + self, AggregateKind, FakeReadCause, Rvalue, Statement, StatementKind, Terminator, |
| 4 | + TerminatorKind, |
4 | 5 | };
|
5 | 6 | use rustc_span::Span;
|
6 | 7 |
|
@@ -59,24 +60,35 @@ fn bcb_to_initial_coverage_spans<'a, 'tcx>(
|
59 | 60 | ) -> impl Iterator<Item = CoverageSpan> + Captures<'a> + Captures<'tcx> {
|
60 | 61 | bcb_data.basic_blocks.iter().flat_map(move |&bb| {
|
61 | 62 | let data = &mir_body[bb];
|
62 |
| - data.statements |
63 |
| - .iter() |
64 |
| - .filter_map(move |statement| { |
65 |
| - filtered_statement_span(statement).map(|span| { |
66 |
| - CoverageSpan::for_statement( |
67 |
| - statement, |
68 |
| - function_source_span(span, body_span), |
69 |
| - span, |
70 |
| - bcb, |
71 |
| - ) |
72 |
| - }) |
73 |
| - }) |
74 |
| - .chain(filtered_terminator_span(data.terminator()).map(|span| { |
75 |
| - CoverageSpan::for_terminator(function_source_span(span, body_span), span, bcb) |
76 |
| - })) |
| 63 | + |
| 64 | + let statement_spans = data.statements.iter().filter_map(move |statement| { |
| 65 | + let expn_span = filtered_statement_span(statement)?; |
| 66 | + let span = function_source_span(expn_span, body_span); |
| 67 | + |
| 68 | + Some(CoverageSpan::new(span, expn_span, bcb, is_closure(statement))) |
| 69 | + }); |
| 70 | + |
| 71 | + let terminator_span = Some(data.terminator()).into_iter().filter_map(move |terminator| { |
| 72 | + let expn_span = filtered_terminator_span(terminator)?; |
| 73 | + let span = function_source_span(expn_span, body_span); |
| 74 | + |
| 75 | + Some(CoverageSpan::new(span, expn_span, bcb, false)) |
| 76 | + }); |
| 77 | + |
| 78 | + statement_spans.chain(terminator_span) |
77 | 79 | })
|
78 | 80 | }
|
79 | 81 |
|
| 82 | +fn is_closure(statement: &Statement<'_>) -> bool { |
| 83 | + match statement.kind { |
| 84 | + StatementKind::Assign(box (_, Rvalue::Aggregate(box ref agg_kind, _))) => match agg_kind { |
| 85 | + AggregateKind::Closure(_, _) | AggregateKind::Coroutine(_, _, _) => true, |
| 86 | + _ => false, |
| 87 | + }, |
| 88 | + _ => false, |
| 89 | + } |
| 90 | +} |
| 91 | + |
80 | 92 | /// If the MIR `Statement` has a span contributive to computing coverage spans,
|
81 | 93 | /// return it; otherwise return `None`.
|
82 | 94 | fn filtered_statement_span(statement: &Statement<'_>) -> Option<Span> {
|
|
0 commit comments