Handle cycles in generic_defaults more gracefully

This commit is contained in:
Florian Diebold 2021-04-29 20:00:43 +02:00
parent 184a0d7c1e
commit b384cfcb81
2 changed files with 22 additions and 0 deletions

View File

@ -70,6 +70,7 @@ fn generic_predicates_for_param(
fn trait_environment(&self, def: GenericDefId) -> Arc<crate::TraitEnvironment>;
#[salsa::invoke(crate::lower::generic_defaults_query)]
#[salsa::cycle(crate::lower::generic_defaults_recover)]
fn generic_defaults(&self, def: GenericDefId) -> Arc<[Binders<Ty>]>;
#[salsa::invoke(InherentImpls::inherent_impls_in_crate_query)]

View File

@ -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<Ty>]> {
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());