From d82a21f9adf840a48c5ddee3dbc474259d0bc1d3 Mon Sep 17 00:00:00 2001 From: clubby789 Date: Sat, 19 Oct 2024 11:11:33 +0000 Subject: [PATCH] Warn on redundant `--cfg` directive when revisions are used --- src/tools/compiletest/src/runtest.rs | 14 +++++++++++++- tests/ui/precondition-checks/layout.rs | 2 -- tests/ui/sanitizer/cfg.rs | 12 ++++++------ .../core-std-import-order-issue-83564.no_std.fixed | 2 +- .../core-std-import-order-issue-83564.rs | 2 +- .../core-std-import-order-issue-83564.std.fixed | 2 +- 6 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index f0452008304..5b8a96a54c2 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -468,7 +468,19 @@ fn set_revision_flags(&self, cmd: &mut Command) { if let Some(revision) = self.revision { let normalized_revision = normalize_revision(revision); - cmd.args(&["--cfg", &normalized_revision]); + let cfg_arg = ["--cfg", &normalized_revision]; + let arg = format!("--cfg={normalized_revision}"); + if self + .props + .compile_flags + .windows(2) + .any(|args| args == cfg_arg || args[0] == arg || args[1] == arg) + { + panic!( + "error: redundant cfg argument `{normalized_revision}` is already created by the revision" + ); + } + cmd.args(cfg_arg); } if !self.props.no_auto_check_cfg { diff --git a/tests/ui/precondition-checks/layout.rs b/tests/ui/precondition-checks/layout.rs index 4fd1bbc4a99..4ee66cc9328 100644 --- a/tests/ui/precondition-checks/layout.rs +++ b/tests/ui/precondition-checks/layout.rs @@ -2,8 +2,6 @@ //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes //@ error-pattern: unsafe precondition(s) violated: Layout::from_size_align_unchecked requires //@ revisions: toolarge badalign -//@[toolarge] compile-flags: --cfg toolarge -//@[badalign] compile-flags: --cfg badalign fn main() { unsafe { diff --git a/tests/ui/sanitizer/cfg.rs b/tests/ui/sanitizer/cfg.rs index b1ba17d5713..7b8f285e41a 100644 --- a/tests/ui/sanitizer/cfg.rs +++ b/tests/ui/sanitizer/cfg.rs @@ -5,19 +5,19 @@ //@ revisions: address cfi kcfi leak memory thread //@compile-flags: -Ctarget-feature=-crt-static //@[address]needs-sanitizer-address -//@[address]compile-flags: -Zsanitizer=address --cfg address +//@[address]compile-flags: -Zsanitizer=address //@[cfi]needs-sanitizer-cfi -//@[cfi]compile-flags: -Zsanitizer=cfi --cfg cfi +//@[cfi]compile-flags: -Zsanitizer=cfi //@[cfi]compile-flags: -Clto -Ccodegen-units=1 //@[kcfi]needs-llvm-components: x86 -//@[kcfi]compile-flags: -Zsanitizer=kcfi --cfg kcfi --target x86_64-unknown-none +//@[kcfi]compile-flags: -Zsanitizer=kcfi --target x86_64-unknown-none //@[kcfi]compile-flags: -C panic=abort //@[leak]needs-sanitizer-leak -//@[leak]compile-flags: -Zsanitizer=leak --cfg leak +//@[leak]compile-flags: -Zsanitizer=leak //@[memory]needs-sanitizer-memory -//@[memory]compile-flags: -Zsanitizer=memory --cfg memory +//@[memory]compile-flags: -Zsanitizer=memory //@[thread]needs-sanitizer-thread -//@[thread]compile-flags: -Zsanitizer=thread --cfg thread +//@[thread]compile-flags: -Zsanitizer=thread #![feature(cfg_sanitize, no_core, lang_items)] #![crate_type="lib"] diff --git a/tests/ui/suggestions/core-std-import-order-issue-83564.no_std.fixed b/tests/ui/suggestions/core-std-import-order-issue-83564.no_std.fixed index 02d667d9844..b7b94a05121 100644 --- a/tests/ui/suggestions/core-std-import-order-issue-83564.no_std.fixed +++ b/tests/ui/suggestions/core-std-import-order-issue-83564.no_std.fixed @@ -4,7 +4,7 @@ // For some reason, Rust 2018 or higher is required to reproduce the bug. //@ run-rustfix //@ revisions: no_std std -//@ [no_std]compile-flags: --cfg=no_std -C panic=abort +//@ [no_std]compile-flags: -C panic=abort #![cfg_attr(no_std, no_std)] use core::num::NonZero; diff --git a/tests/ui/suggestions/core-std-import-order-issue-83564.rs b/tests/ui/suggestions/core-std-import-order-issue-83564.rs index 5bb5bfe176b..4cfc9a6bf74 100644 --- a/tests/ui/suggestions/core-std-import-order-issue-83564.rs +++ b/tests/ui/suggestions/core-std-import-order-issue-83564.rs @@ -4,7 +4,7 @@ // For some reason, Rust 2018 or higher is required to reproduce the bug. //@ run-rustfix //@ revisions: no_std std -//@ [no_std]compile-flags: --cfg=no_std -C panic=abort +//@ [no_std]compile-flags: -C panic=abort #![cfg_attr(no_std, no_std)] fn main() { diff --git a/tests/ui/suggestions/core-std-import-order-issue-83564.std.fixed b/tests/ui/suggestions/core-std-import-order-issue-83564.std.fixed index 3492b42c685..84c7c19d19e 100644 --- a/tests/ui/suggestions/core-std-import-order-issue-83564.std.fixed +++ b/tests/ui/suggestions/core-std-import-order-issue-83564.std.fixed @@ -4,7 +4,7 @@ // For some reason, Rust 2018 or higher is required to reproduce the bug. //@ run-rustfix //@ revisions: no_std std -//@ [no_std]compile-flags: --cfg=no_std -C panic=abort +//@ [no_std]compile-flags: -C panic=abort #![cfg_attr(no_std, no_std)] use std::num::NonZero;