mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 06:41:48 +00:00
Use VariableKinds in Binders
This commit is contained in:
parent
69714d36e6
commit
ad20f00844
7 changed files with 107 additions and 84 deletions
|
@ -66,6 +66,8 @@ pub type ClosureId = chalk_ir::ClosureId<Interner>;
|
|||
pub type OpaqueTyId = chalk_ir::OpaqueTyId<Interner>;
|
||||
pub type PlaceholderIndex = chalk_ir::PlaceholderIndex;
|
||||
|
||||
pub type VariableKind = chalk_ir::VariableKind<Interner>;
|
||||
pub type VariableKinds = chalk_ir::VariableKinds<Interner>;
|
||||
pub type CanonicalVarKinds = chalk_ir::CanonicalVarKinds<Interner>;
|
||||
|
||||
pub type ChalkTraitId = chalk_ir::TraitId<Interner>;
|
||||
|
@ -126,22 +128,26 @@ impl<T> Binders<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Clone> Binders<&T> {
|
||||
pub fn cloned(&self) -> Binders<T> {
|
||||
let (value, binders) = self.into_value_and_skipped_binders();
|
||||
Binders::new(binders, value.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: TypeWalk> Binders<T> {
|
||||
/// Substitutes all variables.
|
||||
pub fn subst(self, subst: &Substitution) -> T {
|
||||
let (value, binders) = self.into_value_and_skipped_binders();
|
||||
assert_eq!(subst.len(&Interner), binders);
|
||||
assert_eq!(subst.len(&Interner), binders.len(&Interner));
|
||||
value.subst_bound_vars(subst)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn make_only_type_binders<T>(num_vars: usize, value: T) -> Binders<T> {
|
||||
Binders::new(
|
||||
VariableKinds::from_iter(
|
||||
&Interner,
|
||||
std::iter::repeat(chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General))
|
||||
.take(num_vars),
|
||||
),
|
||||
value,
|
||||
)
|
||||
}
|
||||
|
||||
impl TraitRef {
|
||||
pub fn self_type_parameter(&self, interner: &Interner) -> &Ty {
|
||||
&self.substitution.at(interner, 0).assert_ty_ref(interner)
|
||||
|
@ -407,8 +413,8 @@ impl Ty {
|
|||
// This is only used by type walking.
|
||||
// Parameters will be walked outside, and projection predicate is not used.
|
||||
// So just provide the Future trait.
|
||||
let impl_bound = Binders::new(
|
||||
0,
|
||||
let impl_bound = Binders::empty(
|
||||
&Interner,
|
||||
WhereClause::Implemented(TraitRef {
|
||||
trait_id: to_chalk_trait_id(future_trait),
|
||||
substitution: Substitution::empty(&Interner),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue