Skip to content

Commit f35b436

Browse files
authored
Unrolled build for rust-lang#117522
Rollup merge of rust-lang#117522 - Urgau:check-cfg-cli-own-lint, r=petrochenkov Remove `--check-cfg` checking of command line `--cfg` args Back in rust-lang#100574 we added to the `unexpected_cfgs` lint the checking of `--cfg` CLI arguments and emitted unexpected names and values for them. The implementation works as expected, but it's usability in particular when using it in combination with Cargo+`RUSTFLAGS` as people who set `RUSTFLAGS=--cfg=tokio_unstable` (or whatever) have `unexpected_cfgs` warnings on all of their crates is debatable. ~~To fix this issue this PR proposes that we split the CLI argument checking into it's own separate allow-by-default lint: `unexpected_cli_cfgs`.~~ ~~This has the advantage of letting people who want CLI warnings have them (although not by default anymore), while still linting on every unexpected cfg name and values in the code.~~ After some discussion with the Cargo team ([Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/check-cfg.20and.20RUSTFLAGS.20interaction)) and member of the compiler team (see below), I propose that we follow the suggestion from `@epage:` never check `--cfg` arguments, but still reserve us the possibility to do it later. We would still lint on unexpected cfgs found in the source code no matter the `--cfg` args passed. This mean reverting rust-lang#100574 but NOT rust-lang#99519. r? `@petrochenkov`
2 parents e24e5af + a5658e6 commit f35b436

19 files changed

+32
-130
lines changed

compiler/rustc_lint/messages.ftl

-6
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,6 @@ lint_builtin_type_alias_generic_bounds = bounds on generic parameters are not en
128128
lint_builtin_type_alias_where_clause = where clauses are not enforced in type aliases
129129
.suggestion = the clause will not be checked when the type alias is used, and should be removed
130130
131-
lint_builtin_unexpected_cli_config_name = unexpected `{$name}` as condition name
132-
.help = was set with `--cfg` but isn't in the `--check-cfg` expected names
133-
134-
lint_builtin_unexpected_cli_config_value = unexpected condition value `{$value}` for condition name `{$name}`
135-
.help = was set with `--cfg` but isn't in the `--check-cfg` expected values
136-
137131
lint_builtin_unpermitted_type_init_label = this code causes undefined behavior when executed
138132
lint_builtin_unpermitted_type_init_label_suggestion = help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
139133

compiler/rustc_lint/src/builtin.rs

-25
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use crate::{
3333
BuiltinMutablesTransmutes, BuiltinNoMangleGeneric, BuiltinNonShorthandFieldPatterns,
3434
BuiltinSpecialModuleNameUsed, BuiltinTrivialBounds, BuiltinTypeAliasGenericBounds,
3535
BuiltinTypeAliasGenericBoundsSuggestion, BuiltinTypeAliasWhereClause,
36-
BuiltinUnexpectedCliConfigName, BuiltinUnexpectedCliConfigValue,
3736
BuiltinUngatedAsyncFnTrackCaller, BuiltinUnpermittedTypeInit,
3837
BuiltinUnpermittedTypeInitSub, BuiltinUnreachablePub, BuiltinUnsafe,
3938
BuiltinUnstableFeatures, BuiltinUnusedDocComment, BuiltinUnusedDocCommentSub,
@@ -60,7 +59,6 @@ use rustc_middle::ty::GenericArgKind;
6059
use rustc_middle::ty::ToPredicate;
6160
use rustc_middle::ty::TypeVisitableExt;
6261
use rustc_middle::ty::{self, Ty, TyCtxt, VariantDef};
63-
use rustc_session::config::ExpectedValues;
6462
use rustc_session::lint::{BuiltinLintDiagnostics, FutureIncompatibilityReason};
6563
use rustc_span::edition::Edition;
6664
use rustc_span::source_map::Spanned;
@@ -2889,26 +2887,3 @@ impl EarlyLintPass for SpecialModuleName {
28892887
}
28902888
}
28912889
}
2892-
2893-
pub use rustc_session::lint::builtin::UNEXPECTED_CFGS;
2894-
2895-
declare_lint_pass!(UnexpectedCfgs => [UNEXPECTED_CFGS]);
2896-
2897-
impl EarlyLintPass for UnexpectedCfgs {
2898-
fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &ast::Crate) {
2899-
let cfg = &cx.sess().parse_sess.config;
2900-
let check_cfg = &cx.sess().parse_sess.check_config;
2901-
for &(name, value) in cfg {
2902-
match check_cfg.expecteds.get(&name) {
2903-
Some(ExpectedValues::Some(values)) if !values.contains(&value) => {
2904-
let value = value.unwrap_or(kw::Empty);
2905-
cx.emit_lint(UNEXPECTED_CFGS, BuiltinUnexpectedCliConfigValue { name, value });
2906-
}
2907-
None if check_cfg.exhaustive_names => {
2908-
cx.emit_lint(UNEXPECTED_CFGS, BuiltinUnexpectedCliConfigName { name });
2909-
}
2910-
_ => { /* expected */ }
2911-
}
2912-
}
2913-
}
2914-
}

