From b384cfcb81ae0db541cfe02213e9d95041b77362 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Thu, 29 Apr 2021 20:00:43 +0200 Subject: Handle cycles in generic_defaults more gracefully --- crates/hir_ty/src/db.rs | 1 + crates/hir_ty/src/lower.rs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) (limited to 'crates/hir_ty') diff --git a/crates/hir_ty/src/db.rs b/crates/hir_ty/src/db.rs index cf67d4266..9da0a02e3 100644 --- a/crates/hir_ty/src/db.rs +++ b/crates/hir_ty/src/db.rs @@ -70,6 +70,7 @@ pub trait HirDatabase: DefDatabase + Upcast { fn trait_environment(&self, def: GenericDefId) -> Arc; #[salsa::invoke(crate::lower::generic_defaults_query)] + #[salsa::cycle(crate::lower::generic_defaults_recover)] fn generic_defaults(&self, def: GenericDefId) -> Arc<[Binders]>; #[salsa::invoke(InherentImpls::inherent_impls_in_crate_query)] diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index 7fd46becd..d01933e6b 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs @@ -1089,6 +1089,27 @@ pub(crate) fn generic_defaults_query( defaults } +pub(crate) fn generic_defaults_recover( + db: &dyn HirDatabase, + _cycle: &[String], + def: &GenericDefId, +) -> Arc<[Binders]> { + let generic_params = generics(db.upcast(), *def); + + // we still need one default per parameter + let defaults = generic_params + .iter() + .enumerate() + .map(|(idx, _)| { + let ty = TyKind::Error.intern(&Interner); + + crate::make_only_type_binders(idx, ty) + }) + .collect(); + + defaults +} + fn fn_sig_for_fn(db: &dyn HirDatabase, def: FunctionId) -> PolyFnSig { let data = db.function_data(def); let resolver = def.resolver(db.upcast()); -- cgit v1.2.3