Skip to content

Commit 1875784

Browse files
committed
Auto merge of #18020 - Veykril:cyclic-deps, r=Veykril
minor: Downgrade cyclic deps error to warning As the issue here is no longer workable for us and this appearing for some repos due to package cycles which can cause we should downgrade it as some people tend to think this breaks r-a when it doesn't
2 parents 8d1d5cd + 2e2f798 commit 1875784

File tree

2 files changed

+8
-48
lines changed

2 files changed

+8
-48
lines changed

crates/base-db/src/input.rs

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -374,64 +374,24 @@ impl CrateGraph {
374374
self.arena.alloc(data)
375375
}
376376

377-
/// Remove the crate from crate graph. If any crates depend on this crate, the dependency would be replaced
378-
/// with the second input.
379-
pub fn remove_and_replace(
380-
&mut self,
381-
id: CrateId,
382-
replace_with: CrateId,
383-
) -> Result<(), CyclicDependenciesError> {
384-
for (x, data) in self.arena.iter() {
385-
if x == id {
386-
continue;
387-
}
388-
for edge in &data.dependencies {
389-
if edge.crate_id == id {
390-
self.check_cycle_after_dependency(edge.crate_id, replace_with)?;
391-
}
392-
}
393-
}
394-
// if everything was ok, start to replace
395-
for (x, data) in self.arena.iter_mut() {
396-
if x == id {
397-
continue;
398-
}
399-
for edge in &mut data.dependencies {
400-
if edge.crate_id == id {
401-
edge.crate_id = replace_with;
402-
}
403-
}
404-
}
405-
Ok(())
406-
}
407-
408377
pub fn add_dep(
409378
&mut self,
410379
from: CrateId,
411380
dep: Dependency,
412381
) -> Result<(), CyclicDependenciesError> {
413382
let _p = tracing::info_span!("add_dep").entered();
414383

415-
self.check_cycle_after_dependency(from, dep.crate_id)?;
416-
417-
self.arena[from].add_dep(dep);
418-
Ok(())
419-
}
420-
421-
/// Check if adding a dep from `from` to `to` creates a cycle. To figure
422-
/// that out, look for a path in the *opposite* direction, from `to` to
423-
/// `from`.
424-
fn check_cycle_after_dependency(
425-
&self,
426-
from: CrateId,
427-
to: CrateId,
428-
) -> Result<(), CyclicDependenciesError> {
429-
if let Some(path) = self.find_path(&mut FxHashSet::default(), to, from) {
384+
// Check if adding a dep from `from` to `to` creates a cycle. To figure
385+
// that out, look for a path in the *opposite* direction, from `to` to
386+
// `from`.
387+
if let Some(path) = self.find_path(&mut FxHashSet::default(), dep.crate_id, from) {
430388
let path = path.into_iter().map(|it| (it, self[it].display_name.clone())).collect();
431389
let err = CyclicDependenciesError { path };
432-
assert!(err.from().0 == from && err.to().0 == to);
390+
assert!(err.from().0 == from && err.to().0 == dep.crate_id);
433391
return Err(err);
434392
}
393+
394+
self.arena[from].add_dep(dep);
435395
Ok(())
436396
}
437397

crates/project-model/src/workspace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,6 @@ fn add_proc_macro_dep(crate_graph: &mut CrateGraph, from: CrateId, to: CrateId,
15541554

15551555
fn add_dep_inner(graph: &mut CrateGraph, from: CrateId, dep: Dependency) {
15561556
if let Err(err) = graph.add_dep(from, dep) {
1557-
tracing::error!("{}", err)
1557+
tracing::warn!("{}", err)
15581558
}
15591559
}

0 commit comments

Comments
 (0)