Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
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
209 changes: 176 additions & 33 deletions compiler/rustc_mir/src/transform/coverage/spans.rs

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions compiler/rustc_mir/src/transform/coverage/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
//! This crate hosts a selection of "unit tests" for components of the `InstrumentCoverage` MIR
//! pass.
//!
//! ```shell
//! ./x.py test --keep-stage 1 compiler/rustc_mir --test-args '--show-output coverage'
//! ```
//!
//! The tests construct a few "mock" objects, as needed, to support the `InstrumentCoverage`
//! functions and algorithms. Mocked objects include instances of `mir::Body`; including
//! `Terminator`s of various `kind`s, and `Span` objects. Some functions used by or used on
Expand Down Expand Up @@ -679,10 +683,15 @@ fn test_make_bcb_counters() {
let mut basic_coverage_blocks = graph::CoverageGraph::from_mir(&mir_body);
let mut coverage_spans = Vec::new();
for (bcb, data) in basic_coverage_blocks.iter_enumerated() {
if let Some(span) =
if let Some((span, expn_span)) =
spans::filtered_terminator_span(data.terminator(&mir_body), body_span)
{
coverage_spans.push(spans::CoverageSpan::for_terminator(span, bcb, data.last_bb()));
coverage_spans.push(spans::CoverageSpan::for_terminator(
span,
expn_span,
bcb,
data.last_bb(),
));
}
}
let mut coverage_counters = counters::CoverageCounters::new(0);
Expand Down
19 changes: 10 additions & 9 deletions compiler/rustc_mir/src/util/spanview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ where
W: Write,
{
let def_id = body.source.def_id();
let body_span = hir_body(tcx, def_id).value.span;
let hir_body = hir_body(tcx, def_id);
if hir_body.is_none() {
return Ok(());
}
let body_span = hir_body.unwrap().value.span;
let mut span_viewables = Vec::new();
for (bb, data) in body.basic_blocks().iter_enumerated() {
match spanview {
Expand Down Expand Up @@ -664,19 +668,16 @@ fn fn_span<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Span {
let hir_id =
tcx.hir().local_def_id_to_hir_id(def_id.as_local().expect("expected DefId is local"));
let fn_decl_span = tcx.hir().span(hir_id);
let body_span = hir_body(tcx, def_id).value.span;
if fn_decl_span.ctxt() == body_span.ctxt() {
fn_decl_span.to(body_span)
if let Some(body_span) = hir_body(tcx, def_id).map(|hir_body| hir_body.value.span) {
if fn_decl_span.ctxt() == body_span.ctxt() { fn_decl_span.to(body_span) } else { body_span }
} else {
// This probably occurs for functions defined via macros
body_span
fn_decl_span
}
}

fn hir_body<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx rustc_hir::Body<'tcx> {
fn hir_body<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option<&'tcx rustc_hir::Body<'tcx>> {
let hir_node = tcx.hir().get_if_local(def_id).expect("expected DefId is local");
let fn_body_id = hir::map::associated_body(hir_node).expect("HIR node is a function with body");
tcx.hir().body(fn_body_id)
hir::map::associated_body(hir_node).map(|fn_body_id| tcx.hir().body(fn_body_id))
}

fn escape_html(s: &str) -> String {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
1| |#![allow(unused_assignments, unused_variables, dead_code)]
2| |
3| 1|fn main() {
4| | // Initialize test constants in a way that cannot be determined at compile time, to ensure
5| | // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from
6| | // dependent conditions.
4| 1| // Initialize test constants in a way that cannot be determined at compile time, to ensure
5| 1| // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from
6| 1| // dependent conditions.
7| 1| let is_true = std::env::args().len() == 1;
8| 1|
9| 1| let mut countdown = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
1| |// This demonstrated Issue #84561: function-like macros produce unintuitive coverage results.
2| |
3| |// expect-exit-status-101
4| 21|#[derive(PartialEq, Eq)]
^0
------------------
| <issue_84561::Foo as core::cmp::PartialEq>::eq:
| 4| 21|#[derive(PartialEq, Eq)]
------------------
| Unexecuted instantiation: <issue_84561::Foo as core::cmp::PartialEq>::ne
------------------
5| |struct Foo(u32);
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));
10| 1| let baz = Foo(0);
11| 1| assert_ne!(baz, Foo(1));
12| 1| println!("{:?}", Foo(1));
13| 1| println!("{:?}", bar);
14| 1| println!("{:?}", baz);
15| 1|
16| 1| assert_eq!(Foo(1), Foo(1));
17| 1| assert_ne!(Foo(0), Foo(1));
18| 1| assert_eq!(Foo(2), Foo(2));
19| 1| let bar = Foo(0);
20| 1| assert_ne!(bar, Foo(3));
21| 1| assert_ne!(Foo(0), Foo(4));
22| 1| assert_eq!(Foo(3), Foo(3), "with a message");
^0
23| 1| println!("{:?}", bar);
24| 1| println!("{:?}", Foo(1));
25| 1|
26| 1| assert_ne!(Foo(0), Foo(5), "{}", if is_true { "true message" } else { "false message" });
^0 ^0 ^0
27| 1| assert_ne!(
28| | Foo(0)
29| | ,
30| | Foo(5)
31| | ,
32| 0| "{}"
33| 0| ,
34| 0| if
35| 0| is_true
36| | {
37| 0| "true message"
38| | } else {
39| 0| "false message"
40| | }
41| | );
42| |
43| 1| let is_true = std::env::args().len() == 1;
44| 1|
45| 1| assert_eq!(
46| 1| Foo(1),
47| 1| Foo(1)
48| 1| );
49| 1| assert_ne!(
50| 1| Foo(0),
51| 1| Foo(1)
52| 1| );
53| 1| assert_eq!(
54| 1| Foo(2),
55| 1| Foo(2)
56| 1| );
57| 1| let bar = Foo(1);
58| 1| assert_ne!(
59| 1| bar,
60| 1| Foo(3)
61| 1| );
62| 1| if is_true {
63| 1| assert_ne!(
64| 1| Foo(0),
65| 1| Foo(4)
66| 1| );
67| | } else {
68| 0| assert_eq!(
69| 0| Foo(3),
70| 0| Foo(3)
71| 0| );
72| | }
73| 1| if is_true {
74| 1| assert_ne!(
75| | Foo(0),
76| | Foo(4),
77| 0| "with a message"
78| | );
79| | } else {
80| 0| assert_eq!(
81| | Foo(3),
82| | Foo(3),
83| 0| "with a message"
84| | );
85| | }
86| 1| assert_ne!(
87| 1| if is_true {
88| 1| Foo(0)
89| | } else {
90| 0| Foo(1)
91| | },
92| | Foo(5)
93| | );
94| 1| assert_ne!(
95| 1| Foo(5),
96| 1| if is_true {
97| 1| Foo(0)
98| | } else {
99| 0| Foo(1)
100| | }
101| | );
102| 1| assert_ne!(
103| 1| if is_true {
104| 1| assert_eq!(
105| 1| Foo(3),
106| 1| Foo(3)
107| 1| );
108| 1| Foo(0)
109| | } else {
110| 0| assert_ne!(
111| 0| if is_true {
112| 0| Foo(0)
113| | } else {
114| 0| Foo(1)
115| | },
116| | Foo(5)
117| | );
118| 0| Foo(1)
119| | },
120| | Foo(5),
121| 0| "with a message"
122| | );
123| 1| assert_eq!(
124| | Foo(1),
125| | Foo(3),
126| 1| "this assert should fail"
127| | );
128| 0| assert_eq!(
129| | Foo(3),
130| | Foo(3),
131| 0| "this assert should not be reached"
132| | );
133| 0|}
134| |
135| |impl std::fmt::Debug for Foo {
136| | fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
137| 7| write!(f, "try and succeed")?;
^0
138| 7| Ok(())
139| 7| }
140| |}
141| |
142| |static mut DEBUG_LEVEL_ENABLED: bool = false;
143| |
144| |macro_rules! debug {
145| | ($($arg:tt)+) => (
146| | if unsafe { DEBUG_LEVEL_ENABLED } {
147| | println!($($arg)+);
148| | }
149| | );
150| |}
151| |
152| 1|fn test1() {
153| 1| debug!("debug is enabled");
^0
154| 1| debug!("debug is enabled");
^0
155| 1| let _ = 0;
156| 1| debug!("debug is enabled");
^0
157| 1| unsafe {
158| 1| DEBUG_LEVEL_ENABLED = true;
159| 1| }
160| 1| debug!("debug is enabled");
161| 1|}
162| |
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|}

Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
3| |use std::fmt::Debug;
4| |
5| 1|pub fn used_function() {
6| | // Initialize test constants in a way that cannot be determined at compile time, to ensure
7| | // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from
8| | // dependent conditions.
6| 1| // Initialize test constants in a way that cannot be determined at compile time, to ensure
7| 1| // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from
8| 1| // dependent conditions.
9| 1| let is_true = std::env::args().len() == 1;
10| 1| let mut countdown = 0;
11| 1| if is_true {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
5| |use std::fmt::Debug;
6| |
7| 1|pub fn used_function() {
8| | // Initialize test constants in a way that cannot be determined at compile time, to ensure
9| | // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from
10| | // dependent conditions.
8| 1| // Initialize test constants in a way that cannot be determined at compile time, to ensure
9| 1| // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from
10| 1| // dependent conditions.
11| 1| let is_true = std::env::args().len() == 1;
12| 1| let mut countdown = 0;
13| 1| if is_true {
Expand All @@ -19,9 +19,9 @@
18| |
19| |#[inline(always)]
20| 1|pub fn used_inline_function() {
21| | // Initialize test constants in a way that cannot be determined at compile time, to ensure
22| | // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from
23| | // dependent conditions.
21| 1| // Initialize test constants in a way that cannot be determined at compile time, to ensure
22| 1| // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from
23| 1| // dependent conditions.
24| 1| let is_true = std::env::args().len() == 1;
25| 1| let mut countdown = 0;
26| 1| if is_true {
Expand Down
Loading