diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 8d8c65a21b7d..088dd0196ad2 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -2777,11 +2777,6 @@ fn prepare_targets_for_publish( }; prepared.push(target); } - // Ensure target order is deterministic, particularly for `cargo vendor` where re-vendoring - // should not cause changes. - // - // `unstable` should be deterministic because we enforce that `t.name` is unique - prepared.sort_unstable_by_key(|t| t.name.clone()); if prepared.is_empty() { Ok(None) diff --git a/src/cargo/util/toml/targets.rs b/src/cargo/util/toml/targets.rs index 261ff67b3200..166e8a700239 100644 --- a/src/cargo/util/toml/targets.rs +++ b/src/cargo/util/toml/targets.rs @@ -744,7 +744,7 @@ fn toml_targets_and_inferred( autodiscover_flag_name: &str, ) -> Vec { let inferred_targets = inferred_to_toml_targets(inferred); - match toml_targets { + let mut toml_targets = match toml_targets { None => { if let Some(false) = autodiscover { vec![] @@ -819,7 +819,13 @@ https://github.com/rust-lang/cargo/issues/5330", targets } - } + }; + // Ensure target order is deterministic, particularly for `cargo vendor` where re-vendoring + // should not cause changes. + // + // `unstable` should be deterministic because we enforce that `t.name` is unique + toml_targets.sort_unstable_by_key(|t| t.name.clone()); + toml_targets } fn inferred_to_toml_targets(inferred: &[(String, PathBuf)]) -> Vec { diff --git a/tests/testsuite/required_features.rs b/tests/testsuite/required_features.rs index f192be50d408..10b552753640 100644 --- a/tests/testsuite/required_features.rs +++ b/tests/testsuite/required_features.rs @@ -1474,12 +1474,12 @@ fn truncated_install_warning_message() { [FINISHED] `release` profile [optimized] target(s) in [..] [WARNING] none of the package's binaries are available for install using the selected features bin \"foo1\" requires the features: `feature1`, `feature2`, `feature3` + bin \"foo10\" requires the features: `feature1`, `feature2`, `feature3`, `feature4`, `feature5` bin \"foo2\" requires the features: `feature2` bin \"foo3\" requires the features: `feature3` bin \"foo4\" requires the features: `feature4`, `feature1` bin \"foo5\" requires the features: `feature1`, `feature2`, `feature3`, `feature4`, `feature5` bin \"foo6\" requires the features: `feature1`, `feature2`, `feature3`, `feature4`, `feature5` - bin \"foo7\" requires the features: `feature1`, `feature2`, `feature3`, `feature4`, `feature5` 4 more targets also requires features not enabled. See them in the Cargo.toml file. Consider enabling some of the needed features by passing, e.g., `--features=\"feature1 feature2 feature3\"`").run(); } diff --git a/tests/testsuite/vendor.rs b/tests/testsuite/vendor.rs index bf701c88788d..6d3e21ce8da8 100644 --- a/tests/testsuite/vendor.rs +++ b/tests/testsuite/vendor.rs @@ -960,20 +960,16 @@ name = "git_dep" path = "src/lib.rs" [[example]] -name = "c" -path = "examples/c.rs" +name = "a" +path = "examples/a.rs" [[example]] name = "b" path = "examples/b.rs" [[example]] -name = "a" -path = "examples/a.rs" - -[[example]] -name = "z" -path = "examples/z.rs" +name = "c" +path = "examples/c.rs" [[example]] name = "x" @@ -983,6 +979,10 @@ path = "examples/x.rs" name = "y" path = "examples/y.rs" +[[example]] +name = "z" +path = "examples/z.rs" + "##]]); }