Skip to content

Commit 74ef21b

Browse files
committed
Auto merge of #13195 - Urgau:check-cfg-rework-comment, r=weihanglo
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.
2 parents 363a2d1 + 2dafb34 commit 74ef21b

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/cargo/core/compiler/mod.rs

+18-7
Original file line numberDiff line numberDiff line change
@@ -1255,14 +1255,25 @@ fn trim_paths_args(
12551255
/// [`check-cfg`]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg
12561256
fn check_cfg_args(cx: &Context<'_, '_>, unit: &Unit) -> Vec<OsString> {
12571257
if cx.bcx.config.cli_unstable().check_cfg {
1258-
// This generate something like this:
1259-
// - cfg()
1260-
// - cfg(feature, values("foo", "bar"))
1258+
// The routine below generates the --check-cfg arguments. Our goals here are to
1259+
// enable the checking of conditionals and pass the list of declared features.
12611260
//
1262-
// NOTE: Despite only explicitly specifying `feature`, well known names and values
1263-
// are implicitly enabled when one or more `--check-cfg` argument is passed.
1264-
// NOTE: Never generate a empty `values()` since it would mean that it's possible
1265-
// to have `cfg(feature)` without a feature name which is impossible.
1261+
// In the simplified case, it would resemble something like this:
1262+
//
1263+
// --check-cfg=cfg() --check-cfg=cfg(feature, values(...))
1264+
//
1265+
// but having `cfg()` is redundant with the second argument (as well-known names
1266+
// and values are implicitly enabled when one or more `--check-cfg` argument is
1267+
// passed) so we don't emit it:
1268+
//
1269+
// --check-cfg=cfg(feature, values(...))
1270+
//
1271+
// expect when there are no features declared, where we can't generate the
1272+
// `cfg(feature, values())` argument since it would mean that it is somehow
1273+
// possible to have a `#[cfg(feature)]` without a feature name, which is
1274+
// impossible and not what we want, so we just generate:
1275+
//
1276+
// --check-cfg=cfg()
12661277

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

0 commit comments

Comments
 (0)