compiler/rustc_lint/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ early_lint_methods!(
179179
IncompleteInternalFeatures: IncompleteInternalFeatures,
180180
RedundantSemicolons: RedundantSemicolons,
181181
UnusedDocComment: UnusedDocComment,
182-
UnexpectedCfgs: UnexpectedCfgs,
183182
]
184183
]
185184
);

compiler/rustc_lint/src/lints.rs

-15
Original file line numberDiff line numberDiff line change
@@ -553,21 +553,6 @@ pub enum BuiltinSpecialModuleNameUsed {
553553
Main,
554554
}
555555

556-
#[derive(LintDiagnostic)]
557-
#[diag(lint_builtin_unexpected_cli_config_name)]
558-
#[help]
559-
pub struct BuiltinUnexpectedCliConfigName {
560-
pub name: Symbol,
561-
}
562-
563-
#[derive(LintDiagnostic)]
564-
#[diag(lint_builtin_unexpected_cli_config_value)]
565-
#[help]
566-
pub struct BuiltinUnexpectedCliConfigValue {
567-
pub name: Symbol,
568-
pub value: Symbol,
569-
}
570-
571556
// deref_into_dyn_supertrait.rs
572557
#[derive(LintDiagnostic)]
573558
#[diag(lint_supertrait_as_deref_target)]

