aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/expr/lower.rs7
-rw-r--r--crates/ra_hir/src/impl_block.rs3
-rw-r--r--crates/ra_hir_def/src/attr.rs3
-rw-r--r--crates/ra_hir_def/src/lib.rs1
-rw-r--r--crates/ra_hir_def/src/nameres/raw.rs6
-rw-r--r--crates/ra_hir_def/src/path.rs3
-rw-r--r--crates/ra_hir_expand/src/hygiene.rs (renamed from crates/ra_hir_def/src/hygiene.rs)22
-rw-r--r--crates/ra_hir_expand/src/lib.rs12
8 files changed, 28 insertions, 29 deletions
diff --git a/crates/ra_hir/src/expr/lower.rs b/crates/ra_hir/src/expr/lower.rs
index 241ad68fd..6463dd65e 100644
--- a/crates/ra_hir/src/expr/lower.rs
+++ b/crates/ra_hir/src/expr/lower.rs
@@ -1,7 +1,10 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use hir_def::{hygiene::Hygiene, path::GenericArgs, type_ref::TypeRef}; 3use hir_def::{path::GenericArgs, type_ref::TypeRef};
4use hir_expand::name::{self, AsName, Name}; 4use hir_expand::{
5 hygiene::Hygiene,
6 name::{self, AsName, Name},
7};
5use ra_arena::Arena; 8use ra_arena::Arena;
6use ra_syntax::{ 9use ra_syntax::{
7 ast::{ 10 ast::{
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs
index 9e4a40017..b1a014074 100644
--- a/crates/ra_hir/src/impl_block.rs
+++ b/crates/ra_hir/src/impl_block.rs
@@ -3,7 +3,8 @@
3use rustc_hash::FxHashMap; 3use rustc_hash::FxHashMap;
4use std::sync::Arc; 4use std::sync::Arc;
5 5
6use hir_def::{attr::Attr, hygiene::Hygiene, type_ref::TypeRef}; 6use hir_def::{attr::Attr, type_ref::TypeRef};
7use hir_expand::hygiene::Hygiene;
7use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; 8use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId};
8use ra_cfg::CfgOptions; 9use ra_cfg::CfgOptions;
9use ra_syntax::{ 10use ra_syntax::{
diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs
index 71f92adc2..0e961ca12 100644
--- a/crates/ra_hir_def/src/attr.rs
+++ b/crates/ra_hir_def/src/attr.rs
@@ -2,6 +2,7 @@
2 2
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use hir_expand::hygiene::Hygiene;
5use mbe::ast_to_token_tree; 6use mbe::ast_to_token_tree;
6use ra_cfg::CfgOptions; 7use ra_cfg::CfgOptions;
7use ra_syntax::{ 8use ra_syntax::{
@@ -10,7 +11,7 @@ use ra_syntax::{
10}; 11};
11use tt::Subtree; 12use tt::Subtree;
12 13
13use crate::{hygiene::Hygiene, path::Path}; 14use crate::path::Path;
14 15
15#[derive(Debug, Clone, PartialEq, Eq)] 16#[derive(Debug, Clone, PartialEq, Eq)]
16pub struct Attr { 17pub struct Attr {
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index 5135dda56..7a6c7b301 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -11,7 +11,6 @@ pub mod db;
11pub mod attr; 11pub mod attr;
12pub mod path; 12pub mod path;
13pub mod type_ref; 13pub mod type_ref;
14pub mod hygiene;
15 14
16// FIXME: this should be private 15// FIXME: this should be private
17pub mod nameres; 16pub mod nameres;
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs
index 56831e409..86c05d602 100644
--- a/crates/ra_hir_def/src/nameres/raw.rs
+++ b/crates/ra_hir_def/src/nameres/raw.rs
@@ -6,6 +6,7 @@ use hir_expand::{
6 ast_id_map::AstIdMap, 6 ast_id_map::AstIdMap,
7 db::AstDatabase, 7 db::AstDatabase,
8 either::Either, 8 either::Either,
9 hygiene::Hygiene,
9 name::{AsName, Name}, 10 name::{AsName, Name},
10}; 11};
11use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; 12use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId};
@@ -14,10 +15,7 @@ use ra_syntax::{
14 AstNode, AstPtr, SourceFile, 15 AstNode, AstPtr, SourceFile,
15}; 16};
16 17
17use crate::{ 18use crate::{attr::Attr, db::DefDatabase2, path::Path, FileAstId, HirFileId, ModuleSource, Source};
18 attr::Attr, db::DefDatabase2, hygiene::Hygiene, path::Path, FileAstId, HirFileId, ModuleSource,
19 Source,
20};
21 19
22/// `RawItems` is a set of top-level items in a file (except for impls). 20/// `RawItems` is a set of top-level items in a file (except for impls).
23/// 21///
diff --git a/crates/ra_hir_def/src/path.rs b/crates/ra_hir_def/src/path.rs
index d0b842a6b..ddabc7ca6 100644
--- a/crates/ra_hir_def/src/path.rs
+++ b/crates/ra_hir_def/src/path.rs
@@ -4,6 +4,7 @@ use std::{iter, sync::Arc};
4 4
5use hir_expand::{ 5use hir_expand::{
6 either::Either, 6 either::Either,
7 hygiene::Hygiene,
7 name::{self, AsName, Name}, 8 name::{self, AsName, Name},
8}; 9};
9use ra_db::CrateId; 10use ra_db::CrateId;
@@ -12,7 +13,7 @@ use ra_syntax::{
12 AstNode, 13 AstNode,
13}; 14};
14 15
15use crate::{hygiene::Hygiene, type_ref::TypeRef, Source}; 16use crate::{type_ref::TypeRef, Source};
16 17
17#[derive(Debug, Clone, PartialEq, Eq, Hash)] 18#[derive(Debug, Clone, PartialEq, Eq, Hash)]
18pub struct Path { 19pub struct Path {
diff --git a/crates/ra_hir_def/src/hygiene.rs b/crates/ra_hir_expand/src/hygiene.rs
index 94de2c57c..77428ec99 100644
--- a/crates/ra_hir_def/src/hygiene.rs
+++ b/crates/ra_hir_expand/src/hygiene.rs
@@ -2,16 +2,15 @@
2//! 2//!
3//! Specifically, `ast` + `Hygiene` allows you to create a `Name`. Note that, at 3//! Specifically, `ast` + `Hygiene` allows you to create a `Name`. Note that, at
4//! this moment, this is horribly incomplete and handles only `$crate`. 4//! this moment, this is horribly incomplete and handles only `$crate`.
5// Should this be moved to `hir_expand`? Seems like it. 5use ra_db::CrateId;
6use ra_syntax::ast;
6 7
7use hir_expand::{ 8use crate::{
8 db::AstDatabase, 9 db::AstDatabase,
9 either::Either, 10 either::Either,
10 name::{AsName, Name}, 11 name::{AsName, Name},
11 HirFileId, 12 HirFileId, HirFileIdRepr,
12}; 13};
13use ra_db::CrateId;
14use ra_syntax::ast;
15 14
16#[derive(Debug)] 15#[derive(Debug)]
17pub struct Hygiene { 16pub struct Hygiene {
@@ -21,15 +20,22 @@ pub struct Hygiene {
21 20
22impl Hygiene { 21impl Hygiene {
23 pub fn new(db: &impl AstDatabase, file_id: HirFileId) -> Hygiene { 22 pub fn new(db: &impl AstDatabase, file_id: HirFileId) -> Hygiene {
24 Hygiene { def_crate: file_id.macro_crate(db) } 23 let def_crate = match file_id.0 {
24 HirFileIdRepr::FileId(_) => None,
25 HirFileIdRepr::MacroFile(macro_file) => {
26 let loc = db.lookup_intern_macro(macro_file.macro_call_id);
27 Some(loc.def.krate)
28 }
29 };
30 Hygiene { def_crate }
25 } 31 }
26 32
27 pub(crate) fn new_unhygienic() -> Hygiene { 33 pub fn new_unhygienic() -> Hygiene {
28 Hygiene { def_crate: None } 34 Hygiene { def_crate: None }
29 } 35 }
30 36
31 // FIXME: this should just return name 37 // FIXME: this should just return name
32 pub(crate) fn name_ref_to_name(&self, name_ref: ast::NameRef) -> Either<Name, CrateId> { 38 pub fn name_ref_to_name(&self, name_ref: ast::NameRef) -> Either<Name, CrateId> {
33 if let Some(def_crate) = self.def_crate { 39 if let Some(def_crate) = self.def_crate {
34 if name_ref.text() == "$crate" { 40 if name_ref.text() == "$crate" {
35 return Either::B(def_crate); 41 return Either::B(def_crate);
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs
index cf28de3d8..5a0e5a19c 100644
--- a/crates/ra_hir_expand/src/lib.rs
+++ b/crates/ra_hir_expand/src/lib.rs
@@ -8,6 +8,7 @@ pub mod db;
8pub mod ast_id_map; 8pub mod ast_id_map;
9pub mod either; 9pub mod either;
10pub mod name; 10pub mod name;
11pub mod hygiene;
11 12
12use std::hash::{Hash, Hasher}; 13use std::hash::{Hash, Hasher};
13 14
@@ -61,17 +62,6 @@ impl HirFileId {
61 } 62 }
62 } 63 }
63 } 64 }
64
65 /// Get the crate which the macro lives in, if it is a macro file.
66 pub fn macro_crate(self, db: &dyn db::AstDatabase) -> Option<CrateId> {
67 match self.0 {
68 HirFileIdRepr::FileId(_) => None,
69 HirFileIdRepr::MacroFile(macro_file) => {
70 let loc = db.lookup_intern_macro(macro_file.macro_call_id);
71 Some(loc.def.krate)
72 }
73 }
74 }
75} 65}
76 66
77#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 67#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]