Allow features to be cyclical
authorWesley Wiser <wwiser@gmail.com>
Wed, 6 Sep 2017 03:04:38 +0000 (23:04 -0400)
committerWesley Wiser <wwiser@gmail.com>
Wed, 6 Sep 2017 23:19:46 +0000 (19:19 -0400)
Fixes #3796

src/cargo/core/resolver/mod.rs
tests/features.rs

index 4b633c26d6947fd01393be0157e76d1bbf9d778a..b720f5f4de4fed0d85c7222d2f4ea3b9c8cc5eb6 100644 (file)
@@ -907,15 +907,22 @@ fn build_features<'a>(s: &'a Summary, method: &'a Method)
             }
             None => {
                 let feat = feat_or_package;
+
+                //if this feature has already been added, then just return Ok
                 if !visited.insert(feat) {
-                    bail!("Cyclic feature dependency: feature `{}` depends \
-                           on itself", feat)
+                    return Ok(());
                 }
+
                 used.insert(feat);
                 match s.features().get(feat) {
                     Some(recursive) => {
                         // This is a feature, add it recursively.
                         for f in recursive {
+                            if f == feat {
+                                bail!("Cyclic feature dependency: feature `{}` depends \
+                                        on itself", feat);
+                            }
+
                             add_feature(s, f, deps, used, visited)?;
                         }
                     }
@@ -924,7 +931,6 @@ fn build_features<'a>(s: &'a Summary, method: &'a Method)
                         deps.entry(feat).or_insert((false, Vec::new())).0 = true;
                     }
                 }
-                visited.remove(feat);
             }
         }
         Ok(())
index bbc78b9420ebad8d42cda5e128604c0888ea119d..0406f7cb3bbc2c0611f1bf9655ed6ef59927718e 100644 (file)
@@ -480,12 +480,10 @@ fn cyclic_feature2() {
             foo = ["bar"]
             bar = ["foo"]
         "#)
-        .file("src/main.rs", "");
+        .file("src/main.rs", "fn main() {}");
 
     assert_that(p.cargo_process("build"),
-                execs().with_status(101).with_stderr("\
-[ERROR] Cyclic feature dependency: feature `[..]` depends on itself
-"));
+                execs().with_status(0).with_stdout(""));
 }
 
 #[test]