aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/traits.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/traits.rs')
-rw-r--r--crates/hir_ty/src/traits.rs34
1 files changed, 13 insertions, 21 deletions
diff --git a/crates/hir_ty/src/traits.rs b/crates/hir_ty/src/traits.rs
index 87c92bd12..7dadd1ffb 100644
--- a/crates/hir_ty/src/traits.rs
+++ b/crates/hir_ty/src/traits.rs
@@ -9,8 +9,8 @@ use hir_def::{lang_item::LangItemTarget, TraitId};
9use stdx::panic_context; 9use stdx::panic_context;
10 10
11use crate::{ 11use crate::{
12 db::HirDatabase, AliasTy, Canonical, DebruijnIndex, HirDisplay, Substitution, TraitRef, Ty, 12 db::HirDatabase, AliasTy, Canonical, DebruijnIndex, HirDisplay, Substitution, Ty, TyKind,
13 TyKind, TypeWalk, WhereClause, 13 TypeWalk, WhereClause,
14}; 14};
15 15
16use self::chalk::{from_chalk, Interner, ToChalk}; 16use self::chalk::{from_chalk, Interner, ToChalk};
@@ -88,20 +88,8 @@ impl<T> InEnvironment<T> {
88/// a certain type implements a certain trait. Proving the Obligation might 88/// a certain type implements a certain trait. Proving the Obligation might
89/// result in additional information about inference variables. 89/// result in additional information about inference variables.
90#[derive(Clone, Debug, PartialEq, Eq, Hash)] 90#[derive(Clone, Debug, PartialEq, Eq, Hash)]
91pub enum Obligation { 91pub enum DomainGoal {
92 /// Prove that a certain type implements a trait (the type is the `Self` type 92 Holds(WhereClause),
93 /// parameter to the `TraitRef`).
94 Trait(TraitRef),
95 AliasEq(AliasEq),
96}
97
98impl Obligation {
99 pub fn from_predicate(predicate: WhereClause) -> Option<Obligation> {
100 match predicate {
101 WhereClause::Implemented(trait_ref) => Some(Obligation::Trait(trait_ref)),
102 WhereClause::AliasEq(alias_eq) => Some(Obligation::AliasEq(alias_eq)),
103 }
104 }
105} 93}
106 94
107#[derive(Clone, Debug, PartialEq, Eq, Hash)] 95#[derive(Clone, Debug, PartialEq, Eq, Hash)]
@@ -136,16 +124,20 @@ impl TypeWalk for AliasEq {
136pub(crate) fn trait_solve_query( 124pub(crate) fn trait_solve_query(
137 db: &dyn HirDatabase, 125 db: &dyn HirDatabase,
138 krate: CrateId, 126 krate: CrateId,
139 goal: Canonical<InEnvironment<Obligation>>, 127 goal: Canonical<InEnvironment<DomainGoal>>,
140) -> Option<Solution> { 128) -> Option<Solution> {
141 let _p = profile::span("trait_solve_query").detail(|| match &goal.value.value { 129 let _p = profile::span("trait_solve_query").detail(|| match &goal.value.value {
142 Obligation::Trait(it) => db.trait_data(it.hir_trait_id()).name.to_string(), 130 DomainGoal::Holds(WhereClause::Implemented(it)) => {
143 Obligation::AliasEq(_) => "alias_eq".to_string(), 131 db.trait_data(it.hir_trait_id()).name.to_string()
132 }
133 DomainGoal::Holds(WhereClause::AliasEq(_)) => "alias_eq".to_string(),
144 }); 134 });
145 log::info!("trait_solve_query({})", goal.value.value.display(db)); 135 log::info!("trait_solve_query({})", goal.value.value.display(db));
146 136
147 if let Obligation::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), .. }) = 137 if let DomainGoal::Holds(WhereClause::AliasEq(AliasEq {
148 &goal.value.value 138 alias: AliasTy::Projection(projection_ty),
139 ..
140 })) = &goal.value.value
149 { 141 {
150 if let TyKind::BoundVar(_) = &projection_ty.substitution[0].interned(&Interner) { 142 if let TyKind::BoundVar(_) = &projection_ty.substitution[0].interned(&Interner) {
151 // Hack: don't ask Chalk to normalize with an unknown self type, it'll say that's impossible 143 // Hack: don't ask Chalk to normalize with an unknown self type, it'll say that's impossible