Skip to content

Commit feef14e

Browse files
committed
breaking endless loop on cyclic features in cargo-add
1 parent eb5baa9 commit feef14e

File tree

7 files changed

+48
-1
lines changed

7 files changed

+48
-1
lines changed

src/cargo/ops/cargo_add/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,8 @@ impl DependencyUI {
726726
.get(next)
727727
.into_iter()
728728
.flatten()
729-
.map(|s| s.as_str()),
729+
.map(|s| s.as_str())
730+
.filter(|s| !activated.contains(s)),
730731
);
731732
activated.extend(
732733
self.available_features
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../add-basic.in
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 case() {
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("test_cyclic_features")
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[workspace]
2+
3+
[package]
4+
name = "cargo-list-test-fixture"
5+
version = "0.0.0"
6+
7+
[dependencies]
8+
test_cyclic_features = "0.1.1"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Updating `dummy-registry` index
2+
Adding test_cyclic_features v0.1.1 to dependencies.
3+
Features:
4+
+ feature-one
5+
+ feature-two

tests/testsuite/cargo_add/cyclic_features/stdout.log

Whitespace-only changes.

tests/testsuite/cargo_add/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ mod add_normalized_name_external;
44
mod build;
55
mod build_prefer_existing_version;
66
mod change_rename_target;
7+
mod cyclic_features;
78
mod default_features;
89
mod deprecated_default_features;
910
mod deprecated_section;
@@ -165,6 +166,12 @@ fn add_registry_packages(alt: bool) {
165166
cargo_test_support::registry::Package::new("test_nonbreaking", "0.1.1")
166167
.alternative(alt)
167168
.publish();
169+
cargo_test_support::registry::Package::new("test_cyclic_features", "0.1.1")
170+
.alternative(alt)
171+
.feature("default", &["feature-one", "feature-two"])
172+
.feature("feature-one", &["feature-two"])
173+
.feature("feature-two", &["feature-one"])
174+
.publish();
168175

169176
// Normalization
170177
cargo_test_support::registry::Package::new("linked-hash-map", "0.5.4")

0 commit comments

Comments
 (0)