aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/generics.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/generics.rs')
-rw-r--r--crates/ra_hir/src/generics.rs15
1 files changed, 9 insertions, 6 deletions
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs
index ccb777492..6865d34ba 100644
--- a/crates/ra_hir/src/generics.rs
+++ b/crates/ra_hir/src/generics.rs
@@ -12,8 +12,8 @@ use crate::{
12 name::SELF_TYPE, 12 name::SELF_TYPE,
13 path::Path, 13 path::Path,
14 type_ref::{TypeBound, TypeRef}, 14 type_ref::{TypeBound, TypeRef},
15 Adt, AsName, Container, Enum, EnumVariant, Function, HasSource, ImplBlock, Name, Struct, Trait, 15 Adt, AsName, Const, Container, Enum, EnumVariant, Function, HasSource, ImplBlock, Name, Struct,
16 TypeAlias, Union, 16 Trait, TypeAlias, Union,
17}; 17};
18 18
19/// Data about a generic parameter (to a function, struct, impl, ...). 19/// Data about a generic parameter (to a function, struct, impl, ...).
@@ -44,7 +44,6 @@ pub struct WherePredicate {
44 pub(crate) bound: TypeBound, 44 pub(crate) bound: TypeBound,
45} 45}
46 46
47// FIXME: consts can have type parameters from their parents (i.e. associated consts of traits)
48#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] 47#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
49pub enum GenericDef { 48pub enum GenericDef {
50 Function(Function), 49 Function(Function),
@@ -55,6 +54,8 @@ pub enum GenericDef {
55 // enum variants cannot have generics themselves, but their parent enums 54 // enum variants cannot have generics themselves, but their parent enums
56 // can, and this makes some code easier to write 55 // can, and this makes some code easier to write
57 EnumVariant(EnumVariant), 56 EnumVariant(EnumVariant),
57 // consts can have type parameters from their parents (i.e. associated consts of traits)
58 Const(Const),
58} 59}
59impl_froms!( 60impl_froms!(
60 GenericDef: Function, 61 GenericDef: Function,
@@ -62,7 +63,8 @@ impl_froms!(
62 Trait, 63 Trait,
63 TypeAlias, 64 TypeAlias,
64 ImplBlock, 65 ImplBlock,
65 EnumVariant 66 EnumVariant,
67 Const
66); 68);
67 69
68impl GenericParams { 70impl GenericParams {
@@ -75,7 +77,7 @@ impl GenericParams {
75 GenericDef::TypeAlias(it) => it.container(db).map(GenericDef::from), 77 GenericDef::TypeAlias(it) => it.container(db).map(GenericDef::from),
76 GenericDef::EnumVariant(it) => Some(it.parent_enum(db).into()), 78 GenericDef::EnumVariant(it) => Some(it.parent_enum(db).into()),
77 GenericDef::Adt(_) | GenericDef::Trait(_) => None, 79 GenericDef::Adt(_) | GenericDef::Trait(_) => None,
78 GenericDef::ImplBlock(_) => None, 80 GenericDef::ImplBlock(_) | GenericDef::Const(_) => None,
79 }; 81 };
80 let mut generics = GenericParams { 82 let mut generics = GenericParams {
81 def, 83 def,
@@ -104,7 +106,7 @@ impl GenericParams {
104 // type-parameter, but rather is a type-alias for impl's target 106 // type-parameter, but rather is a type-alias for impl's target
105 // type, so this is handled by the resolver. 107 // type, so this is handled by the resolver.
106 GenericDef::ImplBlock(it) => generics.fill(&it.source(db).ast, start), 108 GenericDef::ImplBlock(it) => generics.fill(&it.source(db).ast, start),
107 GenericDef::EnumVariant(_) => {} 109 GenericDef::EnumVariant(_) | GenericDef::Const(_) => {}
108 } 110 }
109 111
110 Arc::new(generics) 112 Arc::new(generics)
@@ -198,6 +200,7 @@ impl GenericDef {
198 GenericDef::TypeAlias(inner) => inner.resolver(db), 200 GenericDef::TypeAlias(inner) => inner.resolver(db),
199 GenericDef::ImplBlock(inner) => inner.resolver(db), 201 GenericDef::ImplBlock(inner) => inner.resolver(db),
200 GenericDef::EnumVariant(inner) => inner.parent_enum(db).resolver(db), 202 GenericDef::EnumVariant(inner) => inner.parent_enum(db).resolver(db),
203 GenericDef::Const(inner) => inner.resolver(db),
201 } 204 }
202 } 205 }
203} 206}