Skip to content

Commit c49e38c

Browse files
authored
Small cleanup to normalize_dependencies (#16022)
This PR is a small cleanup to normalize_dependencies that doesn't change any behavior. Previously, `normalize_dependencies` was called with one of 3 different values for the `kind` argument: `None`, `Some(DepKind::Build)`, or `Some(DepKind::Development)`. In particular, `kind` was never `Some(DepKind::Normal)`. This PR drops the `Option` and replaces `None` with `DepKind::Normal`. Also, there was previously a little bit of dead code (that was checking for `None` in a branch where `None` was impossible). This PR removes that.
2 parents 8cf2b14 + 7397427 commit c49e38c

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ fn normalize_toml(
447447
edition,
448448
&features,
449449
original_toml.dependencies.as_ref(),
450-
None,
450+
DepKind::Normal,
451451
&inherit,
452452
&workspace_root,
453453
package_root,
@@ -467,7 +467,7 @@ fn normalize_toml(
467467
edition,
468468
&features,
469469
original_toml.dev_dependencies(),
470-
Some(DepKind::Development),
470+
DepKind::Development,
471471
&inherit,
472472
&workspace_root,
473473
package_root,
@@ -487,7 +487,7 @@ fn normalize_toml(
487487
edition,
488488
&features,
489489
original_toml.build_dependencies(),
490-
Some(DepKind::Build),
490+
DepKind::Build,
491491
&inherit,
492492
&workspace_root,
493493
package_root,
@@ -500,7 +500,7 @@ fn normalize_toml(
500500
edition,
501501
&features,
502502
platform.dependencies.as_ref(),
503-
None,
503+
DepKind::Normal,
504504
&inherit,
505505
&workspace_root,
506506
package_root,
@@ -520,7 +520,7 @@ fn normalize_toml(
520520
edition,
521521
&features,
522522
platform.dev_dependencies(),
523-
Some(DepKind::Development),
523+
DepKind::Development,
524524
&inherit,
525525
&workspace_root,
526526
package_root,
@@ -540,7 +540,7 @@ fn normalize_toml(
540540
edition,
541541
&features,
542542
platform.build_dependencies(),
543-
Some(DepKind::Build),
543+
DepKind::Build,
544544
&inherit,
545545
&workspace_root,
546546
package_root,
@@ -873,7 +873,7 @@ fn normalize_dependencies<'a>(
873873
edition: Edition,
874874
features: &Features,
875875
orig_deps: Option<&BTreeMap<manifest::PackageName, manifest::InheritableDependency>>,
876-
kind: Option<DepKind>,
876+
kind: DepKind,
877877
inherit: &dyn Fn() -> CargoResult<&'a InheritableFields>,
878878
workspace_root: &dyn Fn() -> CargoResult<&'a Path>,
879879
package_root: &Path,
@@ -906,27 +906,27 @@ fn normalize_dependencies<'a>(
906906
if d.public.is_some() {
907907
let with_public_feature = features.require(Feature::public_dependency()).is_ok();
908908
let with_z_public = gctx.cli_unstable().public_dependency;
909-
if matches!(kind, None) {
910-
if !with_public_feature && !with_z_public {
911-
d.public = None;
912-
warnings.push(format!(
913-
"ignoring `public` on dependency {name_in_toml}, pass `-Zpublic-dependency` to enable support for it"
914-
))
909+
match kind {
910+
DepKind::Normal => {
911+
if !with_public_feature && !with_z_public {
912+
d.public = None;
913+
warnings.push(format!(
914+
"ignoring `public` on dependency {name_in_toml}, pass `-Zpublic-dependency` to enable support for it"
915+
));
916+
}
915917
}
916-
} else {
917-
let kind_name = match kind {
918-
Some(k) => k.kind_table(),
919-
None => "dependencies",
920-
};
921-
let hint = format!(
922-
"'public' specifier can only be used on regular dependencies, not {kind_name}",
923-
);
924-
if with_public_feature || with_z_public {
925-
bail!(hint)
926-
} else {
927-
// If public feature isn't enabled in nightly, we instead warn that.
928-
warnings.push(hint);
929-
d.public = None;
918+
DepKind::Development | DepKind::Build => {
919+
let kind_name = kind.kind_table();
920+
let hint = format!(
921+
"'public' specifier can only be used on regular dependencies, not {kind_name}",
922+
);
923+
if with_public_feature || with_z_public {
924+
bail!(hint)
925+
} else {
926+
// If public feature isn't enabled in nightly, we instead warn that.
927+
warnings.push(hint);
928+
d.public = None;
929+
}
930930
}
931931
}
932932
}

0 commit comments

Comments
 (0)