Skip to content

Commit 3d966d3

Browse files
committed
Allow features to be cyclical
Fixes #3796
1 parent f8dc1e9 commit 3d966d3

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/cargo/core/resolver/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -907,15 +907,22 @@ fn build_features<'a>(s: &'a Summary, method: &'a Method)
907907
}
908908
None => {
909909
let feat = feat_or_package;
910+
911+
//if this feature has already been added, then just return Ok
910912
if !visited.insert(feat) {
911-
bail!("Cyclic feature dependency: feature `{}` depends \
912-
on itself", feat)
913+
return Ok(());
913914
}
915+
914916
used.insert(feat);
915917
match s.features().get(feat) {
916918
Some(recursive) => {
917919
// This is a feature, add it recursively.
918920
for f in recursive {
921+
if f == feat {
922+
bail!("Cyclic feature dependency: feature `{}` depends \
923+
on itself", feat);
924+
}
925+
919926
add_feature(s, f, deps, used, visited)?;
920927
}
921928
}
@@ -924,7 +931,6 @@ fn build_features<'a>(s: &'a Summary, method: &'a Method)
924931
deps.entry(feat).or_insert((false, Vec::new())).0 = true;
925932
}
926933
}
927-
visited.remove(feat);
928934
}
929935
}
930936
Ok(())

tests/features.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,12 +480,10 @@ fn cyclic_feature2() {
480480
foo = ["bar"]
481481
bar = ["foo"]
482482
"#)
483-
.file("src/main.rs", "");
483+
.file("src/main.rs", "fn main() {}");
484484

485485
assert_that(p.cargo_process("build"),
486-
execs().with_status(101).with_stderr("\
487-
[ERROR] Cyclic feature dependency: feature `[..]` depends on itself
488-
"));
486+
execs().with_status(0).with_stdout(""));
489487
}
490488

491489
#[test]

0 commit comments

Comments
 (0)