diff options
author | Florian Diebold <[email protected]> | 2020-04-05 17:24:18 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2020-04-05 18:23:18 +0100 |
commit | 952714685a7c0e0a1c9970839ce307806adaa176 (patch) | |
tree | 2d002aa05d91133886bb592ba79e4c9238e37343 /crates/ra_hir_ty/src/autoderef.rs | |
parent | 3659502816134b45448799acf428055e40fdf4fc (diff) |
Upgrade Chalk again
The big change here is counting binders, not
variables (https://github.com/rust-lang/chalk/pull/360). We have to adapt to the
same scheme for our `Ty::Bound`. It's mostly fine though, even makes some things
more clear.
Diffstat (limited to 'crates/ra_hir_ty/src/autoderef.rs')
-rw-r--r-- | crates/ra_hir_ty/src/autoderef.rs | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/crates/ra_hir_ty/src/autoderef.rs b/crates/ra_hir_ty/src/autoderef.rs index 53e81e85d..d91c21e24 100644 --- a/crates/ra_hir_ty/src/autoderef.rs +++ b/crates/ra_hir_ty/src/autoderef.rs | |||
@@ -14,7 +14,7 @@ use crate::{ | |||
14 | db::HirDatabase, | 14 | db::HirDatabase, |
15 | traits::{InEnvironment, Solution}, | 15 | traits::{InEnvironment, Solution}, |
16 | utils::generics, | 16 | utils::generics, |
17 | Canonical, Substs, Ty, TypeWalk, | 17 | BoundVar, Canonical, DebruijnIndex, Substs, Ty, |
18 | }; | 18 | }; |
19 | 19 | ||
20 | const AUTODEREF_RECURSION_LIMIT: usize = 10; | 20 | const AUTODEREF_RECURSION_LIMIT: usize = 10; |
@@ -61,14 +61,13 @@ fn deref_by_trait( | |||
61 | return None; | 61 | return None; |
62 | } | 62 | } |
63 | 63 | ||
64 | // FIXME make the Canonical handling nicer | 64 | // FIXME make the Canonical / bound var handling nicer |
65 | 65 | ||
66 | let parameters = Substs::build_for_generics(&generic_params) | 66 | let parameters = |
67 | .push(ty.value.value.clone().shift_bound_vars(1)) | 67 | Substs::build_for_generics(&generic_params).push(ty.value.value.clone()).build(); |
68 | .build(); | ||
69 | 68 | ||
70 | let projection = super::traits::ProjectionPredicate { | 69 | let projection = super::traits::ProjectionPredicate { |
71 | ty: Ty::Bound(0), | 70 | ty: Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, ty.value.num_vars)), |
72 | projection_ty: super::ProjectionTy { associated_ty: target, parameters }, | 71 | projection_ty: super::ProjectionTy { associated_ty: target, parameters }, |
73 | }; | 72 | }; |
74 | 73 | ||
@@ -93,12 +92,16 @@ fn deref_by_trait( | |||
93 | // we have `impl<T> Deref for Foo<T> { Target = T }`, that should be | 92 | // we have `impl<T> Deref for Foo<T> { Target = T }`, that should be |
94 | // the case. | 93 | // the case. |
95 | for i in 1..vars.0.num_vars { | 94 | for i in 1..vars.0.num_vars { |
96 | if vars.0.value[i] != Ty::Bound((i - 1) as u32) { | 95 | if vars.0.value[i - 1] != Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, i - 1)) |
96 | { | ||
97 | warn!("complex solution for derefing {:?}: {:?}, ignoring", ty.value, solution); | 97 | warn!("complex solution for derefing {:?}: {:?}, ignoring", ty.value, solution); |
98 | return None; | 98 | return None; |
99 | } | 99 | } |
100 | } | 100 | } |
101 | Some(Canonical { value: vars.0.value[0].clone(), num_vars: vars.0.num_vars }) | 101 | Some(Canonical { |
102 | value: vars.0.value[vars.0.value.len() - 1].clone(), | ||
103 | num_vars: vars.0.num_vars, | ||
104 | }) | ||
102 | } | 105 | } |
103 | Solution::Ambig(_) => { | 106 | Solution::Ambig(_) => { |
104 | info!("Ambiguous solution for derefing {:?}: {:?}", ty.value, solution); | 107 | info!("Ambiguous solution for derefing {:?}: {:?}", ty.value, solution); |