]> git.lizzy.rs Git - rust.git/commitdiff
Merge #310
authorbors[bot] <bors[bot]@users.noreply.github.com>
Sat, 22 Dec 2018 14:48:18 +0000 (14:48 +0000)
committerbors[bot] <bors[bot]@users.noreply.github.com>
Sat, 22 Dec 2018 14:48:18 +0000 (14:48 +0000)
310: When constructing a crate graph, detect and forbid cycles. r=matklad a=gfreezy

fixed #300

Co-authored-by: gfreezy <gfreezy@gmail.com>
1  2 
crates/ra_db/src/input.rs

index ead8dfe4837b2c2a01832caba84fc964aa20b1e0,f445e03bc1497e1a2081864f72b55d03bbf7d12a..7c3dd9296d0bd5728fd98298dbac85cb6ea3c01a
@@@ -92,15 -94,13 +94,16 @@@ impl CrateGraph 
          assert!(prev.is_none());
          crate_id
      }
-     // FIXME: check that we don't have cycles here.
-     // Just a simple depth first search from `to` should work,
-     // the graph is small.
      pub fn add_dep(&mut self, from: CrateId, name: SmolStr, to: CrateId) {
+         let mut visited = FxHashSet::default();
+         if self.dfs_find(from, to, &mut visited) {
+             panic!("Cycle dependencies found.")
+         }
          self.arena.get_mut(&from).unwrap().add_dep(name, to)
      }
 +    pub fn is_empty(&self) -> bool {
 +        self.arena.is_empty()
 +    }
      pub fn crate_root(&self, crate_id: CrateId) -> FileId {
          self.arena[&crate_id].file_id
      }