diff options
Diffstat (limited to 'crates/hir_def/src/nameres/collector.rs')
-rw-r--r-- | crates/hir_def/src/nameres/collector.rs | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index 05ceb1efb..19db6cc59 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs | |||
@@ -13,14 +13,14 @@ use hir_expand::{ | |||
13 | builtin_macro::find_builtin_macro, | 13 | builtin_macro::find_builtin_macro, |
14 | name::{AsName, Name}, | 14 | name::{AsName, Name}, |
15 | proc_macro::ProcMacroExpander, | 15 | proc_macro::ProcMacroExpander, |
16 | AttrId, HirFileId, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind, | 16 | FragmentKind, HirFileId, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind, |
17 | }; | 17 | }; |
18 | use hir_expand::{InFile, MacroCallLoc}; | 18 | use hir_expand::{InFile, MacroCallLoc}; |
19 | use rustc_hash::{FxHashMap, FxHashSet}; | 19 | use rustc_hash::{FxHashMap, FxHashSet}; |
20 | use syntax::ast; | 20 | use syntax::ast; |
21 | 21 | ||
22 | use crate::{ | 22 | use crate::{ |
23 | attr::Attrs, | 23 | attr::{AttrId, Attrs}, |
24 | db::DefDatabase, | 24 | db::DefDatabase, |
25 | derive_macro_as_call_id, | 25 | derive_macro_as_call_id, |
26 | intern::Interned, | 26 | intern::Interned, |
@@ -215,7 +215,7 @@ struct MacroDirective { | |||
215 | 215 | ||
216 | #[derive(Clone, Debug, Eq, PartialEq)] | 216 | #[derive(Clone, Debug, Eq, PartialEq)] |
217 | enum MacroDirectiveKind { | 217 | enum MacroDirectiveKind { |
218 | FnLike { ast_id: AstIdWithPath<ast::MacroCall> }, | 218 | FnLike { ast_id: AstIdWithPath<ast::MacroCall>, fragment: FragmentKind }, |
219 | Derive { ast_id: AstIdWithPath<ast::Item>, derive_attr: AttrId }, | 219 | Derive { ast_id: AstIdWithPath<ast::Item>, derive_attr: AttrId }, |
220 | } | 220 | } |
221 | 221 | ||
@@ -481,6 +481,11 @@ impl DefCollector<'_> { | |||
481 | let res = self.def_map.resolve_name_in_extern_prelude(self.db, &extern_crate.name); | 481 | let res = self.def_map.resolve_name_in_extern_prelude(self.db, &extern_crate.name); |
482 | 482 | ||
483 | if let Some(ModuleDefId::ModuleId(m)) = res.take_types() { | 483 | if let Some(ModuleDefId::ModuleId(m)) = res.take_types() { |
484 | if m == self.def_map.module_id(current_module_id) { | ||
485 | cov_mark::hit!(ignore_macro_use_extern_crate_self); | ||
486 | return; | ||
487 | } | ||
488 | |||
484 | cov_mark::hit!(macro_rules_from_other_crates_are_visible_with_macro_use); | 489 | cov_mark::hit!(macro_rules_from_other_crates_are_visible_with_macro_use); |
485 | self.import_all_macros_exported(current_module_id, m.krate); | 490 | self.import_all_macros_exported(current_module_id, m.krate); |
486 | } | 491 | } |
@@ -807,9 +812,10 @@ impl DefCollector<'_> { | |||
807 | let mut res = ReachedFixedPoint::Yes; | 812 | let mut res = ReachedFixedPoint::Yes; |
808 | macros.retain(|directive| { | 813 | macros.retain(|directive| { |
809 | match &directive.kind { | 814 | match &directive.kind { |
810 | MacroDirectiveKind::FnLike { ast_id } => { | 815 | MacroDirectiveKind::FnLike { ast_id, fragment } => { |
811 | match macro_call_as_call_id( | 816 | match macro_call_as_call_id( |
812 | ast_id, | 817 | ast_id, |
818 | *fragment, | ||
813 | self.db, | 819 | self.db, |
814 | self.def_map.krate, | 820 | self.def_map.krate, |
815 | |path| { | 821 | |path| { |
@@ -926,8 +932,9 @@ impl DefCollector<'_> { | |||
926 | 932 | ||
927 | for directive in &self.unexpanded_macros { | 933 | for directive in &self.unexpanded_macros { |
928 | match &directive.kind { | 934 | match &directive.kind { |
929 | MacroDirectiveKind::FnLike { ast_id, .. } => match macro_call_as_call_id( | 935 | MacroDirectiveKind::FnLike { ast_id, fragment } => match macro_call_as_call_id( |
930 | ast_id, | 936 | ast_id, |
937 | *fragment, | ||
931 | self.db, | 938 | self.db, |
932 | self.def_map.krate, | 939 | self.def_map.krate, |
933 | |path| { | 940 | |path| { |
@@ -1496,6 +1503,7 @@ impl ModCollector<'_, '_> { | |||
1496 | let mut error = None; | 1503 | let mut error = None; |
1497 | match macro_call_as_call_id( | 1504 | match macro_call_as_call_id( |
1498 | &ast_id, | 1505 | &ast_id, |
1506 | mac.fragment, | ||
1499 | self.def_collector.db, | 1507 | self.def_collector.db, |
1500 | self.def_collector.def_map.krate, | 1508 | self.def_collector.def_map.krate, |
1501 | |path| { | 1509 | |path| { |
@@ -1524,9 +1532,14 @@ impl ModCollector<'_, '_> { | |||
1524 | } | 1532 | } |
1525 | Ok(Err(_)) => { | 1533 | Ok(Err(_)) => { |
1526 | // Built-in macro failed eager expansion. | 1534 | // Built-in macro failed eager expansion. |
1535 | |||
1536 | // FIXME: don't parse the file here | ||
1537 | let fragment = hir_expand::to_fragment_kind( | ||
1538 | &ast_id.ast_id.to_node(self.def_collector.db.upcast()), | ||
1539 | ); | ||
1527 | self.def_collector.def_map.diagnostics.push(DefDiagnostic::macro_error( | 1540 | self.def_collector.def_map.diagnostics.push(DefDiagnostic::macro_error( |
1528 | self.module_id, | 1541 | self.module_id, |
1529 | MacroCallKind::FnLike { ast_id: ast_id.ast_id }, | 1542 | MacroCallKind::FnLike { ast_id: ast_id.ast_id, fragment }, |
1530 | error.unwrap().to_string(), | 1543 | error.unwrap().to_string(), |
1531 | )); | 1544 | )); |
1532 | return; | 1545 | return; |
@@ -1543,7 +1556,7 @@ impl ModCollector<'_, '_> { | |||
1543 | self.def_collector.unexpanded_macros.push(MacroDirective { | 1556 | self.def_collector.unexpanded_macros.push(MacroDirective { |
1544 | module_id: self.module_id, | 1557 | module_id: self.module_id, |
1545 | depth: self.macro_depth + 1, | 1558 | depth: self.macro_depth + 1, |
1546 | kind: MacroDirectiveKind::FnLike { ast_id }, | 1559 | kind: MacroDirectiveKind::FnLike { ast_id, fragment: mac.fragment }, |
1547 | }); | 1560 | }); |
1548 | } | 1561 | } |
1549 | 1562 | ||