aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/traits.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ty/traits.rs')
-rw-r--r--crates/ra_hir/src/ty/traits.rs31
1 files changed, 23 insertions, 8 deletions
diff --git a/crates/ra_hir/src/ty/traits.rs b/crates/ra_hir/src/ty/traits.rs
index 3e28852b6..718970553 100644
--- a/crates/ra_hir/src/ty/traits.rs
+++ b/crates/ra_hir/src/ty/traits.rs
@@ -67,6 +67,27 @@ fn solve(
67 solution 67 solution
68} 68}
69 69
70/// A set of clauses that we assume to be true. E.g. if we are inside this function:
71/// ```rust
72/// fn foo<T: Default>(t: T) {}
73/// ```
74/// we assume that `T: Default`.
75#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
76pub struct Environment;
77
78/// Something (usually a goal), along with an environment.
79#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
80pub struct InEnvironment<T> {
81 pub environment: Arc<Environment>,
82 pub value: T,
83}
84
85impl<T> InEnvironment<T> {
86 pub fn new(environment: Arc<Environment>, value: T) -> InEnvironment<T> {
87 InEnvironment { environment, value }
88 }
89}
90
70/// Something that needs to be proven (by Chalk) during type checking, e.g. that 91/// Something that needs to be proven (by Chalk) during type checking, e.g. that
71/// a certain type implements a certain trait. Proving the Obligation might 92/// a certain type implements a certain trait. Proving the Obligation might
72/// result in additional information about inference variables. 93/// result in additional information about inference variables.
@@ -97,16 +118,10 @@ pub struct ProjectionPredicate {
97pub(crate) fn implements_query( 118pub(crate) fn implements_query(
98 db: &impl HirDatabase, 119 db: &impl HirDatabase,
99 krate: Crate, 120 krate: Crate,
100 trait_ref: Canonical<TraitRef>, 121 trait_ref: Canonical<InEnvironment<TraitRef>>,
101) -> Option<Solution> { 122) -> Option<Solution> {
102 let _p = profile("implements_query"); 123 let _p = profile("implements_query");
103 let goal: chalk_ir::Goal = trait_ref.value.to_chalk(db).cast(); 124 let canonical = trait_ref.to_chalk(db).cast();
104 debug!("goal: {:?}", goal);
105 let env = chalk_ir::Environment::new();
106 let in_env = chalk_ir::InEnvironment::new(&env, goal);
107 let parameter = chalk_ir::ParameterKind::Ty(chalk_ir::UniverseIndex::ROOT);
108 let canonical =
109 chalk_ir::Canonical { value: in_env, binders: vec![parameter; trait_ref.num_vars] };
110 // We currently don't deal with universes (I think / hope they're not yet 125 // We currently don't deal with universes (I think / hope they're not yet
111 // relevant for our use cases?) 126 // relevant for our use cases?)
112 let u_canonical = chalk_ir::UCanonical { canonical, universes: 1 }; 127 let u_canonical = chalk_ir::UCanonical { canonical, universes: 1 };