Skip to content

Commit 7cefc9d

Browse files
committed
compiletest: add enable-by-default check-cfg
1 parent 221f264 commit 7cefc9d

40 files changed

+107
-58
lines changed

src/tools/compiletest/src/runtest.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,12 +1027,31 @@ impl<'test> TestCx<'test> {
10271027
}
10281028

10291029
fn set_revision_flags(&self, cmd: &mut Command) {
1030+
// Normalize revisions to be lowercase and replace `-`s with `_`s.
1031+
// Otherwise the `--cfg` flag is not valid.
1032+
let normalize_revision = |revision: &str| revision.to_lowercase().replace("-", "_");
1033+
10301034
if let Some(revision) = self.revision {
1031-
// Normalize revisions to be lowercase and replace `-`s with `_`s.
1032-
// Otherwise the `--cfg` flag is not valid.
1033-
let normalized_revision = revision.to_lowercase().replace("-", "_");
1035+
let normalized_revision = normalize_revision(revision);
10341036
cmd.args(&["--cfg", &normalized_revision]);
10351037
}
1038+
1039+
if !self.props.no_auto_check_cfg {
1040+
let mut check_cfg = String::with_capacity(25);
1041+
1042+
// Generate `cfg(FALSE, REV1, ..., REVN)` (for all possible revisions)
1043+
//
1044+
// For compatibility reason we consider the `FALSE` cfg to be expected
1045+
// since it is extensively used in the testsuite.
1046+
check_cfg.push_str("cfg(FALSE");
1047+
for revision in &self.props.revisions {
1048+
check_cfg.push_str(",");
1049+
check_cfg.push_str(&normalize_revision(&revision));
1050+
}
1051+
check_cfg.push_str(")");
1052+
1053+
cmd.args(&["--check-cfg", &check_cfg]);
1054+
}
10361055
}
10371056

10381057
fn typecheck_source(&self, src: String) -> ProcRes {
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Check to see if we can get parameters from an @argsfile file
22
//
33
//@ build-pass
4-
//@ compile-flags: --cfg cmdline_set @{{src-base}}/argfile/commandline-argfile.args
4+
//@ compile-flags: --cfg cmdline_set --check-cfg=cfg(cmdline_set,unbroken)
5+
//@ compile-flags: @{{src-base}}/argfile/commandline-argfile.args
56

67
#[cfg(not(cmdline_set))]
78
compile_error!("cmdline_set not set");
89

910
#[cfg(not(unbroken))]
1011
compile_error!("unbroken not set");
1112

12-
fn main() {
13-
}
13+
fn main() {}

tests/ui/cfg/cfg-in-crate-1.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//@ run-pass
2-
//@ compile-flags: --cfg bar -D warnings
2+
//@ compile-flags: --cfg bar --check-cfg=cfg(bar) -D warnings
3+
34
#![cfg(bar)]
45

56
fn main() {}

tests/ui/cfg/cfg-macros-foo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ run-pass
2-
//@ compile-flags: --cfg foo
2+
//@ compile-flags: --cfg foo --check-cfg=cfg(foo)
33

44
// check that cfg correctly chooses between the macro impls (see also
55
// cfg-macros-notfoo.rs)

tests/ui/cfg/cfg-path-error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//@ check-fail
22

3+
#![allow(unexpected_cfgs)] // invalid cfgs
4+
35
#[cfg(any(foo, foo::bar))]
46
//~^ERROR `cfg` predicate key must be an identifier
57
fn foo1() {}

tests/ui/cfg/cfg-path-error.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
error: `cfg` predicate key must be an identifier
2-
--> $DIR/cfg-path-error.rs:3:16
2+
--> $DIR/cfg-path-error.rs:5:16
33
|
44
LL | #[cfg(any(foo, foo::bar))]
55
| ^^^^^^^^
66

77
error: `cfg` predicate key must be an identifier
8-
--> $DIR/cfg-path-error.rs:7:11
8+
--> $DIR/cfg-path-error.rs:9:11
99
|
1010
LL | #[cfg(any(foo::bar, foo))]
1111
| ^^^^^^^^
1212

1313
error: `cfg` predicate key must be an identifier
14-
--> $DIR/cfg-path-error.rs:11:16
14+
--> $DIR/cfg-path-error.rs:13:16
1515
|
1616
LL | #[cfg(all(foo, foo::bar))]
1717
| ^^^^^^^^
1818

1919
error: `cfg` predicate key must be an identifier
20-
--> $DIR/cfg-path-error.rs:15:11
20+
--> $DIR/cfg-path-error.rs:17:11
2121
|
2222
LL | #[cfg(all(foo::bar, foo))]
2323
| ^^^^^^^^

tests/ui/cfg/cfg_attr.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//@ run-pass
22
//@ compile-flags:--cfg set1 --cfg set2
3-
#![allow(dead_code)]
3+
4+
#![allow(dead_code, unexpected_cfgs)]
5+
46
use std::fmt::Debug;
57

68
struct NotDebugable;

tests/ui/cfg/cfgs-on-items.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//@ run-pass
2-
//@ compile-flags: --cfg fooA --cfg fooB
2+
//@ compile-flags: --cfg fooA --cfg fooB --check-cfg=cfg(fooA,fooB,fooC,bar)
33

44
// fooA AND !bar
5-
65
#[cfg(all(fooA, not(bar)))]
76
fn foo1() -> isize { 1 }
87

tests/ui/cfg/diagnostics-not-a-def.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
#![feature(lint_reasons)]
2+
13
pub mod inner {
4+
#[expect(unexpected_cfgs)]
25
pub fn i_am_here() {
36
#[cfg(feature = "another one that doesn't exist")]
47
loop {}

tests/ui/cfg/diagnostics-not-a-def.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0425]: cannot find function `i_am_not` in module `inner`
2-
--> $DIR/diagnostics-not-a-def.rs:11:12
2+
--> $DIR/diagnostics-not-a-def.rs:14:12
33
|
44
LL | inner::i_am_not();
55
| ^^^^^^^^ not found in `inner`

0 commit comments

Comments
 (0)