From bc185097191e7598f50d39e768acde6c95a4d7d5 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Wed, 25 Oct 2023 11:36:45 +1100 Subject: [PATCH 1/2] coverage: UI test for unstable value `-C instrument-coverage=branch` --- tests/ui/instrument-coverage/except-unused-functions.rs | 3 --- tests/ui/instrument-coverage/except-unused-generics.rs | 3 --- ...xcept-unused-functions.stderr => unstable.branch.stderr} | 0 ...erics.stderr => unstable.except-unused-functions.stderr} | 0 .../unstable.except-unused-generics.stderr | 2 ++ tests/ui/instrument-coverage/unstable.rs | 6 ++++++ 6 files changed, 8 insertions(+), 6 deletions(-) delete mode 100644 tests/ui/instrument-coverage/except-unused-functions.rs delete mode 100644 tests/ui/instrument-coverage/except-unused-generics.rs rename tests/ui/instrument-coverage/{except-unused-functions.stderr => unstable.branch.stderr} (100%) rename tests/ui/instrument-coverage/{except-unused-generics.stderr => unstable.except-unused-functions.stderr} (100%) create mode 100644 tests/ui/instrument-coverage/unstable.except-unused-generics.stderr create mode 100644 tests/ui/instrument-coverage/unstable.rs diff --git a/tests/ui/instrument-coverage/except-unused-functions.rs b/tests/ui/instrument-coverage/except-unused-functions.rs deleted file mode 100644 index 5a0b7d4fef900..0000000000000 --- a/tests/ui/instrument-coverage/except-unused-functions.rs +++ /dev/null @@ -1,3 +0,0 @@ -// compile-flags: -Cinstrument-coverage=except-unused-functions - -fn main() {} diff --git a/tests/ui/instrument-coverage/except-unused-generics.rs b/tests/ui/instrument-coverage/except-unused-generics.rs deleted file mode 100644 index 4b1ddf29026ca..0000000000000 --- a/tests/ui/instrument-coverage/except-unused-generics.rs +++ /dev/null @@ -1,3 +0,0 @@ -// compile-flags: -Cinstrument-coverage=except-unused-generics - -fn main() {} diff --git a/tests/ui/instrument-coverage/except-unused-functions.stderr b/tests/ui/instrument-coverage/unstable.branch.stderr similarity index 100% rename from tests/ui/instrument-coverage/except-unused-functions.stderr rename to tests/ui/instrument-coverage/unstable.branch.stderr diff --git a/tests/ui/instrument-coverage/except-unused-generics.stderr b/tests/ui/instrument-coverage/unstable.except-unused-functions.stderr similarity index 100% rename from tests/ui/instrument-coverage/except-unused-generics.stderr rename to tests/ui/instrument-coverage/unstable.except-unused-functions.stderr diff --git a/tests/ui/instrument-coverage/unstable.except-unused-generics.stderr b/tests/ui/instrument-coverage/unstable.except-unused-generics.stderr new file mode 100644 index 0000000000000..acc633a2a6d2f --- /dev/null +++ b/tests/ui/instrument-coverage/unstable.except-unused-generics.stderr @@ -0,0 +1,2 @@ +error: `-C instrument-coverage=branch` and `-C instrument-coverage=except-*` require `-Z unstable-options` + diff --git a/tests/ui/instrument-coverage/unstable.rs b/tests/ui/instrument-coverage/unstable.rs new file mode 100644 index 0000000000000..c16bcd0bf6d13 --- /dev/null +++ b/tests/ui/instrument-coverage/unstable.rs @@ -0,0 +1,6 @@ +// revisions: branch except-unused-functions except-unused-generics +// [branch] compile-flags: -Cinstrument-coverage=branch +// [except-unused-functions] compile-flags: -Cinstrument-coverage=except-unused-functions +// [except-unused-generics] compile-flags: -Cinstrument-coverage=except-unused-generics + +fn main() {} From 65b0f6adb08385ed984eee6273d65518cd768b80 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Tue, 24 Oct 2023 12:23:00 +1100 Subject: [PATCH 2/2] Remove support for alias `-Z instrument-coverage` This flag was stabilized in rustc 1.60.0 as `-C instrument-coverage`, but the old unstable flag was kept around as an alias to ease migration. --- compiler/rustc_interface/src/tests.rs | 1 - compiler/rustc_session/src/config.rs | 39 ++++++++++++--------------- compiler/rustc_session/src/options.rs | 10 ------- 3 files changed, 17 insertions(+), 33 deletions(-) diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index ec4fd78994e95..657bce7384b4c 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -789,7 +789,6 @@ fn test_unstable_options_tracking_hash() { tracked!(inline_mir, Some(true)); tracked!(inline_mir_hint_threshold, Some(123)); tracked!(inline_mir_threshold, Some(123)); - tracked!(instrument_coverage, Some(InstrumentCoverage::All)); tracked!(instrument_mcount, true); tracked!(instrument_xray, Some(InstrumentXRay::default())); tracked!(link_directives, false); diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 84933588f17fe..78e410488c35a 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -2739,29 +2739,24 @@ pub fn build_session_options( _ => {} } - // Handle both `-Z instrument-coverage` and `-C instrument-coverage`; the latter takes - // precedence. - match (cg.instrument_coverage, unstable_opts.instrument_coverage) { - (Some(ic_c), Some(ic_z)) if ic_c != ic_z => { - handler.early_error( - "incompatible values passed for `-C instrument-coverage` \ - and `-Z instrument-coverage`", - ); - } - (Some(InstrumentCoverage::Off | InstrumentCoverage::All), _) => {} - (Some(_), _) if !unstable_opts.unstable_options => { - handler.early_error( - "`-C instrument-coverage=branch` and `-C instrument-coverage=except-*` \ - require `-Z unstable-options`", - ); - } - (None, None) => {} - (None, ic) => { - handler - .early_warn("`-Z instrument-coverage` is deprecated; use `-C instrument-coverage`"); - cg.instrument_coverage = ic; + // Check for unstable values of `-C instrument-coverage`. + // This is what prevents them from being used on stable compilers. + match cg.instrument_coverage { + // Stable values: + Some(InstrumentCoverage::All | InstrumentCoverage::Off) | None => {} + // Unstable values: + Some( + InstrumentCoverage::Branch + | InstrumentCoverage::ExceptUnusedFunctions + | InstrumentCoverage::ExceptUnusedGenerics, + ) => { + if !unstable_opts.unstable_options { + handler.early_error( + "`-C instrument-coverage=branch` and `-C instrument-coverage=except-*` \ + require `-Z unstable-options`", + ); + } } - _ => {} } if cg.instrument_coverage.is_some() && cg.instrument_coverage != Some(InstrumentCoverage::Off) { diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 77aaf951f0db0..35c167837e5ff 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1593,16 +1593,6 @@ options! { "a default MIR inlining threshold (default: 50)"), input_stats: bool = (false, parse_bool, [UNTRACKED], "gather statistics about the input (default: no)"), - #[rustc_lint_opt_deny_field_access("use `Session::instrument_coverage` instead of this field")] - instrument_coverage: Option = (None, parse_instrument_coverage, [TRACKED], - "instrument the generated code to support LLVM source-based code coverage \ - reports (note, the compiler build config must include `profiler = true`); \ - implies `-C symbol-mangling-version=v0`. Optional values are: - `=all` (implicit value) - `=branch` - `=except-unused-generics` - `=except-unused-functions` - `=off` (default)"), instrument_mcount: bool = (false, parse_bool, [TRACKED], "insert function instrument code for mcount-based tracing (default: no)"), instrument_xray: Option = (None, parse_instrument_xray, [TRACKED],