Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -Z check-cfg-features to enable compile-time checking of features #10408

Merged
merged 3 commits into from
Feb 22, 2022

Conversation

Urgau
Copy link
Member

@Urgau Urgau commented Feb 22, 2022

This pull-request implements the "Cargo support" section of RFC 3013: Checking conditional compilation at compile time.

The support is added in the form of an new unstable flags: -Z check-cfg-features that pass all possible features of a package to rustc unstable --check-cfg command line as --check-cfg=values(feature, ...). This enables compile time checking of feature values in #[cfg], cfg! and #[cfg_attr].

This new flag currently only affects rustc but rustdoc support will be added as soon as it's support is merged.

Note than the intent is that this command line options become the default when stabilizing as suggested in the RFC:

[..] it seems uncontroversial for Cargo to enable checking for feature = "..." values immediately [..]

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @ehuss (or someone else) soon.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 22, 2022
@alexcrichton
Copy link
Member

Nice, thanks!

Would you be up for also adding a test for the up-and-coming namespaced features to ensure that works well too? For example having a test that uses dep:foo as a feature and ensures that the right --check-cfg argument is still passed.

…tion issues

See https://github.com/rust-lang/cargo/runs/5290789288?check_suite_focus=true
Where the expected is: --check-cfg 'values(feature, "f_a", "f_b")'
But we got: --check-cfg "values(feature, /"f_a/", /"f_b/")"
@Urgau
Copy link
Member Author

Urgau commented Feb 22, 2022

Would you be up for also adding a test for the up-and-coming namespaced features to ensure that works well too? For example having a test that uses dep:foo as a feature and ensures that the right --check-cfg argument is still passed.

Done in 4ac4f3d. And just to confirm, in case below bar is not longer a feature, right ? Only f_a and f_b are now features ?

[dependencies]
bar = { path = "bar/", optional = true }
[features]
f_a = ["dep:bar"]
f_b = []

@alexcrichton
Copy link
Member

I believe so, yes, thanks!

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Collaborator

bors commented Feb 22, 2022

📌 Commit 4ac4f3d has been approved by alexcrichton

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 22, 2022
@bors
Copy link
Collaborator

bors commented Feb 22, 2022

⌛ Testing commit 4ac4f3d with merge dcb2888...

@bors
Copy link
Collaborator

bors commented Feb 22, 2022

☀️ Test successful - checks-actions
Approved by: alexcrichton
Pushing dcb2888 to master...

@bors bors merged commit dcb2888 into rust-lang:master Feb 22, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 23, 2022
Update cargo

8 commits in ea2a21c994ca1e4d4c49412827b3cf4dcb158b1d..d6cdde584a1f15ea086bae922e20fd27f7165431
2022-02-15 04:24:07 +0000 to 2022-02-22 19:55:51 +0000
- Add common profile validation. (rust-lang/cargo#10411)
- Add -Z check-cfg-features to enable compile-time checking of features (rust-lang/cargo#10408)
- Remove invalid target-specific dependency example. (rust-lang/cargo#10401)
- Fix errors in `cargo fetch` usage guide (rust-lang/cargo#10398)
- Fix some broken doc links. (rust-lang/cargo#10404)
- Implement "artifact dependencies" (RFC-3028) (rust-lang/cargo#9992)
- Print executable name on cargo test --no-run rust-lang/cargo#2 (rust-lang/cargo#10346)
- Avoid new deprecation warnings from clap 3.1.0 (rust-lang/cargo#10396)
@ehuss ehuss added this to the 1.61.0 milestone Feb 24, 2022
bors added a commit that referenced this pull request Feb 27, 2022
Add -Z check-cfg-features support for rustdoc

This PR is a follow to #10408 where support for compile-time checking of features was implemented for `rustc`.

At the time `rustdoc` support wasn't yet merged, but now that it has been [merged](rust-lang/rust#94154), this pull-request add support for it in the `doc` and `test --doc` (doctest) mode.

r? `@alexcrichton`
bors added a commit that referenced this pull request Apr 12, 2022
Add support for rustc --check-cfg well known names and values

This pull-request add support for `rustc` `--check-cfg` well known names and values.

### What does this PR try to resolve?

This pull-request add support for `rustc` `--check-cfg` well known names and values:

- `-Z check-cfg-well-known-names`: `--check-cfg names()` well known names
- `-Z check-cfg-well-known-values`: `--check-cfg values()` well known values

### How should we test and review this PR?

#### Testing

`cargo check -Z check-cfg-well-known-names` and
`cargo check -Z check-cfg-well-known-values`

#### Review

This PR contains one commit that split `features_args` into `check_cfg_args`, add the well known support in it, adds call to that new function and add documentation and test for those new flags.

### Additional information

This was implemented as two new additional flags because it's most likely that these flags will not be stabilize at the same time and also because some of these flags may become the default.

RFC: rust-lang/rfcs#3013
`-Z check-cfg-features`: #10408
`cargo doc` support: #10428
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants