Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn on redundant --cfg directive when revisions are used #131925

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 13 additions & 1 deletion src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,19 @@ impl<'test> TestCx<'test> {

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 {
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/precondition-checks/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/sanitizer/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/suggestions/core-std-import-order-issue-83564.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading