mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
Replace Substitution::bound_vars and ::type_params_for_generics
This commit is contained in:
parent
715c178f0b
commit
a4d7bdf1c8
7 changed files with 42 additions and 54 deletions
|
@ -2,7 +2,7 @@
|
|||
//! query, but can't be computed directly from `*Data` (ie, which need a `db`).
|
||||
use std::sync::Arc;
|
||||
|
||||
use chalk_ir::DebruijnIndex;
|
||||
use chalk_ir::{BoundVar, DebruijnIndex};
|
||||
use hir_def::{
|
||||
adt::VariantData,
|
||||
db::DefDatabase,
|
||||
|
@ -16,7 +16,7 @@ use hir_def::{
|
|||
};
|
||||
use hir_expand::name::{name, Name};
|
||||
|
||||
use crate::{db::HirDatabase, TraitRef, TypeWalk, WhereClause};
|
||||
use crate::{db::HirDatabase, Interner, Substitution, TraitRef, TyKind, TypeWalk, WhereClause};
|
||||
|
||||
fn direct_super_traits(db: &dyn DefDatabase, trait_: TraitId) -> Vec<TraitId> {
|
||||
let resolver = trait_.resolver(db);
|
||||
|
@ -249,6 +249,26 @@ impl Generics {
|
|||
self.parent_generics.as_ref().and_then(|g| g.find_param(param))
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a Substitution that replaces each parameter by a bound variable.
|
||||
pub(crate) fn bound_vars_subst(&self, debruijn: DebruijnIndex) -> Substitution {
|
||||
Substitution::from_iter(
|
||||
&Interner,
|
||||
self.iter()
|
||||
.enumerate()
|
||||
.map(|(idx, _)| TyKind::BoundVar(BoundVar::new(debruijn, idx)).intern(&Interner)),
|
||||
)
|
||||
}
|
||||
|
||||
/// Returns a Substitution that replaces each parameter by itself (i.e. `Ty::Param`).
|
||||
pub(crate) fn type_params_subst(&self, db: &dyn HirDatabase) -> Substitution {
|
||||
Substitution::from_iter(
|
||||
&Interner,
|
||||
self.iter().map(|(id, _)| {
|
||||
TyKind::Placeholder(crate::to_placeholder_idx(db, id)).intern(&Interner)
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn parent_generic_def(db: &dyn DefDatabase, def: GenericDefId) -> Option<GenericDefId> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue