Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/specialization.rs')
-rw-r--r--crates/hir-ty/src/specialization.rs30
1 files changed, 14 insertions, 16 deletions
diff --git a/crates/hir-ty/src/specialization.rs b/crates/hir-ty/src/specialization.rs
index f4ee4de446..d97a35549c 100644
--- a/crates/hir-ty/src/specialization.rs
+++ b/crates/hir-ty/src/specialization.rs
@@ -1,18 +1,17 @@
//! Impl specialization related things
-use hir_def::{ImplId, nameres::crate_def_map};
+use hir_def::{HasModule, ImplId, nameres::crate_def_map};
use intern::sym;
use tracing::debug;
use crate::{
db::HirDatabase,
+ lower::GenericPredicates,
next_solver::{
DbInterner, TypingMode,
- infer::{
- DbInternerInferExt,
- traits::{Obligation, ObligationCause},
- },
+ infer::{DbInternerInferExt, traits::ObligationCause},
obligation_ctxt::ObligationCtxt,
+ util::clauses_as_obligations,
},
};
@@ -22,6 +21,7 @@ use crate::{
// cannot create a cycle, but a cycle handler is required nevertheless.
fn specializes_query_cycle(
_db: &dyn HirDatabase,
+ _: salsa::Id,
_specializing_impl_def_id: ImplId,
_parent_impl_def_id: ImplId,
) -> bool {
@@ -46,7 +46,7 @@ fn specializes_query(
parent_impl_def_id: ImplId,
) -> bool {
let trait_env = db.trait_environment(specializing_impl_def_id.into());
- let interner = DbInterner::new_with(db, Some(trait_env.krate), trait_env.block);
+ let interner = DbInterner::new_with(db, specializing_impl_def_id.krate(db));
let specializing_impl_signature = db.impl_signature(specializing_impl_def_id);
let parent_impl_signature = db.impl_signature(parent_impl_def_id);
@@ -70,7 +70,7 @@ fn specializes_query(
// create a parameter environment corresponding to an identity instantiation of the specializing impl,
// i.e. the most generic instantiation of the specializing impl.
- let param_env = trait_env.env;
+ let param_env = trait_env;
// Create an infcx, taking the predicates of the specializing impl as assumptions:
let infcx = interner.infer_ctxt().build(TypingMode::non_body_analysis());
@@ -102,14 +102,12 @@ fn specializes_query(
// Now check that the source trait ref satisfies all the where clauses of the target impl.
// This is not just for correctness; we also need this to constrain any params that may
// only be referenced via projection predicates.
- if let Some(predicates) =
- db.generic_predicates(parent_impl_def_id.into()).instantiate(interner, parent_args)
- {
- ocx.register_obligations(
- predicates
- .map(|predicate| Obligation::new(interner, cause.clone(), param_env, predicate)),
- );
- }
+ ocx.register_obligations(clauses_as_obligations(
+ GenericPredicates::query_all(db, parent_impl_def_id.into())
+ .iter_instantiated_copied(interner, parent_args.as_slice()),
+ cause.clone(),
+ param_env,
+ ));
let errors = ocx.evaluate_obligations_error_on_ambiguity();
if !errors.is_empty() {
@@ -150,7 +148,7 @@ pub(crate) fn specializes(
// `#[allow_internal_unstable(specialization)]`, but `#[allow_internal_unstable]`
// is an internal feature, std is not using it for specialization nor is likely to
// ever use it, and we don't have the span information necessary to replicate that.
- let def_map = crate_def_map(db, module.krate());
+ let def_map = crate_def_map(db, module.krate(db));
if !def_map.is_unstable_feature_enabled(&sym::specialization)
&& !def_map.is_unstable_feature_enabled(&sym::min_specialization)
{