diff options
Diffstat (limited to 'crates/ra_hir_expand/src/builtin_macro.rs')
-rw-r--r-- | crates/ra_hir_expand/src/builtin_macro.rs | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/crates/ra_hir_expand/src/builtin_macro.rs b/crates/ra_hir_expand/src/builtin_macro.rs index 7579546d2..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 |
2 | use crate::db::AstDatabase; | ||
3 | use crate::{ | 2 | use 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 | ||
8 | use crate::{quote, EagerMacroId, LazyMacroId, MacroCallId}; | ||
9 | use either::Either; | 7 | use either::Either; |
10 | use mbe::parse_to_token_tree; | 8 | use mbe::parse_to_token_tree; |
11 | use ra_db::FileId; | 9 | use ra_db::FileId; |
12 | use ra_parser::FragmentKind; | 10 | use ra_parser::FragmentKind; |
11 | use ra_syntax::ast::{self, AstToken, HasStringValue}; | ||
13 | 12 | ||
14 | macro_rules! register_builtin { | 13 | macro_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,10 +332,7 @@ fn include_expand( | |||
333 | } | 332 | } |
334 | 333 | ||
335 | fn get_env_inner(db: &dyn AstDatabase, arg_id: EagerMacroId, key: &str) -> Option<String> { | 334 | fn 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 | |||
339 | let krate = *db.relevant_crates(original_file).get(0)?; | ||
340 | db.crate_graph()[krate].env.get(key) | 336 | db.crate_graph()[krate].env.get(key) |
341 | } | 337 | } |
342 | 338 | ||
@@ -395,6 +391,7 @@ mod tests { | |||
395 | 391 | ||
396 | let expander = find_by_name(¯o_calls[0].name().unwrap().as_name()).unwrap(); | 392 | let expander = find_by_name(¯o_calls[0].name().unwrap().as_name()).unwrap(); |
397 | 393 | ||
394 | let krate = CrateId(0); | ||
398 | let file_id = match expander { | 395 | let file_id = match expander { |
399 | Either::Left(expander) => { | 396 | Either::Left(expander) => { |
400 | // the first one should be a macro_rules | 397 | // the first one should be a macro_rules |
@@ -407,6 +404,7 @@ mod tests { | |||
407 | 404 | ||
408 | let loc = MacroCallLoc { | 405 | let loc = MacroCallLoc { |
409 | def, | 406 | def, |
407 | krate, | ||
410 | kind: MacroCallKind::FnLike(AstId::new( | 408 | kind: MacroCallKind::FnLike(AstId::new( |
411 | file_id.into(), | 409 | file_id.into(), |
412 | ast_id_map.ast_id(¯o_calls[1]), | 410 | ast_id_map.ast_id(¯o_calls[1]), |
@@ -419,7 +417,7 @@ mod tests { | |||
419 | Either::Right(expander) => { | 417 | Either::Right(expander) => { |
420 | // the first one should be a macro_rules | 418 | // the first one should be a macro_rules |
421 | let def = MacroDefId { | 419 | let def = MacroDefId { |
422 | krate: Some(CrateId(0)), | 420 | krate: Some(krate), |
423 | ast_id: Some(AstId::new(file_id.into(), ast_id_map.ast_id(¯o_calls[0]))), | 421 | ast_id: Some(AstId::new(file_id.into(), ast_id_map.ast_id(¯o_calls[0]))), |
424 | kind: MacroDefKind::BuiltInEager(expander), | 422 | kind: MacroDefKind::BuiltInEager(expander), |
425 | local_inner: false, | 423 | local_inner: false, |
@@ -433,6 +431,7 @@ mod tests { | |||
433 | def, | 431 | def, |
434 | fragment: FragmentKind::Expr, | 432 | fragment: FragmentKind::Expr, |
435 | subtree: Arc::new(parsed_args.clone()), | 433 | subtree: Arc::new(parsed_args.clone()), |
434 | krate, | ||
436 | file_id: file_id.into(), | 435 | file_id: file_id.into(), |
437 | } | 436 | } |
438 | }); | 437 | }); |
@@ -442,6 +441,7 @@ mod tests { | |||
442 | def, | 441 | def, |
443 | fragment, | 442 | fragment, |
444 | subtree: Arc::new(subtree), | 443 | subtree: Arc::new(subtree), |
444 | krate, | ||
445 | file_id: file_id.into(), | 445 | file_id: file_id.into(), |
446 | }; | 446 | }; |
447 | 447 | ||