diff options
Diffstat (limited to 'crates/ra_hir_def/src/impls.rs')
-rw-r--r-- | crates/ra_hir_def/src/impls.rs | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/crates/ra_hir_def/src/impls.rs b/crates/ra_hir_def/src/impls.rs deleted file mode 100644 index 750a869f2..000000000 --- a/crates/ra_hir_def/src/impls.rs +++ /dev/null | |||
@@ -1,86 +0,0 @@ | |||
1 | //! Defines hir-level representation of impls. | ||
2 | //! | ||
3 | //! The handling is similar, but is not quite the same as for other items, | ||
4 | //! because `impl`s don't have names. | ||
5 | |||
6 | use std::sync::Arc; | ||
7 | |||
8 | use hir_expand::AstId; | ||
9 | use ra_syntax::ast; | ||
10 | |||
11 | use crate::{ | ||
12 | db::DefDatabase2, type_ref::TypeRef, AssocItemId, AstItemDef, ConstLoc, ContainerId, | ||
13 | FunctionLoc, ImplId, Intern, TypeAliasLoc, | ||
14 | }; | ||
15 | |||
16 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
17 | pub struct ImplData { | ||
18 | target_trait: Option<TypeRef>, | ||
19 | target_type: TypeRef, | ||
20 | items: Vec<AssocItemId>, | ||
21 | negative: bool, | ||
22 | } | ||
23 | |||
24 | impl ImplData { | ||
25 | pub(crate) fn impl_data_query(db: &impl DefDatabase2, id: ImplId) -> Arc<ImplData> { | ||
26 | let src = id.source(db); | ||
27 | let items = db.ast_id_map(src.file_id); | ||
28 | |||
29 | let target_trait = src.value.target_trait().map(TypeRef::from_ast); | ||
30 | let target_type = TypeRef::from_ast_opt(src.value.target_type()); | ||
31 | let negative = src.value.is_negative(); | ||
32 | |||
33 | let items = if let Some(item_list) = src.value.item_list() { | ||
34 | item_list | ||
35 | .impl_items() | ||
36 | .map(|item_node| match item_node { | ||
37 | ast::ImplItem::FnDef(it) => { | ||
38 | let def = FunctionLoc { | ||
39 | container: ContainerId::ImplId(id), | ||
40 | ast_id: AstId::new(src.file_id, items.ast_id(&it)), | ||
41 | } | ||
42 | .intern(db); | ||
43 | def.into() | ||
44 | } | ||
45 | ast::ImplItem::ConstDef(it) => { | ||
46 | let def = ConstLoc { | ||
47 | container: ContainerId::ImplId(id), | ||
48 | ast_id: AstId::new(src.file_id, items.ast_id(&it)), | ||
49 | } | ||
50 | .intern(db); | ||
51 | def.into() | ||
52 | } | ||
53 | ast::ImplItem::TypeAliasDef(it) => { | ||
54 | let def = TypeAliasLoc { | ||
55 | container: ContainerId::ImplId(id), | ||
56 | ast_id: AstId::new(src.file_id, items.ast_id(&it)), | ||
57 | } | ||
58 | .intern(db); | ||
59 | def.into() | ||
60 | } | ||
61 | }) | ||
62 | .collect() | ||
63 | } else { | ||
64 | Vec::new() | ||
65 | }; | ||
66 | |||
67 | let res = ImplData { target_trait, target_type, items, negative }; | ||
68 | Arc::new(res) | ||
69 | } | ||
70 | |||
71 | pub fn target_trait(&self) -> Option<&TypeRef> { | ||
72 | self.target_trait.as_ref() | ||
73 | } | ||
74 | |||
75 | pub fn target_type(&self) -> &TypeRef { | ||
76 | &self.target_type | ||
77 | } | ||
78 | |||
79 | pub fn items(&self) -> &[AssocItemId] { | ||
80 | &self.items | ||
81 | } | ||
82 | |||
83 | pub fn is_negative(&self) -> bool { | ||
84 | self.negative | ||
85 | } | ||
86 | } | ||