Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e15ec66

Browse files
committedDec 15, 2020
Auto merge of rust-lang#80055 - GuillaumeGomez:rollup-p09mweg, r=GuillaumeGomez
Rollup of 6 pull requests Successful merges: - rust-lang#79379 (Show hidden elements by default when JS is disabled) - rust-lang#79796 (Hide associated constants too when collapsing implementation) - rust-lang#79958 (Fixes reported bugs in Rust Coverage) - rust-lang#80008 (Fix `cargo-binutils` link) - rust-lang#80016 (Use imports instead of rewriting the type signature of `RustcOptGroup::stable`) - rust-lang#80025 (Replace some `println!` with `tidy_error!` to simplify) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 99baddb + 0dcf99b commit e15ec66

File tree

25 files changed

+657
-96
lines changed

25 files changed

+657
-96
lines changed
 

‎compiler/rustc_interface/src/tests.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ fn test_debugging_options_tracking_hash() {
587587
tracked!(share_generics, Some(true));
588588
tracked!(show_span, Some(String::from("abc")));
589589
tracked!(src_hash_algorithm, Some(SourceFileHashAlgorithm::Sha1));
590-
tracked!(symbol_mangling_version, SymbolManglingVersion::V0);
590+
tracked!(symbol_mangling_version, Some(SymbolManglingVersion::V0));
591591
tracked!(teach, true);
592592
tracked!(thinlto, Some(true));
593593
tracked!(tune_cpu, Some(String::from("abc")));

‎compiler/rustc_metadata/src/creader.rs‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -706,14 +706,21 @@ impl<'a> CrateLoader<'a> {
706706
self.inject_dependency_if(cnum, "a panic runtime", &|data| data.needs_panic_runtime());
707707
}
708708

709-
fn inject_profiler_runtime(&mut self) {
709+
fn inject_profiler_runtime(&mut self, krate: &ast::Crate) {
710710
if (self.sess.opts.debugging_opts.instrument_coverage
711711
|| self.sess.opts.debugging_opts.profile
712712
|| self.sess.opts.cg.profile_generate.enabled())
713713
&& !self.sess.opts.debugging_opts.no_profiler_runtime
714714
{
715715
info!("loading profiler");
716716

717+
if self.sess.contains_name(&krate.attrs, sym::no_core) {
718+
self.sess.err(
719+
"`profiler_builtins` crate (required by compiler options) \
720+
is not compatible with crate attribute `#![no_core]`",
721+
);
722+
}
723+
717724
let name = sym::profiler_builtins;
718725
let cnum = self.resolve_crate(name, DUMMY_SP, CrateDepKind::Implicit, None);
719726
let data = self.cstore.get_crate_data(cnum);
@@ -879,7 +886,7 @@ impl<'a> CrateLoader<'a> {
879886
}
880887

881888
pub fn postprocess(&mut self, krate: &ast::Crate) {
882-
self.inject_profiler_runtime();
889+
self.inject_profiler_runtime(krate);
883890
self.inject_allocator_crate(krate);
884891
self.inject_panic_runtime(krate);
885892

‎compiler/rustc_metadata/src/rmeta/encoder.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
663663
no_builtins: tcx.sess.contains_name(&attrs, sym::no_builtins),
664664
panic_runtime: tcx.sess.contains_name(&attrs, sym::panic_runtime),
665665
profiler_runtime: tcx.sess.contains_name(&attrs, sym::profiler_runtime),
666-
symbol_mangling_version: tcx.sess.opts.debugging_opts.symbol_mangling_version,
666+
symbol_mangling_version: tcx.sess.opts.debugging_opts.get_symbol_mangling_version(),
667667

668668
crate_deps,
669669
dylib_dependency_formats,

‎compiler/rustc_mir/src/transform/coverage/graph.rs‎

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,28 @@ impl CoverageGraph {
3232

3333
// Pre-transform MIR `BasicBlock` successors and predecessors into the BasicCoverageBlock
3434
// equivalents. Note that since the BasicCoverageBlock graph has been fully simplified, the
35-
// each predecessor of a BCB leader_bb should be in a unique BCB, and each successor of a
36-
// BCB last_bb should be in its own unique BCB. Therefore, collecting the BCBs using
37-
// `bb_to_bcb` should work without requiring a deduplication step.
35+
// each predecessor of a BCB leader_bb should be in a unique BCB. It is possible for a
36+
// `SwitchInt` to have multiple targets to the same destination `BasicBlock`, so
37+
// de-duplication is required. This is done without reordering the successors.
3838

39+
let bcbs_len = bcbs.len();
40+
let mut seen = IndexVec::from_elem_n(false, bcbs_len);
3941
let successors = IndexVec::from_fn_n(
4042
|bcb| {
43+
for b in seen.iter_mut() {
44+
*b = false;
45+
}
4146
let bcb_data = &bcbs[bcb];
42-
let bcb_successors =
47+
let mut bcb_successors = Vec::new();
48+
for successor in
4349
bcb_filtered_successors(&mir_body, &bcb_data.terminator(mir_body).kind)
4450
.filter_map(|&successor_bb| bb_to_bcb[successor_bb])
45-
.collect::<Vec<_>>();
46-
debug_assert!({
47-
let mut sorted = bcb_successors.clone();
48-
sorted.sort_unstable();
49-
let initial_len = sorted.len();
50-
sorted.dedup();
51-
sorted.len() == initial_len
52-
});
51+
{
52+
if !seen[successor] {
53+
seen[successor] = true;
54+
bcb_successors.push(successor);
55+
}
56+
}
5357
bcb_successors
5458
},
5559
bcbs.len(),

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ impl<'tcx> MirPass<'tcx> for InstrumentCoverage {
7878
return;
7979
}
8080

81+
match mir_body.basic_blocks()[mir::START_BLOCK].terminator().kind {
82+
TerminatorKind::Unreachable => {
83+
trace!("InstrumentCoverage skipped for unreachable `START_BLOCK`");
84+
return;
85+
}
86+
_ => {}
87+
}
88+
8189
trace!("InstrumentCoverage starting for {:?}", mir_source.def_id());
8290
Instrumentor::new(&self.name(), tcx, mir_body).inject_counters();
8391
trace!("InstrumentCoverage starting for {:?}", mir_source.def_id());

‎compiler/rustc_mir/src/transform/inline.rs‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,6 @@ impl<'tcx> MirPass<'tcx> for Inline {
4141
return;
4242
}
4343

44-
if tcx.sess.opts.debugging_opts.instrument_coverage {
45-
// The current implementation of source code coverage injects code region counters
46-
// into the MIR, and assumes a 1-to-1 correspondence between MIR and source-code-
47-
// based function.
48-
debug!("function inlining is disabled when compiling with `instrument_coverage`");
49-
return;
50-
}
51-
5244
if inline(tcx, body) {
5345
debug!("running simplify cfg on {:?}", body.source);
5446
CfgSimplifier::new(body).simplify();

‎compiler/rustc_session/src/config.rs‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,10 @@ impl DebuggingOptions {
692692
deduplicate_diagnostics: self.deduplicate_diagnostics,
693693
}
694694
}
695+
696+
pub fn get_symbol_mangling_version(&self) -> SymbolManglingVersion {
697+
self.symbol_mangling_version.unwrap_or(SymbolManglingVersion::Legacy)
698+
}
695699
}
696700

697701
// The type of entry function, so users can have their own entry functions
@@ -1757,7 +1761,30 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
17571761
// and reversible name mangling. Note, LLVM coverage tools can analyze coverage over
17581762
// multiple runs, including some changes to source code; so mangled names must be consistent
17591763
// across compilations.
1760-
debugging_opts.symbol_mangling_version = SymbolManglingVersion::V0;
1764+
match debugging_opts.symbol_mangling_version {
1765+
None => {
1766+
debugging_opts.symbol_mangling_version = Some(SymbolManglingVersion::V0);
1767+
}
1768+
Some(SymbolManglingVersion::Legacy) => {
1769+
early_warn(
1770+
error_format,
1771+
"-Z instrument-coverage requires symbol mangling version `v0`, \
1772+
but `-Z symbol-mangling-version=legacy` was specified",
1773+
);
1774+
}
1775+
Some(SymbolManglingVersion::V0) => {}
1776+
}
1777+
1778+
if debugging_opts.mir_opt_level > 1 {
1779+
early_warn(
1780+
error_format,
1781+
&format!(
1782+
"`-Z mir-opt-level={}` (any level > 1) enables function inlining, which \
1783+
limits the effectiveness of `-Z instrument-coverage`.",
1784+
debugging_opts.mir_opt_level,
1785+
),
1786+
);
1787+
}
17611788
}
17621789

17631790
if let Ok(graphviz_font) = std::env::var("RUSTC_GRAPHVIZ_FONT") {
@@ -2162,7 +2189,7 @@ crate mod dep_tracking {
21622189
impl_dep_tracking_hash_via_hash!(Edition);
21632190
impl_dep_tracking_hash_via_hash!(LinkerPluginLto);
21642191
impl_dep_tracking_hash_via_hash!(SwitchWithOptPath);
2165-
impl_dep_tracking_hash_via_hash!(SymbolManglingVersion);
2192+
impl_dep_tracking_hash_via_hash!(Option<SymbolManglingVersion>);
21662193
impl_dep_tracking_hash_via_hash!(Option<SourceFileHashAlgorithm>);
21672194
impl_dep_tracking_hash_via_hash!(TrimmedDefPaths);
21682195

‎compiler/rustc_session/src/options.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -677,12 +677,12 @@ macro_rules! options {
677677
}
678678

679679
fn parse_symbol_mangling_version(
680-
slot: &mut SymbolManglingVersion,
680+
slot: &mut Option<SymbolManglingVersion>,
681681
v: Option<&str>,
682682
) -> bool {
683683
*slot = match v {
684-
Some("legacy") => SymbolManglingVersion::Legacy,
685-
Some("v0") => SymbolManglingVersion::V0,
684+
Some("legacy") => Some(SymbolManglingVersion::Legacy),
685+
Some("v0") => Some(SymbolManglingVersion::V0),
686686
_ => return false,
687687
};
688688
true
@@ -1088,9 +1088,9 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
10881088
"hash algorithm of source files in debug info (`md5`, `sha1`, or `sha256`)"),
10891089
strip: Strip = (Strip::None, parse_strip, [UNTRACKED],
10901090
"tell the linker which information to strip (`none` (default), `debuginfo` or `symbols`)"),
1091-
symbol_mangling_version: SymbolManglingVersion = (SymbolManglingVersion::Legacy,
1091+
symbol_mangling_version: Option<SymbolManglingVersion> = (None,
10921092
parse_symbol_mangling_version, [TRACKED],
1093-
"which mangling version to use for symbol names"),
1093+
"which mangling version to use for symbol names ('legacy' (default) or 'v0')"),
10941094
teach: bool = (false, parse_bool, [TRACKED],
10951095
"show extended diagnostic help (default: no)"),
10961096
terminal_width: Option<usize> = (None, parse_opt_uint, [UNTRACKED],

‎compiler/rustc_symbol_mangling/src/lib.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ fn compute_symbol_name(
245245
// 2. we favor `instantiating_crate` where possible (i.e. when `Some`)
246246
let mangling_version_crate = instantiating_crate.unwrap_or(def_id.krate);
247247
let mangling_version = if mangling_version_crate == LOCAL_CRATE {
248-
tcx.sess.opts.debugging_opts.symbol_mangling_version
248+
tcx.sess.opts.debugging_opts.get_symbol_mangling_version()
249249
} else {
250250
tcx.symbol_mangling_version(mangling_version_crate)
251251
};

‎src/doc/unstable-book/src/compiler-flags/source-based-code-coverage.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ LLVM's supplies two tools—`llvm-profdata` and `llvm-cov`—that process covera
118118
* If you are building the Rust compiler from source, you can optionally use the bundled LLVM tools, built from source. Those tool binaries can typically be found in your build platform directory at something like: `rust/build/x86_64-unknown-linux-gnu/llvm/bin/llvm-*`.
119119
* You can install compatible versions of these tools via `rustup`.
120120

121-
The `rustup` option is guaranteed to install a compatible version of the LLVM tools, but they can be hard to find. We recommend [`cargo-bintools`], which installs Rust-specific wrappers around these and other LLVM tools, so you can invoke them via `cargo` commands!
121+
The `rustup` option is guaranteed to install a compatible version of the LLVM tools, but they can be hard to find. We recommend [`cargo-binutils`], which installs Rust-specific wrappers around these and other LLVM tools, so you can invoke them via `cargo` commands!
122122

123123
```shell
124124
$ rustup component add llvm-tools-preview
@@ -320,8 +320,8 @@ Rust's implementation and workflow for source-based code coverage is based on th
320320
[rustc-dev-guide-how-to-build-and-run]: https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html
321321
[`rustfilt`]: https://crates.io/crates/rustfilt
322322
[`json5format`]: https://crates.io/crates/json5format
323-
[`cargo-bintools`]: https://crates.io/crates/cargo-bintools
323+
[`cargo-binutils`]: https://crates.io/crates/cargo-binutils
324324
[`llvm-profdata merge`]: https://llvm.org/docs/CommandGuide/llvm-profdata.html#profdata-merge
325325
[`llvm-cov report`]: https://llvm.org/docs/CommandGuide/llvm-cov.html#llvm-cov-report
326326
[`llvm-cov show`]: https://llvm.org/docs/CommandGuide/llvm-cov.html#llvm-cov-show
327-
[source-based code coverage in Clang]: https://clang.llvm.org/docs/SourceBasedCodeCoverage.html
327+
[source-based code coverage in Clang]: https://clang.llvm.org/docs/SourceBasedCodeCoverage.html

‎src/librustdoc/html/static/main.js‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,9 +2274,12 @@ function defocusSearchBar() {
22742274

22752275
function implHider(addOrRemove, fullHide) {
22762276
return function(n) {
2277-
var is_method = hasClass(n, "method") || fullHide;
2278-
if (is_method || hasClass(n, "type")) {
2279-
if (is_method === true) {
2277+
var shouldHide =
2278+
fullHide === true ||
2279+
hasClass(n, "method") === true ||
2280+
hasClass(n, "associatedconstant") === true;
2281+
if (shouldHide === true || hasClass(n, "type") === true) {
2282+
if (shouldHide === true) {
22802283
if (addOrRemove) {
22812284
addClass(n, "hidden-by-impl-hider");
22822285
} else {

‎src/librustdoc/html/static/noscript.css‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/*
2+
This whole CSS file is used only in case rustdoc is rendered with javascript disabled. Since a lot
3+
of content is hidden by default (depending on the settings too), we have to overwrite some of the
4+
rules.
5+
*/
6+
17
#main > h2 + div, #main > h2 + h3, #main > h3 + div {
28
display: block;
39
}
@@ -13,3 +19,7 @@
1319
#main > h2 + h3 {
1420
display: flex;
1521
}
22+
23+
#main .impl-items .hidden {
24+
display: block !important;
25+
}

‎src/librustdoc/lib.rs‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,9 @@ fn get_args() -> Option<Vec<String>> {
117117
.collect()
118118
}
119119

120-
fn stable<F>(name: &'static str, f: F) -> RustcOptGroup
121-
where
122-
F: Fn(&mut getopts::Options) -> &mut getopts::Options + 'static,
123-
{
124-
RustcOptGroup::stable(name, f)
125-
}
126-
127-
fn unstable<F>(name: &'static str, f: F) -> RustcOptGroup
128-
where
129-
F: Fn(&mut getopts::Options) -> &mut getopts::Options + 'static,
130-
{
131-
RustcOptGroup::unstable(name, f)
132-
}
133-
134120
fn opts() -> Vec<RustcOptGroup> {
121+
let stable: fn(_, fn(&mut getopts::Options) -> &mut _) -> _ = RustcOptGroup::stable;
122+
let unstable: fn(_, fn(&mut getopts::Options) -> &mut _) -> _ = RustcOptGroup::unstable;
135123
vec![
136124
stable("h", |o| o.optflag("h", "help", "show this help message")),
137125
stable("V", |o| o.optflag("V", "version", "print rustdoc's version")),
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"data": [
3+
{
4+
"files": [
5+
{
6+
"filename": "../coverage/match_or_pattern.rs",
7+
"summary": {
8+
"functions": {
9+
"count": 1,
10+
"covered": 1,
11+
"percent": 100
12+
},
13+
"instantiations": {
14+
"count": 1,
15+
"covered": 1,
16+
"percent": 100
17+
},
18+
"lines": {
19+
"count": 37,
20+
"covered": 33,
21+
"percent": 89.1891891891892
22+
},
23+
"regions": {
24+
"count": 25,
25+
"covered": 17,
26+
"notcovered": 8,
27+
"percent": 68
28+
}
29+
}
30+
}
31+
],
32+
"totals": {
33+
"functions": {
34+
"count": 1,
35+
"covered": 1,
36+
"percent": 100
37+
},
38+
"instantiations": {
39+
"count": 1,
40+
"covered": 1,
41+
"percent": 100
42+
},
43+
"lines": {
44+
"count": 37,
45+
"covered": 33,
46+
"percent": 89.1891891891892
47+
},
48+
"regions": {
49+
"count": 25,
50+
"covered": 17,
51+
"notcovered": 8,
52+
"percent": 68
53+
}
54+
}
55+
}
56+
],
57+
"type": "llvm.coverage.json.export",
58+
"version": "2.0.1"
59+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
1| |#![feature(or_patterns)]
2+
2| |
3+
3| 1|fn main() {
4+
4| 1| // Initialize test constants in a way that cannot be determined at compile time, to ensure
5+
5| 1| // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from
6+
6| 1| // dependent conditions.
7+
7| 1| let is_true = std::env::args().len() == 1;
8+
8| 1|
9+
9| 1| let mut a: u8 = 0;
10+
10| 1| let mut b: u8 = 0;
11+
11| 1| if is_true {
12+
12| 1| a = 2;
13+
13| 1| b = 0;
14+
14| 1| }
15+
^0
16+
15| 1| match (a, b) {
17+
16| | // Or patterns generate MIR `SwitchInt` with multiple targets to the same `BasicBlock`.
18+
17| | // This test confirms a fix for Issue #79569.
19+
18| 0| (0 | 1, 2 | 3) => {}
20+
19| 1| _ => {}
21+
20| | }
22+
21| 1| if is_true {
23+
22| 1| a = 0;
24+
23| 1| b = 0;
25+
24| 1| }
26+
^0
27+
25| 1| match (a, b) {
28+
26| 0| (0 | 1, 2 | 3) => {}
29+
27| 1| _ => {}
30+
28| | }
31+
29| 1| if is_true {
32+
30| 1| a = 2;
33+
31| 1| b = 2;
34+
32| 1| }
35+
^0
36+
33| 1| match (a, b) {
37+
34| 0| (0 | 1, 2 | 3) => {}
38+
35| 1| _ => {}
39+
36| | }
40+
37| 1| if is_true {
41+
38| 1| a = 0;
42+
39| 1| b = 2;
43+
40| 1| }
44+
^0
45+
41| 1| match (a, b) {
46+
42| 1| (0 | 1, 2 | 3) => {}
47+
43| 0| _ => {}
48+
44| | }
49+
45| 1|}
50+

‎src/test/run-make-fulldeps/coverage-reports/expected_show_coverage_counters.async.txt‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,8 @@ Counter in file 0 79:14 -> 79:16, 0
2828
Counter in file 0 81:1 -> 81:2, 0
2929
Counter in file 0 91:25 -> 91:34, 0
3030
Counter in file 0 5:1 -> 5:25, #1
31-
Counter in file 0 5:25 -> 6:14, #1
32-
Counter in file 0 7:9 -> 7:10, #2
33-
Counter in file 0 9:9 -> 9:10, (#1 - #2)
34-
Counter in file 0 11:1 -> 11:2, (#2 + (#1 - #2))
3531
Counter in file 0 21:1 -> 21:23, #1
32+
Counter in file 0 17:20 -> 17:21, #1
3633
Counter in file 0 67:5 -> 67:23, #1
3734
Counter in file 0 38:1 -> 38:19, #1
3835
Counter in file 0 38:19 -> 42:12, #1
@@ -46,14 +43,18 @@ Counter in file 0 44:27 -> 44:32, #8
4643
Counter in file 0 44:36 -> 44:38, (#6 + 0)
4744
Counter in file 0 45:14 -> 45:16, #7
4845
Counter in file 0 47:1 -> 47:2, (#5 + (#6 + #7))
46+
Counter in file 0 13:20 -> 13:21, #1
4947
Counter in file 0 29:1 -> 29:22, #1
5048
Counter in file 0 93:1 -> 101:2, #1
5149
Counter in file 0 91:1 -> 91:25, #1
50+
Counter in file 0 5:25 -> 6:14, #1
51+
Counter in file 0 7:9 -> 7:10, #2
52+
Counter in file 0 9:9 -> 9:10, (#1 - #2)
53+
Counter in file 0 11:1 -> 11:2, (#2 + (#1 - #2))
5254
Counter in file 0 51:5 -> 52:18, #1
5355
Counter in file 0 53:13 -> 53:14, #2
5456
Counter in file 0 63:13 -> 63:14, (#1 - #2)
5557
Counter in file 0 65:5 -> 65:6, (#2 + (#1 - #2))
56-
Counter in file 0 17:20 -> 17:21, #1
5758
Counter in file 0 49:1 -> 68:12, #1
5859
Counter in file 0 69:9 -> 69:10, #2
5960
Counter in file 0 69:14 -> 69:27, (#1 + 0)
@@ -70,7 +71,6 @@ Counter in file 0 87:14 -> 87:16, #3
7071
Counter in file 0 89:1 -> 89:2, (#3 + (#2 + (#1 - (#3 + #2))))
7172
Counter in file 0 17:1 -> 17:20, #1
7273
Counter in file 0 66:5 -> 66:23, #1
73-
Counter in file 0 13:20 -> 13:21, #1
7474
Counter in file 0 17:9 -> 17:10, #1
7575
Counter in file 0 17:9 -> 17:10, #1
7676
Counter in file 0 117:17 -> 117:19, #1
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
Counter in file 0 3:1 -> 11:15, #1
2+
Counter in file 0 11:16 -> 14:6, #2
3+
Counter in file 0 14:6 -> 14:7, (#1 - #2)
4+
Counter in file 0 15:11 -> 15:17, (#2 + (#1 - #2))
5+
Counter in file 0 18:27 -> 18:29, #5
6+
Counter in file 0 19:14 -> 19:16, (#3 + #4)
7+
Counter in file 0 21:8 -> 21:15, ((#3 + #4) + #5)
8+
Counter in file 0 21:16 -> 24:6, #6
9+
Counter in file 0 24:6 -> 24:7, (((#3 + #4) + #5) - #6)
10+
Counter in file 0 25:11 -> 25:17, (#6 + (((#3 + #4) + #5) - #6))
11+
Counter in file 0 26:27 -> 26:29, #9
12+
Counter in file 0 27:14 -> 27:16, (#7 + #8)
13+
Counter in file 0 29:8 -> 29:15, ((#7 + #8) + #9)
14+
Counter in file 0 29:16 -> 32:6, #10
15+
Counter in file 0 32:6 -> 32:7, (((#7 + #8) + #9) - #10)
16+
Counter in file 0 33:11 -> 33:17, (#10 + (((#7 + #8) + #9) - #10))
17+
Counter in file 0 34:27 -> 34:29, #13
18+
Counter in file 0 35:14 -> 35:16, (#11 + #12)
19+
Counter in file 0 37:8 -> 37:15, ((#11 + #12) + #13)
20+
Counter in file 0 37:16 -> 40:6, #14
21+
Counter in file 0 40:6 -> 40:7, (((#11 + #12) + #13) - #14)
22+
Counter in file 0 41:11 -> 41:17, (#14 + (((#11 + #12) + #13) - #14))
23+
Counter in file 0 42:27 -> 42:29, #17
24+
Counter in file 0 43:14 -> 43:16, (#15 + #16)
25+
Counter in file 0 45:1 -> 45:2, ((#15 + #16) + #17)
26+
Emitting segments for file: ../coverage/match_or_pattern.rs
27+
Combined regions:
28+
3:1 -> 11:15 (count=1)
29+
11:16 -> 14:6 (count=1)
30+
14:6 -> 14:7 (count=0)
31+
15:11 -> 15:17 (count=1)
32+
18:27 -> 18:29 (count=0)
33+
19:14 -> 19:16 (count=1)
34+
21:8 -> 21:15 (count=1)
35+
21:16 -> 24:6 (count=1)
36+
24:6 -> 24:7 (count=0)
37+
25:11 -> 25:17 (count=1)
38+
26:27 -> 26:29 (count=0)
39+
27:14 -> 27:16 (count=1)
40+
29:8 -> 29:15 (count=1)
41+
29:16 -> 32:6 (count=1)
42+
32:6 -> 32:7 (count=0)
43+
33:11 -> 33:17 (count=1)
44+
34:27 -> 34:29 (count=0)
45+
35:14 -> 35:16 (count=1)
46+
37:8 -> 37:15 (count=1)
47+
37:16 -> 40:6 (count=1)
48+
40:6 -> 40:7 (count=0)
49+
41:11 -> 41:17 (count=1)
50+
42:27 -> 42:29 (count=1)
51+
43:14 -> 43:16 (count=0)
52+
45:1 -> 45:2 (count=1)
53+
Segment at 3:1 (count = 1), RegionEntry
54+
Segment at 11:15 (count = 0), Skipped
55+
Segment at 11:16 (count = 1), RegionEntry
56+
Segment at 14:6 (count = 0), RegionEntry
57+
Segment at 14:7 (count = 0), Skipped
58+
Segment at 15:11 (count = 1), RegionEntry
59+
Segment at 15:17 (count = 0), Skipped
60+
Segment at 18:27 (count = 0), RegionEntry
61+
Segment at 18:29 (count = 0), Skipped
62+
Segment at 19:14 (count = 1), RegionEntry
63+
Segment at 19:16 (count = 0), Skipped
64+
Segment at 21:8 (count = 1), RegionEntry
65+
Segment at 21:15 (count = 0), Skipped
66+
Segment at 21:16 (count = 1), RegionEntry
67+
Segment at 24:6 (count = 0), RegionEntry
68+
Segment at 24:7 (count = 0), Skipped
69+
Segment at 25:11 (count = 1), RegionEntry
70+
Segment at 25:17 (count = 0), Skipped
71+
Segment at 26:27 (count = 0), RegionEntry
72+
Segment at 26:29 (count = 0), Skipped
73+
Segment at 27:14 (count = 1), RegionEntry
74+
Segment at 27:16 (count = 0), Skipped
75+
Segment at 29:8 (count = 1), RegionEntry
76+
Segment at 29:15 (count = 0), Skipped
77+
Segment at 29:16 (count = 1), RegionEntry
78+
Segment at 32:6 (count = 0), RegionEntry
79+
Segment at 32:7 (count = 0), Skipped
80+
Segment at 33:11 (count = 1), RegionEntry
81+
Segment at 33:17 (count = 0), Skipped
82+
Segment at 34:27 (count = 0), RegionEntry
83+
Segment at 34:29 (count = 0), Skipped
84+
Segment at 35:14 (count = 1), RegionEntry
85+
Segment at 35:16 (count = 0), Skipped
86+
Segment at 37:8 (count = 1), RegionEntry
87+
Segment at 37:15 (count = 0), Skipped
88+
Segment at 37:16 (count = 1), RegionEntry
89+
Segment at 40:6 (count = 0), RegionEntry
90+
Segment at 40:7 (count = 0), Skipped
91+
Segment at 41:11 (count = 1), RegionEntry
92+
Segment at 41:17 (count = 0), Skipped
93+
Segment at 42:27 (count = 1), RegionEntry
94+
Segment at 42:29 (count = 0), Skipped
95+
Segment at 43:14 (count = 0), RegionEntry
96+
Segment at 43:16 (count = 0), Skipped
97+
Segment at 45:1 (count = 1), RegionEntry
98+
Segment at 45:2 (count = 0), Skipped

‎src/test/run-make-fulldeps/coverage-spanview/expected_mir_dump.match_or_pattern/match_or_pattern.main.-------.InstrumentCoverage.0.html‎

Lines changed: 271 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#![feature(or_patterns)]
2+
3+
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.
7+
let is_true = std::env::args().len() == 1;
8+
9+
let mut a: u8 = 0;
10+
let mut b: u8 = 0;
11+
if is_true {
12+
a = 2;
13+
b = 0;
14+
}
15+
match (a, b) {
16+
// Or patterns generate MIR `SwitchInt` with multiple targets to the same `BasicBlock`.
17+
// This test confirms a fix for Issue #79569.
18+
(0 | 1, 2 | 3) => {}
19+
_ => {}
20+
}
21+
if is_true {
22+
a = 0;
23+
b = 0;
24+
}
25+
match (a, b) {
26+
(0 | 1, 2 | 3) => {}
27+
_ => {}
28+
}
29+
if is_true {
30+
a = 2;
31+
b = 2;
32+
}
33+
match (a, b) {
34+
(0 | 1, 2 | 3) => {}
35+
_ => {}
36+
}
37+
if is_true {
38+
a = 0;
39+
b = 2;
40+
}
41+
match (a, b) {
42+
(0 | 1, 2 | 3) => {}
43+
_ => {}
44+
}
45+
}

‎src/tools/clippy/src/driver.rs‎

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn arg_value<'a, T: Deref<Target = str>>(
4141

4242
match arg.next().or_else(|| args.next()) {
4343
Some(v) if pred(v) => return Some(v),
44-
_ => {},
44+
_ => {}
4545
}
4646
}
4747
None
@@ -121,11 +121,12 @@ You can use tool lints to allow or deny lints from your code, eg.:
121121

122122
const BUG_REPORT_URL: &str = "https://github.com/rust-lang/rust-clippy/issues/new";
123123

124-
static ICE_HOOK: SyncLazy<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static>> = SyncLazy::new(|| {
125-
let hook = panic::take_hook();
126-
panic::set_hook(Box::new(|info| report_clippy_ice(info, BUG_REPORT_URL)));
127-
hook
128-
});
124+
static ICE_HOOK: SyncLazy<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static>> =
125+
SyncLazy::new(|| {
126+
let hook = panic::take_hook();
127+
panic::set_hook(Box::new(|info| report_clippy_ice(info, BUG_REPORT_URL)));
128+
hook
129+
});
129130

130131
fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
131132
// Invoke our ICE handler, which prints the actual panic message and optionally a backtrace
@@ -257,14 +258,17 @@ pub fn main() {
257258

258259
// Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument.
259260
// We're invoking the compiler programmatically, so we ignore this/
260-
let wrapper_mode = orig_args.get(1).map(Path::new).and_then(Path::file_stem) == Some("rustc".as_ref());
261+
let wrapper_mode =
262+
orig_args.get(1).map(Path::new).and_then(Path::file_stem) == Some("rustc".as_ref());
261263

262264
if wrapper_mode {
263265
// we still want to be able to invoke it normally though
264266
orig_args.remove(1);
265267
}
266268

267-
if !wrapper_mode && (orig_args.iter().any(|a| a == "--help" || a == "-h") || orig_args.len() == 1) {
269+
if !wrapper_mode
270+
&& (orig_args.iter().any(|a| a == "--help" || a == "-h") || orig_args.len() == 1)
271+
{
268272
display_help();
269273
exit(0);
270274
}
@@ -285,13 +289,11 @@ pub fn main() {
285289
if clippy_enabled {
286290
args.extend(vec!["--cfg".into(), r#"feature="cargo-clippy""#.into()]);
287291
if let Ok(extra_args) = env::var("CLIPPY_ARGS") {
288-
args.extend(extra_args.split("__CLIPPY_HACKERY__").filter_map(|s| {
289-
if s.is_empty() {
290-
None
291-
} else {
292-
Some(s.to_string())
293-
}
294-
}));
292+
args.extend(
293+
extra_args
294+
.split("__CLIPPY_HACKERY__")
295+
.filter_map(|s| if s.is_empty() { None } else { Some(s.to_string()) }),
296+
);
295297
}
296298
}
297299
let mut clippy = ClippyCallbacks;

‎src/tools/tidy/src/deps.rs‎

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,12 @@ fn check_exceptions(metadata: &Metadata, bad: &mut bool) {
214214
for (name, license) in EXCEPTIONS {
215215
// Check that the package actually exists.
216216
if !metadata.packages.iter().any(|p| p.name == *name) {
217-
println!(
217+
tidy_error!(
218+
bad,
218219
"could not find exception package `{}`\n\
219220
Remove from EXCEPTIONS list if it is no longer used.",
220221
name
221222
);
222-
*bad = true;
223223
}
224224
// Check that the license hasn't changed.
225225
for pkg in metadata.packages.iter().filter(|p| p.name == *name) {
@@ -232,11 +232,11 @@ fn check_exceptions(metadata: &Metadata, bad: &mut bool) {
232232
}
233233
match &pkg.license {
234234
None => {
235-
println!(
235+
tidy_error!(
236+
bad,
236237
"dependency exception `{}` does not declare a license expression",
237238
pkg.id
238239
);
239-
*bad = true;
240240
}
241241
Some(pkg_license) => {
242242
if pkg_license.as_str() != *license {
@@ -273,8 +273,7 @@ fn check_exceptions(metadata: &Metadata, bad: &mut bool) {
273273
let license = match &pkg.license {
274274
Some(license) => license,
275275
None => {
276-
println!("dependency `{}` does not define a license expression", pkg.id,);
277-
*bad = true;
276+
tidy_error!(bad, "dependency `{}` does not define a license expression", pkg.id);
278277
continue;
279278
}
280279
};
@@ -286,8 +285,7 @@ fn check_exceptions(metadata: &Metadata, bad: &mut bool) {
286285
// general, these should never be added.
287286
continue;
288287
}
289-
println!("invalid license `{}` in `{}`", license, pkg.id);
290-
*bad = true;
288+
tidy_error!(bad, "invalid license `{}` in `{}`", license, pkg.id);
291289
}
292290
}
293291
}
@@ -300,12 +298,12 @@ fn check_dependencies(metadata: &Metadata, bad: &mut bool) {
300298
// Check that the PERMITTED_DEPENDENCIES does not have unused entries.
301299
for name in PERMITTED_DEPENDENCIES {
302300
if !metadata.packages.iter().any(|p| p.name == *name) {
303-
println!(
301+
tidy_error!(
302+
bad,
304303
"could not find allowed package `{}`\n\
305304
Remove from PERMITTED_DEPENDENCIES list if it is no longer used.",
306305
name
307306
);
308-
*bad = true;
309307
}
310308
}
311309
// Get the list in a convenient form.
@@ -322,11 +320,10 @@ fn check_dependencies(metadata: &Metadata, bad: &mut bool) {
322320
}
323321

324322
if !unapproved.is_empty() {
325-
println!("Dependencies not explicitly permitted:");
323+
tidy_error!(bad, "Dependencies not explicitly permitted:");
326324
for dep in unapproved {
327325
println!("* {}", dep);
328326
}
329-
*bad = true;
330327
}
331328
}
332329

@@ -381,16 +378,17 @@ fn check_crate_duplicate(metadata: &Metadata, bad: &mut bool) {
381378
let matches: Vec<_> = metadata.packages.iter().filter(|pkg| pkg.name == name).collect();
382379
match matches.len() {
383380
0 => {
384-
println!(
381+
tidy_error!(
382+
bad,
385383
"crate `{}` is missing, update `check_crate_duplicate` \
386384
if it is no longer used",
387385
name
388386
);
389-
*bad = true;
390387
}
391388
1 => {}
392389
_ => {
393-
println!(
390+
tidy_error!(
391+
bad,
394392
"crate `{}` is duplicated in `Cargo.lock`, \
395393
it is too expensive to build multiple times, \
396394
so make sure only one version appears across all dependencies",
@@ -399,7 +397,6 @@ fn check_crate_duplicate(metadata: &Metadata, bad: &mut bool) {
399397
for pkg in matches {
400398
println!(" * {}", pkg.id);
401399
}
402-
*bad = true;
403400
}
404401
}
405402
}

‎src/tools/tidy/src/extdeps.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ pub fn check(root: &Path, bad: &mut bool) {
2727

2828
// Ensure source is allowed.
2929
if !ALLOWED_SOURCES.contains(&&*source) {
30-
println!("invalid source: {}", source);
31-
*bad = true;
30+
tidy_error!(bad, "invalid source: {}", source);
3231
}
3332
}
3433
}

‎src/tools/tidy/src/features.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ fn collect_lang_features_in(base: &Path, file: &str, bad: &mut bool) -> Features
330330
let issue_str = parts.next().unwrap().trim();
331331
let tracking_issue = if issue_str.starts_with("None") {
332332
if level == Status::Unstable && !next_feature_omits_tracking_issue {
333-
*bad = true;
334333
tidy_error!(
335334
bad,
336335
"{}:{}: no tracking issue for feature {}",

‎src/tools/tidy/src/lib.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ macro_rules! t {
2828
}
2929

3030
macro_rules! tidy_error {
31+
($bad:expr, $fmt:expr) => ({
32+
*$bad = true;
33+
eprintln!("tidy error: {}", $fmt);
34+
});
3135
($bad:expr, $fmt:expr, $($arg:tt)*) => ({
3236
*$bad = true;
3337
eprint!("tidy error: ");

‎src/tools/tidy/src/ui_tests.rs‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,12 @@ pub fn check(path: &Path, bad: &mut bool) {
6767
let testname =
6868
file_path.file_name().unwrap().to_str().unwrap().split_once('.').unwrap().0;
6969
if !file_path.with_file_name(testname).with_extension("rs").exists() {
70-
println!("Stray file with UI testing output: {:?}", file_path);
71-
*bad = true;
70+
tidy_error!(bad, "Stray file with UI testing output: {:?}", file_path);
7271
}
7372

7473
if let Ok(metadata) = fs::metadata(file_path) {
7574
if metadata.len() == 0 {
76-
println!("Empty file with UI testing output: {:?}", file_path);
77-
*bad = true;
75+
tidy_error!(bad, "Empty file with UI testing output: {:?}", file_path);
7876
}
7977
}
8078
}

0 commit comments

Comments
 (0)
This repository has been archived.