Warn on redundant --cfg directive when revisions are used

This commit is contained in:
clubby789 2024-10-19 11:11:33 +00:00
parent b27f33a4d9
commit d82a21f9ad
6 changed files with 22 additions and 12 deletions

View File

@ -468,7 +468,19 @@ impl<'test> TestCx<'test> {
if let Some(revision) = self.revision { if let Some(revision) = self.revision {
let normalized_revision = normalize_revision(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 { if !self.props.no_auto_check_cfg {

View File

@ -2,8 +2,6 @@
//@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes //@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
//@ error-pattern: unsafe precondition(s) violated: Layout::from_size_align_unchecked requires //@ error-pattern: unsafe precondition(s) violated: Layout::from_size_align_unchecked requires
//@ revisions: toolarge badalign //@ revisions: toolarge badalign
//@[toolarge] compile-flags: --cfg toolarge
//@[badalign] compile-flags: --cfg badalign
fn main() { fn main() {
unsafe { unsafe {

View File

@ -5,19 +5,19 @@
//@ revisions: address cfi kcfi leak memory thread //@ revisions: address cfi kcfi leak memory thread
//@compile-flags: -Ctarget-feature=-crt-static //@compile-flags: -Ctarget-feature=-crt-static
//@[address]needs-sanitizer-address //@[address]needs-sanitizer-address
//@[address]compile-flags: -Zsanitizer=address --cfg address //@[address]compile-flags: -Zsanitizer=address
//@[cfi]needs-sanitizer-cfi //@[cfi]needs-sanitizer-cfi
//@[cfi]compile-flags: -Zsanitizer=cfi --cfg cfi //@[cfi]compile-flags: -Zsanitizer=cfi
//@[cfi]compile-flags: -Clto -Ccodegen-units=1 //@[cfi]compile-flags: -Clto -Ccodegen-units=1
//@[kcfi]needs-llvm-components: x86 //@[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 //@[kcfi]compile-flags: -C panic=abort
//@[leak]needs-sanitizer-leak //@[leak]needs-sanitizer-leak
//@[leak]compile-flags: -Zsanitizer=leak --cfg leak //@[leak]compile-flags: -Zsanitizer=leak
//@[memory]needs-sanitizer-memory //@[memory]needs-sanitizer-memory
//@[memory]compile-flags: -Zsanitizer=memory --cfg memory //@[memory]compile-flags: -Zsanitizer=memory
//@[thread]needs-sanitizer-thread //@[thread]needs-sanitizer-thread
//@[thread]compile-flags: -Zsanitizer=thread --cfg thread //@[thread]compile-flags: -Zsanitizer=thread
#![feature(cfg_sanitize, no_core, lang_items)] #![feature(cfg_sanitize, no_core, lang_items)]
#![crate_type="lib"] #![crate_type="lib"]

View File

@ -4,7 +4,7 @@
// For some reason, Rust 2018 or higher is required to reproduce the bug. // For some reason, Rust 2018 or higher is required to reproduce the bug.
//@ run-rustfix //@ run-rustfix
//@ revisions: no_std std //@ 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)] #![cfg_attr(no_std, no_std)]
use core::num::NonZero; use core::num::NonZero;

View File

@ -4,7 +4,7 @@
// For some reason, Rust 2018 or higher is required to reproduce the bug. // For some reason, Rust 2018 or higher is required to reproduce the bug.
//@ run-rustfix //@ run-rustfix
//@ revisions: no_std std //@ 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)] #![cfg_attr(no_std, no_std)]
fn main() { fn main() {

View File

@ -4,7 +4,7 @@
// For some reason, Rust 2018 or higher is required to reproduce the bug. // For some reason, Rust 2018 or higher is required to reproduce the bug.
//@ run-rustfix //@ run-rustfix
//@ revisions: no_std std //@ 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)] #![cfg_attr(no_std, no_std)]
use std::num::NonZero; use std::num::NonZero;