Repository: rust-analyzer/rust-analyzer
Pull request #3428 (2020-03-03 17:51:22)

Move reference classification to ra_ide_db
Lost some marks along the way :-(



bors r+
🤖


Patch:
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index a3d617e1f0..c9b14d0c80 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -47,8 +47,8 @@ mod marks;
 use std::hash::Hash;
 
 use hir_expand::{
-    ast_id_map::FileAstId, db::AstDatabase, eager::expand_eager_macro, hygiene::Hygiene, AstId,
-    HirFileId, InFile, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind,
+    ast_id_map::FileAstId, db::AstDatabase, hygiene::Hygiene, AstId, HirFileId, InFile,
+    MacroCallId, MacroCallKind, MacroDefId,
 };
 use ra_arena::{impl_arena_id, RawId};
 use ra_db::{impl_intern_key, salsa, CrateId};
@@ -459,21 +459,8 @@ impl AsMacroCall for AstIdWithPath<ast::MacroCall> {
         db: &impl AstDatabase,
         resolver: impl Fn(path::ModPath) -> Option<MacroDefId>,
     ) -> Option<MacroCallId> {
-        let def: MacroDefId = resolver(self.path.clone())?;
-
-        if let MacroDefKind::BuiltInEager(_) = def.kind {
-            let macro_call = InFile::new(self.ast_id.file_id, self.ast_id.to_node(db));
-            let hygiene = Hygiene::new(db, self.ast_id.file_id);
-
-            Some(
-                expand_eager_macro(db, macro_call, def, &|path: ast::Path| {
-                    resolver(path::ModPath::from_src(path, &hygiene)?)
-                })?
-                .into(),
-            )
-        } else {
-            Some(def.as_lazy_macro(db, MacroCallKind::FnLike(self.ast_id)).into())
-        }
+        let def = resolver(self.path.clone())?;
+        Some(def.as_call_id(db, MacroCallKind::FnLike(self.ast_id)))
     }
 }
 
@@ -484,6 +471,6 @@ impl AsMacroCall for AstIdWithPath<ast::ModuleItem> {
         resolver: impl Fn(path::ModPath) -> Option<MacroDefId>,
     ) -> Option<MacroCallId> {
         let def = resolver(self.path.clone())?;
-        Some(def.as_lazy_macro(db, MacroCallKind::Attr(self.ast_id)).into())
+        Some(def.as_call_id(db, MacroCallKind::Attr(self.ast_id)))
     }
 }
diff --git a/crates/ra_hir_expand/src/builtin_derive.rs b/crates/ra_hir_expand/src/builtin_derive.rs
index 87224481ce..d0e3eaf7e9 100644
--- a/crates/ra_hir_expand/src/builtin_derive.rs
+++ b/crates/ra_hir_expand/src/builtin_derive.rs
@@ -9,7 +9,7 @@ use ra_syntax::{
 };
 
 use crate::db::AstDatabase;
