internal: don't panic when the crate graph isn't ready #19351

This commit is contained in:
David Barsky 2025-03-13 13:38:29 -04:00
parent 3fc655b239
commit 788232b355
14 changed files with 50 additions and 30 deletions

View file

@ -314,11 +314,11 @@ impl<'db> SemanticsImpl<'db> {
tree
}
/// If not crate is found for the file, returns the last crate in topological order.
pub fn first_crate_or_default(&self, file: FileId) -> Crate {
/// If not crate is found for the file, try to return the last crate in topological order.
pub fn first_crate(&self, file: FileId) -> Option<Crate> {
match self.file_to_module_defs(file).next() {
Some(module) => module.krate(),
None => (*self.db.all_crates().last().unwrap()).into(),
Some(module) => Some(module.krate()),
None => self.db.all_crates().last().copied().map(Into::into),
}
}

View file

@ -77,7 +77,10 @@ impl<'a> SymbolCollector<'a> {
symbols: Default::default(),
work: Default::default(),
current_container_name: None,
display_target: DisplayTarget::from_crate(db, *db.all_crates().last().unwrap()),
display_target: DisplayTarget::from_crate(
db,
*db.all_crates().last().expect("no crate graph present"),
),
}
}