Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/infer/unify.rs')
-rw-r--r--crates/hir-ty/src/infer/unify.rs62
1 files changed, 22 insertions, 40 deletions
diff --git a/crates/hir-ty/src/infer/unify.rs b/crates/hir-ty/src/infer/unify.rs
index afb89fe1e5..b68fefc515 100644
--- a/crates/hir-ty/src/infer/unify.rs
+++ b/crates/hir-ty/src/infer/unify.rs
@@ -16,8 +16,8 @@ use triomphe::Arc;
use super::{InferOk, InferResult, InferenceContext, TypeError};
use crate::{
- consteval::unknown_const, db::HirDatabase, fold_generic_args, fold_tys_and_consts,
- static_lifetime, to_chalk_trait_id, traits::FnTrait, AliasEq, AliasTy, BoundVar, Canonical,
+ consteval::unknown_const, db::HirDatabase, error_lifetime, fold_generic_args,
+ fold_tys_and_consts, to_chalk_trait_id, traits::FnTrait, AliasEq, AliasTy, BoundVar, Canonical,
Const, ConstValue, DebruijnIndex, DomainGoal, GenericArg, GenericArgData, Goal, GoalData,
Guidance, InEnvironment, InferenceVar, Interner, Lifetime, OpaqueTyId, ParamKind, ProjectionTy,
ProjectionTyExt, Scalar, Solution, Substitution, TraitEnvironment, Ty, TyBuilder, TyExt,
@@ -43,40 +43,21 @@ impl InferenceContext<'_> {
let obligations = pending_obligations
.iter()
.filter_map(|obligation| match obligation.value.value.goal.data(Interner) {
- GoalData::DomainGoal(DomainGoal::Holds(
- clause @ WhereClause::AliasEq(AliasEq {
- alias: AliasTy::Projection(projection),
- ..
- }),
- )) => {
- let projection_self = projection.self_type_parameter(self.db);
- let uncanonical = chalk_ir::Substitute::apply(
- &obligation.free_vars,
- projection_self,
- Interner,
- );
- if matches!(
- self.resolve_ty_shallow(&uncanonical).kind(Interner),
- TyKind::InferenceVar(iv, TyVariableKind::General) if *iv == root,
- ) {
- Some(chalk_ir::Substitute::apply(
- &obligation.free_vars,
- clause.clone(),
- Interner,
- ))
- } else {
- None
- }
- }
- GoalData::DomainGoal(DomainGoal::Holds(
- clause @ WhereClause::Implemented(trait_ref),
- )) => {
- let trait_ref_self = trait_ref.self_type_parameter(Interner);
- let uncanonical = chalk_ir::Substitute::apply(
- &obligation.free_vars,
- trait_ref_self,
- Interner,
- );
+ GoalData::DomainGoal(DomainGoal::Holds(clause)) => {
+ let ty = match clause {
+ WhereClause::AliasEq(AliasEq {
+ alias: AliasTy::Projection(projection),
+ ..
+ }) => projection.self_type_parameter(self.db),
+ WhereClause::Implemented(trait_ref) => {
+ trait_ref.self_type_parameter(Interner)
+ }
+ WhereClause::TypeOutlives(to) => to.ty.clone(),
+ _ => return None,
+ };
+
+ let uncanonical =
+ chalk_ir::Substitute::apply(&obligation.free_vars, ty, Interner);
if matches!(
self.resolve_ty_shallow(&uncanonical).kind(Interner),
TyKind::InferenceVar(iv, TyVariableKind::General) if *iv == root,
@@ -121,8 +102,9 @@ impl<T: HasInterner<Interner = Interner>> Canonicalized<T> {
VariableKind::Ty(TyVariableKind::General) => ctx.new_type_var().cast(Interner),
VariableKind::Ty(TyVariableKind::Integer) => ctx.new_integer_var().cast(Interner),
VariableKind::Ty(TyVariableKind::Float) => ctx.new_float_var().cast(Interner),
- // Chalk can sometimes return new lifetime variables. We just use the static lifetime everywhere
- VariableKind::Lifetime => static_lifetime().cast(Interner),
+ // Chalk can sometimes return new lifetime variables. We just replace them by errors
+ // for now.
+ VariableKind::Lifetime => error_lifetime().cast(Interner),
VariableKind::Const(ty) => ctx.new_const_var(ty.clone()).cast(Interner),
}),
);
@@ -1020,11 +1002,11 @@ mod resolve {
_var: InferenceVar,
_outer_binder: DebruijnIndex,
) -> Lifetime {
- // fall back all lifetimes to 'static -- currently we don't deal
+ // fall back all lifetimes to 'error -- currently we don't deal
// with any lifetimes, but we can sometimes get some lifetime
// variables through Chalk's unification, and this at least makes
// sure we don't leak them outside of inference
- crate::static_lifetime()
+ crate::error_lifetime()
}
}
}