diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-10-31 08:24:03 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-10-31 08:24:03 +0000 |
commit | d067afb064a7fa67b172abf561b7d80740cd6f18 (patch) | |
tree | ddf0901cdf3aa454d6bfce3fa142191c22563494 /crates/ra_hir_def | |
parent | 7973c91281837bbb5c5a0bf3b1c71a5b52654b20 (diff) | |
parent | 1602db7d7d6aa38b4ee50de8cbe734529853d615 (diff) |
Merge #2141
2141: add ModuleDefId to hir_def r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 8cbff673c..93ad40005 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -23,7 +23,7 @@ use ra_arena::{impl_arena_id, RawId}; | |||
23 | use ra_db::{salsa, CrateId, FileId}; | 23 | use ra_db::{salsa, CrateId, FileId}; |
24 | use ra_syntax::{ast, AstNode, SyntaxNode}; | 24 | use ra_syntax::{ast, AstNode, SyntaxNode}; |
25 | 25 | ||
26 | use crate::db::InternDatabase; | 26 | use crate::{builtin_type::BuiltinType, db::InternDatabase}; |
27 | 27 | ||
28 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] | 28 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] |
29 | pub struct Source<T> { | 29 | pub struct Source<T> { |
@@ -256,7 +256,7 @@ pub struct EnumVariantId { | |||
256 | } | 256 | } |
257 | 257 | ||
258 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 258 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
259 | pub(crate) struct LocalEnumVariantId(RawId); | 259 | pub struct LocalEnumVariantId(RawId); |
260 | impl_arena_id!(LocalEnumVariantId); | 260 | impl_arena_id!(LocalEnumVariantId); |
261 | 261 | ||
262 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 262 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
@@ -306,3 +306,57 @@ impl AstItemDef<ast::TypeAliasDef> for TypeAliasId { | |||
306 | db.lookup_intern_type_alias(self) | 306 | db.lookup_intern_type_alias(self) |
307 | } | 307 | } |
308 | } | 308 | } |
309 | |||
310 | macro_rules! impl_froms { | ||
311 | ($e:ident: $($v:ident $(($($sv:ident),*))?),*) => { | ||
312 | $( | ||
313 | impl From<$v> for $e { | ||
314 | fn from(it: $v) -> $e { | ||
315 | $e::$v(it) | ||
316 | } | ||
317 | } | ||
318 | $($( | ||
319 | impl From<$sv> for $e { | ||
320 | fn from(it: $sv) -> $e { | ||
321 | $e::$v($v::$sv(it)) | ||
322 | } | ||
323 | } | ||
324 | )*)? | ||
325 | )* | ||
326 | } | ||
327 | } | ||
328 | |||
329 | /// A Data Type | ||
330 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | ||
331 | pub enum AdtId { | ||
332 | StructId(StructId), | ||
333 | UnionId(UnionId), | ||
334 | EnumId(EnumId), | ||
335 | } | ||
336 | impl_froms!(AdtId: StructId, UnionId, EnumId); | ||
337 | |||
338 | /// The defs which can be visible in the module. | ||
339 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
340 | pub enum ModuleDefId { | ||
341 | ModuleId(ModuleId), | ||
342 | FunctionId(FunctionId), | ||
343 | AdtId(AdtId), | ||
344 | // Can't be directly declared, but can be imported. | ||
345 | EnumVariantId(EnumVariantId), | ||
346 | ConstId(ConstId), | ||
347 | StaticId(StaticId), | ||
348 | TraitId(TraitId), | ||
349 | TypeAliasId(TypeAliasId), | ||
350 | BuiltinType(BuiltinType), | ||
351 | } | ||
352 | impl_froms!( | ||
353 | ModuleDefId: ModuleId, | ||
354 | FunctionId, | ||
355 | AdtId(StructId, EnumId, UnionId), | ||
356 | EnumVariantId, | ||
357 | ConstId, | ||
358 | StaticId, | ||
359 | TraitId, | ||
360 | TypeAliasId, | ||
361 | BuiltinType | ||
362 | ); | ||