aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/generics.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-24 14:54:18 +0000
committerAleksey Kladov <[email protected]>2019-01-24 14:54:18 +0000
commit60a607d33f1c50acd0a4218da32abe35b2941e38 (patch)
treefa1e5e1785cb04186ed07e04e3e5c1c73bb83c79 /crates/ra_hir/src/generics.rs
parentc57a8579888643e73e12dd0ca23e81f88608c52f (diff)
new struct id
Diffstat (limited to 'crates/ra_hir/src/generics.rs')
-rw-r--r--crates/ra_hir/src/generics.rs15
1 files changed, 14 insertions, 1 deletions
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs
index 88c53705f..e10b85ec9 100644
--- a/crates/ra_hir/src/generics.rs
+++ b/crates/ra_hir/src/generics.rs
@@ -7,7 +7,7 @@ use std::sync::Arc;
7 7
8use ra_syntax::ast::{self, AstNode, NameOwner, TypeParamsOwner}; 8use ra_syntax::ast::{self, AstNode, NameOwner, TypeParamsOwner};
9 9
10use crate::{db::HirDatabase, DefId, Name, AsName, Function}; 10use crate::{db::HirDatabase, DefId, Name, AsName, Function, Struct};
11 11
12/// Data about a generic parameter (to a function, struct, impl, ...). 12/// Data about a generic parameter (to a function, struct, impl, ...).
13#[derive(Clone, PartialEq, Eq, Debug)] 13#[derive(Clone, PartialEq, Eq, Debug)]
@@ -25,6 +25,7 @@ pub struct GenericParams {
25#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] 25#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
26pub enum GenericDef { 26pub enum GenericDef {
27 Function(Function), 27 Function(Function),
28 Struct(Struct),
28 Def(DefId), 29 Def(DefId),
29} 30}
30 31
@@ -34,6 +35,12 @@ impl From<Function> for GenericDef {
34 } 35 }
35} 36}
36 37
38impl From<Struct> for GenericDef {
39 fn from(func: Struct) -> GenericDef {
40 GenericDef::Struct(func)
41 }
42}
43
37impl From<DefId> for GenericDef { 44impl From<DefId> for GenericDef {
38 fn from(def_id: DefId) -> GenericDef { 45 fn from(def_id: DefId) -> GenericDef {
39 GenericDef::Def(def_id) 46 GenericDef::Def(def_id)
@@ -53,6 +60,12 @@ impl GenericParams {
53 generics.fill(type_param_list) 60 generics.fill(type_param_list)
54 } 61 }
55 } 62 }
63 GenericDef::Struct(s) => {
64 let (_, struct_def) = s.source(db);
65 if let Some(type_param_list) = struct_def.type_param_list() {
66 generics.fill(type_param_list)
67 }
68 }
56 GenericDef::Def(def_id) => { 69 GenericDef::Def(def_id) => {
57 let (_file_id, node) = def_id.source(db); 70 let (_file_id, node) = def_id.source(db);
58 if let Some(type_param_list) = node.children().find_map(ast::TypeParamList::cast) { 71 if let Some(type_param_list) = node.children().find_map(ast::TypeParamList::cast) {