aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-03-03 17:30:08 +0000
committerGitHub <[email protected]>2020-03-03 17:30:08 +0000
commit7a322f9afff05b88507a6956a2d84a3abef0a0d6 (patch)
treef811a7f405edca2b7e0c32666604117ef6486229 /crates/ra_hir_def
parent13b25d73b56ede36d1680efc19f5c11b0669b96c (diff)
parent4d5e80c6c86aa6bfee50e9f8b80b365c3120ed80 (diff)
Merge #3392
3392: Implement concat eager macro r=matklad a=edwin0cheng This PR implements the following things: 1. Add basic eager macro infrastructure by introducing `EagerCallId` such that the new `MacroCallId` is defined as : ``` #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum MacroCallId { LazyMacro(LazyMacroId), EagerMacro(EagerMacroId), } ``` 2. Add `concat!` builtin macro. Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r--crates/ra_hir_def/src/lib.rs23
1 files changed, 18 insertions, 5 deletions
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index c9b14d0c8..a3d617e1f 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -47,8 +47,8 @@ mod marks;
47use std::hash::Hash; 47use std::hash::Hash;
48 48
49use hir_expand::{ 49use hir_expand::{
50 ast_id_map::FileAstId, db::AstDatabase, hygiene::Hygiene, AstId, HirFileId, InFile, 50 ast_id_map::FileAstId, db::AstDatabase, eager::expand_eager_macro, hygiene::Hygiene, AstId,
51 MacroCallId, MacroCallKind, MacroDefId, 51 HirFileId, InFile, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind,
52}; 52};
53use ra_arena::{impl_arena_id, RawId}; 53use ra_arena::{impl_arena_id, RawId};
54use ra_db::{impl_intern_key, salsa, CrateId}; 54use ra_db::{impl_intern_key, salsa, CrateId};
@@ -459,8 +459,21 @@ impl AsMacroCall for AstIdWithPath<ast::MacroCall> {
459 db: &impl AstDatabase, 459 db: &impl AstDatabase,
460 resolver: impl Fn(path::ModPath) -> Option<MacroDefId>, 460 resolver: impl Fn(path::ModPath) -> Option<MacroDefId>,
461 ) -> Option<MacroCallId> { 461 ) -> Option<MacroCallId> {
462 let def = resolver(self.path.clone())?; 462 let def: MacroDefId = resolver(self.path.clone())?;
463 Some(def.as_call_id(db, MacroCallKind::FnLike(self.ast_id))) 463
464 if let MacroDefKind::BuiltInEager(_) = def.kind {
465 let macro_call = InFile::new(self.ast_id.file_id, self.ast_id.to_node(db));
466 let hygiene = Hygiene::new(db, self.ast_id.file_id);
467
468 Some(
469 expand_eager_macro(db, macro_call, def, &|path: ast::Path| {
470 resolver(path::ModPath::from_src(path, &hygiene)?)
471 })?
472 .into(),
473 )
474 } else {
475 Some(def.as_lazy_macro(db, MacroCallKind::FnLike(self.ast_id)).into())
476 }
464 } 477 }
465} 478}
466 479
@@ -471,6 +484,6 @@ impl AsMacroCall for AstIdWithPath<ast::ModuleItem> {
471 resolver: impl Fn(path::ModPath) -> Option<MacroDefId>, 484 resolver: impl Fn(path::ModPath) -> Option<MacroDefId>,
472 ) -> Option<MacroCallId> { 485 ) -> Option<MacroCallId> {
473 let def = resolver(self.path.clone())?; 486 let def = resolver(self.path.clone())?;
474 Some(def.as_call_id(db, MacroCallKind::Attr(self.ast_id))) 487 Some(def.as_lazy_macro(db, MacroCallKind::Attr(self.ast_id)).into())
475 } 488 }
476} 489}