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.rs12
1 files changed, 9 insertions, 3 deletions
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs
index 9929331d3..521e47090 100644
--- a/crates/ra_hir/src/generics.rs
+++ b/crates/ra_hir/src/generics.rs
@@ -11,8 +11,8 @@ use crate::{
11 db::{AstDatabase, DefDatabase, HirDatabase}, 11 db::{AstDatabase, DefDatabase, HirDatabase},
12 path::Path, 12 path::Path,
13 type_ref::TypeRef, 13 type_ref::TypeRef,
14 AdtDef, AsName, Container, Enum, Function, HasSource, ImplBlock, Name, Struct, Trait, 14 AdtDef, AsName, Container, Enum, EnumVariant, Function, HasSource, ImplBlock, Name, Struct,
15 TypeAlias, Union, 15 Trait, TypeAlias, Union,
16}; 16};
17 17
18/// Data about a generic parameter (to a function, struct, impl, ...). 18/// Data about a generic parameter (to a function, struct, impl, ...).
@@ -50,8 +50,11 @@ pub enum GenericDef {
50 Trait(Trait), 50 Trait(Trait),
51 TypeAlias(TypeAlias), 51 TypeAlias(TypeAlias),
52 ImplBlock(ImplBlock), 52 ImplBlock(ImplBlock),
53 // enum variants cannot have generics themselves, but their parent enums
54 // can, and this makes some code easier to write
55 EnumVariant(EnumVariant),
53} 56}
54impl_froms!(GenericDef: Function, Struct, Union, Enum, Trait, TypeAlias, ImplBlock); 57impl_froms!(GenericDef: Function, Struct, Union, Enum, Trait, TypeAlias, ImplBlock, EnumVariant);
55 58
56impl GenericParams { 59impl GenericParams {
57 pub(crate) fn generic_params_query( 60 pub(crate) fn generic_params_query(
@@ -62,6 +65,7 @@ impl GenericParams {
62 let parent = match def { 65 let parent = match def {
63 GenericDef::Function(it) => it.container(db).map(GenericDef::from), 66 GenericDef::Function(it) => it.container(db).map(GenericDef::from),
64 GenericDef::TypeAlias(it) => it.container(db).map(GenericDef::from), 67 GenericDef::TypeAlias(it) => it.container(db).map(GenericDef::from),
68 GenericDef::EnumVariant(it) => Some(it.parent_enum(db).into()),
65 GenericDef::Struct(_) 69 GenericDef::Struct(_)
66 | GenericDef::Union(_) 70 | GenericDef::Union(_)
67 | GenericDef::Enum(_) 71 | GenericDef::Enum(_)
@@ -86,6 +90,7 @@ impl GenericParams {
86 } 90 }
87 GenericDef::TypeAlias(it) => generics.fill(&*it.source(db).ast, start), 91 GenericDef::TypeAlias(it) => generics.fill(&*it.source(db).ast, start),
88 GenericDef::ImplBlock(it) => generics.fill(&*it.source(db).ast, start), 92 GenericDef::ImplBlock(it) => generics.fill(&*it.source(db).ast, start),
93 GenericDef::EnumVariant(_) => {}
89 } 94 }
90 95
91 Arc::new(generics) 96 Arc::new(generics)
@@ -184,6 +189,7 @@ impl GenericDef {
184 GenericDef::Trait(inner) => inner.resolver(db), 189 GenericDef::Trait(inner) => inner.resolver(db),
185 GenericDef::TypeAlias(inner) => inner.resolver(db), 190 GenericDef::TypeAlias(inner) => inner.resolver(db),
186 GenericDef::ImplBlock(inner) => inner.resolver(db), 191 GenericDef::ImplBlock(inner) => inner.resolver(db),
192 GenericDef::EnumVariant(inner) => inner.parent_enum(db).resolver(db),
187 } 193 }
188 } 194 }
189} 195}