From db8d29320855d68ee9af04ceeb7d1aceda8e63b7 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 2 Jan 2019 00:37:36 +0300 Subject: move macro id to ids --- crates/ra_hir/src/db.rs | 4 ++-- crates/ra_hir/src/ids.rs | 34 +++++++++++++++++++++++++++++++- crates/ra_hir/src/lib.rs | 4 ++-- crates/ra_hir/src/macros.rs | 36 ++-------------------------------- crates/ra_hir/src/query_definitions.rs | 2 +- 5 files changed, 40 insertions(+), 40 deletions(-) diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index c0b56f30a..8259bd699 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -4,11 +4,11 @@ use ra_syntax::{SyntaxNode, SourceFileNode}; use ra_db::{SourceRootId, LocationIntener, SyntaxDatabase, Cancelable}; use crate::{ - DefLoc, DefId, Name, HirFileId, + DefLoc, DefId, MacroCallLoc, MacroCallId, Name, HirFileId, SourceFileItems, SourceItemId, query_definitions, FnScopes, - macros::{MacroCallLoc, MacroCallId, MacroExpansion}, + macros::MacroExpansion, module::{ModuleId, ModuleTree, ModuleSource, nameres::{ItemMap, InputModuleItems}}, ty::{InferenceResult, Ty}, diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index cd32033f3..aa6b2d2aa 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs @@ -2,7 +2,7 @@ use ra_db::{SourceRootId, LocationIntener, Cancelable, FileId}; use ra_syntax::{SourceFileNode, SyntaxKind, SyntaxNode, SyntaxNodeRef, SourceFile, AstNode, ast}; use crate::{ - MacroCallId, HirDatabase, PerNs, ModuleId, Module, Def, Function, Struct, Enum, + HirDatabase, PerNs, ModuleId, Module, Def, Function, Struct, Enum, arena::{Arena, Id}, }; @@ -77,6 +77,38 @@ impl From for HirFileId { } } +/// `MacroCallId` identifies a particular macro invocation, like +/// `println!("Hello, {}", world)`. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub struct MacroCallId(u32); +ra_db::impl_numeric_id!(MacroCallId); + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub struct MacroCallLoc { + pub(crate) source_root_id: SourceRootId, + pub(crate) module_id: ModuleId, + pub(crate) source_item_id: SourceItemId, +} + +impl MacroCallId { + pub(crate) fn loc( + self, + db: &impl AsRef>, + ) -> MacroCallLoc { + db.as_ref().id2loc(self) + } +} + +impl MacroCallLoc { + #[allow(unused)] + pub(crate) fn id( + &self, + db: &impl AsRef>, + ) -> MacroCallId { + db.as_ref().loc2id(&self) + } +} + /// Def's are a core concept of hir. A `Def` is an Item (function, module, etc) /// in a specific module. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 5e939b79e..018ead9fb 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -42,8 +42,8 @@ pub use self::{ path::{Path, PathKind}, name::Name, krate::Crate, - ids::{HirFileId, DefId, DefLoc}, - macros::{MacroDef, MacroInput, MacroExpansion, MacroCallId, MacroCallLoc}, + ids::{HirFileId, DefId, DefLoc, MacroCallId, MacroCallLoc}, + macros::{MacroDef, MacroInput, MacroExpansion}, module::{Module, ModuleId, Problem, nameres::{ItemMap, PerNs, Namespace}, ModuleScope, Resolution}, function::{Function, FnScopes}, adt::{Struct, Enum}, diff --git a/crates/ra_hir/src/macros.rs b/crates/ra_hir/src/macros.rs index 288fbe3c6..71646b22d 100644 --- a/crates/ra_hir/src/macros.rs +++ b/crates/ra_hir/src/macros.rs @@ -1,44 +1,12 @@ use std::sync::Arc; -use ra_db::{SourceRootId, LocalSyntaxPtr, LocationIntener}; +use ra_db::LocalSyntaxPtr; use ra_syntax::{ TextRange, TextUnit, SourceFileNode, AstNode, SyntaxNode, ast::{self, NameOwner}, }; -use crate::{module::ModuleId, SourceItemId, HirDatabase}; - -/// Def's are a core concept of hir. A `Def` is an Item (function, module, etc) -/// in a specific module. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct MacroCallId(u32); -ra_db::impl_numeric_id!(MacroCallId); - -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct MacroCallLoc { - pub(crate) source_root_id: SourceRootId, - pub(crate) module_id: ModuleId, - pub(crate) source_item_id: SourceItemId, -} - -impl MacroCallId { - pub(crate) fn loc( - self, - db: &impl AsRef>, - ) -> MacroCallLoc { - db.as_ref().id2loc(self) - } -} - -impl MacroCallLoc { - #[allow(unused)] - pub(crate) fn id( - &self, - db: &impl AsRef>, - ) -> MacroCallId { - db.as_ref().loc2id(&self) - } -} +use crate::{HirDatabase, MacroCallId}; // Hard-coded defs for now :-( #[derive(Debug, Clone, PartialEq, Eq, Hash)] diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs index bc1f91938..a5d99beda 100644 --- a/crates/ra_hir/src/query_definitions.rs +++ b/crates/ra_hir/src/query_definitions.rs @@ -12,7 +12,7 @@ use ra_db::{SourceRootId, Cancelable,}; use crate::{ SourceFileItems, SourceItemId, DefKind, Function, DefId, Name, AsName, HirFileId, - macros::MacroCallLoc, + MacroCallLoc, db::HirDatabase, function::FnScopes, module::{ -- cgit v1.2.3