aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2019-05-19 10:44:29 +0100
committerEdwin Cheng <[email protected]>2019-05-19 10:44:29 +0100
commite74d8f148b805f9f6cb1331d1a96f680948da399 (patch)
tree38d94ce707d8cc6248edcf2bf36d4667ea8a4a52 /crates/ra_hir/src
parent64ab5ab10d32e7e8ec085af818d3d94211aea39b (diff)
Add default type to GenericParam
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/generics.rs13
1 files changed, 10 insertions, 3 deletions
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs
index c29b96f50..a635c7184 100644
--- a/crates/ra_hir/src/generics.rs
+++ b/crates/ra_hir/src/generics.rs
@@ -5,7 +5,7 @@
5 5
6use std::sync::Arc; 6use std::sync::Arc;
7 7
8use ra_syntax::ast::{self, NameOwner, TypeParamsOwner, TypeBoundsOwner}; 8use ra_syntax::ast::{self, NameOwner, TypeParamsOwner, TypeBoundsOwner, DefaultTypeParamOwner};
9 9
10use crate::{ 10use crate::{
11 db::{ HirDatabase, DefDatabase}, 11 db::{ HirDatabase, DefDatabase},
@@ -18,6 +18,7 @@ pub struct GenericParam {
18 // FIXME: give generic params proper IDs 18 // FIXME: give generic params proper IDs
19 pub(crate) idx: u32, 19 pub(crate) idx: u32,
20 pub(crate) name: Name, 20 pub(crate) name: Name,
21 pub(crate) default: Option<Path>,
21} 22}
22 23
23/// Data about the generic parameters of a function, struct, impl, etc. 24/// Data about the generic parameters of a function, struct, impl, etc.
@@ -68,7 +69,11 @@ impl GenericParams {
68 GenericDef::Enum(it) => generics.fill(&*it.source(db).1, start), 69 GenericDef::Enum(it) => generics.fill(&*it.source(db).1, start),
69 GenericDef::Trait(it) => { 70 GenericDef::Trait(it) => {
70 // traits get the Self type as an implicit first type parameter 71 // traits get the Self type as an implicit first type parameter
71 generics.params.push(GenericParam { idx: start, name: Name::self_type() }); 72 generics.params.push(GenericParam {
73 idx: start,
74 name: Name::self_type(),
75 default: None,
76 });
72 generics.fill(&*it.source(db).1, start + 1); 77 generics.fill(&*it.source(db).1, start + 1);
73 } 78 }
74 GenericDef::TypeAlias(it) => generics.fill(&*it.source(db).1, start), 79 GenericDef::TypeAlias(it) => generics.fill(&*it.source(db).1, start),
@@ -90,7 +95,9 @@ impl GenericParams {
90 fn fill_params(&mut self, params: &ast::TypeParamList, start: u32) { 95 fn fill_params(&mut self, params: &ast::TypeParamList, start: u32) {
91 for (idx, type_param) in params.type_params().enumerate() { 96 for (idx, type_param) in params.type_params().enumerate() {
92 let name = type_param.name().map(AsName::as_name).unwrap_or_else(Name::missing); 97 let name = type_param.name().map(AsName::as_name).unwrap_or_else(Name::missing);
93 let param = GenericParam { idx: idx as u32 + start, name: name.clone() }; 98 let default = type_param.default_type().and_then(|t| t.path()).and_then(Path::from_ast);
99
100 let param = GenericParam { idx: idx as u32 + start, name: name.clone(), default };
94 self.params.push(param); 101 self.params.push(param);
95 102
96 let type_ref = TypeRef::Path(name.into()); 103 let type_ref = TypeRef::Path(name.into());