diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-20 11:47:50 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-20 11:47:50 +0000 |
commit | 4d67032bbb3e1f97ee7af43cb6f056d01f791ca2 (patch) | |
tree | 70a77a26ca09d8d5cd843b1cd9d59af229cd0daf /crates/hir_ty/src/traits.rs | |
parent | 5ac0290f533eed295c6e92564d7530d41cf45d6e (diff) | |
parent | 7ec3b66f7a3ac0a33cf435bc3596fdac542fc52a (diff) |
Merge #8117
8117: Turn Obligation into something similar to chalk_ir::DomainGoal r=flodiebold a=flodiebold
This includes starting to make use of Chalk's `Cast` trait.
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/hir_ty/src/traits.rs')
-rw-r--r-- | crates/hir_ty/src/traits.rs | 34 |
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}; | |||
9 | use stdx::panic_context; | 9 | use stdx::panic_context; |
10 | 10 | ||
11 | use crate::{ | 11 | use 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 | ||
16 | use self::chalk::{from_chalk, Interner, ToChalk}; | 16 | use 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)] |
91 | pub enum Obligation { | 91 | pub 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 | |||
98 | impl 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 { | |||
136 | pub(crate) fn trait_solve_query( | 124 | pub(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 |