Skip to content

Commit cfe5389

Browse files
authored
Rollup merge of rust-lang#131925 - clubby789:redundant-revision-cfg, r=jieyouxu
Warn on redundant `--cfg` directive when revisions are used r? `@jieyouxu` Fixes rust-lang#131390 Not sure of the best way to test this
2 parents 6d3d0f2 + d82a21f commit cfe5389

File tree

6 files changed

+22
-12
lines changed

6 files changed

+22
-12
lines changed

Diff for: src/tools/compiletest/src/runtest.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,19 @@ impl<'test> TestCx<'test> {
468468

469469
if let Some(revision) = self.revision {
470470
let normalized_revision = normalize_revision(revision);
471-
cmd.args(&["--cfg", &normalized_revision]);
471+
let cfg_arg = ["--cfg", &normalized_revision];
472+
let arg = format!("--cfg={normalized_revision}");
473+
if self
474+
.props
475+
.compile_flags
476+
.windows(2)
477+
.any(|args| args == cfg_arg || args[0] == arg || args[1] == arg)
478+
{
479+
panic!(
480+
"error: redundant cfg argument `{normalized_revision}` is already created by the revision"
481+
);
482+
}
483+
cmd.args(cfg_arg);
472484
}
473485

474486
if !self.props.no_auto_check_cfg {

Diff for: tests/ui/precondition-checks/layout.rs

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
//@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
33
//@ error-pattern: unsafe precondition(s) violated: Layout::from_size_align_unchecked requires
44
//@ revisions: toolarge badalign
5-
//@[toolarge] compile-flags: --cfg toolarge
6-
//@[badalign] compile-flags: --cfg badalign
75

86
fn main() {
97
unsafe {

Diff for: tests/ui/sanitizer/cfg.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
//@ revisions: address cfi kcfi leak memory thread
66
//@compile-flags: -Ctarget-feature=-crt-static
77
//@[address]needs-sanitizer-address
8-
//@[address]compile-flags: -Zsanitizer=address --cfg address
8+
//@[address]compile-flags: -Zsanitizer=address
99
//@[cfi]needs-sanitizer-cfi
10-
//@[cfi]compile-flags: -Zsanitizer=cfi --cfg cfi
10+
//@[cfi]compile-flags: -Zsanitizer=cfi
1111
//@[cfi]compile-flags: -Clto -Ccodegen-units=1
1212
//@[kcfi]needs-llvm-components: x86
13-
//@[kcfi]compile-flags: -Zsanitizer=kcfi --cfg kcfi --target x86_64-unknown-none
13+
//@[kcfi]compile-flags: -Zsanitizer=kcfi --target x86_64-unknown-none
1414
//@[kcfi]compile-flags: -C panic=abort
1515
//@[leak]needs-sanitizer-leak
16-
//@[leak]compile-flags: -Zsanitizer=leak --cfg leak
16+
//@[leak]compile-flags: -Zsanitizer=leak
1717
//@[memory]needs-sanitizer-memory
18-
//@[memory]compile-flags: -Zsanitizer=memory --cfg memory
18+
//@[memory]compile-flags: -Zsanitizer=memory
1919
//@[thread]needs-sanitizer-thread
20-
//@[thread]compile-flags: -Zsanitizer=thread --cfg thread
20+
//@[thread]compile-flags: -Zsanitizer=thread
2121

2222
#![feature(cfg_sanitize, no_core, lang_items)]
2323
#![crate_type="lib"]

Diff for: tests/ui/suggestions/core-std-import-order-issue-83564.no_std.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// For some reason, Rust 2018 or higher is required to reproduce the bug.
55
//@ run-rustfix
66
//@ revisions: no_std std
7-
//@ [no_std]compile-flags: --cfg=no_std -C panic=abort
7+
//@ [no_std]compile-flags: -C panic=abort
88
#![cfg_attr(no_std, no_std)]
99

1010
use core::num::NonZero;

Diff for: tests/ui/suggestions/core-std-import-order-issue-83564.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// For some reason, Rust 2018 or higher is required to reproduce the bug.
55
//@ run-rustfix
66
//@ revisions: no_std std
7-
//@ [no_std]compile-flags: --cfg=no_std -C panic=abort
7+
//@ [no_std]compile-flags: -C panic=abort
88
#![cfg_attr(no_std, no_std)]
99

1010
fn main() {

Diff for: tests/ui/suggestions/core-std-import-order-issue-83564.std.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// For some reason, Rust 2018 or higher is required to reproduce the bug.
55
//@ run-rustfix
66
//@ revisions: no_std std
7-
//@ [no_std]compile-flags: --cfg=no_std -C panic=abort
7+
//@ [no_std]compile-flags: -C panic=abort
88
#![cfg_attr(no_std, no_std)]
99

1010
use std::num::NonZero;

0 commit comments

Comments
 (0)