Skip to content

Commit 05166ef

Browse files
committed
Add -Zcheck-target-cfgs and check-target-cfgs in preparation for linting
1 parent 518bea3 commit 05166ef

File tree

3 files changed

+71
-38
lines changed

3 files changed

+71
-38
lines changed

src/cargo/core/features.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,9 @@ features! {
579579

580580
/// Allows use of multiple build scripts.
581581
(unstable, multiple_build_scripts, "", "reference/unstable.html#multiple-build-scripts"),
582+
583+
/// Allows checking target cfgs and configuring the `cargo.unexpected_cfgs` lint
584+
(unstable, check_target_cfgs, "", "reference/unstable.html#check-target-cfgs"),
582585
}
583586

584587
/// Status and metadata for a single unstable feature.
@@ -825,6 +828,7 @@ unstable_cli_options!(
825828
#[serde(deserialize_with = "deserialize_comma_separated_list")]
826829
build_std_features: Option<Vec<String>> = ("Configure features enabled for the standard library itself when building the standard library"),
827830
cargo_lints: bool = ("Enable the `[lints.cargo]` table"),
831+
check_target_cfgs: bool = ("Enable unexpected cfgs checking in `[target.'cfg(...)']` tables"),
828832
checksum_freshness: bool = ("Use a checksum to determine if output is fresh rather than filesystem mtime"),
829833
codegen_backend: bool = ("Enable the `codegen-backend` option in profiles in .cargo/config.toml file"),
830834
config_include: bool = ("Enable the `include` key in config files"),
@@ -1335,6 +1339,7 @@ impl CliUnstable {
13351339
"build-std" => self.build_std = Some(parse_list(v)),
13361340
"build-std-features" => self.build_std_features = Some(parse_list(v)),
13371341
"cargo-lints" => self.cargo_lints = parse_empty(k, v)?,
1342+
"check-target-cfgs" => self.check_target_cfgs = parse_empty(k, v)?,
13381343
"codegen-backend" => self.codegen_backend = parse_empty(k, v)?,
13391344
"config-include" => self.config_include = parse_empty(k, v)?,
13401345
"direct-minimal-versions" => self.direct_minimal_versions = parse_empty(k, v)?,

src/doc/src/reference/unstable.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ Each new feature described below should explain how to use it.
129129
* [warnings](#warnings) --- controls warning behavior; options for allowing or denying warnings.
130130
* [Package message format](#package-message-format) --- Message format for `cargo package`.
131131
* [`fix-edition`](#fix-edition) --- A permanently unstable edition migration helper.
132+
* [check-target-cfgs](#check-target-cfgs) --- Allows checking unexpected cfgs in `[target.'cfg(...)']`
132133

133134
## allow-features
134135

@@ -1968,6 +1969,31 @@ For example:
19681969
cargo +nightly fix -Zfix-edition=end=2024,future
19691970
```
19701971

1972+
## check-target-cfgs
1973+
1974+
* Tracking Issue: [#00000](https://github.com/rust-lang/cargo/issues/00000)
1975+
1976+
This feature checks for unexpected cfgs in `[target.'cfg(...)']` entries, based
1977+
on `rustc --print=check-cfg`.
1978+
1979+
```sh
1980+
cargo check -Zcheck-target-cfgs
1981+
```
1982+
1983+
It follows the lint Rust `unexpected_cfgs` lint configuration:
1984+
1985+
```toml
1986+
[target.'cfg(foo)'.dependencies]
1987+
cfg-if = "1.0"
1988+
1989+
[lints.cargo.unexpected_cfgs]
1990+
level = "deny"
1991+
1992+
[lints.rust.unexpected_cfgs]
1993+
level = "warn"
1994+
check-cfg = ['cfg(foo)']
1995+
```
1996+
19711997
# Stabilized and removed features
19721998

19731999
## Compile progress

tests/testsuite/cargo/z_help/stdout.term.svg

Lines changed: 40 additions & 38 deletions
Loading

0 commit comments

Comments
 (0)