-use crate::{name, quote, LazyMacroId, MacroDefId, MacroDefKind};
+use crate::{name, quote, MacroCallId, MacroDefId, MacroDefKind};
 
 macro_rules! register_builtin {
     ( $($trait:ident => $expand:ident),* ) => {
@@ -22,7 +22,7 @@ macro_rules! register_builtin {
             pub fn expand(
                 &self,
                 db: &dyn AstDatabase,
-                id: LazyMacroId,
+                id: MacroCallId,
                 tt: &tt::Subtree,
             ) -> Result<tt::Subtree, mbe::ExpandError> {
                 let expander = match *self {
@@ -155,7 +155,7 @@ fn expand_simple_derive(
 
 fn copy_expand(
     _db: &dyn AstDatabase,
-    _id: LazyMacroId,
+    _id: MacroCallId,
     tt: &tt::Subtree,
 ) -> Result<tt::Subtree, mbe::ExpandError> {
     expand_simple_derive(tt, quote! { std::marker::Copy })
@@ -163,7 +163,7 @@ fn copy_expand(
 
 fn clone_expand(
     _db: &dyn AstDatabase,
-    _id: LazyMacroId,
+    _id: MacroCallId,
     tt: &tt::Subtree,
 ) -> Result<tt::Subtree, mbe::ExpandError> {
     expand_simple_derive(tt, quote! { std::clone::Clone })
@@ -171,7 +171,7 @@ fn clone_expand(
 
 fn default_expand(
     _db: &dyn AstDatabase,
-    _id: LazyMacroId,
+    _id: MacroCallId,
     tt: &tt::Subtree,
 ) -> Result<tt::Subtree, mbe::ExpandError> {
     expand_simple_derive(tt, quote! { std::default::Default })
@@ -179,7 +179,7 @@ fn default_expand(
 
 fn debug_expand(
     _db: &dyn AstDatabase,
-    _id: LazyMacroId,
+    _id: MacroCallId,
     tt: &tt::Subtree,
 ) -> Result<tt::Subtree, mbe::ExpandError> {
     expand_simple_derive(tt, quote! { std::fmt::Debug })
@@ -187,7 +187,7 @@ fn debug_expand(
 
 fn hash_expand(
     _db: &dyn AstDatabase,
-    _id: LazyMacroId,
+    _id: MacroCallId,
     tt: &tt::Subtree,
 ) -> Result<tt::Subtree, mbe::ExpandError> {
     expand_simple_derive(tt, quote! { std::hash::Hash })
@@ -195,7 +195,7 @@ fn hash_expand(
 
 fn eq_expand(
     _db: &dyn AstDatabase,
-    _id: LazyMacroId,
+    _id: MacroCallId,
     tt: &tt::Subtree,
 ) -> Result<tt::Subtree, mbe::ExpandError> {
     expand_simple_derive(tt, quote! { std::cmp::Eq })
@@ -203,7 +203,7 @@ fn eq_expand(
 
 fn partial_eq_expand(
     _db: &dyn AstDatabase,
-    _id: LazyMacroId,
+    _id: MacroCallId,
     tt: &tt::Subtree,
 ) -> Result<tt::Subtree, mbe::ExpandError> {
     expand_simple_derive(tt, quote! { std::cmp::PartialEq })
@@ -211,7 +211,7 @@ fn partial_eq_expand(
 
 fn ord_expand(
     _db: &dyn AstDatabase,
-    _id: LazyMacroId,
+    _id: MacroCallId,
     tt: &tt::Subtree,
 ) -> Result<tt::Subtree, mbe::ExpandError> {
     expand_simple_derive(tt, quote! { std::cmp::Ord })
@@ -219,7 +219,7 @@ fn ord_expand(
 
 fn partial_ord_expand(
     _db: &dyn AstDatabase,
-    _id: LazyMacroId,
+    _id: MacroCallId,
     tt: &tt::Subtree,
 ) -> Result<tt::Subtree, mbe::ExpandError> {
     expand_simple_derive(tt, quote! { std::cmp::PartialOrd })
@@ -228,7 +228,7 @@ fn partial_ord_expand(
 #[cfg(test)]
 mod tests {
     use super::*;
-    use crate::{test_db::TestDB, AstId, MacroCallId, MacroCallKind, MacroCallLoc};
+    use crate::{test_db::TestDB, AstId, MacroCallKind, MacroCallLoc};
     use ra_db::{fixture::WithFixture, SourceDatabase};
 
     fn expand_builtin_derive(s: &str, expander: BuiltinDeriveExpander) -> String {
@@ -248,7 +248,7 @@ mod tests {
             kind: MacroCallKind::Attr(AstId::new(file_id.into(), ast_id_map.ast_id(&items[0]))),
         };
 
-        let id: MacroCallId = db.intern_macro(loc).into();
+        let id = db.intern_macro(loc);
         let parsed = db.parse_or_expand(id.as_file()).unwrap();
 
         // FIXME text() for syntax nodes parsed from token tree looks weird
diff --git a/crates/ra_hir_expand/src/builtin_macro.rs b/crates/ra_hir_expand/src/builtin_macro.rs
index 1f380b5716..f2bb0bddbb 100644
--- a/crates/ra_hir_expand/src/builtin_macro.rs
+++ b/crates/ra_hir_expand/src/builtin_macro.rs
@@ -1,31 +1,24 @@
 //! Builtin macro
 use crate::db::AstDatabase;
 use crate::{
-    ast::{self, AstToken, HasStringValue},
-    name, AstId, CrateId, MacroDefId, MacroDefKind, TextUnit,
+    ast::{self},
+    name, AstId, CrateId, MacroCallId, MacroDefId, MacroDefKind, TextUnit,
 };
 
-use crate::{quote, LazyMacroId};
-use either::Either;
-use ra_parser::FragmentKind;
+use crate::quote;
 
 macro_rules! register_builtin {
-    ( LAZY: $(($name:ident, $kind: ident) => $expand:ident),* , EAGER: $(($e_name:ident, $e_kind: ident) => $e_expand:ident),*  ) => {
+    ( $(($name:ident, $kind: ident) => $expand:ident),* ) => {
         #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
         pub enum BuiltinFnLikeExpander {
             $($kind),*
         }
 
-        #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
-        pub enum EagerExpander {
-            $($e_kind),*
-        }
-
         impl BuiltinFnLikeExpander {
             pub fn expand(
                 &self,
                 db: &dyn AstDatabase,
-                id: LazyMacroId,
+                id: MacroCallId,
                 tt: &tt::Subtree,
             ) -> Result<tt::Subtree, mbe::ExpandError> {
                 let expander = match *self {
@@ -33,54 +26,28 @@ macro_rules! register_builtin {
                 };
                 expander(db, id, tt)
             }
-        }
 
-        impl EagerExpander {
-            pub fn expand(
-                &self,
-                tt: &tt::Subtree,
-            ) -> Result<(tt::Subtree, FragmentKind), mbe::ExpandError> {
-                let expander = match *self {
-                    $( EagerExpander::$e_kind => $e_expand, )*
-                };
-                expander(tt)
+            fn by_name(ident: &name::Name) -> Option<BuiltinFnLikeExpander> {
+                match ident {
+                    $( id if id == &name::name![$name] => Some(BuiltinFnLikeExpander::$kind), )*
+                    _ => return None,
+                }
             }
         }
 
-        fn find_by_name(ident: &name::Name) -> Option<Either<BuiltinFnLikeExpander, EagerExpander>> {
-            match ident {
-                $( id if id == &name::name![$name] => Some(Either::Left(BuiltinFnLikeExpander::$kind)), )*
-                $( id if id == &name::name![$e_name] => Some(Either::Right(EagerExpander::$e_kind)), )*
-                _ => return None,
-            }
+        pub fn find_builtin_macro(
+            ident: &name::Name,
+            krate: CrateId,
+            ast_id: AstId<ast::MacroCall>,
+        ) -> Option<MacroDefId> {
+            let kind = BuiltinFnLikeExpander::by_name(ident)?;
+
+            Some(MacroDefId { krate: Some(krate), ast_id: Some(ast_id), kind: MacroDefKind::BuiltIn(kind) })
         }
     };
 }
 
-pub fn find_builtin_macro(
-    ident: &name::Name,
-    krate: CrateId,
-    ast_id: AstId<ast::MacroCall>,
-) -> Option<MacroDefId> {
-    let kind = find_by_name(ident)?;
-
-    match kind {
-        Either::Left(kind) => Some(MacroDefId {
-            krate: Some(krate),
-            ast_id: Some(ast_id),
-            kind: MacroDefKind::BuiltIn(kind),
-        }),
-        Either::Right(kind) => Some(MacroDefId {
-            krate: Some(krate),
-            ast_id: Some(ast_id),
-            kind: MacroDefKind::BuiltInEager(kind),
-        }),
-    }
-}
-
 register_builtin! {
-    LAZY:
-
     (column, Column) => column_expand,
     (compile_error, CompileError) => compile_error_expand,
     (file, File) => file_expand,
@@ -91,16 +58,12 @@ register_builtin! {
     (option_env, OptionEnv) => option_env_expand,
     // format_args_nl only differs in that it adds a newline in the end,
     // so we use the same stub expansion for now
-    (format_args_nl, FormatArgsNl) => format_args_expand,
-
-    EAGER:
-    // eagers
-    (concat, Concat) => concat_expand
+    (format_args_nl, FormatArgsNl) => format_args_expand
 }
 
 fn line_expand(
     _db: &dyn AstDatabase,
-    _id: LazyMacroId,
+    _id: MacroCallId,
     _tt: &tt::Subtree,
 ) -> Result<tt::Subtree, mbe::ExpandError> {
     // dummy implementation for type-checking purposes
@@ -114,7 +77,7 @@ fn line_expand(
 
 fn stringify_expand(
     db: &dyn AstDatabase,
-    id: LazyMacroId,
+    id: MacroCallId,
     _tt: &tt::Subtree,
 ) -> Result<tt::Subtree, mbe::ExpandError> {
     let loc = db.lookup_intern_macro(id);
@@ -136,7 +99,7 @@ fn stringify_expand(
 
 fn env_expand(
     _db: &dyn AstDatabase,
-    _id: LazyMacroId,
+    _id: MacroCallId,
     _tt: &tt::Subtree,
 ) -> Result<tt::Subtree, mbe::ExpandError> {
     // dummy implementation for type-checking purposes
@@ -147,7 +110,7 @@ fn env_expand(
 
 fn option_env_expand(
     _db: &dyn AstDatabase,
-    _id: LazyMacroId,
+    _id: MacroCallId,
     _tt: &tt::Subtree,
 ) -> Result<tt::Subtree, mbe::ExpandError> {
     // dummy implementation for type-checking purposes
@@ -158,7 +121,7 @@ fn option_env_expand(
 
 fn column_expand(
     _db: &dyn AstDatabase,
-    _id: LazyMacroId,
+    _id: MacroCallId,
     _tt: &tt::Subtree,
 ) -> Result<tt::Subtree, mbe::ExpandError> {
     // dummy implementation for type-checking purposes
@@ -172,7 +135,7 @@ fn column_expand(
 
 fn file_expand(
     _db: &dyn AstDatabase,
-    _id: LazyMacroId,
+    _id: MacroCallId,
     _tt: &tt::Subtree,
 ) -> Result<tt::Subtree, mbe::ExpandError> {
     // FIXME: RA purposefully lacks knowledge of absolute file names
@@ -188,7 +151,7 @@ fn file_expand(
 
 fn compile_error_expand(
     _db: &dyn AstDatabase,
-    _id: LazyMacroId,
+    _id: MacroCallId,
     tt: &tt::Subtree,
 ) -> Result<tt::Subtree, mbe::ExpandError> {
     if tt.count() == 1 {
@@ -205,7 +168,7 @@ fn compile_error_expand(
 
 fn format_args_expand(
     _db: &dyn AstDatabase,
-    _id: LazyMacroId,
+    _id: MacroCallId,
     tt: &tt::Subtree,
 ) -> Result<tt::Subtree, mbe::ExpandError> {
     // We expand `format_args!("", a1, a2)` to
@@ -245,44 +208,23 @@ fn format_args_expand(
     Ok(expanded)
 }
 
-fn unquote_str(lit: &tt::Literal) -> Option<String> {
-    let lit = ast::make::tokens::literal(&lit.to_string());
-    let token = ast::String::cast(lit)?;
-    token.value()
-}
-
-fn concat_expand(tt: &tt::Subtree) -> Result<(tt::Subtree, FragmentKind), mbe::ExpandError> {
-    let mut text = String::new();
-    for (i, t) in tt.token_trees.iter().enumerate() {
-        match t {
-            tt::TokenTree::Leaf(tt::Leaf::Literal(it)) if i % 2 == 0 => {
-                text += &unquote_str(&it).ok_or_else(|| mbe::ExpandError::ConversionError)?;
-            }
-            tt::TokenTree::Leaf(tt::Leaf::Punct(punct)) if i % 2 == 1 && punct.char == ',' => (),
-            _ => return Err(mbe::ExpandError::UnexpectedToken),
-        }
-    }
-
-    Ok((quote!(#text), FragmentKind::Expr))
-}
-
 #[cfg(test)]
 mod tests {
     use super::*;
-    use crate::{name::AsName, test_db::TestDB, AstNode, MacroCallId, MacroCallKind, MacroCallLoc};
+    use crate::{name::AsName, test_db::TestDB, AstNode, MacroCallKind, MacroCallLoc};
     use ra_db::{fixture::WithFixture, SourceDatabase};
     use ra_syntax::ast::NameOwner;
 
-    fn expand_builtin_macro(ra_fixture: &str) -> String {
-        let (db, file_id) = TestDB::with_single_file(&ra_fixture);
+    fn expand_builtin_macro(s: &str) -> String {
+        let (db, file_id) = TestDB::with_single_file(&s);
         let parsed = db.parse(file_id);
         let macro_calls: Vec<_> =
             parsed.syntax_node().descendants().filter_map(ast::MacroCall::cast).collect();
 
         let ast_id_map = db.ast_id_map(file_id.into());
 
-        let expander = find_by_name(&macro_calls[0].name().unwrap().as_name()).unwrap();
-        let expander = expander.left().unwrap();
+        let expander =
+            BuiltinFnLikeExpander::by_name(&macro_calls[0].name().unwrap().as_name()).unwrap();
 
         // the first one should be a macro_rules
         let def = MacroDefId {
@@ -299,7 +241,7 @@ mod tests {
             )),
         };
 
-        let id: MacroCallId = db.intern_macro(loc).into();
+        let id = db.intern_macro(loc);
         let parsed = db.parse_or_expand(id.as_file()).unwrap();
 
         parsed.text().to_string()
diff --git a/crates/ra_hir_expand/src/db.rs b/crates/ra_hir_expand/src/db.rs
index 32e0d5ced3..70d9692383 100644
--- a/crates/ra_hir_expand/src/db.rs
+++ b/crates/ra_hir_expand/src/db.rs
@@ -9,9 +9,8 @@ use ra_prof::profile;
 use ra_syntax::{AstNode, Parse, SyntaxKind::*, SyntaxNode};
 
 use crate::{
-    ast_id_map::AstIdMap, BuiltinDeriveExpander, BuiltinFnLikeExpander, EagerCallLoc, EagerMacroId,
-    HirFileId, HirFileIdRepr, LazyMacroId, MacroCallId, MacroCallLoc, MacroDefId, MacroDefKind,
-    MacroFile,
+    ast_id_map::AstIdMap, BuiltinDeriveExpander, BuiltinFnLikeExpander, HirFileId, HirFileIdRepr,
+    MacroCallId, MacroCallLoc, MacroDefId, MacroDefKind, MacroFile,
 };
 
 #[derive(Debug, Clone, Eq, PartialEq)]
@@ -25,7 +24,7 @@ impl TokenExpander {
     pub fn expand(
         &self,
         db: &dyn AstDatabase,
-        id: LazyMacroId,
+        id: MacroCallId,
         tt: &tt::Subtree,
     ) -> Result<tt::Subtree, mbe::ExpandError> {
         match self {
@@ -61,15 +60,12 @@ pub trait AstDatabase: SourceDatabase {
     fn parse_or_expand(&self, file_id: HirFileId) -> Option<SyntaxNode>;
 
     #[salsa::interned]
-    fn intern_macro(&self, macro_call: MacroCallLoc) -> LazyMacroId;
+    fn intern_macro(&self, macro_call: MacroCallLoc) -> MacroCallId;
     fn macro_arg(&self, id: MacroCallId) -> Option<Arc<(tt::Subtree, mbe::TokenMap)>>;
     fn macro_def(&self, id: MacroDefId) -> Option<Arc<(TokenExpander, mbe::TokenMap)>>;
     fn parse_macro(&self, macro_file: MacroFile)
         -> Option<(Parse<SyntaxNode>, Arc<mbe::TokenMap>)>;
     fn macro_expand(&self, macro_call: MacroCallId) -> Result<Arc<tt::Subtree>, String>;
-
-    #[salsa::interned]
-    fn intern_eager_expansion(&self, eager: EagerCallLoc) -> EagerMacroId;
 }
 
 pub(crate) fn ast_id_map(db: &dyn AstDatabase, file_id: HirFileId) -> Arc<AstIdMap> {
@@ -105,7 +101,6 @@ pub(crate) fn macro_def(
         MacroDefKind::BuiltInDerive(expander) => {
             Some(Arc::new((TokenExpander::BuiltinDerive(expander), mbe::TokenMap::default())))
         }
-        MacroDefKind::BuiltInEager(_expander) => None,
     }
 }
 
@@ -113,13 +108,6 @@ pub(crate) fn macro_arg(
     db: &dyn AstDatabase,
     id: MacroCallId,
 ) -> Option<Arc<(tt::Subtree, mbe::TokenMap)>> {
-    let id = match id {
-        MacroCallId::LazyMacro(id) => id,
-        MacroCallId::EagerMacro(_id) => {
-            // FIXME: support macro_arg for eager macro
-            return None;
-        }
-    };
     let loc = db.lookup_intern_macro(id);
     let arg = loc.kind.arg(db)?;
     let (tt, tmap) = mbe::syntax_node_to_token_tree(&arg)?;
@@ -130,18 +118,11 @@ pub(crate) fn macro_expand(
     db: &dyn AstDatabase,
     id: MacroCallId,
 ) -> Result<Arc<tt::Subtree>, String> {
-    let lazy_id = match id {
-        MacroCallId::LazyMacro(id) => id,
-        MacroCallId::EagerMacro(id) => {
-            return Ok(db.lookup_intern_eager_expansion(id).subtree);
-        }
-    };
-
-    let loc = db.lookup_intern_macro(lazy_id);
+    let loc = db.lookup_intern_macro(id);
     let macro_arg = db.macro_arg(id).ok_or("Fail to args in to tt::TokenTree")?;
 
     let macro_rules = db.macro_def(loc.def).ok_or("Fail to find macro definition")?;
-    let tt = macro_rules.0.expand(db, lazy_id, &macro_arg.0).map_err(|err| format!("{:?}", err))?;
+    let tt = macro_rules.0.expand(db, id, &macro_arg.0).map_err(|err| format!("{:?}", err))?;
     // Set a hard limit for the expanded tt
     let count = tt.count();
     if count > 65536 {
@@ -172,20 +153,9 @@ pub(crate) fn parse_macro(
             // Note:
             // The final goal we would like to make all parse_macro success,
             // such that the following log will not call anyway.
-            match macro_call_id {
-                MacroCallId::LazyMacro(id) => {
-                    let loc: MacroCallLoc = db.lookup_intern_macro(id);
-                    let node = loc.kind.node(db);
-                    log::warn!(
-                        "fail on macro_parse: (reason: {} macro_call: {:#})",
-                        err,
-                        node.value
-                    );
-                }
-                _ => {
-                    log::warn!("fail on macro_parse: (reason: {})", err);
-                }
-            }
+            let loc: MacroCallLoc = db.lookup_intern_macro(macro_call_id);
+            let node = loc.kind.node(db);
+            log::warn!("fail on macro_parse: (reason: {} macro_call: {:#})", err, node.value);
         })
         .ok()?;
 
@@ -197,14 +167,8 @@ pub(crate) fn parse_macro(
 
 /// Given a `MacroCallId`, return what `FragmentKind` it belongs to.
 /// FIXME: Not completed
-fn to_fragment_kind(db: &dyn AstDatabase, id: MacroCallId) -> FragmentKind {
-    let lazy_id = match id {
-        MacroCallId::LazyMacro(id) => id,
-        MacroCallId::EagerMacro(id) => {
-            return db.lookup_intern_eager_expansion(id).fragment;
-        }
-    };
-    let syn = db.lookup_intern_macro(lazy_id).kind.node(db).value;
+fn to_fragment_kind(db: &dyn AstDatabase, macro_call_id: MacroCallId) -> FragmentKind {
+    let syn = db.lookup_intern_macro(macro_call_id).kind.node(db).value;
 
     let parent = match syn.parent() {
         Some(it) => it,
diff --git a/crates/ra_hir_expand/src/eager.rs b/crates/ra_hir_expand/src/eager.rs
deleted file mode 100644
index 7fcdfab5ae..0000000000
--- a/crates/ra_hir_expand/src/eager.rs
+++ /dev/null
@@ -1,112 +0,0 @@
-//! Eager expansion related utils
-//!
-//! Here is a dump of a discussion from Vadim Petrochenkov about Eager Expansion and
-//! Its name resolution :
-//!
-//! > Eagerly expanded macros (and also macros eagerly expanded by eagerly expanded macros,
-//! > which actually happens in practice too!) are resolved at the location of the "root" macro
-//! > that performs the eager expansion on its arguments.
-//! > If some name cannot be resolved at the eager expansion time it's considered unresolved,
-//! > even if becomes available later (e.g. from a glob import or other macro).
-//!
-//! > Eagerly expanded macros don't add anything to the module structure of the crate and
-//! > don't build any speculative module structures, i.e. they are expanded in a "flat"
-//! > way even if tokens in them look like modules.
-//!
-//! > In other words, it kinda works for simple cases for which it was originally intended,
-//! > and we need to live with it because it's available on stable and widely relied upon.
-//!
-//!
-//! See the full discussion : https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Eager.20expansion.20of.20built-in.20macros
-
-use crate::{
-    ast::{self, AstNode},
-    db::AstDatabase,
-    EagerCallLoc, EagerMacroId, InFile, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind,
-};
-
-use ra_parser::FragmentKind;
-use ra_syntax::{algo::replace_descendants, SyntaxElement, SyntaxNode};
-use std::{collections::HashMap, sync::Arc};
-
-pub fn expand_eager_macro(
-    db: &impl AstDatabase,
-    macro_call: InFile<ast::MacroCall>,
-    def: MacroDefId,
-    resolver: &dyn Fn(ast::Path) -> Option<MacroDefId>,
-) -> Option<EagerMacroId> {
-    let args = macro_call.value.token_tree()?;
-    let parsed_args = mbe::ast_to_token_tree(&args)?.0;
-    let parsed_args = mbe::token_tree_to_syntax_node(&parsed_args, FragmentKind::Expr).ok()?.0;
-    let result = eager_macro_recur(db, macro_call.with_value(parsed_args.syntax_node()), resolver)?;
-
-    let subtree = to_subtree(&result)?;
-
-    if let MacroDefKind::BuiltInEager(eager) = def.kind {
-        let (subtree, fragment) = eager.expand(&subtree).ok()?;
-        let eager =
-            EagerCallLoc { def, fragment, subtree: Arc::new(subtree), file_id: macro_call.file_id };
-
-        Some(db.intern_eager_expansion(eager))
-    } else {
-        None
-    }
-}
-
-fn to_subtree(node: &SyntaxNode) -> Option<tt::Subtree> {
-    let mut subtree = mbe::syntax_node_to_token_tree(node)?.0;
-    subtree.delimiter = None;
-    Some(subtree)
-}
-
-fn lazy_expand(
-    db: &impl AstDatabase,
-    def: &MacroDefId,
-    macro_call: InFile<ast::MacroCall>,
-) -> Option<InFile<SyntaxNode>> {
-    let ast_id = db.ast_id_map(macro_call.file_id).ast_id(&macro_call.value);
-
-    let id: MacroCallId =
-        def.as_lazy_macro(db, MacroCallKind::FnLike(macro_call.with_value(ast_id))).into();
-
-    db.parse_or_expand(id.as_file()).map(|node| InFile::new(id.as_file(), node))
-}
-
-fn eager_macro_recur(
-    db: &impl AstDatabase,
-    curr: InFile<SyntaxNode>,
-    macro_resolver: &dyn Fn(ast::Path) -> Option<MacroDefId>,
-) -> Option<SyntaxNode> {
-    let mut original = curr.value.clone();
-
-    let children = curr.value.descendants().filter_map(ast::MacroCall::cast);
-    let mut replaces: HashMap<SyntaxElement, SyntaxElement> = HashMap::default();
-
-    // Collect replacement
-    for child in children {
-        let def: MacroDefId = macro_resolver(child.path()?)?;
-        let insert = match def.kind {
-            MacroDefKind::BuiltInEager(_) => {
-                let id: MacroCallId =
-                    expand_eager_macro(db, curr.with_value(child.clone()), def, macro_resolver)?
-                        .into();
-                db.parse_or_expand(id.as_file())?
-            }
-            MacroDefKind::Declarative
-            | MacroDefKind::BuiltIn(_)
-            | MacroDefKind::BuiltInDerive(_) => {
-                let expanded = lazy_expand(db, &def, curr.with_value(child.clone()))?;
-                // replace macro inside
-                eager_macro_recur(db, expanded, macro_resolver)?
-            }
-        };
-
-        replaces.insert(child.syntax().clone().into(), insert.into());
-    }
-
-    if !replaces.is_empty() {
-        original = replace_descendants(&original, |n| replaces.get(n).cloned());
-    }
-
-    Some(original)
-}
diff --git a/crates/ra_hir_expand/src/hygiene.rs b/crates/ra_hir_expand/src/hygiene.rs
index cb554ae4be..2e8a533f70 100644
--- a/crates/ra_hir_expand/src/hygiene.rs
+++ b/crates/ra_hir_expand/src/hygiene.rs
@@ -9,7 +9,7 @@ use ra_syntax::ast;
 use crate::{
     db::AstDatabase,
     name::{AsName, Name},
-    HirFileId, HirFileIdRepr, MacroCallId, MacroDefKind,
+    HirFileId, HirFileIdRepr, MacroDefKind,
 };
 
 #[derive(Debug)]
@@ -22,18 +22,14 @@ impl Hygiene {
     pub fn new(db: &impl AstDatabase, file_id: HirFileId) -> Hygiene {
         let def_crate = match file_id.0 {
             HirFileIdRepr::FileId(_) => None,
-            HirFileIdRepr::MacroFile(macro_file) => match macro_file.macro_call_id {
-                MacroCallId::LazyMacro(id) => {
-                    let loc = db.lookup_intern_macro(id);
-                    match loc.def.kind {
-                        MacroDefKind::Declarative => loc.def.krate,
-                        MacroDefKind::BuiltIn(_) => None,
-                        MacroDefKind::BuiltInDerive(_) => None,
-                        MacroDefKind::BuiltInEager(_) => None,
-                    }
+            HirFileIdRepr::MacroFile(macro_file) => {
+                let loc = db.lookup_intern_macro(macro_file.macro_call_id);
+                match loc.def.kind {
+                    MacroDefKind::Declarative => loc.def.krate,
+                    MacroDefKind::BuiltIn(_) => None,
+                    MacroDefKind::BuiltInDerive(_) => None,
                 }
-                MacroCallId::EagerMacro(_id) => None,
-            },
+            }
         };
         Hygiene { def_crate }
     }
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs
index 3fce73e8ad..9506f2e1cd 100644
--- a/crates/ra_hir_expand/src/lib.rs
+++ b/crates/ra_hir_expand/src/lib.rs
@@ -12,7 +12,6 @@ pub mod diagnostics;
 pub mod builtin_derive;
 pub mod builtin_macro;
 pub mod quote;
-pub mod eager;
 
 use std::hash::Hash;
 use std::sync::Arc;
@@ -26,7 +25,7 @@ use ra_syntax::{
 
 use crate::ast_id_map::FileAstId;
 use crate::builtin_derive::BuiltinDeriveExpander;
-use crate::builtin_macro::{BuiltinFnLikeExpander, EagerExpander};
+use crate::builtin_macro::BuiltinFnLikeExpander;
 
 #[cfg(test)]
 mod test_db;
@@ -71,17 +70,8 @@ impl HirFileId {
         match self.0 {
             HirFileIdRepr::FileId(file_id) => file_id,
             HirFileIdRepr::MacroFile(macro_file) => {
-                let file_id = match macro_file.macro_call_id {
-                    MacroCallId::LazyMacro(id) => {
-                        let loc = db.lookup_intern_macro(id);
-                        loc.kind.file_id()
-                    }
-                    MacroCallId::EagerMacro(id) => {
-                        let loc = db.lookup_intern_eager_expansion(id);
-                        loc.file_id
-                    }
-                };
-                file_id.original_file(db)
+                let loc = db.lookup_intern_macro(macro_file.macro_call_id);
+                loc.kind.file_id().original_file(db)
             }
         }
     }
@@ -91,14 +81,7 @@ impl HirFileId {
         match self.0 {
             HirFileIdRepr::FileId(_) => None,
             HirFileIdRepr::MacroFile(macro_file) => {
-                let lazy_id = match macro_file.macro_call_id {
-                    MacroCallId::LazyMacro(id) => id,
-                    MacroCallId::EagerMacro(_id) => {
-                        // FIXME: handle call node for eager macro
-                        return None;
-                    }
-                };
-                let loc = db.lookup_intern_macro(lazy_id);
+                let loc = db.lookup_intern_macro(macro_file.macro_call_id);
                 Some(loc.kind.node(db))
             }
         }
@@ -109,14 +92,7 @@ impl HirFileId {
         match self.0 {
             HirFileIdRepr::FileId(_) => None,
             HirFileIdRepr::MacroFile(macro_file) => {
-                let lazy_id = match macro_file.macro_call_id {
-                    MacroCallId::LazyMacro(id) => id,
-                    MacroCallId::EagerMacro(_id) => {
-                        // FIXME: handle expansion_info for eager macro
-                        return None;
-                    }
-                };
-                let loc: MacroCallLoc = db.lookup_intern_macro(lazy_id);
+                let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
 
                 let arg_tt = loc.kind.arg(db)?;
                 let def_tt = loc.def.ast_id?.to_node(db).token_tree()?;
@@ -142,13 +118,7 @@ impl HirFileId {
         match self.0 {
             HirFileIdRepr::FileId(_) => None,
             HirFileIdRepr::MacroFile(macro_file) => {
-                let lazy_id = match macro_file.macro_call_id {
-                    MacroCallId::LazyMacro(id) => id,
-                    MacroCallId::EagerMacro(_id) => {
-                        return None;
-                    }
-                };
-                let loc: MacroCallLoc = db.lookup_intern_macro(lazy_id);
+                let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
                 let item = match loc.def.kind {
                     MacroDefKind::BuiltInDerive(_) => loc.kind.node(db),
                     _ => return None,
@@ -167,44 +137,16 @@ pub struct MacroFile {
 /// `MacroCallId` identifies a particular macro invocation, like
 /// `println!("Hello, {}", world)`.
 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
-pub enum MacroCallId {
-    LazyMacro(LazyMacroId),
-    EagerMacro(EagerMacroId),
-}
-
-#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
-pub struct LazyMacroId(salsa::InternId);
-impl salsa::InternKey for LazyMacroId {
-    fn from_intern_id(v: salsa::InternId) -> Self {
-        LazyMacroId(v)
-    }
-    fn as_intern_id(&self) -> salsa::InternId {
-        self.0
-    }
-}
-
-#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
-pub struct EagerMacroId(salsa::InternId);
-impl salsa::InternKey for EagerMacroId {
+pub struct MacroCallId(salsa::InternId);
+impl salsa::InternKey for MacroCallId {
     fn from_intern_id(v: salsa::InternId) -> Self {
-        EagerMacroId(v)
+        MacroCallId(v)
     }
     fn as_intern_id(&self) -> salsa::InternId {
         self.0
     }
 }
 
-impl From<LazyMacroId> for MacroCallId {
-    fn from(it: LazyMacroId) -> Self {
-        MacroCallId::LazyMacro(it)
-    }
-}
-impl From<EagerMacroId> for MacroCallId {
-    fn from(it: EagerMacroId) -> Self {
-        MacroCallId::EagerMacro(it)
-    }
-}
-
 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
 pub struct MacroDefId {
     // FIXME: krate and ast_id are currently optional because we don't have a
@@ -219,7 +161,7 @@ pub struct MacroDefId {
 }
 
 impl MacroDefId {
-    pub fn as_lazy_macro(self, db: &dyn db::AstDatabase, kind: MacroCallKind) -> LazyMacroId {
+    pub fn as_call_id(self, db: &dyn db::AstDatabase, kind: MacroCallKind) -> MacroCallId {
         db.intern_macro(MacroCallLoc { def: self, kind })
     }
 }
@@ -230,7 +172,6 @@ pub enum MacroDefKind {
     BuiltIn(BuiltinFnLikeExpander),
     // FIXME: maybe just Builtin and rename BuiltinFnLikeExpander to BuiltinExpander
     BuiltInDerive(BuiltinDeriveExpander),
-    BuiltInEager(EagerExpander),
 }
 
 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -276,14 +217,6 @@ impl MacroCallId {
     }
 }
 
-#[derive(Debug, Clone, PartialEq, Eq, Hash)]
-pub struct EagerCallLoc {
-    pub(crate) def: MacroDefId,
-    pub(crate) fragment: FragmentKind,
-    pub(crate) subtree: Arc<tt::Subtree>,
-    pub(crate) file_id: HirFileId,
-}
-
 /// ExpansionInfo mainly describes how to map text range between src and expanded macro
 #[derive(Debug, Clone, PartialEq, Eq)]
 pub struct ExpansionInfo {
@@ -297,7 +230,6 @@ pub struct ExpansionInfo {
 }
 
 pub use mbe::Origin;
-use ra_parser::FragmentKind;
 
 impl ExpansionInfo {
     pub fn call_node(&self) -> Option<InFile<SyntaxNode>> {
diff --git a/crates/ra_hir_expand/src/name.rs b/crates/ra_hir_expand/src/name.rs
index 036cf7d1e0..b2e10f445f 100644
--- a/crates/ra_hir_expand/src/name.rs
+++ b/crates/ra_hir_expand/src/name.rs
@@ -173,7 +173,6 @@ pub mod known {
         compile_error,
         line,
         stringify,
-        concat,
         format_args,
         format_args_nl,
         env,
diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs
index c9c14561a8..d57451cc8c 100644
--- a/crates/ra_ide/src/display/navigation_target.rs
+++ b/crates/ra_ide/src/display/navigation_target.rs
@@ -3,7 +3,7 @@
 use either::Either;
 use hir::{original_range, AssocItem, FieldSource, HasSource, InFile, ModuleSource};
 use ra_db::{FileId, SourceDatabase};
-use ra_ide_db::RootDatabase;
+use ra_ide_db::{defs::Definition, RootDatabase};
 use ra_syntax::{
     ast::{self, DocCommentsOwner, NameOwner},
     match_ast, AstNode, SmolStr,
@@ -11,11 +11,7 @@ use ra_syntax::{
     TextRange,
 };
 
-use crate::{
-    // expand::original_range,
-    references::Definition,
-    FileSymbol,
-};
+use crate::FileSymbol;
 
 use super::short_label::ShortLabel;
 
diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs
index 76ee232a3a..4a8107d60e 100644
--- a/crates/ra_ide/src/goto_definition.rs
+++ b/crates/ra_ide/src/goto_definition.rs
@@ -1,7 +1,10 @@
 //! FIXME: write short doc here
 
 use hir::Semantics;
-use ra_ide_db::{defs::classify_name, symbol_index, RootDatabase};
+use ra_ide_db::{
+    defs::{classify_name, classify_name_ref},
+    symbol_index, RootDatabase,
+};
 use ra_syntax::{
     ast::{self},
     match_ast, AstNode,
@@ -11,7 +14,6 @@ use ra_syntax::{
 
 use crate::{
     display::{ToNav, TryToNav},
-    references::classify_name_ref,
     FilePosition, NavigationTarget, RangeInfo,
 };
 
@@ -94,7 +96,7 @@ pub(crate) fn reference_definition(
 
 #[cfg(test)]
 mod tests {
-    use test_utils::{assert_eq_text, covers};
+    use test_utils::assert_eq_text;
 
     use crate::mock_analysis::analysis_and_position;
 
@@ -206,7 +208,6 @@ mod tests {
 
     #[test]
     fn goto_def_for_macros() {
-        covers!(goto_def_for_macros);
         check_goto(
             "
             //- /lib.rs
@@ -223,7 +224,6 @@ mod tests {
 
     #[test]
     fn goto_def_for_macros_from_other_crates() {
-        covers!(goto_def_for_macros);
         check_goto(
             "
             //- /lib.rs
@@ -335,7 +335,6 @@ mod tests {
 
     #[test]
     fn goto_def_for_methods() {
-        covers!(goto_def_for_methods);
         check_goto(
             "
             //- /lib.rs
@@ -355,7 +354,6 @@ mod tests {
 
     #[test]
     fn goto_def_for_fields() {
-        covers!(goto_def_for_fields);
         check_goto(
             "
             //- /lib.rs
@@ -374,7 +372,6 @@ mod tests {
 
     #[test]
     fn goto_def_for_record_fields() {
-        covers!(goto_def_for_record_fields);
         check_goto(
             "
             //- /lib.rs
@@ -787,7 +784,6 @@ mod tests {
 
     #[test]
     fn goto_def_for_field_init_shorthand() {
-        covers!(goto_def_for_field_init_shorthand);
         check_goto(
             "
             //- /lib.rs
diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs
index 26c8996bc1..e9c6825570 100644
--- a/crates/ra_ide/src/hover.rs
+++ b/crates/ra_ide/src/hover.rs
@@ -2,7 +2,7 @@
 
 use hir::{Adt, HasSource, HirDisplay, Semantics};
 use ra_ide_db::{
-    defs::{classify_name, Definition},
+    defs::{classify_name, classify_name_ref, Definition},
     RootDatabase,
 };
 use ra_syntax::{
@@ -14,7 +14,6 @@ use ra_syntax::{
 
 use crate::{
     display::{macro_label, rust_code_markup, rust_code_markup_with_doc, ShortLabel},
-    references::classify_name_ref,
     FilePosition, RangeInfo,
 };
 
diff --git a/crates/ra_ide/src/marks.rs b/crates/ra_ide/src/marks.rs
index 7b8b727b4a..1236cb773c 100644
--- a/crates/ra_ide/src/marks.rs
+++ b/crates/ra_ide/src/marks.rs
@@ -3,11 +3,6 @@
 test_utils::marks!(
     inserts_angle_brackets_for_generics
     inserts_parens_for_function_calls
-    goto_def_for_macros
-    goto_def_for_methods
-    goto_def_for_fields
-    goto_def_for_record_fields
-    goto_def_for_field_init_shorthand
     call_info_bad_offset
     dont_complete_current_use
     test_resolve_parent_module_on_module_decl
diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs
index 95a5c1914d..67be3f6c9b 100644
--- a/crates/ra_ide/src/references.rs
+++ b/crates/ra_ide/src/references.rs
@@ -9,14 +9,16 @@
 //! at the index that the match starts at and its tree parent is
 //! resolved to the search element definition, we get a reference.
 
-mod classify;
 mod rename;
 mod search_scope;
 
 use hir::Semantics;
 use once_cell::unsync::Lazy;
 use ra_db::SourceDatabaseExt;
-use ra_ide_db::RootDatabase;
+use ra_ide_db::{
+    defs::{classify_name, classify_name_ref, Definition},
+    RootDatabase,
+};
 use ra_prof::profile;
 use ra_syntax::{
     algo::find_node_at_offset,
@@ -27,11 +29,7 @@ use test_utils::tested_by;
 
 use crate::{display::TryToNav, FilePosition, FileRange, NavigationTarget, RangeInfo};
 
-pub(crate) use self::{
-    classify::{classify_name_ref, NameRefClass},
-    rename::rename,
-};
-pub(crate) use ra_ide_db::defs::{classify_name, Definition};
+pub(crate) use self::rename::rename;
 
 pub use self::search_scope::SearchScope;
 
diff --git a/crates/ra_ide/src/references/classify.rs b/crates/ra_ide/src/references/classify.rs
deleted file mode 100644
index 0bbf893f87..0000000000
--- a/crates/ra_ide/src/references/classify.rs
+++ /dev/null
@@ -1,84 +0,0 @@
-//! Functions that are used to classify an element from its definition or reference.
-
-use hir::{Local, PathResolution, Semantics};
-use ra_ide_db::defs::Definition;
-use ra_ide_db::RootDatabase;
-use ra_prof::profile;
-use ra_syntax::{ast, AstNode};
-use test_utils::tested_by;
-
-pub enum NameRefClass {
-    Definition(Definition),
-    FieldShorthand { local: Local, field: Definition },
-}
-
-impl NameRefClass {
-    pub fn definition(self) -> Definition {
-        match self {
-            NameRefClass::Definition(def) => def,
-            NameRefClass::FieldShorthand { local, field: _ } => Definition::Local(local),
-        }
-    }
-}
-
-pub(crate) fn classify_name_ref(
-    sema: &Semantics<RootDatabase>,
-    name_ref: &ast::NameRef,
-) -> Option<NameRefClass> {
-    let _p = profile("classify_name_ref");
-
-    let parent = name_ref.syntax().parent()?;
-
-    if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) {
-        tested_by!(goto_def_for_methods);
-        if let Some(func) = sema.resolve_method_call(&method_call) {
-            return Some(NameRefClass::Definition(Definition::ModuleDef(func.into())));
-        }
-    }
-
-    if let Some(field_expr) = ast::FieldExpr::cast(parent.clone()) {
-        tested_by!(goto_def_for_fields);
-        if let Some(field) = sema.resolve_field(&field_expr) {
-            return Some(NameRefClass::Definition(Definition::StructField(field)));
-        }
-    }
-
-    if let Some(record_field) = ast::RecordField::cast(parent.clone()) {
-        tested_by!(goto_def_for_record_fields);
-        tested_by!(goto_def_for_field_init_shorthand);
-        if let Some((field, local)) = sema.resolve_record_field(&record_field) {
-            let field = Definition::StructField(field);
-            let res = match local {
-                None => NameRefClass::Definition(field),
-                Some(local) => NameRefClass::FieldShorthand { field, local },
-            };
-            return Some(res);
-        }
-    }
-
-    if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) {
-        tested_by!(goto_def_for_macros);
-        if let Some(macro_def) = sema.resolve_macro_call(&macro_call) {
-            return Some(NameRefClass::Definition(Definition::Macro(macro_def)));
-        }
-    }
-
-    let path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?;
-    let resolved = sema.resolve_path(&path)?;
-    let res = match resolved {
-        PathResolution::Def(def) => Definition::ModuleDef(def),
-        PathResolution::AssocItem(item) => {
-            let def = match item {
-                hir::AssocItem::Function(it) => it.into(),
-                hir::AssocItem::Const(it) => it.into(),
-                hir::AssocItem::TypeAlias(it) => it.into(),
-            };
-            Definition::ModuleDef(def)
-        }
-        PathResolution::Local(local) => Definition::Local(local),
-        PathResolution::TypeParam(par) => Definition::TypeParam(par),
-        PathResolution::Macro(def) => Definition::Macro(def),
-        PathResolution::SelfType(impl_def) => Definition::SelfType(impl_def),
-    };
-    Some(NameRefClass::Definition(res))
-}
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs
index 9e0ee21589..7fc94d3cdb 100644
--- a/crates/ra_ide/src/syntax_highlighting.rs
+++ b/crates/ra_ide/src/syntax_highlighting.rs
@@ -7,7 +7,7 @@ mod tests;
 
 use hir::{Name, Semantics};
 use ra_ide_db::{
-    defs::{classify_name, Definition, NameClass},
+    defs::{classify_name, classify_name_ref, Definition, NameClass, NameRefClass},
     RootDatabase,
 };
 use ra_prof::profile;
@@ -19,11 +19,7 @@ use ra_syntax::{
 };
 use rustc_hash::FxHashMap;
 
-use crate::{
-    call_info::call_info_for_token,
-    references::{classify_name_ref, NameRefClass},
-    Analysis, FileId,
-};
+use crate::{call_info::call_info_for_token, Analysis, FileId};
 
 pub(crate) use html::highlight_as_html;
 pub use tags::{Highlight, HighlightModifier, HighlightModifiers, HighlightTag};
diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs
index 215daa4418..f057435bf6 100644
--- a/crates/ra_ide_db/src/defs.rs
+++ b/crates/ra_ide_db/src/defs.rs
@@ -6,8 +6,8 @@
 // FIXME: this badly needs rename/rewrite (matklad, 2020-02-06).
 
 use hir::{
-    Adt, FieldSource, HasSource, ImplDef, Local, MacroDef, Module, ModuleDef, Name, Semantics,
-    StructField, TypeParam,
+    Adt, FieldSource, HasSource, ImplDef, Local, MacroDef, Module, ModuleDef, Name, PathResolution,
+    Semantics, StructField, TypeParam,
 };
 use ra_prof::profile;
 use ra_syntax::{
@@ -117,6 +117,8 @@ impl NameClass {
 }
 
 pub fn classify_name(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Option<NameClass> {
+    let _p = profile("classify_name");
+
     if let Some(bind_pat) = name.syntax().parent().and_then(ast::BindPat::cast) {
         if let Some(def) = sema.resolve_bind_pat_to_const(&bind_pat) {
             return Some(NameClass::ConstReference(Definition::ModuleDef(def)));
@@ -127,7 +129,6 @@ pub fn classify_name(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Option
 }
 
 fn classify_name_inner(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Option<Definition> {
-    let _p = profile("classify_name");
     let parent = name.syntax().parent()?;
 
     match_ast! {
@@ -192,3 +193,74 @@ fn classify_name_inner(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Opti
         }
     }
 }
+
+pub enum NameRefClass {
+    Definition(Definition),
+    FieldShorthand { local: Local, field: Definition },
+}
+
+impl NameRefClass {
+    pub fn definition(self) -> Definition {
+        match self {
+            NameRefClass::Definition(def) => def,
+            NameRefClass::FieldShorthand { local, field: _ } => Definition::Local(local),
+        }
+    }
+}
+
+pub fn classify_name_ref(
+    sema: &Semantics<RootDatabase>,
+    name_ref: &ast::NameRef,
+) -> Option<NameRefClass> {
+    let _p = profile("classify_name_ref");
+
+    let parent = name_ref.syntax().parent()?;
+
+    if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) {
+        if let Some(func) = sema.resolve_method_call(&method_call) {
+            return Some(NameRefClass::Definition(Definition::ModuleDef(func.into())));
+        }
+    }
+
+    if let Some(field_expr) = ast::FieldExpr::cast(parent.clone()) {
+        if let Some(field) = sema.resolve_field(&field_expr) {
+            return Some(NameRefClass::Definition(Definition::StructField(field)));
+        }
+    }
+
+    if let Some(record_field) = ast::RecordField::cast(parent.clone()) {
+        if let Some((field, local)) = sema.resolve_record_field(&record_field) {
+            let field = Definition::StructField(field);
+            let res = match local {
+                None => NameRefClass::Definition(field),
+                Some(local) => NameRefClass::FieldShorthand { field, local },
+            };
+            return Some(res);
+        }
+    }
+
+    if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) {
+        if let Some(macro_def) = sema.resolve_macro_call(&macro_call) {
+            return Some(NameRefClass::Definition(Definition::Macro(macro_def)));
+        }
+    }
+
+    let path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?;
+    let resolved = sema.resolve_path(&path)?;
+    let res = match resolved {
+        PathResolution::Def(def) => Definition::ModuleDef(def),
+        PathResolution::AssocItem(item) => {
+            let def = match item {
+                hir::AssocItem::Function(it) => it.into(),
+                hir::AssocItem::Const(it) => it.into(),
+                hir::AssocItem::TypeAlias(it) => it.into(),
+            };
+            Definition::ModuleDef(def)
+        }
+        PathResolution::Local(local) => Definition::Local(local),
+        PathResolution::TypeParam(par) => Definition::TypeParam(par),
+        PathResolution::Macro(def) => Definition::Macro(def),
+        PathResolution::SelfType(impl_def) => Definition::SelfType(impl_def),
+    };
+    Some(NameRefClass::Definition(res))
+}
diff --git a/crates/ra_parser/src/lib.rs b/crates/ra_parser/src/lib.rs
index 652492c1ed..81055746b5 100644
--- a/crates/ra_parser/src/lib.rs
+++ b/crates/ra_parser/src/lib.rs
@@ -83,7 +83,7 @@ pub fn parse(token_source: &mut dyn TokenSource, tree_sink: &mut dyn TreeSink) {
     parse_from_tokens(token_source, tree_sink, grammar::root);
 }
 
-#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
+#[derive(Clone, Copy)]
 pub enum FragmentKind {
     Path,
     Expr,
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs
index 0da24560ea..3f11b747f0 100644
--- a/crates/ra_syntax/src/ast/make.rs
+++ b/crates/ra_syntax/src/ast/make.rs
@@ -219,7 +219,7 @@ fn unroot(n: SyntaxNode) -> SyntaxNode {
 }
 
 pub mod tokens {
-    use crate::{ast, AstNode, Parse, SourceFile, SyntaxKind::*, SyntaxToken, T};
+    use crate::{AstNode, Parse, SourceFile, SyntaxKind::*, SyntaxToken, T};
     use once_cell::sync::Lazy;
 
     pub(super) static SOURCE_FILE: Lazy<Parse<SourceFile>> =
@@ -251,12 +251,6 @@ pub mod tokens {
         sf.syntax().first_child_or_token().unwrap().into_token().unwrap()
     }
 
-    pub fn literal(text: &str) -> SyntaxToken {
-        assert_eq!(text.trim(), text);
-        let lit: ast::Literal = super::ast_from_text(&format!("fn f() {{ let _ = {}; }}", text));
-        lit.syntax().first_child_or_token().unwrap().into_token().unwrap()
-    }
-
     pub fn single_newline() -> SyntaxToken {
         SOURCE_FILE
             .tree()


Test patch:
diff --git a/crates/ra_hir_ty/src/tests/macros.rs b/crates/ra_hir_ty/src/tests/macros.rs
index 55386c0303..53cd81d464 100644
--- a/crates/ra_hir_ty/src/tests/macros.rs
+++ b/crates/ra_hir_ty/src/tests/macros.rs
@@ -419,25 +419,6 @@ fn main() {
     );
 }
 
-#[test]
-fn infer_builtin_macros_concat() {
-    assert_snapshot!(
-        infer(r#"
-#[rustc_builtin_macro]
-macro_rules! concat {() => {}}
-
-fn main() {
-    let x = concat!("hello", concat!("world", "!"));
-}
-"#),
-        @r###"
-    ![0; 13) '"helloworld!"': &str
-    [66; 122) '{     ...")); }': ()
-    [76; 77) 'x': &str
-    "###
-    );
-}
-
 #[test]
 fn infer_derive_clone_simple() {
     let (db, pos) = TestDB::with_position(