aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/traits.rs
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-07-08 20:43:52 +0100
committerFlorian Diebold <[email protected]>2019-07-08 20:47:37 +0100
commit9afbf2dff43dee3227358f10162d4c77d192ce7a (patch)
tree82d38315b9be21dec920f59389ea89cdb3ae0a41 /crates/ra_hir/src/ty/traits.rs
parent15862fc04183c7f9b3f3af666336a594a6a52cd9 (diff)
Unify `normalize` and `implements` to simplify code
Diffstat (limited to 'crates/ra_hir/src/ty/traits.rs')
-rw-r--r--crates/ra_hir/src/ty/traits.rs21
1 files changed, 4 insertions, 17 deletions
diff --git a/crates/ra_hir/src/ty/traits.rs b/crates/ra_hir/src/ty/traits.rs
index 01f350bc1..d99843319 100644
--- a/crates/ra_hir/src/ty/traits.rs
+++ b/crates/ra_hir/src/ty/traits.rs
@@ -93,7 +93,7 @@ impl<T> InEnvironment<T> {
93/// Something that needs to be proven (by Chalk) during type checking, e.g. that 93/// Something that needs to be proven (by Chalk) during type checking, e.g. that
94/// a certain type implements a certain trait. Proving the Obligation might 94/// a certain type implements a certain trait. Proving the Obligation might
95/// result in additional information about inference variables. 95/// result in additional information about inference variables.
96#[derive(Clone, Debug, PartialEq, Eq)] 96#[derive(Clone, Debug, PartialEq, Eq, Hash)]
97pub enum Obligation { 97pub enum Obligation {
98 /// Prove that a certain type implements a trait (the type is the `Self` type 98 /// Prove that a certain type implements a trait (the type is the `Self` type
99 /// parameter to the `TraitRef`). 99 /// parameter to the `TraitRef`).
@@ -116,11 +116,11 @@ pub struct ProjectionPredicate {
116 pub ty: Ty, 116 pub ty: Ty,
117} 117}
118 118
119/// Check using Chalk whether trait is implemented for given parameters including `Self` type. 119/// Solve a trait goal using Chalk.
120pub(crate) fn implements_query( 120pub(crate) fn solve_query(
121 db: &impl HirDatabase, 121 db: &impl HirDatabase,
122 krate: Crate, 122 krate: Crate,
123 trait_ref: Canonical<InEnvironment<TraitRef>>, 123 trait_ref: Canonical<InEnvironment<Obligation>>,
124) -> Option<Solution> { 124) -> Option<Solution> {
125 let _p = profile("implements_query"); 125 let _p = profile("implements_query");
126 let canonical = trait_ref.to_chalk(db).cast(); 126 let canonical = trait_ref.to_chalk(db).cast();
@@ -131,19 +131,6 @@ pub(crate) fn implements_query(
131 solution.map(|solution| solution_from_chalk(db, solution)) 131 solution.map(|solution| solution_from_chalk(db, solution))
132} 132}
133 133
134pub(crate) fn normalize_query(
135 db: &impl HirDatabase,
136 krate: Crate,
137 projection: Canonical<InEnvironment<ProjectionPredicate>>,
138) -> Option<Solution> {
139 let canonical = projection.to_chalk(db).cast();
140 // We currently don't deal with universes (I think / hope they're not yet
141 // relevant for our use cases?)
142 let u_canonical = chalk_ir::UCanonical { canonical, universes: 1 };
143 let solution = solve(db, krate, &u_canonical);
144 solution.map(|solution| solution_from_chalk(db, solution))
145}
146
147fn solution_from_chalk(db: &impl HirDatabase, solution: chalk_solve::Solution) -> Solution { 134fn solution_from_chalk(db: &impl HirDatabase, solution: chalk_solve::Solution) -> Solution {
148 let convert_subst = |subst: chalk_ir::Canonical<chalk_ir::Substitution>| { 135 let convert_subst = |subst: chalk_ir::Canonical<chalk_ir::Substitution>| {
149 let value = subst 136 let value = subst