new struct id

This commit is contained in:
Aleksey Kladov 2019-01-24 17:54:18 +03:00
parent c57a857988
commit 60a607d33f
12 changed files with 200 additions and 106 deletions

View file

@ -7,7 +7,7 @@ use std::sync::Arc;
use ra_syntax::ast::{self, AstNode, NameOwner, TypeParamsOwner};
use crate::{db::HirDatabase, DefId, Name, AsName, Function};
use crate::{db::HirDatabase, DefId, Name, AsName, Function, Struct};
/// Data about a generic parameter (to a function, struct, impl, ...).
#[derive(Clone, PartialEq, Eq, Debug)]
@ -25,6 +25,7 @@ pub struct GenericParams {
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
pub enum GenericDef {
Function(Function),
Struct(Struct),
Def(DefId),
}
@ -34,6 +35,12 @@ impl From<Function> for GenericDef {
}
}
impl From<Struct> for GenericDef {
fn from(func: Struct) -> GenericDef {
GenericDef::Struct(func)
}
}
impl From<DefId> for GenericDef {
fn from(def_id: DefId) -> GenericDef {
GenericDef::Def(def_id)
@ -53,6 +60,12 @@ impl GenericParams {
generics.fill(type_param_list)
}
}
GenericDef::Struct(s) => {
let (_, struct_def) = s.source(db);
if let Some(type_param_list) = struct_def.type_param_list() {
generics.fill(type_param_list)
}
}
GenericDef::Def(def_id) => {
let (_file_id, node) = def_id.source(db);
if let Some(type_param_list) = node.children().find_map(ast::TypeParamList::cast) {