Skip to content

Commit 04519ad

Browse files
committed
Auto merge of #11612 - hi-rustin:rustin-patch-cargo-add, r=epage
`cargo add` check `[dependencies]` order without considering the dotted item ### What does this PR try to resolve? Try to close #11584 `cargo check` check `[dependencies]` order without considering the dotted item. ### How should we test and review this PR? See the unit test.
2 parents 3fee600 + 1d67d0f commit 04519ad

File tree

8 files changed

+61
-1
lines changed

8 files changed

+61
-1
lines changed

src/cargo/ops/cargo_add/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ pub fn add(workspace: &Workspace<'_>, options: &AddOptions<'_>) -> CargoResult<(
9898
.get_table(&dep_table)
9999
.map(TomlItem::as_table)
100100
.map_or(true, |table_option| {
101-
table_option.map_or(true, |table| is_sorted(table.iter().map(|(name, _)| name)))
101+
table_option.map_or(true, |table| {
102+
is_sorted(table.get_values().iter_mut().map(|(key, _)| {
103+
// get_values key paths always have at least one key.
104+
key.remove(0)
105+
}))
106+
})
102107
});
103108
for dep in deps {
104109
print_action_msg(&mut options.config.shell(), &dep, &dep_table)?;

tests/testsuite/cargo_add/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ mod quiet;
100100
mod registry;
101101
mod rename;
102102
mod require_weak;
103+
mod sorted_table_with_dotted_item;
103104
mod target;
104105
mod target_cfg;
105106
mod unknown_inherited_feature;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[workspace]
2+
3+
[package]
4+
name = "cargo-list-test-fixture"
5+
version = "0.0.0"
6+
7+
[dependencies]
8+
toml = "0.1.1"
9+
versioned-package = "0.1.1"
10+
11+
[dependencies.my-build-package1]
12+
version = "0.1.1"
13+

tests/testsuite/cargo_add/sorted_table_with_dotted_item/in/src/lib.rs

Whitespace-only changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use cargo_test_support::compare::assert_ui;
2+
use cargo_test_support::prelude::*;
3+
use cargo_test_support::Project;
4+
5+
use crate::cargo_add::init_registry;
6+
use cargo_test_support::curr_dir;
7+
8+
#[cargo_test]
9+
fn sorted_table_with_dotted_item() {
10+
init_registry();
11+
let project = Project::from_template(curr_dir!().join("in"));
12+
let project_root = project.root();
13+
let cwd = &project_root;
14+
15+
snapbox::cmd::Command::cargo_ui()
16+
.arg("add")
17+
.arg_line("unrelateed-crate")
18+
.current_dir(cwd)
19+
.assert()
20+
.success()
21+
.stdout_matches_path(curr_dir!().join("stdout.log"))
22+
.stderr_matches_path(curr_dir!().join("stderr.log"));
23+
24+
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
25+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[workspace]
2+
3+
[package]
4+
name = "cargo-list-test-fixture"
5+
version = "0.0.0"
6+
7+
[dependencies]
8+
toml = "0.1.1"
9+
unrelateed-crate = "99999.0.0"
10+
versioned-package = "0.1.1"
11+
12+
[dependencies.my-build-package1]
13+
version = "0.1.1"
14+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Updating `dummy-registry` index
2+
Adding unrelateed-crate v99999.0.0 to dependencies.

tests/testsuite/cargo_add/sorted_table_with_dotted_item/stdout.log

Whitespace-only changes.

0 commit comments

Comments
 (0)