Compress code

This commit is contained in:
Aleksey Kladov 2020-11-17 11:50:54 +01:00
parent a6960fb3b8
commit e4927d52e2
2 changed files with 42 additions and 66 deletions

View file

@ -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<CrateDisplayName>),
to: (CrateId, Option<CrateDisplayName>),
}
impl fmt::Display for CyclicDependenciesError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let render = |(id, name): &(CrateId, Option<CrateDisplayName>)| match name {
Some(it) => format!("{}({:?})", it, id),
None => format!("{:?}", id),
};
write!(f, "cyclic deps: {} -> {}", render(&self.from), render(&self.to))
}
}
#[cfg(test)]
mod tests {