compiler/rustc_lint_defs/src/builtin.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3439,6 +3439,7 @@ declare_lint_pass! {
34393439
UNCONDITIONAL_PANIC,
34403440
UNCONDITIONAL_RECURSION,
34413441
UNDEFINED_NAKED_FUNCTION_ABI,
3442+
UNEXPECTED_CFGS,
34423443
UNFULFILLED_LINT_EXPECTATIONS,
34433444
UNINHABITED_STATIC,
34443445
UNKNOWN_CRATE_TYPES,

src/doc/unstable-book/src/compiler-flags/check-cfg.md

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ and `cfg!(name = "value")` call. It will check that the `"value"` specified is p
3535
list of expected values. If `"value"` is not in it, then `rustc` will report an `unexpected_cfgs`
3636
lint diagnostic. The default diagnostic level for this lint is `Warn`.
3737

38+
The command line `--cfg` arguments are currently *NOT* checked but may very well be checked in
39+
the future.
40+
3841
To enable checking of values, but to provide an empty set of expected values, use these forms:
3942

4043
```bash
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: unexpected `cfg` condition name: `unknown_key`
2-
--> $DIR/exhaustive-names-values.rs:12:7
2+
--> $DIR/exhaustive-names-values.rs:11:7
33
|
44
LL | #[cfg(unknown_key = "value")]
55
| ^^^^^^^^^^^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL | #[cfg(unknown_key = "value")]
88
= note: `#[warn(unexpected_cfgs)]` on by default
99

1010
warning: unexpected `cfg` condition value: `value`
11-
--> $DIR/exhaustive-names-values.rs:16:7
11+
--> $DIR/exhaustive-names-values.rs:15:7
1212
|
1313
LL | #[cfg(test = "value")]
1414
| ^^^^----------
@@ -17,9 +17,5 @@ LL | #[cfg(test = "value")]
1717
|
1818
= note: no expected value for `test`
1919

20-
warning: unexpected `empty_cfg` as condition name
21-
|
22-
= help: was set with `--cfg` but isn't in the `--check-cfg` expected names
23-
24-
warning: 3 warnings emitted
20+
warning: 2 warnings emitted
2521

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: unexpected `cfg` condition name: `unknown_key`
2-
--> $DIR/exhaustive-names-values.rs:12:7
2+
--> $DIR/exhaustive-names-values.rs:11:7
33
|
44
LL | #[cfg(unknown_key = "value")]
55
| ^^^^^^^^^^^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL | #[cfg(unknown_key = "value")]
88
= note: `#[warn(unexpected_cfgs)]` on by default
99

1010
warning: unexpected `cfg` condition value: `value`
11-
--> $DIR/exhaustive-names-values.rs:16:7
11+
--> $DIR/exhaustive-names-values.rs:15:7
1212
|
1313
LL | #[cfg(test = "value")]
1414
| ^^^^----------
@@ -17,9 +17,5 @@ LL | #[cfg(test = "value")]
1717
|
1818
= note: no expected value for `test`
1919

20-
warning: unexpected `empty_names_values` as condition name
21-
|
22-
= help: was set with `--cfg` but isn't in the `--check-cfg` expected names
23-
24-
warning: 3 warnings emitted
20+
warning: 2 warnings emitted
2521

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: unexpected `cfg` condition name: `unknown_key`
2-
--> $DIR/exhaustive-names-values.rs:12:7
2+
--> $DIR/exhaustive-names-values.rs:11:7
33
|
44
LL | #[cfg(unknown_key = "value")]
55
| ^^^^^^^^^^^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL | #[cfg(unknown_key = "value")]
88
= note: `#[warn(unexpected_cfgs)]` on by default
99

1010
warning: unexpected `cfg` condition value: `value`
11-
--> $DIR/exhaustive-names-values.rs:16:7
11+
--> $DIR/exhaustive-names-values.rs:15:7
1212
|
1313
LL | #[cfg(test = "value")]
1414
| ^^^^----------
@@ -18,16 +18,12 @@ LL | #[cfg(test = "value")]
1818
= note: no expected value for `test`
1919

2020
warning: unexpected `cfg` condition value: `unk`
21-
--> $DIR/exhaustive-names-values.rs:20:7
21+
--> $DIR/exhaustive-names-values.rs:19:7
2222
|
2323
LL | #[cfg(feature = "unk")]
2424
| ^^^^^^^^^^^^^^^
2525
|
2626
= note: expected values for `feature` are: `std`
2727

28-
warning: unexpected condition value `` for condition name `feature`
29-
|
30-
= help: was set with `--cfg` but isn't in the `--check-cfg` expected values
31-
32-
warning: 4 warnings emitted
28+
warning: 3 warnings emitted
3329

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: unexpected `cfg` condition name: `unknown_key`
2-
--> $DIR/exhaustive-names-values.rs:12:7
2+
--> $DIR/exhaustive-names-values.rs:11:7
33
|
44
LL | #[cfg(unknown_key = "value")]
55
| ^^^^^^^^^^^^^^^^^^^^^
@@ -8,7 +8,7 @@ LL | #[cfg(unknown_key = "value")]
88
= note: `#[warn(unexpected_cfgs)]` on by default
99

1010
warning: unexpected `cfg` condition value: `value`
11-
--> $DIR/exhaustive-names-values.rs:16:7
11+
--> $DIR/exhaustive-names-values.rs:15:7
1212
|
1313
LL | #[cfg(test = "value")]
1414
| ^^^^----------
@@ -18,16 +18,12 @@ LL | #[cfg(test = "value")]
1818
= note: no expected value for `test`
1919

2020
warning: unexpected `cfg` condition value: `unk`
21-
--> $DIR/exhaustive-names-values.rs:20:7
21+
--> $DIR/exhaustive-names-values.rs:19:7
2222
|
2323
LL | #[cfg(feature = "unk")]
2424
| ^^^^^^^^^^^^^^^
2525
|
2626
= note: expected values for `feature` are: `std`
2727

28-
warning: unexpected `full` as condition name
29-
|
30-
= help: was set with `--cfg` but isn't in the `--check-cfg` expected names
31-
32-
warning: 4 warnings emitted
28+
warning: 3 warnings emitted
3329

tests/ui/check-cfg/exhaustive-names-values.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// Check warning for unexpected cfg in the code and in the CLI
2-
// arguments (here the revision cfg).
1+
// Check warning for unexpected cfg in the code.
32
//
43
// check-pass
54
// revisions: empty_names_values empty_cfg feature full

tests/ui/check-cfg/exhaustive-names.empty_names.stderr

+1-5
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,5 @@ LL | #[cfg(unknown_key = "value")]
77
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
88
= note: `#[warn(unexpected_cfgs)]` on by default
99

10-
warning: unexpected `empty_names` as condition name
11-
|
12-
= help: was set with `--cfg` but isn't in the `--check-cfg` expected names
13-
14-
warning: 2 warnings emitted
10+
warning: 1 warning emitted
1511

tests/ui/check-cfg/exhaustive-names.exhaustive_names.stderr

+1-5
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,5 @@ LL | #[cfg(unknown_key = "value")]
77
= help: expected names are: `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
88
= note: `#[warn(unexpected_cfgs)]` on by default
99

10-
warning: unexpected `exhaustive_names` as condition name
11-
|
12-
= help: was set with `--cfg` but isn't in the `--check-cfg` expected names
13-
14-
warning: 2 warnings emitted
10+
warning: 1 warning emitted
1511

tests/ui/check-cfg/exhaustive-values.empty_cfg.stderr

+1-5
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,5 @@ LL | #[cfg(test = "value")]
99
= note: no expected value for `test`
1010
= note: `#[warn(unexpected_cfgs)]` on by default
1111

12-
warning: unexpected `empty_cfg` as condition name
13-
|
14-
= help: was set with `--cfg` but isn't in the `--check-cfg` expected names
15-
16-
warning: 2 warnings emitted
12+
warning: 1 warning emitted
1713

tests/ui/check-cfg/mix.cfg.stderr

+1-9
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,6 @@ LL | #[cfg_attr(uu, test)]
3838
|
3939
= help: expected names are: `cfg`, `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `names_values`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
4040

41-
warning: unexpected condition value `bar` for condition name `feature`
42-
|
43-
= help: was set with `--cfg` but isn't in the `--check-cfg` expected values
44-
45-
warning: unexpected `unknown_name` as condition name
46-
|
47-
= help: was set with `--cfg` but isn't in the `--check-cfg` expected names
48-
4941
warning: unexpected `cfg` condition name: `widnows`
5042
--> $DIR/mix.rs:43:10
5143
|
@@ -188,5 +180,5 @@ LL | cfg!(all(feature = "zebra", feature = "zebra", feature = "zebra"));
188180
|
189181
= note: expected values for `feature` are: `foo`
190182

191-
warning: 28 warnings emitted
183+
warning: 26 warnings emitted
192184

tests/ui/check-cfg/mix.names_values.stderr

+1-9
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,6 @@ LL | #[cfg_attr(uu, test)]
3838
|
3939
= help: expected names are: `cfg`, `debug_assertions`, `doc`, `doctest`, `feature`, `miri`, `names_values`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
4040

41-
warning: unexpected condition value `bar` for condition name `feature`
42-
|
43-
= help: was set with `--cfg` but isn't in the `--check-cfg` expected values
44-
45-
warning: unexpected `unknown_name` as condition name
46-
|
47-
= help: was set with `--cfg` but isn't in the `--check-cfg` expected names
48-
4941
warning: unexpected `cfg` condition name: `widnows`
5042
--> $DIR/mix.rs:43:10
5143
|
@@ -188,5 +180,5 @@ LL | cfg!(all(feature = "zebra", feature = "zebra", feature = "zebra"));
188180
|
189181
= note: expected values for `feature` are: `foo`
190182

191-
warning: 28 warnings emitted
183+
warning: 26 warnings emitted
192184

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: unexpected `cfg` condition value: `sedre`
2-
--> $DIR/unexpected-cfg-value.rs:11:7
2+
--> $DIR/unexpected-cfg-value.rs:9:7
33
|
44
LL | #[cfg(feature = "sedre")]
55
| ^^^^^^^^^^-------
@@ -10,16 +10,12 @@ LL | #[cfg(feature = "sedre")]
1010
= note: `#[warn(unexpected_cfgs)]` on by default
1111

1212
warning: unexpected `cfg` condition value: `rand`
13-
--> $DIR/unexpected-cfg-value.rs:18:7
13+
--> $DIR/unexpected-cfg-value.rs:16:7
1414
|
1515
LL | #[cfg(feature = "rand")]
1616
| ^^^^^^^^^^^^^^^^
1717
|
1818
= note: expected values for `feature` are: `full`, `serde`
1919

20-
warning: unexpected condition value `rand` for condition name `feature`
21-
|
22-
= help: was set with `--cfg` but isn't in the `--check-cfg` expected values
23-
24-
warning: 3 warnings emitted
20+
warning: 2 warnings emitted
2521

tests/ui/check-cfg/unexpected-cfg-value.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
// Check warning for invalid configuration value in the code and
2-
// in the cli
1+
// Check for unexpected configuration value in the code.
32
//
43
// check-pass
54
// revisions: values cfg
6-
// compile-flags: --cfg=feature="rand" -Z unstable-options
7-
// compile-flags: --check-cfg=cfg(values,cfg)
5+
// compile-flags: -Z unstable-options
86
// [values]compile-flags: --check-cfg=values(feature,"serde","full")
97
// [cfg]compile-flags: --check-cfg=cfg(feature,values("serde","full"))
108

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: unexpected `cfg` condition value: `sedre`
2-
--> $DIR/unexpected-cfg-value.rs:11:7
2+
--> $DIR/unexpected-cfg-value.rs:9:7
33
|
44
LL | #[cfg(feature = "sedre")]
55
| ^^^^^^^^^^-------
@@ -10,16 +10,12 @@ LL | #[cfg(feature = "sedre")]
1010
= note: `#[warn(unexpected_cfgs)]` on by default
1111

1212
warning: unexpected `cfg` condition value: `rand`
13-
--> $DIR/unexpected-cfg-value.rs:18:7
13+
--> $DIR/unexpected-cfg-value.rs:16:7
1414
|
1515
LL | #[cfg(feature = "rand")]
1616
| ^^^^^^^^^^^^^^^^
1717
|
1818
= note: expected values for `feature` are: `full`, `serde`
1919

20-
warning: unexpected condition value `rand` for condition name `feature`
21-
|
22-
= help: was set with `--cfg` but isn't in the `--check-cfg` expected values
23-
24-
warning: 3 warnings emitted
20+
warning: 2 warnings emitted
2521

0 commit comments

Comments
 (0)