mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-28 20:16:58 +03:00
Add generic params to impl blocks
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
|
||||
use ra_syntax::ast::{self, NameOwner, TypeParamsOwner};
|
||||
|
||||
use crate::{db::PersistentHirDatabase, Name, AsName, Function, Struct, Enum, Trait, Type};
|
||||
use crate::{db::PersistentHirDatabase, Name, AsName, Function, Struct, Enum, Trait, Type, ImplBlock};
|
||||
|
||||
/// Data about a generic parameter (to a function, struct, impl, ...).
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
@@ -30,8 +30,9 @@ pub enum GenericDef {
|
||||
Enum(Enum),
|
||||
Trait(Trait),
|
||||
Type(Type),
|
||||
ImplBlock(ImplBlock),
|
||||
}
|
||||
impl_froms!(GenericDef: Function, Struct, Enum, Trait, Type);
|
||||
impl_froms!(GenericDef: Function, Struct, Enum, Trait, Type, ImplBlock);
|
||||
|
||||
impl GenericParams {
|
||||
pub(crate) fn generic_params_query(
|
||||
@@ -45,6 +46,7 @@ pub(crate) fn generic_params_query(
|
||||
GenericDef::Enum(it) => generics.fill(&*it.source(db).1),
|
||||
GenericDef::Trait(it) => generics.fill(&*it.source(db).1),
|
||||
GenericDef::Type(it) => generics.fill(&*it.source(db).1),
|
||||
GenericDef::ImplBlock(it) => generics.fill(&*it.source(db).1),
|
||||
}
|
||||
|
||||
Arc::new(generics)
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
type_ref::TypeRef,
|
||||
ids::LocationCtx,
|
||||
resolve::Resolver,
|
||||
ty::Ty,
|
||||
ty::Ty, generics::GenericParams
|
||||
};
|
||||
|
||||
use crate::code_model_api::{Module, ModuleSource};
|
||||
@@ -38,7 +38,7 @@ pub fn get(&self, source: &ModuleSource, impl_id: ImplId) -> TreeArc<ast::ImplBl
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct ImplBlock {
|
||||
module: Module,
|
||||
impl_id: ImplId,
|
||||
@@ -58,7 +58,7 @@ pub(crate) fn from_id(module: Module, impl_id: ImplId) -> ImplBlock {
|
||||
}
|
||||
|
||||
/// Returns the syntax of the impl block
|
||||
pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::ImplBlock>) {
|
||||
pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::ImplBlock>) {
|
||||
let source_map = db.impls_in_module_source_map(self.module);
|
||||
let (file_id, source) = self.module.definition_source(db);
|
||||
(file_id, source_map.get(&source, self.impl_id))
|
||||
@@ -72,11 +72,11 @@ pub fn module(&self) -> Module {
|
||||
self.module
|
||||
}
|
||||
|
||||
pub fn target_trait_ref(&self, db: &impl HirDatabase) -> Option<TypeRef> {
|
||||
pub fn target_trait_ref(&self, db: &impl PersistentHirDatabase) -> Option<TypeRef> {
|
||||
db.impls_in_module(self.module).impls[self.impl_id].target_trait().cloned()
|
||||
}
|
||||
|
||||
pub fn target_type(&self, db: &impl HirDatabase) -> TypeRef {
|
||||
pub fn target_type(&self, db: &impl PersistentHirDatabase) -> TypeRef {
|
||||
db.impls_in_module(self.module).impls[self.impl_id].target_type().clone()
|
||||
}
|
||||
|
||||
@@ -96,10 +96,14 @@ pub fn target_trait(&self, db: &impl HirDatabase) -> Option<Trait> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn items(&self, db: &impl HirDatabase) -> Vec<ImplItem> {
|
||||
pub fn items(&self, db: &impl PersistentHirDatabase) -> Vec<ImplItem> {
|
||||
db.impls_in_module(self.module).impls[self.impl_id].items().to_vec()
|
||||
}
|
||||
|
||||
pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> {
|
||||
db.generic_params((*self).into())
|
||||
}
|
||||
|
||||
pub fn resolver(&self, db: &impl HirDatabase) -> Resolver {
|
||||
let r = self.module().resolver(db);
|
||||
// TODO: add generics
|
||||
|
||||
@@ -1352,6 +1352,7 @@ fn to_owned(&self) -> TreeArc<ImplBlock> { TreeArc::cast(self.syntax.to_owned())
|
||||
}
|
||||
|
||||
|
||||
impl ast::TypeParamsOwner for ImplBlock {}
|
||||
impl ImplBlock {
|
||||
pub fn item_list(&self) -> Option<&ItemList> {
|
||||
super::child_opt(self)
|
||||
|
||||
@@ -322,7 +322,7 @@ Grammar(
|
||||
],
|
||||
options: ["TypeRef"]
|
||||
),
|
||||
"ImplBlock": (options: ["ItemList"]),
|
||||
"ImplBlock": (options: ["ItemList"], traits: ["TypeParamsOwner"]),
|
||||
|
||||
"ParenType": (options: ["TypeRef"]),
|
||||
"TupleType": ( collections: [["fields", "TypeRef"]] ),
|
||||
|
||||
Reference in New Issue
Block a user