Skip to content

Commit 51a138e

Browse files
committed
Don't allow test revisions that conflict with built in cfgs
1 parent b27f33a commit 51a138e

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

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

+17
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ pub struct Config {
376376
pub only_modified: bool,
377377

378378
pub target_cfgs: OnceLock<TargetCfgs>,
379+
pub builtin_cfg_names: OnceLock<HashSet<String>>,
379380

380381
pub nocapture: bool,
381382

@@ -440,6 +441,11 @@ impl Config {
440441
self.target_cfg().panic == PanicStrategy::Unwind
441442
}
442443

444+
/// Get the list of builtin, 'well known' cfgs
445+
pub fn builtin_cfg_names(&self) -> &HashSet<String> {
446+
self.builtin_cfg_names.get_or_init(|| builtin_cfg_names(self))
447+
}
448+
443449
pub fn has_threads(&self) -> bool {
444450
// Wasm targets don't have threads unless `-threads` is in the target
445451
// name, such as `wasm32-wasip1-threads`.
@@ -651,6 +657,17 @@ pub enum Endian {
651657
Big,
652658
}
653659

660+
fn builtin_cfg_names(config: &Config) -> HashSet<String> {
661+
rustc_output(
662+
config,
663+
&["--print=check-cfg", "-Zunstable-options", "--check-cfg=cfg()"],
664+
Default::default(),
665+
)
666+
.lines()
667+
.map(|l| if let Some((name, _)) = l.split_once('=') { name.to_string() } else { l.to_string() })
668+
.collect()
669+
}
670+
654671
fn rustc_output(config: &Config, args: &[&str], envs: HashMap<String, String>) -> String {
655672
let mut command = Command::new(&config.rustc_path);
656673
add_dylib_path(&mut command, iter::once(&config.compile_lib_path));

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

+1
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
356356
force_rerun: matches.opt_present("force-rerun"),
357357

358358
target_cfgs: OnceLock::new(),
359+
builtin_cfg_names: OnceLock::new(),
359360

360361
nocapture: matches.opt_present("nocapture"),
361362

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

+3
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,9 @@ impl<'test> TestCx<'test> {
468468

469469
if let Some(revision) = self.revision {
470470
let normalized_revision = normalize_revision(revision);
471+
if self.config.builtin_cfg_names().contains(&normalized_revision) {
472+
panic!("error: revision `{normalized_revision}` collides with a builtin cfg");
473+
}
471474
cmd.args(&["--cfg", &normalized_revision]);
472475
}
473476

Diff for: tests/ui/lint/lint-missing-doc-expect.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Make sure that `#[expect(missing_docs)]` is always correctly fulfilled.
22

33
//@ check-pass
4-
//@ revisions: lib bin test
4+
//@ revisions: lib bin test_
55
//@ [lib]compile-flags: --crate-type lib
66
//@ [bin]compile-flags: --crate-type bin
7-
//@ [test]compile-flags: --test
7+
//@ [test_]compile-flags: --test
88

99
#[expect(missing_docs)]
1010
pub fn foo() {}

0 commit comments

Comments
 (0)