mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 21:35:20 +00:00
Compress code
This commit is contained in:
parent
a6960fb3b8
commit
e4927d52e2
2 changed files with 42 additions and 66 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue