diff options
-rw-r--r-- | crates/ra_db/src/input.rs | 35 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 2 |
2 files changed, 31 insertions, 6 deletions
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index bf26048f2..e6af99035 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs | |||
@@ -254,12 +254,12 @@ impl CrateGraph { | |||
254 | return false; | 254 | return false; |
255 | } | 255 | } |
256 | 256 | ||
257 | if target == from { | ||
258 | return true; | ||
259 | } | ||
260 | |||
257 | for dep in &self[from].dependencies { | 261 | for dep in &self[from].dependencies { |
258 | let crate_id = dep.crate_id; | 262 | let crate_id = dep.crate_id; |
259 | if crate_id == target { | ||
260 | return true; | ||
261 | } | ||
262 | |||
263 | if self.dfs_find(target, crate_id, visited) { | 263 | if self.dfs_find(target, crate_id, visited) { |
264 | return true; | 264 | return true; |
265 | } | 265 | } |
@@ -369,7 +369,7 @@ mod tests { | |||
369 | use super::{CfgOptions, CrateGraph, CrateName, Dependency, Edition::Edition2018, Env, FileId}; | 369 | use super::{CfgOptions, CrateGraph, CrateName, Dependency, Edition::Edition2018, Env, FileId}; |
370 | 370 | ||
371 | #[test] | 371 | #[test] |
372 | fn it_should_panic_because_of_cycle_dependencies() { | 372 | fn detect_cyclic_dependency_indirect() { |
373 | let mut graph = CrateGraph::default(); | 373 | let mut graph = CrateGraph::default(); |
374 | let crate1 = graph.add_crate_root( | 374 | let crate1 = graph.add_crate_root( |
375 | FileId(1u32), | 375 | FileId(1u32), |
@@ -404,6 +404,31 @@ mod tests { | |||
404 | } | 404 | } |
405 | 405 | ||
406 | #[test] | 406 | #[test] |
407 | fn detect_cyclic_dependency_direct() { | ||
408 | let mut graph = CrateGraph::default(); | ||
409 | let crate1 = graph.add_crate_root( | ||
410 | FileId(1u32), | ||
411 | Edition2018, | ||
412 | None, | ||
413 | CfgOptions::default(), | ||
414 | Env::default(), | ||
415 | Default::default(), | ||
416 | Default::default(), | ||
417 | ); | ||
418 | let crate2 = graph.add_crate_root( | ||
419 | FileId(2u32), | ||
420 | Edition2018, | ||
421 | None, | ||
422 | CfgOptions::default(), | ||
423 | Env::default(), | ||
424 | Default::default(), | ||
425 | Default::default(), | ||
426 | ); | ||
427 | assert!(graph.add_dep(crate1, CrateName::new("crate2").unwrap(), crate2).is_ok()); | ||
428 | assert!(graph.add_dep(crate2, CrateName::new("crate2").unwrap(), crate2).is_err()); | ||
429 | } | ||
430 | |||
431 | #[test] | ||
407 | fn it_works() { | 432 | fn it_works() { |
408 | let mut graph = CrateGraph::default(); | 433 | let mut graph = CrateGraph::default(); |
409 | let crate1 = graph.add_crate_root( | 434 | let crate1 = graph.add_crate_root( |
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 77baa4c69..b8f6aac8f 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -36,8 +36,8 @@ pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: CrateDefMap) -> Cr | |||
36 | 36 | ||
37 | // populate external prelude | 37 | // populate external prelude |
38 | for dep in &crate_graph[def_map.krate].dependencies { | 38 | for dep in &crate_graph[def_map.krate].dependencies { |
39 | let dep_def_map = db.crate_def_map(dep.crate_id); | ||
40 | log::debug!("crate dep {:?} -> {:?}", dep.name, dep.crate_id); | 39 | log::debug!("crate dep {:?} -> {:?}", dep.name, dep.crate_id); |
40 | let dep_def_map = db.crate_def_map(dep.crate_id); | ||
41 | def_map.extern_prelude.insert( | 41 | def_map.extern_prelude.insert( |
42 | dep.as_name(), | 42 | dep.as_name(), |
43 | ModuleId { krate: dep.crate_id, local_id: dep_def_map.root }.into(), | 43 | ModuleId { krate: dep.crate_id, local_id: dep_def_map.root }.into(), |