Skip to content

Commit

Permalink
Auto merge of #13195 - Urgau:check-cfg-rework-comment, r=weihanglo
Browse files Browse the repository at this point in the history
Rework `--check-cfg` generation comment

While working on something related to `--check-cfg`, I looked back at this comment and realized it could be improved, so here is my PR improving it.
  • Loading branch information
bors committed Dec 22, 2023
2 parents 363a2d1 + 2dafb34 commit 74ef21b
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1255,14 +1255,25 @@ fn trim_paths_args(
/// [`check-cfg`]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg
fn check_cfg_args(cx: &Context<'_, '_>, unit: &Unit) -> Vec<OsString> {
if cx.bcx.config.cli_unstable().check_cfg {
// This generate something like this:
// - cfg()
// - cfg(feature, values("foo", "bar"))
// The routine below generates the --check-cfg arguments. Our goals here are to
// enable the checking of conditionals and pass the list of declared features.
//
// NOTE: Despite only explicitly specifying `feature`, well known names and values
// are implicitly enabled when one or more `--check-cfg` argument is passed.
// NOTE: Never generate a empty `values()` since it would mean that it's possible
// to have `cfg(feature)` without a feature name which is impossible.
// In the simplified case, it would resemble something like this:
//
// --check-cfg=cfg() --check-cfg=cfg(feature, values(...))
//
// but having `cfg()` is redundant with the second argument (as well-known names
// and values are implicitly enabled when one or more `--check-cfg` argument is
// passed) so we don't emit it:
//
// --check-cfg=cfg(feature, values(...))
//
// expect when there are no features declared, where we can't generate the
// `cfg(feature, values())` argument since it would mean that it is somehow
// possible to have a `#[cfg(feature)]` without a feature name, which is
// impossible and not what we want, so we just generate:
//
// --check-cfg=cfg()

let gross_cap_estimation = unit.pkg.summary().features().len() * 7 + 25;
let mut arg_feature = OsString::with_capacity(gross_cap_estimation);
Expand Down

0 comments on commit 74ef21b

Please sign in to comment.