From 17691ee974c8eee31b24c59fae7123dfc5486ef6 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 15 Apr 2022 20:17:50 +0200 Subject: [PATCH] Slightly optimize `Resolver::krate` --- crates/hir_def/src/resolver.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/hir_def/src/resolver.rs b/crates/hir_def/src/resolver.rs index 2a990765ea..f3dcdcfa4a 100644 --- a/crates/hir_def/src/resolver.rs +++ b/crates/hir_def/src/resolver.rs @@ -448,7 +448,13 @@ impl Resolver { } pub fn krate(&self) -> CrateId { - self.module_scope().0.krate() + self.scopes + .get(0) + .and_then(|scope| match scope { + Scope::ModuleScope(m) => Some(m.def_map.krate()), + _ => None, + }) + .expect("module scope invariant violated") } pub fn where_predicates_in_scope(