diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir_ty/src/lib.rs | 5 | ||||
-rw-r--r-- | crates/hir_ty/src/lower.rs | 18 | ||||
-rw-r--r-- | crates/hir_ty/src/traits/chalk/mapping.rs | 2 | ||||
-rw-r--r-- | crates/hir_ty/src/utils.rs | 10 | ||||
-rw-r--r-- | crates/hir_ty/src/walk.rs | 22 |
5 files changed, 32 insertions, 25 deletions
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index 827317fce..daf379ef8 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs | |||
@@ -124,7 +124,7 @@ impl<T> Binders<T> { | |||
124 | where | 124 | where |
125 | T: TypeWalk, | 125 | T: TypeWalk, |
126 | { | 126 | { |
127 | Binders::empty(&Interner, value.shift_bound_vars(DebruijnIndex::ONE)) | 127 | Binders::empty(&Interner, value.shifted_in_from(DebruijnIndex::ONE)) |
128 | } | 128 | } |
129 | } | 129 | } |
130 | 130 | ||
@@ -209,7 +209,8 @@ impl CallableSig { | |||
209 | params_and_return: fn_ptr | 209 | params_and_return: fn_ptr |
210 | .substs | 210 | .substs |
211 | .clone() | 211 | .clone() |
212 | .shift_bound_vars_out(DebruijnIndex::ONE) | 212 | .shifted_out_to(DebruijnIndex::ONE) |
213 | .expect("unexpected lifetime vars in fn ptr") | ||
213 | .interned() | 214 | .interned() |
214 | .iter() | 215 | .iter() |
215 | .map(|arg| arg.assert_ty_ref(&Interner).clone()) | 216 | .map(|arg| arg.assert_ty_ref(&Interner).clone()) |
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index 66e72c814..48c26f471 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs | |||
@@ -483,7 +483,7 @@ impl<'a> TyLoweringContext<'a> { | |||
483 | }; | 483 | }; |
484 | // We need to shift in the bound vars, since | 484 | // We need to shift in the bound vars, since |
485 | // associated_type_shorthand_candidates does not do that | 485 | // associated_type_shorthand_candidates does not do that |
486 | let substs = substs.shift_bound_vars(self.in_binders); | 486 | let substs = substs.shifted_in_from(self.in_binders); |
487 | // FIXME handle type parameters on the segment | 487 | // FIXME handle type parameters on the segment |
488 | return Some( | 488 | return Some( |
489 | TyKind::Alias(AliasTy::Projection(ProjectionTy { | 489 | TyKind::Alias(AliasTy::Projection(ProjectionTy { |
@@ -831,20 +831,20 @@ pub fn associated_type_shorthand_candidates<R>( | |||
831 | }; | 831 | }; |
832 | 832 | ||
833 | match res { | 833 | match res { |
834 | // FIXME: how to correctly handle higher-ranked bounds here? | ||
835 | TypeNs::SelfType(impl_id) => search( | 834 | TypeNs::SelfType(impl_id) => search( |
836 | db.impl_trait(impl_id)? | 835 | // we're _in_ the impl -- the binders get added back later. Correct, |
837 | .into_value_and_skipped_binders() | 836 | // but it would be nice to make this more explicit |
838 | .0 | 837 | db.impl_trait(impl_id)?.into_value_and_skipped_binders().0, |
839 | .shift_bound_vars_out(DebruijnIndex::ONE), | ||
840 | ), | 838 | ), |
841 | TypeNs::GenericParam(param_id) => { | 839 | TypeNs::GenericParam(param_id) => { |
842 | let predicates = db.generic_predicates_for_param(param_id); | 840 | let predicates = db.generic_predicates_for_param(param_id); |
843 | let res = predicates.iter().find_map(|pred| match pred.skip_binders().skip_binders() { | 841 | let res = predicates.iter().find_map(|pred| match pred.skip_binders().skip_binders() { |
844 | // FIXME: how to correctly handle higher-ranked bounds here? | 842 | // FIXME: how to correctly handle higher-ranked bounds here? |
845 | WhereClause::Implemented(tr) => { | 843 | WhereClause::Implemented(tr) => search( |
846 | search(tr.clone().shift_bound_vars_out(DebruijnIndex::ONE)) | 844 | tr.clone() |
847 | } | 845 | .shifted_out_to(DebruijnIndex::ONE) |
846 | .expect("FIXME unexpected higher-ranked trait bound"), | ||
847 | ), | ||
848 | _ => None, | 848 | _ => None, |
849 | }); | 849 | }); |
850 | if let res @ Some(_) = res { | 850 | if let res @ Some(_) = res { |
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index 9db2b0c2f..c3b148cab 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs | |||
@@ -531,7 +531,7 @@ pub(super) fn generic_predicate_to_inline_bound( | |||
531 | ) -> Option<chalk_ir::Binders<rust_ir::InlineBound<Interner>>> { | 531 | ) -> Option<chalk_ir::Binders<rust_ir::InlineBound<Interner>>> { |
532 | // An InlineBound is like a GenericPredicate, except the self type is left out. | 532 | // An InlineBound is like a GenericPredicate, except the self type is left out. |
533 | // We don't have a special type for this, but Chalk does. | 533 | // We don't have a special type for this, but Chalk does. |
534 | let self_ty_shifted_in = self_ty.clone().shift_bound_vars(DebruijnIndex::ONE); | 534 | let self_ty_shifted_in = self_ty.clone().shifted_in_from(DebruijnIndex::ONE); |
535 | let (pred, binders) = pred.as_ref().into_value_and_skipped_binders(); | 535 | let (pred, binders) = pred.as_ref().into_value_and_skipped_binders(); |
536 | match pred { | 536 | match pred { |
537 | WhereClause::Implemented(trait_ref) => { | 537 | WhereClause::Implemented(trait_ref) => { |
diff --git a/crates/hir_ty/src/utils.rs b/crates/hir_ty/src/utils.rs index c7786a199..d11708299 100644 --- a/crates/hir_ty/src/utils.rs +++ b/crates/hir_ty/src/utils.rs | |||
@@ -66,9 +66,11 @@ fn direct_super_trait_refs(db: &dyn HirDatabase, trait_ref: &TraitRef) -> Vec<Tr | |||
66 | .filter_map(|pred| { | 66 | .filter_map(|pred| { |
67 | pred.as_ref().filter_map(|pred| match pred.skip_binders() { | 67 | pred.as_ref().filter_map(|pred| match pred.skip_binders() { |
68 | // FIXME: how to correctly handle higher-ranked bounds here? | 68 | // FIXME: how to correctly handle higher-ranked bounds here? |
69 | WhereClause::Implemented(tr) => { | 69 | WhereClause::Implemented(tr) => Some( |
70 | Some(tr.clone().shift_bound_vars_out(DebruijnIndex::ONE)) | 70 | tr.clone() |
71 | } | 71 | .shifted_out_to(DebruijnIndex::ONE) |
72 | .expect("FIXME unexpected higher-ranked trait bound"), | ||
73 | ), | ||
72 | _ => None, | 74 | _ => None, |
73 | }) | 75 | }) |
74 | }) | 76 | }) |
@@ -103,6 +105,8 @@ pub(super) fn all_super_traits(db: &dyn DefDatabase, trait_: TraitId) -> Vec<Tra | |||
103 | /// we have `Self: Trait<u32, i32>` and `Trait<T, U>: OtherTrait<U>` we'll get | 105 | /// we have `Self: Trait<u32, i32>` and `Trait<T, U>: OtherTrait<U>` we'll get |
104 | /// `Self: OtherTrait<i32>`. | 106 | /// `Self: OtherTrait<i32>`. |
105 | pub(super) fn all_super_trait_refs(db: &dyn HirDatabase, trait_ref: TraitRef) -> Vec<TraitRef> { | 107 | pub(super) fn all_super_trait_refs(db: &dyn HirDatabase, trait_ref: TraitRef) -> Vec<TraitRef> { |
108 | // FIXME: replace by Chalk's `super_traits`, maybe make this a query | ||
109 | |||
106 | // we need to take care a bit here to avoid infinite loops in case of cycles | 110 | // we need to take care a bit here to avoid infinite loops in case of cycles |
107 | // (i.e. if we have `trait A: B; trait B: A;`) | 111 | // (i.e. if we have `trait A: B; trait B: A;`) |
108 | let mut result = vec![trait_ref]; | 112 | let mut result = vec![trait_ref]; |
diff --git a/crates/hir_ty/src/walk.rs b/crates/hir_ty/src/walk.rs index b1e22da0a..b85e6ab4d 100644 --- a/crates/hir_ty/src/walk.rs +++ b/crates/hir_ty/src/walk.rs | |||
@@ -82,7 +82,7 @@ pub trait TypeWalk { | |||
82 | *ty = substs.interned()[bound.index] | 82 | *ty = substs.interned()[bound.index] |
83 | .assert_ty_ref(&Interner) | 83 | .assert_ty_ref(&Interner) |
84 | .clone() | 84 | .clone() |
85 | .shift_bound_vars(binders); | 85 | .shifted_in_from(binders); |
86 | } | 86 | } |
87 | } | 87 | } |
88 | }, | 88 | }, |
@@ -92,7 +92,7 @@ pub trait TypeWalk { | |||
92 | } | 92 | } |
93 | 93 | ||
94 | /// Shifts up debruijn indices of `TyKind::Bound` vars by `n`. | 94 | /// Shifts up debruijn indices of `TyKind::Bound` vars by `n`. |
95 | fn shift_bound_vars(self, n: DebruijnIndex) -> Self | 95 | fn shifted_in_from(self, n: DebruijnIndex) -> Self |
96 | where | 96 | where |
97 | Self: Sized, | 97 | Self: Sized, |
98 | { | 98 | { |
@@ -108,20 +108,22 @@ pub trait TypeWalk { | |||
108 | } | 108 | } |
109 | 109 | ||
110 | /// Shifts debruijn indices of `TyKind::Bound` vars out (down) by `n`. | 110 | /// Shifts debruijn indices of `TyKind::Bound` vars out (down) by `n`. |
111 | fn shift_bound_vars_out(self, n: DebruijnIndex) -> Self | 111 | fn shifted_out_to(self, n: DebruijnIndex) -> Option<Self> |
112 | where | 112 | where |
113 | Self: Sized + std::fmt::Debug, | 113 | Self: Sized + std::fmt::Debug, |
114 | { | 114 | { |
115 | self.fold_binders( | 115 | Some(self.fold_binders( |
116 | &mut |ty, binders| match ty.kind(&Interner) { | 116 | &mut |ty, binders| { |
117 | TyKind::BoundVar(bound) if bound.debruijn >= binders => { | 117 | match ty.kind(&Interner) { |
118 | TyKind::BoundVar(bound.shifted_out_to(n).unwrap_or(bound.clone())) | 118 | TyKind::BoundVar(bound) if bound.debruijn >= binders => { |
119 | .intern(&Interner) | 119 | TyKind::BoundVar(bound.shifted_out_to(n).unwrap_or(bound.clone())) |
120 | .intern(&Interner) | ||
121 | } | ||
122 | _ => ty, | ||
120 | } | 123 | } |
121 | _ => ty, | ||
122 | }, | 124 | }, |
123 | DebruijnIndex::INNERMOST, | 125 | DebruijnIndex::INNERMOST, |
124 | ) | 126 | )) |
125 | } | 127 | } |
126 | } | 128 | } |
127 | 129 | ||