From e4927d52e296c744b2c4bf7b42a10d019b9acff7 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 17 Nov 2020 11:50:54 +0100 Subject: Compress code --- crates/base_db/src/input.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'crates/base_db') diff --git a/crates/base_db/src/input.rs b/crates/base_db/src/input.rs index 31907ed98..98ba372ad 100644 --- a/crates/base_db/src/input.rs +++ b/crates/base_db/src/input.rs @@ -225,7 +225,10 @@ impl CrateGraph { to: CrateId, ) -> Result<(), CyclicDependenciesError> { if self.dfs_find(from, to, &mut FxHashSet::default()) { - return Err(CyclicDependenciesError); + return Err(CyclicDependenciesError { + from: (from, self[from].display_name.clone()), + to: (to, self[to].display_name.clone()), + }); } self.arena.get_mut(&from).unwrap().add_dep(name, to); Ok(()) @@ -421,7 +424,20 @@ impl fmt::Display for ParseEditionError { impl std::error::Error for ParseEditionError {} #[derive(Debug)] -pub struct CyclicDependenciesError; +pub struct CyclicDependenciesError { + from: (CrateId, Option), + to: (CrateId, Option), +} + +impl fmt::Display for CyclicDependenciesError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let render = |(id, name): &(CrateId, Option)| match name { + Some(it) => format!("{}({:?})", it, id), + None => format!("{:?}", id), + }; + write!(f, "cyclic deps: {} -> {}", render(&self.from), render(&self.to)) + } +} #[cfg(test)] mod tests { -- cgit v1.2.3