aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ids.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ids.rs')
-rw-r--r--crates/ra_hir/src/ids.rs32
1 files changed, 21 insertions, 11 deletions
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
index 4b4e07e58..9aae58bb6 100644
--- a/crates/ra_hir/src/ids.rs
+++ b/crates/ra_hir/src/ids.rs
@@ -9,7 +9,7 @@ use ra_arena::{Arena, RawId, ArenaId, impl_arena_id};
9 9
10use crate::{ 10use crate::{
11 HirDatabase, Def, 11 HirDatabase, Def,
12 Module, Trait, Type, Static, Const, 12 Module, Trait, Type,
13}; 13};
14 14
15#[derive(Debug, Default)] 15#[derive(Debug, Default)]
@@ -20,6 +20,8 @@ pub struct HirInterner {
20 structs: LocationIntener<ItemLoc<ast::StructDef>, StructId>, 20 structs: LocationIntener<ItemLoc<ast::StructDef>, StructId>,
21 enums: LocationIntener<ItemLoc<ast::EnumDef>, EnumId>, 21 enums: LocationIntener<ItemLoc<ast::EnumDef>, EnumId>,
22 enum_variants: LocationIntener<ItemLoc<ast::EnumVariant>, EnumVariantId>, 22 enum_variants: LocationIntener<ItemLoc<ast::EnumVariant>, EnumVariantId>,
23 consts: LocationIntener<ItemLoc<ast::ConstDef>, ConstId>,
24 statics: LocationIntener<ItemLoc<ast::StaticDef>, StaticId>,
23} 25}
24 26
25impl HirInterner { 27impl HirInterner {
@@ -246,6 +248,24 @@ impl AstItemDef<ast::EnumVariant> for EnumVariantId {
246 } 248 }
247} 249}
248 250
251#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
252pub struct ConstId(RawId);
253impl_arena_id!(ConstId);
254impl AstItemDef<ast::ConstDef> for ConstId {
255 fn interner(interner: &HirInterner) -> &LocationIntener<ItemLoc<ast::ConstDef>, Self> {
256 &interner.consts
257 }
258}
259
260#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
261pub struct StaticId(RawId);
262impl_arena_id!(StaticId);
263impl AstItemDef<ast::StaticDef> for StaticId {
264 fn interner(interner: &HirInterner) -> &LocationIntener<ItemLoc<ast::StaticDef>, Self> {
265 &interner.statics
266 }
267}
268
249/// Def's are a core concept of hir. A `Def` is an Item (function, module, etc) 269/// Def's are a core concept of hir. A `Def` is an Item (function, module, etc)
250/// in a specific module. 270/// in a specific module.
251#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 271#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -261,8 +281,6 @@ pub struct DefLoc {
261 281
262#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 282#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
263pub(crate) enum DefKind { 283pub(crate) enum DefKind {
264 Const,
265 Static,
266 Trait, 284 Trait,
267 Type, 285 Type,
268 Item, 286 Item,
@@ -286,14 +304,6 @@ impl DefId {
286 pub fn resolve(self, db: &impl HirDatabase) -> Def { 304 pub fn resolve(self, db: &impl HirDatabase) -> Def {
287 let loc = self.loc(db); 305 let loc = self.loc(db);
288 match loc.kind { 306 match loc.kind {
289 DefKind::Const => {
290 let def = Const::new(self);
291 Def::Const(def)
292 }
293 DefKind::Static => {
294 let def = Static::new(self);
295 Def::Static(def)
296 }
297 DefKind::Trait => { 307 DefKind::Trait => {
298 let def = Trait::new(self); 308 let def = Trait::new(self);
299 Def::Trait(def) 309 Def::Trait(def)