mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Move generic_params query to HIR
This commit is contained in:
parent
c51dcb1c4b
commit
cb642fc578
4 changed files with 37 additions and 27 deletions
|
@ -5,13 +5,12 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use hir_expand::name::{self, AsName, Name};
|
||||
|
||||
use ra_syntax::ast::{self, NameOwner, TypeBoundsOwner, TypeParamsOwner};
|
||||
|
||||
use crate::{
|
||||
db::DefDatabase2,
|
||||
type_ref::{TypeBound, TypeRef},
|
||||
AdtId, AstItemDef, GenericDefId, HasSource, Lookup,
|
||||
AdtId, AstItemDef, ContainerId, GenericDefId, HasSource, Lookup,
|
||||
};
|
||||
|
||||
/// Data about a generic parameter (to a function, struct, impl, ...).
|
||||
|
@ -43,7 +42,15 @@ pub struct WherePredicate {
|
|||
}
|
||||
|
||||
impl GenericParams {
|
||||
pub fn new(
|
||||
pub(crate) fn generic_params_query(
|
||||
db: &impl DefDatabase2,
|
||||
def: GenericDefId,
|
||||
) -> Arc<GenericParams> {
|
||||
let parent_generics = parent_generic_def(db, def).map(|it| db.generic_params(it));
|
||||
Arc::new(GenericParams::new(db, def.into(), parent_generics))
|
||||
}
|
||||
|
||||
fn new(
|
||||
db: &impl DefDatabase2,
|
||||
def: GenericDefId,
|
||||
parent_params: Option<Arc<GenericParams>>,
|
||||
|
@ -161,3 +168,19 @@ impl GenericParams {
|
|||
vec
|
||||
}
|
||||
}
|
||||
|
||||
fn parent_generic_def(db: &impl DefDatabase2, def: GenericDefId) -> Option<GenericDefId> {
|
||||
let container = match def {
|
||||
GenericDefId::FunctionId(it) => it.lookup(db).container,
|
||||
GenericDefId::TypeAliasId(it) => it.lookup(db).container,
|
||||
GenericDefId::ConstId(it) => it.lookup(db).container,
|
||||
GenericDefId::EnumVariantId(it) => return Some(it.parent.into()),
|
||||
GenericDefId::AdtId(_) | GenericDefId::TraitId(_) | GenericDefId::ImplId(_) => return None,
|
||||
};
|
||||
|
||||
match container {
|
||||
ContainerId::ImplId(it) => Some(it.into()),
|
||||
ContainerId::TraitId(it) => Some(it.into()),
|
||||
ContainerId::ModuleId(_) => None,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue