mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
Rename shift_bound_vars{_out} to align with Chalk
This commit is contained in:
parent
fbab69cbff
commit
a316d58360
5 changed files with 32 additions and 25 deletions
|
@ -124,7 +124,7 @@ impl<T> Binders<T> {
|
||||||
where
|
where
|
||||||
T: TypeWalk,
|
T: TypeWalk,
|
||||||
{
|
{
|
||||||
Binders::empty(&Interner, value.shift_bound_vars(DebruijnIndex::ONE))
|
Binders::empty(&Interner, value.shifted_in_from(DebruijnIndex::ONE))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,7 +209,8 @@ impl CallableSig {
|
||||||
params_and_return: fn_ptr
|
params_and_return: fn_ptr
|
||||||
.substs
|
.substs
|
||||||
.clone()
|
.clone()
|
||||||
.shift_bound_vars_out(DebruijnIndex::ONE)
|
.shifted_out_to(DebruijnIndex::ONE)
|
||||||
|
.expect("unexpected lifetime vars in fn ptr")
|
||||||
.interned()
|
.interned()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|arg| arg.assert_ty_ref(&Interner).clone())
|
.map(|arg| arg.assert_ty_ref(&Interner).clone())
|
||||||
|
|
|
@ -483,7 +483,7 @@ impl<'a> TyLoweringContext<'a> {
|
||||||
};
|
};
|
||||||
// We need to shift in the bound vars, since
|
// We need to shift in the bound vars, since
|
||||||
// associated_type_shorthand_candidates does not do that
|
// associated_type_shorthand_candidates does not do that
|
||||||
let substs = substs.shift_bound_vars(self.in_binders);
|
let substs = substs.shifted_in_from(self.in_binders);
|
||||||
// FIXME handle type parameters on the segment
|
// FIXME handle type parameters on the segment
|
||||||
return Some(
|
return Some(
|
||||||
TyKind::Alias(AliasTy::Projection(ProjectionTy {
|
TyKind::Alias(AliasTy::Projection(ProjectionTy {
|
||||||
|
@ -831,20 +831,20 @@ pub fn associated_type_shorthand_candidates<R>(
|
||||||
};
|
};
|
||||||
|
|
||||||
match res {
|
match res {
|
||||||
// FIXME: how to correctly handle higher-ranked bounds here?
|
|
||||||
TypeNs::SelfType(impl_id) => search(
|
TypeNs::SelfType(impl_id) => search(
|
||||||
db.impl_trait(impl_id)?
|
// we're _in_ the impl -- the binders get added back later. Correct,
|
||||||
.into_value_and_skipped_binders()
|
// but it would be nice to make this more explicit
|
||||||
.0
|
db.impl_trait(impl_id)?.into_value_and_skipped_binders().0,
|
||||||
.shift_bound_vars_out(DebruijnIndex::ONE),
|
|
||||||
),
|
),
|
||||||
TypeNs::GenericParam(param_id) => {
|
TypeNs::GenericParam(param_id) => {
|
||||||
let predicates = db.generic_predicates_for_param(param_id);
|
let predicates = db.generic_predicates_for_param(param_id);
|
||||||
let res = predicates.iter().find_map(|pred| match pred.skip_binders().skip_binders() {
|
let res = predicates.iter().find_map(|pred| match pred.skip_binders().skip_binders() {
|
||||||
// FIXME: how to correctly handle higher-ranked bounds here?
|
// FIXME: how to correctly handle higher-ranked bounds here?
|
||||||
WhereClause::Implemented(tr) => {
|
WhereClause::Implemented(tr) => search(
|
||||||
search(tr.clone().shift_bound_vars_out(DebruijnIndex::ONE))
|
tr.clone()
|
||||||
}
|
.shifted_out_to(DebruijnIndex::ONE)
|
||||||
|
.expect("FIXME unexpected higher-ranked trait bound"),
|
||||||
|
),
|
||||||
_ => None,
|
_ => None,
|
||||||
});
|
});
|
||||||
if let res @ Some(_) = res {
|
if let res @ Some(_) = res {
|
||||||
|
|
|
@ -531,7 +531,7 @@ pub(super) fn generic_predicate_to_inline_bound(
|
||||||
) -> Option<chalk_ir::Binders<rust_ir::InlineBound<Interner>>> {
|
) -> Option<chalk_ir::Binders<rust_ir::InlineBound<Interner>>> {
|
||||||
// An InlineBound is like a GenericPredicate, except the self type is left out.
|
// An InlineBound is like a GenericPredicate, except the self type is left out.
|
||||||
// We don't have a special type for this, but Chalk does.
|
// We don't have a special type for this, but Chalk does.
|
||||||
let self_ty_shifted_in = self_ty.clone().shift_bound_vars(DebruijnIndex::ONE);
|
let self_ty_shifted_in = self_ty.clone().shifted_in_from(DebruijnIndex::ONE);
|
||||||
let (pred, binders) = pred.as_ref().into_value_and_skipped_binders();
|
let (pred, binders) = pred.as_ref().into_value_and_skipped_binders();
|
||||||
match pred {
|
match pred {
|
||||||
WhereClause::Implemented(trait_ref) => {
|
WhereClause::Implemented(trait_ref) => {
|
||||||
|
|
|
@ -66,9 +66,11 @@ fn direct_super_trait_refs(db: &dyn HirDatabase, trait_ref: &TraitRef) -> Vec<Tr
|
||||||
.filter_map(|pred| {
|
.filter_map(|pred| {
|
||||||
pred.as_ref().filter_map(|pred| match pred.skip_binders() {
|
pred.as_ref().filter_map(|pred| match pred.skip_binders() {
|
||||||
// FIXME: how to correctly handle higher-ranked bounds here?
|
// FIXME: how to correctly handle higher-ranked bounds here?
|
||||||
WhereClause::Implemented(tr) => {
|
WhereClause::Implemented(tr) => Some(
|
||||||
Some(tr.clone().shift_bound_vars_out(DebruijnIndex::ONE))
|
tr.clone()
|
||||||
}
|
.shifted_out_to(DebruijnIndex::ONE)
|
||||||
|
.expect("FIXME unexpected higher-ranked trait bound"),
|
||||||
|
),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -103,6 +105,8 @@ pub(super) fn all_super_traits(db: &dyn DefDatabase, trait_: TraitId) -> Vec<Tra
|
||||||
/// we have `Self: Trait<u32, i32>` and `Trait<T, U>: OtherTrait<U>` we'll get
|
/// we have `Self: Trait<u32, i32>` and `Trait<T, U>: OtherTrait<U>` we'll get
|
||||||
/// `Self: OtherTrait<i32>`.
|
/// `Self: OtherTrait<i32>`.
|
||||||
pub(super) fn all_super_trait_refs(db: &dyn HirDatabase, trait_ref: TraitRef) -> Vec<TraitRef> {
|
pub(super) fn all_super_trait_refs(db: &dyn HirDatabase, trait_ref: TraitRef) -> Vec<TraitRef> {
|
||||||
|
// FIXME: replace by Chalk's `super_traits`, maybe make this a query
|
||||||
|
|
||||||
// we need to take care a bit here to avoid infinite loops in case of cycles
|
// we need to take care a bit here to avoid infinite loops in case of cycles
|
||||||
// (i.e. if we have `trait A: B; trait B: A;`)
|
// (i.e. if we have `trait A: B; trait B: A;`)
|
||||||
let mut result = vec![trait_ref];
|
let mut result = vec![trait_ref];
|
||||||
|
|
|
@ -82,7 +82,7 @@ pub trait TypeWalk {
|
||||||
*ty = substs.interned()[bound.index]
|
*ty = substs.interned()[bound.index]
|
||||||
.assert_ty_ref(&Interner)
|
.assert_ty_ref(&Interner)
|
||||||
.clone()
|
.clone()
|
||||||
.shift_bound_vars(binders);
|
.shifted_in_from(binders);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -92,7 +92,7 @@ pub trait TypeWalk {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shifts up debruijn indices of `TyKind::Bound` vars by `n`.
|
/// Shifts up debruijn indices of `TyKind::Bound` vars by `n`.
|
||||||
fn shift_bound_vars(self, n: DebruijnIndex) -> Self
|
fn shifted_in_from(self, n: DebruijnIndex) -> Self
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
|
@ -108,20 +108,22 @@ pub trait TypeWalk {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shifts debruijn indices of `TyKind::Bound` vars out (down) by `n`.
|
/// Shifts debruijn indices of `TyKind::Bound` vars out (down) by `n`.
|
||||||
fn shift_bound_vars_out(self, n: DebruijnIndex) -> Self
|
fn shifted_out_to(self, n: DebruijnIndex) -> Option<Self>
|
||||||
where
|
where
|
||||||
Self: Sized + std::fmt::Debug,
|
Self: Sized + std::fmt::Debug,
|
||||||
{
|
{
|
||||||
self.fold_binders(
|
Some(self.fold_binders(
|
||||||
&mut |ty, binders| match ty.kind(&Interner) {
|
&mut |ty, binders| {
|
||||||
TyKind::BoundVar(bound) if bound.debruijn >= binders => {
|
match ty.kind(&Interner) {
|
||||||
TyKind::BoundVar(bound.shifted_out_to(n).unwrap_or(bound.clone()))
|
TyKind::BoundVar(bound) if bound.debruijn >= binders => {
|
||||||
.intern(&Interner)
|
TyKind::BoundVar(bound.shifted_out_to(n).unwrap_or(bound.clone()))
|
||||||
|
.intern(&Interner)
|
||||||
|
}
|
||||||
|
_ => ty,
|
||||||
}
|
}
|
||||||
_ => ty,
|
|
||||||
},
|
},
|
||||||
DebruijnIndex::INNERMOST,
|
DebruijnIndex::INNERMOST,
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue