diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/generics.rs | 13 |
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 | ||
6 | use std::sync::Arc; | 6 | use std::sync::Arc; |
7 | 7 | ||
8 | use ra_syntax::ast::{self, NameOwner, TypeParamsOwner, TypeBoundsOwner}; | 8 | use ra_syntax::ast::{self, NameOwner, TypeParamsOwner, TypeBoundsOwner, DefaultTypeParamOwner}; |
9 | 9 | ||
10 | use crate::{ | 10 | use 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()); |