Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3090b01
Use flex more consistently.
Apr 22, 2021
5bd3187
Point out that behavior might be switched on 2015 and 2018 editions t…
est31 Apr 26, 2021
12642d9
Add a paragraph with possible alternatives on older editions
est31 Apr 27, 2021
aeb67ad
Drop branching blocks with same span as expanded macro
richkadel Apr 26, 2021
2c4fc3e
More improvements to macro coverage
richkadel Apr 26, 2021
bbf6bce
spanview debug output caused ICE when a function had no body
richkadel Apr 25, 2021
fd85fd3
addressed review feedback
richkadel Apr 28, 2021
31ae3b2
Add HAS_RE_LATE_BOUND if there are bound vars
jackh726 Apr 28, 2021
5f82e22
Don't rebind in transitive_bounds_that_define_assoc_type
jackh726 Apr 28, 2021
3e016a7
Minor grammar tweaks for readability
Ben-Lichtman Apr 29, 2021
8c04695
Remove unnecessary CSS rules for search results
GuillaumeGomez Apr 29, 2021
a20831e
Remove unneeded bottom margin on search results
GuillaumeGomez Apr 29, 2021
a352336
Ignore doctests in bootstrap
est31 Apr 29, 2021
da6261e
make feature recommendations optional
lcnr Apr 29, 2021
20b569f
Drop alias `reduce` for `fold` - we have a `reduce` function
joshtriplett Apr 29, 2021
16ff6c8
Fix labels for regression issue template
camelid Apr 29, 2021
2fb2f0b
Add std::os::unix::fs::chroot to change the root directory of the cur…
joshtriplett Apr 29, 2021
6d18bcf
Rollup merge of #84451 - torhovland:flex, r=jsha
jackh726 Apr 29, 2021
49effb0
Rollup merge of #84582 - richkadel:issue-84561, r=tmandry
jackh726 Apr 29, 2021
f82e345
Rollup merge of #84590 - est31:array_into_iter, r=nikomatsakis
jackh726 Apr 29, 2021
b88ea41
Rollup merge of #84682 - jackh726:transitive_bounds_rebind, r=nikomat…
jackh726 Apr 29, 2021
9274e3c
Rollup merge of #84683 - Ben-Lichtman:grammar, r=jonas-schievink
jackh726 Apr 29, 2021
dbaefd3
Rollup merge of #84688 - GuillaumeGomez:remove-unnecessary-css-for-se…
jackh726 Apr 29, 2021
d2c6ba2
Rollup merge of #84690 - GuillaumeGomez:unneeded-bottom-margin-search…
jackh726 Apr 29, 2021
6f279a3
Rollup merge of #84705 - lcnr:const_generics-rec, r=joshtriplett
jackh726 Apr 29, 2021
39f0fdc
Rollup merge of #84706 - joshtriplett:reduce-aliases, r=m-ou-se
jackh726 Apr 29, 2021
7702e48
Rollup merge of #84713 - camelid:fix-regression-issue-template, r=Mar…
jackh726 Apr 29, 2021
ac134c3
Rollup merge of #84716 - joshtriplett:chroot, r=dtolnay
jackh726 Apr 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
addressed review feedback
  • Loading branch information
richkadel committed Apr 28, 2021
commit fd85fd308b536bd42073f58636358ca147822947
52 changes: 40 additions & 12 deletions compiler/rustc_mir/src/transform/coverage/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use rustc_middle::ty::TyCtxt;
use rustc_span::source_map::original_sp;
use rustc_span::{BytePos, ExpnKind, MacroKind, Span, Symbol};

use std::cell::RefCell;
use std::cmp::Ordering;

