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.rs54
1 files changed, 0 insertions, 54 deletions
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs
deleted file mode 100644
index f1bf2ee9d..000000000
--- a/crates/ra_hir/src/generics.rs
+++ /dev/null
@@ -1,54 +0,0 @@
1//! Temp module to wrap hir_def::generics
2use std::sync::Arc;
3
4use crate::{
5 db::DefDatabase, Adt, Const, Container, Enum, EnumVariant, Function, ImplBlock, Struct, Trait,
6 TypeAlias, Union,
7};
8
9pub use hir_def::generics::{GenericParam, GenericParams, WherePredicate};
10
11#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
12pub enum GenericDef {
13 Function(Function),
14 Adt(Adt),
15 Trait(Trait),
16 TypeAlias(TypeAlias),
17 ImplBlock(ImplBlock),
18 // enum variants cannot have generics themselves, but their parent enums
19 // can, and this makes some code easier to write
20 EnumVariant(EnumVariant),
21 // consts can have type parameters from their parents (i.e. associated consts of traits)
22 Const(Const),
23}
24impl_froms!(
25 GenericDef: Function,
26 Adt(Struct, Enum, Union),
27 Trait,
28 TypeAlias,
29 ImplBlock,
30 EnumVariant,
31 Const
32);
33
34impl From<Container> for GenericDef {
35 fn from(c: Container) -> Self {
36 match c {
37 Container::Trait(trait_) => trait_.into(),
38 Container::ImplBlock(impl_block) => impl_block.into(),
39 }
40 }
41}
42
43pub trait HasGenericParams: Copy {
44 fn generic_params(self, db: &impl DefDatabase) -> Arc<GenericParams>;
45}
46
47impl<T> HasGenericParams for T
48where
49 T: Into<GenericDef> + Copy,
50{
51 fn generic_params(self, db: &impl DefDatabase) -> Arc<GenericParams> {
52 db.generic_params(self.into().into())
53 }
54}