aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/hygiene.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/hygiene.rs')
-rw-r--r--crates/ra_hir_def/src/hygiene.rs40
1 files changed, 0 insertions, 40 deletions
diff --git a/crates/ra_hir_def/src/hygiene.rs b/crates/ra_hir_def/src/hygiene.rs
deleted file mode 100644
index 94de2c57c..000000000
--- a/crates/ra_hir_def/src/hygiene.rs
+++ /dev/null
@@ -1,40 +0,0 @@
1//! This modules handles hygiene information.
2//!
3//! Specifically, `ast` + `Hygiene` allows you to create a `Name`. Note that, at
4//! this moment, this is horribly incomplete and handles only `$crate`.
5// Should this be moved to `hir_expand`? Seems like it.
6
7use hir_expand::{
8 db::AstDatabase,
9 either::Either,
10 name::{AsName, Name},
11 HirFileId,
12};
13use ra_db::CrateId;
14use ra_syntax::ast;
15
16#[derive(Debug)]
17pub struct Hygiene {
18 // This is what `$crate` expands to
19 def_crate: Option<CrateId>,
20}
21
22impl Hygiene {
23 pub fn new(db: &impl AstDatabase, file_id: HirFileId) -> Hygiene {
24 Hygiene { def_crate: file_id.macro_crate(db) }
25 }
26
27 pub(crate) fn new_unhygienic() -> Hygiene {
28 Hygiene { def_crate: None }
29 }
30
31 // FIXME: this should just return name
32 pub(crate) fn name_ref_to_name(&self, name_ref: ast::NameRef) -> Either<Name, CrateId> {
33 if let Some(def_crate) = self.def_crate {
34 if name_ref.text() == "$crate" {
35 return Either::B(def_crate);
36 }
37 }
38 Either::A(name_ref.as_name())
39 }
40}