#[derive(Debug, Copy, Clone)]
Expand Down Expand Up @@ -68,6 +69,7 @@ impl CoverageStatement {
pub(super) struct CoverageSpan {
pub span: Span,
pub expn_span: Span,
pub current_macro_or_none: RefCell<Option<Option<Symbol>>>,
pub bcb: BasicCoverageBlock,
pub coverage_statements: Vec<CoverageStatement>,
pub is_closure: bool,
Expand All @@ -78,6 +80,7 @@ impl CoverageSpan {
Self {
span: fn_sig_span,
expn_span: fn_sig_span,
current_macro_or_none: Default::default(),
bcb: START_BCB,
coverage_statements: vec![],
is_closure: false,
Expand All @@ -103,6 +106,7 @@ impl CoverageSpan {
Self {
span,
expn_span,
current_macro_or_none: Default::default(),
bcb,
coverage_statements: vec![CoverageStatement::Statement(bb, span, stmt_index)],
is_closure,
Expand All @@ -118,6 +122,7 @@ impl CoverageSpan {
Self {
span,
expn_span,
current_macro_or_none: Default::default(),
bcb,
coverage_statements: vec![CoverageStatement::Terminator(bb, span)],
is_closure: false,
Expand Down Expand Up @@ -174,15 +179,19 @@ impl CoverageSpan {
.join("\n")
}

/// If the span is part of a macro, and the macro is visible (expands directly to the given
/// body_span), returns the macro name symbol.
/// If the span is part of a macro, returns the macro name symbol.
pub fn current_macro(&self) -> Option<Symbol> {
if let ExpnKind::Macro(MacroKind::Bang, current_macro) =
self.expn_span.ctxt().outer_expn_data().kind
{
return Some(current_macro);
}
None
self.current_macro_or_none
.borrow_mut()
.get_or_insert_with(|| {
if let ExpnKind::Macro(MacroKind::Bang, current_macro) =
self.expn_span.ctxt().outer_expn_data().kind
{
return Some(current_macro);
}
None
})
.map(|symbol| symbol)
}

/// If the span is part of a macro, and the macro is visible (expands directly to the given
Expand Down Expand Up @@ -474,8 +483,8 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
self.curr().expn_span.ctxt() != prev_expn_span.ctxt()
}) {
let merged_prefix_len = self.curr_original_span.lo() - self.curr().span.lo();
let after_macro_bang = merged_prefix_len
+ BytePos(visible_macro.to_string().bytes().count() as u32 + 1);
let after_macro_bang =
merged_prefix_len + BytePos(visible_macro.as_str().bytes().count() as u32 + 1);
let mut macro_name_cov = self.curr().clone();
self.curr_mut().span =
self.curr().span.with_lo(self.curr().span.lo() + after_macro_bang);
Expand Down Expand Up @@ -766,6 +775,9 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
}
}

/// See `function_source_span()` for a description of the two returned spans.
/// If the MIR `Statement` is not contributive to computing coverage spans,
/// returns `None`.
pub(super) fn filtered_statement_span(
statement: &'a Statement<'tcx>,
body_span: Span,
Expand Down Expand Up @@ -811,6 +823,9 @@ pub(super) fn filtered_statement_span(
}
}

/// See `function_source_span()` for a description of the two returned spans.
/// If the MIR `Terminator` is not contributive to computing coverage spans,
/// returns `None`.
pub(super) fn filtered_terminator_span(
terminator: &'a Terminator<'tcx>,
body_span: Span,
Expand Down Expand Up @@ -844,8 +859,21 @@ pub(super) fn filtered_terminator_span(
}
}

/// Returns the span within the function source body, and the given span, which will be different
/// if the given span is an expansion (macro, syntactic sugar, etc.).
/// Returns two spans from the given span (the span associated with a
/// `Statement` or `Terminator`):
///
/// 1. An extrapolated span (pre-expansion[^1]) corresponding to a range within
/// the function's body source. This span is guaranteed to be contained
/// within, or equal to, the `body_span`. If the extrapolated span is not
/// contained within the `body_span`, the `body_span` is returned.
/// 2. The actual `span` value from the `Statement`, before expansion.
///
/// Only the first span is used when computing coverage code regions. The second
/// span is useful if additional expansion data is needed (such as to look up
/// the macro name for a composed span within that macro).)
///
/// [^1]Expansions result from Rust syntax including macros, syntactic
/// sugar, etc.).
#[inline]
fn function_source_span(span: Span, body_span: Span) -> (Span, Span) {
let original_span = original_sp(span, body_span).with_ctxt(body_span.ctxt());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
| Unexecuted instantiation: <issue_84561::Foo as core::cmp::PartialEq>::ne
------------------
5| |struct Foo(u32);
6| 1|fn test2() {
6| 1|fn test3() {
7| 1| let is_true = std::env::args().len() == 1;
8| 1| let bar = Foo(1);
9| 1| assert_eq!(bar, Foo(1));
Expand Down Expand Up @@ -173,8 +173,24 @@
160| 1| debug!("debug is enabled");
161| 1|}
162| |
163| 1|fn main() {
164| 1| test1();
165| 1| test2();
166| 1|}
163| |macro_rules! call_debug {
164| | ($($arg:tt)+) => (
165| 1| fn call_print(s: &str) {
166| 1| print!("{}", s);
167| 1| }
168| |
169| | call_print("called from call_debug: ");
170| | debug!($($arg)+);
171| | );
172| |}
173| |
174| 1|fn test2() {
175| 1| call_debug!("debug is enabled");
176| 1|}
177| |
178| 1|fn main() {
179| 1| test1();
180| 1| test2();
181| 1| test3();
182| 1|}

18 changes: 17 additions & 1 deletion src/test/run-make-fulldeps/coverage/issue-84561.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// expect-exit-status-101
#[derive(PartialEq, Eq)]
struct Foo(u32);
fn test2() {
fn test3() {
let is_true = std::env::args().len() == 1;
let bar = Foo(1);
assert_eq!(bar, Foo(1));
Expand Down Expand Up @@ -160,7 +160,23 @@ fn test1() {
debug!("debug is enabled");
}

macro_rules! call_debug {
($($arg:tt)+) => (
fn call_print(s: &str) {
print!("{}", s);
}

call_print("called from call_debug: ");
debug!($($arg)+);
);
}

fn test2() {
call_debug!("debug is enabled");
}

fn main() {
test1();
test2();
test3();
}