aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_expand/src/builtin_macro.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-06-11 11:08:24 +0100
committerAleksey Kladov <[email protected]>2020-06-11 11:13:14 +0100
commitfac7b0e252ab305f5c8d69b04c46c587ee021aa9 (patch)
treec8a90f4da1a3ab9f949466dd651d1983231674e8 /crates/ra_hir_expand/src/builtin_macro.rs
parentd8a5d39c2d05fb59b6c243935111714e18334599 (diff)
Don't guess macro expansion crate
Diffstat (limited to 'crates/ra_hir_expand/src/builtin_macro.rs')
-rw-r--r--crates/ra_hir_expand/src/builtin_macro.rs17
1 files changed, 9 insertions, 8 deletions
diff --git a/crates/ra_hir_expand/src/builtin_macro.rs b/crates/ra_hir_expand/src/builtin_macro.rs
index 93da3f149..b50eb347c 100644
--- a/crates/ra_hir_expand/src/builtin_macro.rs
+++ b/crates/ra_hir_expand/src/builtin_macro.rs
@@ -1,15 +1,14 @@
1//! Builtin macro 1//! Builtin macro
2use crate::db::AstDatabase;
3use crate::{ 2use crate::{
4 ast::{self, AstToken, HasStringValue}, 3 db::AstDatabase, name, quote, AstId, CrateId, EagerMacroId, LazyMacroId, MacroCallId,
5 name, AstId, CrateId, MacroDefId, MacroDefKind, TextSize, 4 MacroDefId, MacroDefKind, TextSize,
6}; 5};
7 6
8use crate::{guess_crate, quote, EagerMacroId, LazyMacroId, MacroCallId};
9use either::Either; 7use either::Either;
10use mbe::parse_to_token_tree; 8use mbe::parse_to_token_tree;
11use ra_db::FileId; 9use ra_db::FileId;
12use ra_parser::FragmentKind; 10use ra_parser::FragmentKind;
11use ra_syntax::ast::{self, AstToken, HasStringValue};
13 12
14macro_rules! register_builtin { 13macro_rules! register_builtin {
15 ( LAZY: $(($name:ident, $kind: ident) => $expand:ident),* , EAGER: $(($e_name:ident, $e_kind: ident) => $e_expand:ident),* ) => { 14 ( LAZY: $(($name:ident, $kind: ident) => $expand:ident),* , EAGER: $(($e_name:ident, $e_kind: ident) => $e_expand:ident),* ) => {
@@ -333,9 +332,7 @@ fn include_expand(
333} 332}
334 333
335fn get_env_inner(db: &dyn AstDatabase, arg_id: EagerMacroId, key: &str) -> Option<String> { 334fn get_env_inner(db: &dyn AstDatabase, arg_id: EagerMacroId, key: &str) -> Option<String> {
336 let call_id: MacroCallId = arg_id.into(); 335 let krate = db.lookup_intern_eager_expansion(arg_id).krate;
337 let original_file = call_id.as_file().original_file(db);
338 let krate = guess_crate(db, original_file)?;
339 db.crate_graph()[krate].env.get(key) 336 db.crate_graph()[krate].env.get(key)
340} 337}
341 338
@@ -394,6 +391,7 @@ mod tests {
394 391
395 let expander = find_by_name(&macro_calls[0].name().unwrap().as_name()).unwrap(); 392 let expander = find_by_name(&macro_calls[0].name().unwrap().as_name()).unwrap();
396 393
394 let krate = CrateId(0);
397 let file_id = match expander { 395 let file_id = match expander {
398 Either::Left(expander) => { 396 Either::Left(expander) => {
399 // the first one should be a macro_rules 397 // the first one should be a macro_rules
@@ -406,6 +404,7 @@ mod tests {
406 404
407 let loc = MacroCallLoc { 405 let loc = MacroCallLoc {
408 def, 406 def,
407 krate,
409 kind: MacroCallKind::FnLike(AstId::new( 408 kind: MacroCallKind::FnLike(AstId::new(
410 file_id.into(), 409 file_id.into(),
411 ast_id_map.ast_id(&macro_calls[1]), 410 ast_id_map.ast_id(&macro_calls[1]),
@@ -418,7 +417,7 @@ mod tests {
418 Either::Right(expander) => { 417 Either::Right(expander) => {
419 // the first one should be a macro_rules 418 // the first one should be a macro_rules
420 let def = MacroDefId { 419 let def = MacroDefId {
421 krate: Some(CrateId(0)), 420 krate: Some(krate),
422 ast_id: Some(AstId::new(file_id.into(), ast_id_map.ast_id(&macro_calls[0]))), 421 ast_id: Some(AstId::new(file_id.into(), ast_id_map.ast_id(&macro_calls[0]))),
423 kind: MacroDefKind::BuiltInEager(expander), 422 kind: MacroDefKind::BuiltInEager(expander),
424 local_inner: false, 423 local_inner: false,
@@ -432,6 +431,7 @@ mod tests {
432 def, 431 def,
433 fragment: FragmentKind::Expr, 432 fragment: FragmentKind::Expr,
434 subtree: Arc::new(parsed_args.clone()), 433 subtree: Arc::new(parsed_args.clone()),
434 krate,
435 file_id: file_id.into(), 435 file_id: file_id.into(),
436 } 436 }
437 }); 437 });
@@ -441,6 +441,7 @@ mod tests {
441 def, 441 def,
442 fragment, 442 fragment,
443 subtree: Arc::new(subtree), 443 subtree: Arc::new(subtree),
444 krate,
444 file_id: file_id.into(), 445 file_id: file_id.into(),
445 }; 446 };
446 447