diff options
author | Aleksey Kladov <[email protected]> | 2020-11-17 10:50:54 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-11-17 10:52:28 +0000 |
commit | e4927d52e296c744b2c4bf7b42a10d019b9acff7 (patch) | |
tree | 5d76352253b21a31c56a95b9dfb5c90a4c368d1b /crates/base_db | |
parent | a6960fb3b889c8c2ad41004f5294991a1da6d416 (diff) |
Compress code
Diffstat (limited to 'crates/base_db')
-rw-r--r-- | crates/base_db/src/input.rs | 20 |
1 files changed, 18 insertions, 2 deletions
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 { | |||
225 | to: CrateId, | 225 | to: CrateId, |
226 | ) -> Result<(), CyclicDependenciesError> { | 226 | ) -> Result<(), CyclicDependenciesError> { |
227 | if self.dfs_find(from, to, &mut FxHashSet::default()) { | 227 | if self.dfs_find(from, to, &mut FxHashSet::default()) { |
228 | return Err(CyclicDependenciesError); | 228 | return Err(CyclicDependenciesError { |
229 | from: (from, self[from].display_name.clone()), | ||
230 | to: (to, self[to].display_name.clone()), | ||
231 | }); | ||
229 | } | 232 | } |
230 | self.arena.get_mut(&from).unwrap().add_dep(name, to); | 233 | self.arena.get_mut(&from).unwrap().add_dep(name, to); |
231 | Ok(()) | 234 | Ok(()) |
@@ -421,7 +424,20 @@ impl fmt::Display for ParseEditionError { | |||
421 | impl std::error::Error for ParseEditionError {} | 424 | impl std::error::Error for ParseEditionError {} |
422 | 425 | ||
423 | #[derive(Debug)] | 426 | #[derive(Debug)] |
424 | pub struct CyclicDependenciesError; | 427 | pub struct CyclicDependenciesError { |
428 | from: (CrateId, Option<CrateDisplayName>), | ||
429 | to: (CrateId, Option<CrateDisplayName>), | ||
430 | } | ||
431 | |||
432 | impl fmt::Display for CyclicDependenciesError { | ||
433 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
434 | let render = |(id, name): &(CrateId, Option<CrateDisplayName>)| match name { | ||
435 | Some(it) => format!("{}({:?})", it, id), | ||
436 | None => format!("{:?}", id), | ||
437 | }; | ||
438 | write!(f, "cyclic deps: {} -> {}", render(&self.from), render(&self.to)) | ||
439 | } | ||
440 | } | ||
425 | 441 | ||
426 | #[cfg(test)] | 442 | #[cfg(test)] |
427 | mod tests { | 443 | mod tests { |