Skip to content

Commit 3faf282

Browse files
authored
Rollup merge of #152925 - ferrocene:hoverbear/improve-revision-flag-check, r=clubby789,jieyouxu
Improve runtest revision redundant cfg check While attempting to ingest #148034 via ferrocene/ferrocene#2172 we noticed a test failure, as we add some `compile_flags` to tests. We saw a failure looking like this: ``` Testing stage1 with compiletest suite=mir-opt mode=mir-opt (x86_64-unknown-linux-gnu) running 2 tests 2026-02-20T20:21:28.846102Z ERROR compiletest::runtest: redundant cfg argument `copy` is already created by the revision [mir-opt] tests/mir-opt/pre-codegen/copy_and_clone.rs#COPY ... F . ``` While my Rust checkout passed: ``` Testing stage1 with compiletest suite=mir-opt mode=mir-opt (x86_64-unknown-linux-gnu) running 2 tests .. test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 381 filtered out; finished in 107.10ms ``` This caused me to add some debugging statements. Ferrocene: ``` 2026-02-20T21:05:39.808427Z ERROR compiletest::runtest: "copy": does ["--edition=2015", "--cfg=copy"] contain `"--cfg=copy"` or `["--cfg", "copy"]`? true 2026-02-20T21:05:39.808427Z ERROR compiletest::runtest: "clone": does ["--edition=2015"] contain `"--cfg=clone"` or `["--cfg", "clone"]`? false 2026-02-20T21:05:39.808435Z ERROR compiletest::runtest: redundant cfg argument `copy` is already created by the revision ``` Rust: ``` 2026-02-20T21:04:18.493158Z ERROR compiletest::runtest: "copy": does ["--cfg=copy"] contain `"--cfg=copy"` or `["--cfg", "copy"]`? false 2026-02-20T21:04:18.493158Z ERROR compiletest::runtest: "clone": does [] contain `"--cfg=clone"` or `["--cfg", "clone"]`? false ``` I noticed while reviewing the related functionality that there is a call to `.windows(2)` in the relevant check for redundant cfgs: https://github.com/rust-lang/rust/blob/0376d43d443cba463a0b6a6ec9140ea17d7b7130/src/tools/compiletest/src/runtest.rs#L507-L511 Noting: https://github.com/rust-lang/rust/blob/0376d43d443cba463a0b6a6ec9140ea17d7b7130/library/core/src/slice/mod.rs#L1064-L1066 Because of this, the revision check was getting an empty iterator when `self.props.compile_flags` was length 0 or 1. This fix adjusts the check to handle such cases. I went ahead and fixed the relevant test (4b3cd9b) that was impacted by this. I do not suspect there are others, at least within the scope that Ferrocene tests, as we have not previously seen this failure.
2 parents 48cf90f + 3c9ca9b commit 3faf282

2 files changed

Lines changed: 5 additions & 7 deletions

File tree

src/tools/compiletest/src/runtest.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -504,12 +504,11 @@ impl<'test> TestCx<'test> {
504504
let normalized_revision = normalize_revision(revision);
505505
let cfg_arg = ["--cfg", &normalized_revision];
506506
let arg = format!("--cfg={normalized_revision}");
507-
if self
508-
.props
509-
.compile_flags
510-
.windows(2)
511-
.any(|args| args == cfg_arg || args[0] == arg || args[1] == arg)
512-
{
507+
// Handle if compile_flags is length 1
508+
let contains_arg =
509+
self.props.compile_flags.iter().any(|considered_arg| *considered_arg == arg);
510+
let contains_cfg_arg = self.props.compile_flags.windows(2).any(|args| args == cfg_arg);
511+
if contains_arg || contains_cfg_arg {
513512
error!(
514513
"redundant cfg argument `{normalized_revision}` is already created by the \
515514
revision"

tests/mir-opt/pre-codegen/copy_and_clone.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@ [COPY] compile-flags: --cfg=copy
21
//@ revisions: COPY CLONE
32

43
// Test case from https://github.com/rust-lang/rust/issues/128081.

0 commit comments

Comments
 (0)