diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index 5070f016d3c6..69ac4644941d 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -376,6 +376,7 @@ pub struct Config { pub only_modified: bool, pub target_cfgs: OnceLock, + pub builtin_cfg_names: OnceLock>, pub nocapture: bool, @@ -443,6 +444,11 @@ pub fn can_unwind(&self) -> bool { self.target_cfg().panic == PanicStrategy::Unwind } + /// Get the list of builtin, 'well known' cfg names + pub fn builtin_cfg_names(&self) -> &HashSet { + self.builtin_cfg_names.get_or_init(|| builtin_cfg_names(self)) + } + pub fn has_threads(&self) -> bool { // Wasm targets don't have threads unless `-threads` is in the target // name, such as `wasm32-wasip1-threads`. @@ -654,6 +660,18 @@ pub enum Endian { Big, } +fn builtin_cfg_names(config: &Config) -> HashSet { + rustc_output( + config, + &["--print=check-cfg", "-Zunstable-options", "--check-cfg=cfg()"], + Default::default(), + ) + .lines() + .map(|l| if let Some((name, _)) = l.split_once('=') { name.to_string() } else { l.to_string() }) + .chain(std::iter::once(String::from("test"))) + .collect() +} + fn rustc_output(config: &Config, args: &[&str], envs: HashMap) -> String { let mut command = Command::new(&config.rustc_path); add_dylib_path(&mut command, iter::once(&config.compile_lib_path)); diff --git a/src/tools/compiletest/src/lib.rs b/src/tools/compiletest/src/lib.rs index 0f514db42bf9..490df3132285 100644 --- a/src/tools/compiletest/src/lib.rs +++ b/src/tools/compiletest/src/lib.rs @@ -362,6 +362,7 @@ fn make_absolute(path: PathBuf) -> PathBuf { force_rerun: matches.opt_present("force-rerun"), target_cfgs: OnceLock::new(), + builtin_cfg_names: OnceLock::new(), nocapture: matches.opt_present("nocapture"), diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 7db37af60d2c..42e5dcf258fc 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -478,6 +478,9 @@ fn set_revision_flags(&self, cmd: &mut Command) { "error: redundant cfg argument `{normalized_revision}` is already created by the revision" ); } + if self.config.builtin_cfg_names().contains(&normalized_revision) { + panic!("error: revision `{normalized_revision}` collides with a builtin cfg"); + } cmd.args(cfg_arg); } diff --git a/tests/ui/lint/lint-missing-doc-expect.rs b/tests/ui/lint/lint-missing-doc-expect.rs index 991f65003dc2..b1abf8b69620 100644 --- a/tests/ui/lint/lint-missing-doc-expect.rs +++ b/tests/ui/lint/lint-missing-doc-expect.rs @@ -1,10 +1,10 @@ // Make sure that `#[expect(missing_docs)]` is always correctly fulfilled. //@ check-pass -//@ revisions: lib bin test +//@ revisions: lib bin test_ //@ [lib]compile-flags: --crate-type lib //@ [bin]compile-flags: --crate-type bin -//@ [test]compile-flags: --test +//@ [test_]compile-flags: --test #[expect(missing_docs)] pub fn foo() {}